Skip to content

Conversation

@khamutov
Copy link
Contributor

@khamutov khamutov commented May 4, 2019

  • Have you followed the guidelines in our
    Contributing document?

  • Does your PR affect documented changes or does it add new functionality
    that should be documented? If yes, have you created a PR for
    dvc.org documenting it or at
    least opened an issue for it? If so, please add a link to it. Created PR dvc.org#290


Fixes #1613

Add parsing user ssh config for username and port. However settings from remote url has the priority over ssh config.

Copy link
Contributor

@efiop efiop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @khamutov !

Thanks a lot for the patch! 🚀 Looks great! Please see a few comments down below.


user_config_file = os.path.expanduser("~/.ssh/config")
user_ssh_config = dict()
if self.host:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate why if self.host is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efiop it's fix only for tests :(

dependency test
https://github.com/iterative/dvc/blob/master/tests/func/test_dependency.py#L20
create remotes with empty configs

here the actual place where empty remote config created
https://github.com/iterative/dvc/blob/master/dvc/output/base.py#L74

also we have weird place
https://github.com/iterative/dvc/blob/master/dvc/remote/ssh/__init__.py#L37

self.url = config.get(Config.SECTION_REMOTE_URL, "ssh://")

obviously ssh will not work with such default url and it should be error.
I think it also fix for dependency test, but right now I don't know how make it beautiful. But I will research it as a separate task.

user_config_file = os.path.expanduser("~/.ssh/config")
user_ssh_config = dict()
if self.host:
if os.path.exists(user_config_file):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put all of this config parsing logic into a separate method/function and use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@efiop
Copy link
Contributor

efiop commented May 4, 2019

Also, could you please submit a fix for https://dvc.org/doc/commands-reference/remote-modify for SSH?

@khamutov
Copy link
Contributor Author

khamutov commented May 5, 2019

Also, could you please submit a fix for https://dvc.org/doc/commands-reference/remote-modify for SSH?

Amend to docs, created PR dvc.org#290

Copy link
Contributor

@efiop efiop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks great! 🙂

One more thing, would you be so kind to also add a test to tests/unit/remote/ssh/test_ssh.py to make sure that your patch works as expected? E.g. that user, port, hostname are read from ssh config properly and in correct order.

parsed = urlparse(self.url)
self.host = parsed.hostname

user_ssh_config = self._load_user_ssh_config(self.host)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, if we are looking up Host in the ssh config, shouldn't we use HostName after that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, we should use HostName from ssh config if it exists.

@khamutov
Copy link
Contributor Author

khamutov commented May 5, 2019

One more thing, would you be so kind to also add a test to tests/unit/remote/ssh/test_ssh.py to make sure that your patch works as expected? E.g. that user, port, hostname are read from ssh config properly and in correct order.

add tests and also add using IdentityFile from ssh config

@efiop
Copy link
Contributor

efiop commented May 5, 2019

@khamutov Thanks! :) Just a heads up: your tests are failing.


@staticmethod
def _load_user_ssh_config(hostname):
user_config_file = os.path.expanduser("~/.ssh/config")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iterative/dvc.org#290 (comment) Let's use os.path.join("~", ".ssh", "config") instead, since on windows it won't resolve it properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accepted, will fix it after test passed on Travis

"""

# compat version for mock library version 2
# mock 2.0.0 can't iterate in mock_open
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just adjust mock version requirements in tests/requirement.txt up to the needed version, we just didn't update it for a long time 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I misinterpreted mock documentation "Version 2.0.0 is the last version compatible with Python 2.6." But we have min version 2.7 :)

Copy link
Contributor

@efiop efiop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thank you so much! 🎉

@efiop efiop merged commit 6408b58 into iterative:master May 7, 2019
@efiop
Copy link
Contributor

efiop commented May 10, 2019

Hi @khamutov !

Thanks again for your contribution! We would love to have a chance to meet you :) Would you be willing to have a hangouts call with us some time? Btw, I see you are from Moscow, our OG dvc creator @dmpetrov is going to present at Data Fest this weekend, please feel free to come say hi if you are attending too 🙂

Thanks,
Ruslan

@dmpetrov
Copy link
Member

@khamutov I’d love to meet. Please let me know if you are in DataFest today. I’m giving a talk about open source tools for ml processes (including DVC). Also I’m staying in Moscow till Tuesday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DVC could use the unix SSH client config files

3 participants