-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: refactor ssh related functions in test helper classes #3123
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,23 +66,6 @@ def _should_test_gcp(): | |
return True | ||
|
||
|
||
def _should_test_ssh(): | ||
do_test = env2bool("DVC_TEST_SSH", undefined=None) | ||
if do_test is not None: | ||
return do_test | ||
|
||
# FIXME: enable on windows | ||
if os.name == "nt": | ||
return False | ||
|
||
try: | ||
check_output(["ssh", "-o", "BatchMode=yes", "127.0.0.1", "ls"]) | ||
except (CalledProcessError, IOError): | ||
return False | ||
|
||
return True | ||
|
||
|
||
def _should_test_hdfs(): | ||
if platform.system() != "Linux": | ||
return False | ||
|
@@ -114,31 +97,6 @@ def get_local_url(): | |
return get_local_storagepath() | ||
|
||
|
||
def get_ssh_url(): | ||
return "ssh://{}@127.0.0.1:22{}".format( | ||
getpass.getuser(), get_local_storagepath() | ||
) | ||
|
||
|
||
def get_ssh_url_mocked(user, port): | ||
path = get_local_storagepath() | ||
if os.name == "nt": | ||
# NOTE: On Windows get_local_storagepath() will return an ntpath | ||
# that looks something like `C:\some\path`, which is not compatible | ||
# with SFTP paths [1], so we need to convert it to a proper posixpath. | ||
# To do that, we should construct a posixpath that would be relative | ||
# to the server's root. In our case our ssh server is running with | ||
# `c:/` as a root, and our URL format requires absolute paths, so the | ||
# resulting path would look like `/some/path`. | ||
# | ||
# [1]https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-6 | ||
drive, path = os.path.splitdrive(path) | ||
assert drive.lower() == "c:" | ||
path = path.replace("\\", "/") | ||
url = "ssh://{}@127.0.0.1:{}{}".format(user, port, path) | ||
return url | ||
|
||
|
||
def get_hdfs_url(): | ||
return "hdfs://{}@127.0.0.1{}".format( | ||
getpass.getuser(), get_local_storagepath() | ||
|
@@ -269,8 +227,53 @@ def get_url(): | |
|
||
|
||
class SSH: | ||
should_test = _should_test_ssh | ||
get_url = get_ssh_url | ||
@staticmethod | ||
def should_test(): | ||
do_test = env2bool("DVC_TEST_SSH", undefined=None) | ||
if do_test is not None: | ||
return do_test | ||
|
||
# FIXME: enable on windows | ||
if os.name == "nt": | ||
return False | ||
|
||
try: | ||
check_output(["ssh", "-o", "BatchMode=yes", "127.0.0.1", "ls"]) | ||
except (CalledProcessError, IOError): | ||
return False | ||
|
||
return True | ||
|
||
@staticmethod | ||
def get_url(): | ||
return "ssh://{}@127.0.0.1:22{}".format( | ||
getpass.getuser(), get_local_storagepath() | ||
) | ||
|
||
|
||
class SSHMocked: | ||
should_test = lambda: True # noqa: E731 | ||
|
||
@staticmethod | ||
def get_url(user, port): | ||
path = get_local_storagepath() | ||
if os.name == "nt": | ||
# NOTE: On Windows get_local_storagepath() will return an | ||
# ntpath that looks something like `C:\some\path`, which is not | ||
# compatible with SFTP paths [1], so we need to convert it to | ||
# a proper posixpath. | ||
# To do that, we should construct a posixpath that would be | ||
# relative to the server's root. | ||
# In our case our ssh server is running with `c:/` as a root, | ||
# and our URL format requires absolute paths, so the | ||
# resulting path would look like `/some/path`. | ||
# | ||
Comment on lines
+261
to
+270
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I splitted the comment here as it was getting more than 80chars. |
||
# [1]https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-6 | ||
drive, path = os.path.splitdrive(path) | ||
assert drive.lower() == "c:" | ||
path = path.replace("\\", "/") | ||
url = "ssh://{}@127.0.0.1:{}{}".format(user, port, path) | ||
return url | ||
|
||
|
||
class HDFS: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find any usage of this, probably, because we are moving away from real server to mocked ssh server? Anyway, I didn't want to change this atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skshetry I think it is still used in tests/func/test_api.py . We are close to getting rid of it, that is true π Let's not tackle it in this PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it is still used in
dvc/tests/func/test_api.py
Line 26 in 028d30e
I only grepped for the
get_ssh_url
/SSH.get_url
and didn't find any. π€¦ββοΈ