def test_validate_deployment_checks_each_slave_is_connected( self, slaves_to_validate, connected_slaves, host_name_to_uid, is_valid, ): def get_host_id(host): if host in host_name_to_uid: return host_name_to_uid[host] else: return str(uuid.uuid4()) self.patch('app.util.network.Network.get_host_id', new=get_host_id) deploy_subcommand = DeploySubcommand() deploy_subcommand._registered_slave_hostnames = MagicMock(return_value=connected_slaves) deploy_subcommand._SLAVE_REGISTRY_TIMEOUT_SEC = 1 deploy_subcommand._non_registered_slaves = MagicMock() validate = partial(deploy_subcommand._validate_successful_deployment, 'master_host_url', slaves_to_validate) if not is_valid: with self.assertRaises(SystemExit): validate() else: validate()
def test_non_registered_slaves_returns_empty_list_if_all_registered(self): registered_hosts = ['host_1', 'host_2'] slaves_to_validate = ['host_1', 'host_2'] def get_host_id(*args, **kwargs): if args[0] == 'host_1': return 'host_id_1' elif args[0] == 'host_2': return 'host_id_2' else: return 'blah' old_host_id = Network.get_host_id Network.get_host_id = get_host_id deploy_subcommand = DeploySubcommand() non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate) Network.get_host_id = old_host_id self.assertEquals(0, len(non_registered))
def test_non_registered_slaves_returns_empty_list_if_all_registered(self): registered_hosts = ['host_1', 'host_2'] slaves_to_validate = ['host_1', 'host_2'] def rsa_key(*args, **kwargs): if args[0] == 'host_1': return 'rsa_key_1' elif args[0] == 'host_2': return 'rsa_key_2' else: return 'blah' old_rsa_key = Network.rsa_key Network.rsa_key = rsa_key deploy_subcommand = DeploySubcommand() non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate) Network.rsa_key = old_rsa_key self.assertEquals(0, len(non_registered))
def test_non_registered_slaves_returns_empty_list_if_all_registered(self): registered_hosts = ['host_1', 'host_2'] slaves_to_validate = ['host_1', 'host_2'] def rsa_key(*args, **kwargs): if args[0] == 'host_1': return 'rsa_key_1' elif args[0] == 'host_2': return 'rsa_key_2' else: return 'blah' old_rsa_key = Network.rsa_key Network.rsa_key = rsa_key deploy_subcommand = DeploySubcommand() non_registered = deploy_subcommand._non_registered_slaves( registered_hosts, slaves_to_validate) Network.rsa_key = old_rsa_key self.assertEquals(0, len(non_registered))
def test_non_registered_slaves_returns_empty_list_with_slaves_with_same_host_ids_but_different_names(self): registered_hosts = ['host_1_alias', 'host_2_alias'] slaves_to_validate = ['host_1', 'host_2'] def get_host_id(*args, **kwargs): if args[0] == 'host_1': return 'host_id_1' elif args[0] == 'host_2': return 'host_id_2' elif args[0] == 'host_1_alias': return 'host_id_1' elif args[0] == 'host_2_alias': return 'host_id_2' else: return 'blah' self.patch('app.util.network.Network.get_host_id', new=get_host_id) deploy_subcommand = DeploySubcommand() non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate) self.assertEquals(0, len(non_registered))
def test_non_registered_slaves_returns_non_registered_slaves(self): registered_hosts = ['host_1', 'host_3'] slaves_to_validate = ['host_1', 'host_2', 'host_3', 'host_4'] def get_host_id(*args, **kwargs): if args[0] == 'host_1': return 'host_id_1' elif args[0] == 'host_2': return 'host_id_2' elif args[0] == 'host_3': return 'host_id_3' elif args[0] == 'host_4': return 'host_id_4' else: return 'blah' self.patch('app.util.network.Network.get_host_id', new=get_host_id) deploy_subcommand = DeploySubcommand() non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate) self.assertEquals(len(non_registered), 2) self.assertTrue('host_2' in non_registered) self.assertTrue('host_4' in non_registered)