Do not rely on predefined UUIDs in tests

Change-Id: I0e9d73351a92e133cd6c484b5fb415ae005314b0
This commit is contained in:
Dmitry Tantsur 2023-04-25 17:32:09 +02:00
parent 2f71e5d512
commit b7954ad720
No known key found for this signature in database
GPG Key ID: 315B2AF9FD216C60
3 changed files with 21 additions and 13 deletions

View File

@ -249,6 +249,7 @@ class TestRBACModelBeforeScopesBase(TestACLBase):
resource_class="CUSTOM_TEST") resource_class="CUSTOM_TEST")
fake_db_node = db_utils.create_test_node( fake_db_node = db_utils.create_test_node(
chassis_id=None, chassis_id=None,
uuid='1be26c0b-03f2-4d2e-ae87-c02d7f33c123',
driver='fake-driverz', driver='fake-driverz',
owner='z') owner='z')
fake_db_node_alloced = db_utils.create_test_node( fake_db_node_alloced = db_utils.create_test_node(
@ -262,12 +263,14 @@ class TestRBACModelBeforeScopesBase(TestACLBase):
dict(node_id=allocated_node_id)) dict(node_id=allocated_node_id))
fake_vif_port_id = "ee21d58f-5de2-4956-85ff-33935ea1ca00" fake_vif_port_id = "ee21d58f-5de2-4956-85ff-33935ea1ca00"
fake_db_port = db_utils.create_test_port( fake_db_port = db_utils.create_test_port(
uuid='1be26c0b-03f2-4d2e-ae87-c02d7f33c781',
node_id=fake_db_node['id'], node_id=fake_db_node['id'],
internal_info={'tenant_vif_port_id': fake_vif_port_id}) internal_info={'tenant_vif_port_id': fake_vif_port_id})
fake_db_portgroup = db_utils.create_test_portgroup( fake_db_portgroup = db_utils.create_test_portgroup(
uuid="6eb02b44-18a3-4659-8c0b-8d2802581ae4", uuid="6eb02b44-18a3-4659-8c0b-8d2802581ae4",
node_id=fake_db_node['id']) node_id=fake_db_node['id'])
fake_db_chassis = db_utils.create_test_chassis( fake_db_chassis = db_utils.create_test_chassis(
uuid='e74c40e0-d825-11e2-a28f-0800200c9a66',
drivers=['fake-hardware', 'fake-driverz', 'fake-driver']) drivers=['fake-hardware', 'fake-driverz', 'fake-driver'])
fake_db_deploy_template = db_utils.create_test_deploy_template() fake_db_deploy_template = db_utils.create_test_deploy_template()
fake_db_conductor = db_utils.create_test_conductor() fake_db_conductor = db_utils.create_test_conductor()

View File

@ -59,9 +59,9 @@ class DbNodeTestCase(base.DbTestCase):
traits=['trait1', 'trait2']) traits=['trait1', 'trait2'])
def test_create_node_already_exists(self): def test_create_node_already_exists(self):
utils.create_test_node() node = utils.create_test_node()
self.assertRaises(exception.NodeAlreadyExists, self.assertRaises(exception.NodeAlreadyExists,
utils.create_test_node) utils.create_test_node, uuid=node.uuid)
def test_create_node_instance_already_associated(self): def test_create_node_instance_already_associated(self):
instance = uuidutils.generate_uuid() instance = uuidutils.generate_uuid()

View File

@ -262,7 +262,7 @@ def create_test_node(**kw):
# Let DB generate an ID if one isn't specified explicitly. # Let DB generate an ID if one isn't specified explicitly.
# Creating a node with tags or traits will raise an exception. If tags or # Creating a node with tags or traits will raise an exception. If tags or
# traits are not specified explicitly just delete them. # traits are not specified explicitly just delete them.
for field in {'id', 'tags', 'traits'}: for field in {'id', 'uuid', 'tags', 'traits'}:
if field not in kw: if field not in kw:
del node[field] del node[field]
dbapi = db_api.get_instance() dbapi = db_api.get_instance()
@ -305,8 +305,9 @@ def create_test_port(**kw):
""" """
port = get_test_port(**kw) port = get_test_port(**kw)
# Let DB generate ID if it isn't specified explicitly # Let DB generate ID if it isn't specified explicitly
if 'id' not in kw: for field in ('id', 'uuid'):
del port['id'] if field not in kw:
del port[field]
dbapi = db_api.get_instance() dbapi = db_api.get_instance()
return dbapi.create_port(port) return dbapi.create_port(port)
@ -337,8 +338,9 @@ def create_test_volume_connector(**kw):
""" """
connector = get_test_volume_connector(**kw) connector = get_test_volume_connector(**kw)
# Let DB generate ID if it isn't specified explicitly # Let DB generate ID if it isn't specified explicitly
if 'id' not in kw: for field in ('id', 'uuid'):
del connector['id'] if field not in kw:
del connector[field]
dbapi = db_api.get_instance() dbapi = db_api.get_instance()
return dbapi.create_volume_connector(connector) return dbapi.create_volume_connector(connector)
@ -371,8 +373,9 @@ def create_test_volume_target(**kw):
""" """
target = get_test_volume_target(**kw) target = get_test_volume_target(**kw)
# Let DB generate ID if it isn't specified explicitly # Let DB generate ID if it isn't specified explicitly
if 'id' not in kw: for field in ('id', 'uuid'):
del target['id'] if field not in kw:
del target[field]
dbapi = db_api.get_instance() dbapi = db_api.get_instance()
return dbapi.create_volume_target(target) return dbapi.create_volume_target(target)
@ -400,8 +403,9 @@ def create_test_chassis(**kw):
""" """
chassis = get_test_chassis(**kw) chassis = get_test_chassis(**kw)
# Let DB generate ID if it isn't specified explicitly # Let DB generate ID if it isn't specified explicitly
if 'id' not in kw: for field in ('id', 'uuid'):
del chassis['id'] if field not in kw:
del chassis[field]
dbapi = db_api.get_instance() dbapi = db_api.get_instance()
return dbapi.create_chassis(chassis) return dbapi.create_chassis(chassis)
@ -476,8 +480,9 @@ def create_test_portgroup(**kw):
""" """
portgroup = get_test_portgroup(**kw) portgroup = get_test_portgroup(**kw)
# Let DB generate ID if it isn't specified explicitly # Let DB generate ID if it isn't specified explicitly
if 'id' not in kw: for field in ('id', 'uuid'):
del portgroup['id'] if field not in kw:
del portgroup[field]
dbapi = db_api.get_instance() dbapi = db_api.get_instance()
return dbapi.create_portgroup(portgroup) return dbapi.create_portgroup(portgroup)