def test_get_node_list_with_filters(self):
    ch1 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
    ch2 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
    node1 = utils.create_test_node(driver='driver-one', instance_uuid=uuidutils.generate_uuid(), reservation='fake-host', uuid=uuidutils.generate_uuid(), chassis_id=ch1['id'])
    node2 = utils.create_test_node(driver='driver-two', uuid=uuidutils.generate_uuid(), chassis_id=ch2['id'], maintenance=True, fault='boom', resource_class='foo', conductor_group='group1', power_state='power on')
    res = self.dbapi.get_node_list(filters={'chassis_uuid': ch1['uuid']})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'chassis_uuid': ch2['uuid']})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'driver': 'driver-one'})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'driver': 'bad-driver'})
    self.assertEqual([], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'associated': True})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'associated': False})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'reserved': True})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'reserved': False})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'maintenance': True})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'maintenance': False})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_nodeinfo_list(filters={'fault': 'boom'})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_nodeinfo_list(filters={'fault': 'moob'})
    self.assertEqual([], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'resource_class': 'foo'})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'conductor_group': 'group1'})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'conductor_group': 'group2'})
    self.assertEqual([], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'id': node1.id})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'uuid': node1.uuid})
    self.assertEqual([node1.id], [r.id for r in res])
    uuids = [uuidutils.generate_uuid(), node1.uuid, uuidutils.generate_uuid()]
    res = self.dbapi.get_node_list(filters={'uuid_in': uuids})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'with_power_state': True})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'with_power_state': False})
    self.assertEqual([node1.id], [r.id for r in res])
    filters = {'bad_filter': 'foo'}
    self.assertRaisesRegex(ValueError, 'bad_filter', self.dbapi.get_node_list, filters=filters)
    filters = {'bad_filter': 'foo', 'id': node1.id}
    self.assertRaisesRegex(ValueError, 'bad_filter', self.dbapi.get_node_list, filters=filters)
def test_get_node_list_with_filters(self):
    ch1 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
    ch2 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
    node1 = utils.create_test_node(driver='driver-one', instance_uuid=uuidutils.generate_uuid(), reservation='fake-host', uuid=uuidutils.generate_uuid(), chassis_id=ch1['id'])
    node2 = utils.create_test_node(driver='driver-two', uuid=uuidutils.generate_uuid(), chassis_id=ch2['id'], maintenance=True, fault='boom', resource_class='foo', conductor_group='group1', power_state='power on')
    res = self.dbapi.get_node_list(filters={'chassis_uuid': ch1['uuid']})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'chassis_uuid': ch2['uuid']})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'driver': 'driver-one'})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'driver': 'bad-driver'})
    self.assertEqual([], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'associated': True})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'associated': False})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'reserved': True})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'reserved': False})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'maintenance': True})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'maintenance': False})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_nodeinfo_list(filters={'fault': 'boom'})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_nodeinfo_list(filters={'fault': 'moob'})
    self.assertEqual([], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'resource_class': 'foo'})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'conductor_group': 'group1'})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'conductor_group': 'group2'})
    self.assertEqual([], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'id': node1.id})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'uuid': node1.uuid})
    self.assertEqual([node1.id], [r.id for r in res])
    uuids = [uuidutils.generate_uuid(), node1.uuid, uuidutils.generate_uuid()]
    res = self.dbapi.get_node_list(filters={'uuid_in': uuids})
    self.assertEqual([node1.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'with_power_state': True})
    self.assertEqual([node2.id], [r.id for r in res])
    res = self.dbapi.get_node_list(filters={'with_power_state': False})
    self.assertEqual([node1.id], [r.id for r in res])
    filters = {'bad_filter': 'foo'}
    self.assertRaisesRegex(ValueError, 'bad_filter', self.dbapi.get_node_list, filters=filters)
    filters = {'bad_filter': 'foo', 'id': node1.id}
    self.assertRaisesRegex(ValueError, 'bad_filter', self.dbapi.get_node_list, filters=filters)