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 param_comparison_uses_config(self): conf = Config(overrides={'user': '******'}) c = Connection( user='******', host='myhost', port=123, config=conf ) template = "<Connection host=myhost port=123>" assert repr(c) == template
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 kwarg_wins_over_config(self): # TODO: should this be more of a merge-down? c = Config(overrides={"connect_kwargs": {"origin": "config"}}) cxn = Connection( "host", connect_kwargs={"origin": "kwarg"}, config=c ) assert cxn.connect_kwargs == {"origin": "kwarg"}
def param_comparison_uses_config(self): conf = Config(overrides={"user": "******"}) c = Connection( user="******", host="myhost", port=123, config=conf ) template = "<Connection host=myhost port=123>" assert repr(c) == template
def accepts_configuration_value(self): config = Config(overrides={ 'timeouts': { 'connect': 10 }, 'load_ssh_configs': False, }) assert Connection('host', config=config).connect_timeout == 10
def accepts_configuration_value(self): config = Config( overrides={ "timeouts": {"connect": 10}, "load_ssh_configs": False, } ) assert Connection("host", config=config).connect_timeout == 10
def accepts_configuration_value(self): config = Config( overrides={ "forward_agent": True, "load_ssh_configs": False, } ) assert Connection("host", config=config).forward_agent is True
def accepts_configuration_value(self): gw = Connection("jumpbox") config = Config( overrides={"gateway": gw, "load_ssh_configs": False} ) # TODO: the fact that they will be eq, but _not_ necessarily be # the same object, could be problematic in some cases... cxn = Connection("host", config=config) assert cxn.gateway == gw
def kwarg_wins_over_config(self): # TODO: should this be more of a merge-down? c = Config(overrides={'connect_kwargs': {'origin': 'config'}}) cxn = Connection( 'host', connect_kwargs={'origin': 'kwarg'}, config=c, ) assert cxn.connect_kwargs == {'origin': 'kwarg'}
def accepts_configuration_value(self): gw = Connection('jumpbox') config = Config(overrides={ 'gateway': gw, 'load_ssh_configs': False, }) # TODO: the fact that they will be eq, but _not_ necessarily be # the same object, could be problematic in some cases... cxn = Connection('host', config=config) assert cxn.gateway == gw
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 accepts_config_user_option(self): config = Config(overrides={"user": "******"}) assert Connection("host", config=config).user == "nobody"
def kwarg_wins_over_config(self): config = Config(overrides={"forward_agent": True}) cxn = Connection("host", forward_agent=False, config=config) assert cxn.forward_agent is False
def shorthand_wins_over_config(self): config = Config(overrides={"port": 2222}) cxn = Connection("host:123", config=config) assert cxn.port == 123
def kwarg_wins_over_config(self): config = Config(overrides={"port": 2222}) cxn = Connection("host", port=123, config=config) assert cxn.port == 123
def accepts_configuration_value(self): config = Config(overrides={ 'forward_agent': True, 'load_ssh_configs': False, }) assert Connection('host', config=config).forward_agent is True
def may_be_configured(self): c = Config(overrides={"connect_kwargs": {"origin": "config"}}) cxn = Connection("host", config=c) assert cxn.connect_kwargs == {"origin": "config"}
def kwarg_wins_over_config(self): config = Config(overrides={"timeouts": {"connect": 20}}) cxn = Connection("host", connect_timeout=100, config=config) assert cxn.connect_timeout == 100
def may_be_configured(self): c = Config(overrides={'connect_kwargs': {'origin': 'config'}}) cxn = Connection('host', config=c) assert cxn.connect_kwargs == {'origin': 'config'}
def can_be_specified(self): c = Config(overrides={'user': '******', 'custom': 'option'}) config = Connection('host', config=c).config assert c is config assert config['user'] == 'me' assert config['custom'] == 'option'
def kwarg_wins_over_config(self): config = Config(overrides={'timeouts': {'connect': 20}}) cxn = Connection('host', connect_timeout=100, config=config) assert cxn.connect_timeout == 100
def can_be_specified(self): c = Config(overrides={"user": "******", "custom": "option"}) config = Connection("host", config=c).config assert c is config assert config["user"] == "me" assert config["custom"] == "option"
def kwarg_wins_over_config(self): config = Config(overrides={"user": "******"}) cxn = Connection("host", user="******", config=config) assert cxn.user == "somebody"
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"}
def kwarg_wins_over_config(self): config = Config(overrides={'port': 2222}) cxn = Connection('host', port=123, config=config) assert cxn.port == 123
def accepts_configuration_port(self): config = Config(overrides={"port": 2222}) assert Connection("host", config=config).port == 2222
def shorthand_wins_over_config(self): config = Config(overrides={'port': 2222}) cxn = Connection('host:123', config=config) assert cxn.port == 123
def shorthand_wins_over_config(self): config = Config(overrides={"user": "******"}) cxn = Connection("somebody@host", config=config) assert cxn.user == "somebody"
def accepts_configuration_port(self): config = Config(overrides={'port': 2222}) assert Connection('host', config=config).port == 2222