Skip to content
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

Issue #336, ssh_config_file and ssh_known_hosts_file True behaviour with system transport #337

Merged
merged 6 commits into from
Jun 16, 2024

Conversation

bennnnnnnn
Copy link
Contributor

Description

See issue #336, when passing True to the ssh_config_file and using the system transport, you now effectively get the same behaviour as the regular ssh client (no -F args are passed). That means that both the user and the system ssh config are respected. I also implemented the same change for the known_hosts_file.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Added necessary tests in test_base_base_driver.py, did a real-world test against a device

Checklist:

  • My code follows the style guidelines of this project (no GitHub actions complaints! run make lint before
    committing!)
  • I have commented my code, pydocstyle and darglint are happy, docstrings are in google docstring format, and all
    docstrings include a summary, args, returns and raises fields (even if N/A)
  • I have added tests that prove my fix is effective or that my feature works, if adding "functional" tests please
    note if there are any considerations for the vrnetlab setup
  • New and existing unit tests pass locally with my changes

Copy link
Owner

@carlmontanari carlmontanari left a comment

Choose a reason for hiding this comment

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

very nice! I think there is one nit pick from one of the linters for a line length thing and I left a few comments. I can help tweak a few things here and there if you are busy but we are defo close to getting this merged! thanks a ton for the work on this!

@@ -613,16 +618,19 @@ def _resolve_ssh_config(self, ssh_config_file: str) -> str:
N/A

"""
self.logger.debug("attempting to resolve 'ssh_config_file' file")
self.logger.debug(f"attempting to resolve 'ssh_config_file' file {ssh_config_file}")
Copy link
Owner

Choose a reason for hiding this comment

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

nice, that seems like an obviously better thing to log 😁

resolved_ssh_config_file = str(Path("/etc/ssh/ssh_config"))
if ssh_config_file == "" and transport == "system":
resolved_ssh_config_file = BaseTransport.SSH_SYSTEM_CONFIG_MAGIC_STRING
else:
Copy link
Owner

Choose a reason for hiding this comment

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

haven't looked too closely yet, but can we maybe "flatten" this out a bit if possible? guard clause or something -- like if this thing return, then no extra indented else block (hopefully that makes sense)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, flat is indeed better, should be better now!

resolved_ssh_known_hosts = str(Path("/etc/ssh/ssh_known_hosts"))
if ssh_known_hosts == "" and transport == "system":
resolved_ssh_known_hosts = BaseTransport.SSH_SYSTEM_CONFIG_MAGIC_STRING
else:
Copy link
Owner

Choose a reason for hiding this comment

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

same "flatten-y" comment here (if possible/easy, if not we can ignore -- and sorry just looking quickly so maybe this is a bad comment!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it the same way as above :-)

@@ -23,6 +23,8 @@ class BasePluginTransportArgs:


class BaseTransport(ABC):
SSH_SYSTEM_CONFIG_MAGIC_STRING: str = "__SCRAPLI_RULES__"
Copy link
Owner

Choose a reason for hiding this comment

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

lol, while I love and appreciate this placeholder string... lets do two things:

  1. I think this is really only ever going to be relevant for system transport right? if "yes", maybe we should put the it in the system transport package?
  2. hah scrapli does rule, but maybe we call it something more descriptive for the variable and the actual string -- like SYSTEM_TRANSPORT_SSH_CONFIG_TRUE: str = "SYSTEM_TRANSPORT_SSH_CONFIG_TRUE" lol so much less fun but probably more understandable :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah probably not the best place to drop a compliment, but hey 😆 I changed it to what you suggested!


if self.plugin_transport_args.ssh_config_file:
self.open_cmd.extend(["-F", self.plugin_transport_args.ssh_config_file])
if (
Copy link
Owner

Choose a reason for hiding this comment

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

two things here:

  1. if possible and we can flatten things a bit, lets do that :P (sorry for nit picks but flat is good :D)

  2. should we have a second magic string for this since users could set known hosts -> True but not ssh config file? (I think? its been a while, maybe im wrong about that too hah)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flattened out, and good point that we should add a separate variable for the known_hosts_file ( I was being lazy 😁 ) added it!

)
def test_setup_ssh_file_args_resolved(fs_, base_driver, test_data):
def test_setup_ssh_file_args_resolved(fs_, test_data, base_driver):
Copy link
Owner

Choose a reason for hiding this comment

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

🔥 nice, thank you for adding test cases!

@carlmontanari
Copy link
Owner

boom, LGTM, thanks a bunch @bennnnnnnn !!

@carlmontanari carlmontanari merged commit c9d4710 into carlmontanari:main Jun 16, 2024
11 of 12 checks passed
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.

2 participants