def _get_host_arguments(machine): """Get parameters to construct a host object. There are currently 2 use cases for creating a host. 1. Through the server_job, in which case the server_job injects the appropriate ssh parameters into our name space and they are available as the variables ssh_user, ssh_pass etc. 2. Directly through factory.create_host, in which case we use the same defaults as used in the server job to create a host. @param machine: machine dict @return: A dictionary containing arguments for host specifically hostname, afe_host, user, password, port, ssh_verbosity_flag and ssh_options. """ hostname, afe_host = server_utils.get_host_info_from_machine(machine) connection_pool = server_utils.get_connection_pool_from_machine(machine) host_info_store = host_info.get_store_from_machine(machine) info = host_info_store.get() g = globals() user = info.attributes.get('ssh_user', g.get('ssh_user', DEFAULT_SSH_USER)) password = info.attributes.get('ssh_pass', g.get('ssh_pass', DEFAULT_SSH_PASS)) port = info.attributes.get('ssh_port', g.get('ssh_port', DEFAULT_SSH_PORT)) ssh_verbosity_flag = info.attributes.get( 'ssh_verbosity_flag', g.get('ssh_verbosity_flag', DEFAULT_SSH_VERBOSITY)) ssh_options = info.attributes.get( 'ssh_options', g.get('ssh_options', DEFAULT_SSH_OPTIONS)) hostname, user, password, port = server_utils.parse_machine( hostname, user, password, port) host_args = { 'hostname': hostname, 'afe_host': afe_host, 'host_info_store': host_info_store, 'user': user, 'password': password, 'port': int(port), 'ssh_verbosity_flag': ssh_verbosity_flag, 'ssh_options': ssh_options, 'connection_pool': connection_pool, } return host_args
def test_machine_is_string(self): machine = 'hostname' self.assertTrue( isinstance(host_info.get_store_from_machine(machine), host_info.InMemoryHostInfoStore))
def test_machine_is_dict(self): machine = {'something': 'else', 'host_info_store': 5} self.assertEqual(host_info.get_store_from_machine(machine), 5)
def test_machine_is_string(self): """We return a trivial store when machine is a string.""" machine = 'hostname' self.assertTrue( isinstance(host_info.get_store_from_machine(machine), host_info.InMemoryHostInfoStore))
def test_machine_is_dict(self): """We extract the store when machine is a dict.""" machine = {'something': 'else', 'host_info_store': 5} self.assertEqual(host_info.get_store_from_machine(machine), 5)