def setUp(self): super(TestNodeFacade, self).setUp() self.version = 'v1' self.res_uri = '/api/{version}/nodes/'.format(version=self.version) self.fake_node = utils.get_fake_node() self.fake_nodes = [utils.get_fake_node() for _ in range(10)] self.client = fuelclient.get_client('node', self.version)
def test_env_remove_nodes_all(self): nodes = [24, 25, 26] env_id = 42 expected_body = [] for n in nodes: expected_body.append({'id': n}) fake_nodes = [utils.get_fake_node(node_name='node_' + str(n), node_id=n, cluster=env_id) for n in nodes] expected_uri = self.get_object_uri(self.res_uri, env_id, '/unassignment/') matcher_get = self.m_request.get( '/api/v1/nodes/?cluster_id={}'.format(env_id), json=fake_nodes ) matcher_post = self.m_request.post(expected_uri, json={}) self.client.remove_nodes(env_id) self.assertTrue(matcher_get.called) self.assertTrue(matcher_post.called) for unassignment in matcher_post.last_request.json(): # Check whether all unassignments are expected self.assertIn(unassignment, expected_body)
def test_node_list_with_labels(self): labels = ['key1'] fake_nodes = [ utils.get_fake_node( node_name='node_1', labels={'key1': 'val1'}), utils.get_fake_node( node_name='node_2', labels={'key2': 'val2'}), utils.get_fake_node( node_name='node_3', labels={'key1': 'val2', 'key3': 'val3'}) ] matcher_get = self.m_request.get(self.res_uri, json=fake_nodes) data = self.client.get_all(labels=labels) self.assertTrue(matcher_get.called) self.assertEqual(len(data), 2) self.assertEqual(data[0]['name'], 'node_1') self.assertEqual(data[1]['name'], 'node_3')
def test_undiscover_nodes_by_env(self): env_id = 24 node_ids = ['42', '43', '44'] fake_nodes = [utils.get_fake_node(node_name='node_' + n_id, node_id=n_id, cluster=env_id) for n_id in node_ids] nodes_matcher = self.m_request.get(self.res_uri, json=fake_nodes) self.assertRaises(error.ActionException, self.client.undiscover_nodes, env_id=env_id, node_id=None, force=False) self.assertTrue(nodes_matcher.called)
def test_settings_override_called(self, m_update): cmd = ('--os-password tpass --os-username tname --os-tenant-name tten ' 'node list') self.m_client.get_all.return_value = [utils.get_fake_node() for _ in range(10)] self.exec_command(cmd) m_update.assert_called_once_with(mock.ANY) passed_settings = m_update.call_args[0][0] self.assertEqual('tname', passed_settings.os_username) self.assertEqual('tpass', passed_settings.os_password) self.assertEqual('tten', passed_settings.os_tenant_name)
def test_undiscover_nodes_by_env_force(self): env_id = 24 node_ids = ['42', '43', '44'] expected_uri = '/api/v1/nodes/?ids={node_ids}'.format( node_ids=','.join(node_ids)) fake_nodes = [utils.get_fake_node(node_name='node_' + n_id, node_id=n_id, cluster=env_id) for n_id in node_ids] nodes_matcher = self.m_request.get(self.res_uri, json=fake_nodes) matcher = self.m_request.delete(expected_uri, json={}) self.client.undiscover_nodes(env_id=env_id, node_id=None, force=True) self.assertTrue(matcher.called) self.assertTrue(nodes_matcher.called) self.assertEqual([','.join(node_ids)], matcher.last_request.qs.get('ids'))
def get_random_nodes(cls, number): """Returns specified number of random fake nodes.""" return [utils.get_fake_node() for i in six_moves.range(number)]