Пример #1
0
 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
Пример #2
0
 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
Пример #3
0
 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)
Пример #4
0
 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"}
Пример #5
0
 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
Пример #6
0
 def accepts_configuration_value(self):
     config = Config(overrides={
         'timeouts': {
             'connect': 10
         },
         'load_ssh_configs': False,
     })
     assert Connection('host', config=config).connect_timeout == 10
Пример #7
0
 def accepts_configuration_value(self):
     config = Config(
         overrides={
             "timeouts": {"connect": 10},
             "load_ssh_configs": False,
         }
     )
     assert Connection("host", config=config).connect_timeout == 10
Пример #8
0
 def accepts_configuration_value(self):
     config = Config(
         overrides={
             "forward_agent": True,
             "load_ssh_configs": False,
         }
     )
     assert Connection("host", config=config).forward_agent is True
Пример #9
0
 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
Пример #10
0
 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'}
Пример #11
0
 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
Пример #12
0
 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
Пример #13
0
 def accepts_config_user_option(self):
     config = Config(overrides={"user": "******"})
     assert Connection("host", config=config).user == "nobody"
Пример #14
0
 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
Пример #15
0
 def shorthand_wins_over_config(self):
     config = Config(overrides={"port": 2222})
     cxn = Connection("host:123", config=config)
     assert cxn.port == 123
Пример #16
0
 def kwarg_wins_over_config(self):
     config = Config(overrides={"port": 2222})
     cxn = Connection("host", port=123, config=config)
     assert cxn.port == 123
Пример #17
0
 def accepts_configuration_value(self):
     config = Config(overrides={
         'forward_agent': True,
         'load_ssh_configs': False,
     })
     assert Connection('host', config=config).forward_agent is True
Пример #18
0
 def may_be_configured(self):
     c = Config(overrides={"connect_kwargs": {"origin": "config"}})
     cxn = Connection("host", config=c)
     assert cxn.connect_kwargs == {"origin": "config"}
Пример #19
0
 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
Пример #20
0
 def may_be_configured(self):
     c = Config(overrides={'connect_kwargs': {'origin': 'config'}})
     cxn = Connection('host', config=c)
     assert cxn.connect_kwargs == {'origin': 'config'}
Пример #21
0
 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'
Пример #22
0
 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
Пример #23
0
 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"
Пример #24
0
 def kwarg_wins_over_config(self):
     config = Config(overrides={"user": "******"})
     cxn = Connection("host", user="******", config=config)
     assert cxn.user == "somebody"
Пример #25
0
 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"}
Пример #26
0
 def kwarg_wins_over_config(self):
     config = Config(overrides={'port': 2222})
     cxn = Connection('host', port=123, config=config)
     assert cxn.port == 123
Пример #27
0
 def accepts_configuration_port(self):
     config = Config(overrides={"port": 2222})
     assert Connection("host", config=config).port == 2222
Пример #28
0
 def shorthand_wins_over_config(self):
     config = Config(overrides={'port': 2222})
     cxn = Connection('host:123', config=config)
     assert cxn.port == 123
Пример #29
0
 def shorthand_wins_over_config(self):
     config = Config(overrides={"user": "******"})
     cxn = Connection("somebody@host", config=config)
     assert cxn.user == "somebody"
Пример #30
0
 def accepts_configuration_port(self):
     config = Config(overrides={'port': 2222})
     assert Connection('host', config=config).port == 2222