def merges_sources(self, client, ssh, invoke, kwarg, expected): config_kwargs = {} if ssh: # SSH config with 2x IdentityFile directives. config_kwargs["runtime_ssh_path"] = join( support, "ssh_config", "runtime_identity.conf") if invoke: # Use overrides config level to mimic --identity use NOTE: (the # fact that --identity is an override, and thus overrides eg # invoke config file values is part of invoke's config test # suite) config_kwargs["overrides"] = { "connect_kwargs": { "key_filename": ["configured.key"] } } conf = Config_(**config_kwargs) connect_kwargs = {} if kwarg: # Stitch in connect_kwargs value connect_kwargs = {"key_filename": ["kwarg.key"]} # Tie in all sources that were configured & open() Connection("runtime", config=conf, connect_kwargs=connect_kwargs).open() # Ensure we got the expected list of keys kwargs = client.connect.call_args[1] if expected: assert kwargs["key_filename"] == expected else: # No key filenames -> it's not even passed in as connect_kwargs # is gonna be a blank dict assert "key_filename" not in kwargs
def _runtime_config(self, overrides=None, basename="runtime"): confname = "{}.conf".format(basename) runtime_path = join(support, "ssh_config", confname) if overrides is None: overrides = {} return Config_(runtime_ssh_path=runtime_path, overrides=overrides)
def hostname_directive_overrides_host_attr(self): # TODO: not 100% convinced this is the absolute most # obvious API for 'translation' of given hostname to # ssh-configured hostname, but it feels okay for now. path = join(support, "ssh_config", "overridden_hostname.conf") config = Config_(runtime_ssh_path=path) cxn = Connection("aliasname", config=config) assert cxn.host == "realname" assert cxn.original_host == "aliasname" assert cxn.port == 2222
def effectively_blank_when_no_loaded_config(self): c = Config_(ssh_config=SSHConfig()) cxn = Connection("host", config=c) # NOTE: paramiko always injects this even if you look up a host # that has no rules, even wildcard ones. assert cxn.ssh_config == {"hostname": "host"}