Merge "Removed hardcoded IDs from "chassis" test resources"
This commit is contained in:
commit
058cc1c0d5
@ -78,7 +78,7 @@ class TestListChassis(api_base.FunctionalTest):
|
||||
ch_list = []
|
||||
for id_ in range(5):
|
||||
chassis = obj_utils.create_test_chassis(
|
||||
self.context, id=id_, uuid=uuidutils.generate_uuid())
|
||||
self.context, uuid=uuidutils.generate_uuid())
|
||||
ch_list.append(chassis.uuid)
|
||||
data = self.get_json('/chassis')
|
||||
self.assertEqual(len(ch_list), len(data['chassis']))
|
||||
@ -87,7 +87,7 @@ class TestListChassis(api_base.FunctionalTest):
|
||||
|
||||
def test_links(self):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
obj_utils.create_test_chassis(self.context, id=1, uuid=uuid)
|
||||
obj_utils.create_test_chassis(self.context, uuid=uuid)
|
||||
data = self.get_json('/chassis/%s' % uuid)
|
||||
self.assertIn('links', data.keys())
|
||||
self.assertEqual(2, len(data['links']))
|
||||
@ -98,7 +98,7 @@ class TestListChassis(api_base.FunctionalTest):
|
||||
|
||||
def test_collection_links(self):
|
||||
for id in range(5):
|
||||
obj_utils.create_test_chassis(self.context, id=id,
|
||||
obj_utils.create_test_chassis(self.context,
|
||||
uuid=uuidutils.generate_uuid())
|
||||
data = self.get_json('/chassis/?limit=3')
|
||||
self.assertEqual(3, len(data['chassis']))
|
||||
@ -109,7 +109,7 @@ class TestListChassis(api_base.FunctionalTest):
|
||||
def test_collection_links_default_limit(self):
|
||||
cfg.CONF.set_override('max_limit', 3, 'api')
|
||||
for id_ in range(5):
|
||||
obj_utils.create_test_chassis(self.context, id=id_,
|
||||
obj_utils.create_test_chassis(self.context,
|
||||
uuid=uuidutils.generate_uuid())
|
||||
data = self.get_json('/chassis')
|
||||
self.assertEqual(3, len(data['chassis']))
|
||||
@ -187,8 +187,7 @@ class TestPatch(api_base.FunctionalTest):
|
||||
def test_replace_multi(self):
|
||||
extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
|
||||
chassis = obj_utils.create_test_chassis(self.context, extra=extra,
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
id=1)
|
||||
uuid=uuidutils.generate_uuid())
|
||||
new_value = 'new value'
|
||||
response = self.patch_json('/chassis/%s' % chassis.uuid,
|
||||
[{'path': '/extra/foo2',
|
||||
@ -202,8 +201,7 @@ class TestPatch(api_base.FunctionalTest):
|
||||
|
||||
def test_remove_singular(self):
|
||||
chassis = obj_utils.create_test_chassis(self.context, extra={'a': 'b'},
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
id=1)
|
||||
uuid=uuidutils.generate_uuid())
|
||||
response = self.patch_json('/chassis/%s' % chassis.uuid,
|
||||
[{'path': '/description', 'op': 'remove'}])
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
@ -219,8 +217,7 @@ class TestPatch(api_base.FunctionalTest):
|
||||
extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
|
||||
chassis = obj_utils.create_test_chassis(self.context, extra=extra,
|
||||
description="foobar",
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
id=1)
|
||||
uuid=uuidutils.generate_uuid())
|
||||
|
||||
# Removing one item from the collection
|
||||
response = self.patch_json('/chassis/%s' % chassis.uuid,
|
||||
@ -344,7 +341,7 @@ class TestPost(api_base.FunctionalTest):
|
||||
|
||||
def test_post_nodes_subresource(self):
|
||||
chassis = obj_utils.create_test_chassis(self.context)
|
||||
ndict = apiutils.node_post_data(chassis_id=None)
|
||||
ndict = apiutils.node_post_data()
|
||||
ndict['chassis_uuid'] = chassis.uuid
|
||||
response = self.post_json('/chassis/nodes', ndict,
|
||||
expect_errors=True)
|
||||
|
@ -120,7 +120,7 @@ class TestTopLevelFunctions(base.TestCase):
|
||||
class TestNodeObject(base.TestCase):
|
||||
|
||||
def test_node_init(self):
|
||||
node_dict = test_api_utils.node_post_data(chassis_id=None)
|
||||
node_dict = test_api_utils.node_post_data()
|
||||
del node_dict['instance_uuid']
|
||||
node = api_node.Node(**node_dict)
|
||||
self.assertEqual(wtypes.Unset, node.instance_uuid)
|
||||
@ -159,7 +159,8 @@ class TestListNodes(test_api_base.FunctionalTest):
|
||||
self.assertEqual([], data['nodes'])
|
||||
|
||||
def test_one(self):
|
||||
node = obj_utils.create_test_node(self.context)
|
||||
node = obj_utils.create_test_node(self.context,
|
||||
chassis_id=self.chassis.id)
|
||||
data = self.get_json('/nodes',
|
||||
headers={api_base.Version.string: str(api_v1.MAX_VER)})
|
||||
self.assertIn('instance_uuid', data['nodes'][0])
|
||||
@ -184,7 +185,8 @@ class TestListNodes(test_api_base.FunctionalTest):
|
||||
self.assertNotIn('chassis_id', data['nodes'][0])
|
||||
|
||||
def test_get_one(self):
|
||||
node = obj_utils.create_test_node(self.context)
|
||||
node = obj_utils.create_test_node(self.context,
|
||||
chassis_id=self.chassis.id)
|
||||
data = self.get_json('/nodes/%s' % node.uuid,
|
||||
headers={api_base.Version.string: str(api_v1.MAX_VER)})
|
||||
self.assertEqual(node.uuid, data['uuid'])
|
||||
@ -205,7 +207,8 @@ class TestListNodes(test_api_base.FunctionalTest):
|
||||
self.assertNotIn('chassis_id', data)
|
||||
|
||||
def test_detail(self):
|
||||
node = obj_utils.create_test_node(self.context)
|
||||
node = obj_utils.create_test_node(self.context,
|
||||
chassis_id=self.chassis.id)
|
||||
data = self.get_json('/nodes/detail',
|
||||
headers={api_base.Version.string: str(api_v1.MAX_VER)})
|
||||
self.assertEqual(node.uuid, data['nodes'][0]["uuid"])
|
||||
@ -530,7 +533,8 @@ class TestListNodes(test_api_base.FunctionalTest):
|
||||
node = obj_utils.create_test_node(
|
||||
self.context,
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
instance_uuid=uuidutils.generate_uuid())
|
||||
instance_uuid=uuidutils.generate_uuid(),
|
||||
chassis_id=self.chassis.id)
|
||||
instance_uuid = node.instance_uuid
|
||||
|
||||
data = self.get_json('/nodes/detail?instance_uuid=%s' % instance_uuid)
|
||||
@ -734,9 +738,11 @@ class TestPatch(test_api_base.FunctionalTest):
|
||||
def setUp(self):
|
||||
super(TestPatch, self).setUp()
|
||||
self.chassis = obj_utils.create_test_chassis(self.context)
|
||||
self.node = obj_utils.create_test_node(self.context, name='node-57')
|
||||
self.node = obj_utils.create_test_node(self.context, name='node-57',
|
||||
chassis_id=self.chassis.id)
|
||||
self.node_no_name = obj_utils.create_test_node(self.context,
|
||||
uuid='deadbeef-0000-1111-2222-333333333333')
|
||||
uuid='deadbeef-0000-1111-2222-333333333333',
|
||||
chassis_id=self.chassis.id)
|
||||
p = mock.patch.object(rpcapi.ConductorAPI, 'get_topic_for')
|
||||
self.mock_gtf = p.start()
|
||||
self.mock_gtf.return_value = 'test-topic'
|
||||
@ -1421,7 +1427,6 @@ class TestDelete(test_api_base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDelete, self).setUp()
|
||||
self.chassis = obj_utils.create_test_chassis(self.context)
|
||||
p = mock.patch.object(rpcapi.ConductorAPI, 'get_topic_for')
|
||||
self.mock_gtf = p.start()
|
||||
self.mock_gtf.return_value = 'test-topic'
|
||||
@ -1537,7 +1542,6 @@ class TestPut(test_api_base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPut, self).setUp()
|
||||
self.chassis = obj_utils.create_test_chassis(self.context)
|
||||
self.node = obj_utils.create_test_node(self.context,
|
||||
provision_state=states.AVAILABLE, name='node-39')
|
||||
p = mock.patch.object(rpcapi.ConductorAPI, 'get_topic_for')
|
||||
|
@ -25,40 +25,36 @@ from ironic.tests.db import utils
|
||||
|
||||
class DbChassisTestCase(base.DbTestCase):
|
||||
|
||||
def _create_test_chassis(self, **kwargs):
|
||||
ch = utils.get_test_chassis(**kwargs)
|
||||
self.dbapi.create_chassis(ch)
|
||||
return ch
|
||||
def setUp(self):
|
||||
super(DbChassisTestCase, self).setUp()
|
||||
self.chassis = utils.create_test_chassis()
|
||||
|
||||
def test_get_chassis_list(self):
|
||||
uuids = []
|
||||
uuids = [self.chassis.uuid]
|
||||
for i in range(1, 6):
|
||||
n = utils.get_test_chassis(id=i, uuid=uuidutils.generate_uuid())
|
||||
self.dbapi.create_chassis(n)
|
||||
uuids.append(six.text_type(n['uuid']))
|
||||
ch = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
|
||||
uuids.append(six.text_type(ch.uuid))
|
||||
res = self.dbapi.get_chassis_list()
|
||||
res_uuids = [r.uuid for r in res]
|
||||
six.assertCountEqual(self, uuids, res_uuids)
|
||||
|
||||
def test_get_chassis_by_id(self):
|
||||
ch = self._create_test_chassis()
|
||||
chassis = self.dbapi.get_chassis_by_id(ch['id'])
|
||||
chassis = self.dbapi.get_chassis_by_id(self.chassis.id)
|
||||
|
||||
self.assertEqual(ch['uuid'], chassis.uuid)
|
||||
self.assertEqual(self.chassis.uuid, chassis.uuid)
|
||||
|
||||
def test_get_chassis_by_uuid(self):
|
||||
ch = self._create_test_chassis()
|
||||
chassis = self.dbapi.get_chassis_by_uuid(ch['uuid'])
|
||||
chassis = self.dbapi.get_chassis_by_uuid(self.chassis.uuid)
|
||||
|
||||
self.assertEqual(ch['id'], chassis.id)
|
||||
self.assertEqual(self.chassis.id, chassis.id)
|
||||
|
||||
def test_get_chassis_that_does_not_exist(self):
|
||||
self.assertRaises(exception.ChassisNotFound,
|
||||
self.dbapi.get_chassis_by_id, 666)
|
||||
|
||||
def test_update_chassis(self):
|
||||
ch = self._create_test_chassis()
|
||||
res = self.dbapi.update_chassis(ch['id'], {'description': 'hello'})
|
||||
res = self.dbapi.update_chassis(self.chassis.id,
|
||||
{'description': 'hello'})
|
||||
|
||||
self.assertEqual('hello', res.description)
|
||||
|
||||
@ -67,32 +63,27 @@ class DbChassisTestCase(base.DbTestCase):
|
||||
self.dbapi.update_chassis, 666, {'description': ''})
|
||||
|
||||
def test_update_chassis_uuid(self):
|
||||
ch = self._create_test_chassis()
|
||||
self.assertRaises(exception.InvalidParameterValue,
|
||||
self.dbapi.update_chassis, ch['id'],
|
||||
self.dbapi.update_chassis, self.chassis.id,
|
||||
{'uuid': 'hello'})
|
||||
|
||||
def test_destroy_chassis(self):
|
||||
ch = self._create_test_chassis()
|
||||
self.dbapi.destroy_chassis(ch['id'])
|
||||
self.dbapi.destroy_chassis(self.chassis.id)
|
||||
|
||||
self.assertRaises(exception.ChassisNotFound,
|
||||
self.dbapi.get_chassis_by_id, ch['id'])
|
||||
self.dbapi.get_chassis_by_id, self.chassis.id)
|
||||
|
||||
def test_destroy_chassis_that_does_not_exist(self):
|
||||
self.assertRaises(exception.ChassisNotFound,
|
||||
self.dbapi.destroy_chassis, 666)
|
||||
|
||||
def test_destroy_chassis_with_nodes(self):
|
||||
ch = self._create_test_chassis()
|
||||
utils.create_test_node(chassis_id=ch['id'])
|
||||
utils.create_test_node(chassis_id=self.chassis.id)
|
||||
|
||||
self.assertRaises(exception.ChassisNotEmpty,
|
||||
self.dbapi.destroy_chassis, ch['id'])
|
||||
self.dbapi.destroy_chassis, self.chassis.id)
|
||||
|
||||
def test_create_chassis_already_exists(self):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
self._create_test_chassis(id=1, uuid=uuid)
|
||||
self.assertRaises(exception.ChassisAlreadyExists,
|
||||
self._create_test_chassis,
|
||||
id=2, uuid=uuid)
|
||||
utils.create_test_chassis,
|
||||
uuid=self.chassis.uuid)
|
||||
|
@ -33,9 +33,6 @@ class DbNodeTestCase(base.DbTestCase):
|
||||
def test_create_node(self):
|
||||
utils.create_test_node()
|
||||
|
||||
def test_create_node_nullable_chassis_id(self):
|
||||
utils.create_test_node(chassis_id=None)
|
||||
|
||||
def test_create_node_already_exists(self):
|
||||
utils.create_test_node()
|
||||
self.assertRaises(exception.NodeAlreadyExists,
|
||||
@ -200,10 +197,8 @@ class DbNodeTestCase(base.DbTestCase):
|
||||
six.assertCountEqual(self, uuids, res_uuids)
|
||||
|
||||
def test_get_node_list_with_filters(self):
|
||||
ch1 = utils.get_test_chassis(id=1, uuid=uuidutils.generate_uuid())
|
||||
ch2 = utils.get_test_chassis(id=2, uuid=uuidutils.generate_uuid())
|
||||
self.dbapi.create_chassis(ch1)
|
||||
self.dbapi.create_chassis(ch2)
|
||||
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(),
|
||||
|
@ -188,7 +188,7 @@ def get_test_node(**kw):
|
||||
'id': kw.get('id', 123),
|
||||
'name': kw.get('name', None),
|
||||
'uuid': kw.get('uuid', '1be26c0b-03f2-4d2e-ae87-c02d7f33c123'),
|
||||
'chassis_id': kw.get('chassis_id', 42),
|
||||
'chassis_id': kw.get('chassis_id', None),
|
||||
'conductor_affinity': kw.get('conductor_affinity', None),
|
||||
'power_state': kw.get('power_state', states.NOSTATE),
|
||||
'target_power_state': kw.get('target_power_state', states.NOSTATE),
|
||||
@ -273,6 +273,23 @@ def get_test_chassis(**kw):
|
||||
}
|
||||
|
||||
|
||||
def create_test_chassis(**kw):
|
||||
"""Create test chassis entry in DB and return Chassis DB object.
|
||||
|
||||
Function to be used to create test Chassis objects in the database.
|
||||
|
||||
:param kw: kwargs with overriding values for chassis's attributes.
|
||||
:returns: Test Chassis DB object.
|
||||
|
||||
"""
|
||||
chassis = get_test_chassis(**kw)
|
||||
# Let DB generate ID if it isn't specified explicitly
|
||||
if 'id' not in kw:
|
||||
del chassis['id']
|
||||
dbapi = db_api.get_instance()
|
||||
return dbapi.create_chassis(chassis)
|
||||
|
||||
|
||||
def get_test_conductor(**kw):
|
||||
return {
|
||||
'id': kw.get('id', 6),
|
||||
|
@ -79,6 +79,9 @@ def get_test_chassis(ctxt, **kw):
|
||||
that a create() could be used to commit it to the DB.
|
||||
"""
|
||||
db_chassis = db_utils.get_test_chassis(**kw)
|
||||
# Let DB generate ID if it isn't specified explicitly
|
||||
if 'id' not in kw:
|
||||
del db_chassis['id']
|
||||
chassis = objects.Chassis(ctxt)
|
||||
for key in db_chassis:
|
||||
setattr(chassis, key, db_chassis[key])
|
||||
|
Loading…
Reference in New Issue
Block a user