Use association_proxy for port groups node_uuid
This change adds 'node_uuid' to: ironic.objects.portgroup.Portgroup 'node_uuid' is a relationship using association_proxy in models.Portgroup. Using the association_proxy removes the need to do the node lookup to populate node uuid for portgroups in the api controller. NOTE: On portgroup create a read is added to read the port from the database, this ensures node_uuid is loaded and solves the DetachedInstanceError which is otherwise raised. The test test_list_with_deleted_port_group was deleted, if the portgroup does not exist porgroup_uuid on the port will be None, no need for extra handling of that case. Bumps Portgroup object version to 1.5 Change-Id: I4317d034b6661da4248935cb0b9cb095982cc052
This commit is contained in:
@@ -680,7 +680,7 @@ expected_object_fingerprints = {
|
||||
'MyObj': '1.5-9459d30d6954bffc7a9afd347a807ca6',
|
||||
'Chassis': '1.3-d656e039fd8ae9f34efc232ab3980905',
|
||||
'Port': '1.11-97bf15b61224f26c65e90f007d78bfd2',
|
||||
'Portgroup': '1.4-71923a81a86743b313b190f5c675e258',
|
||||
'Portgroup': '1.5-df4dc15967f67114d51176a98a901a83',
|
||||
'Conductor': '1.3-d3f53e853b4d58cae5bfbd9a8341af4a',
|
||||
'EventType': '1.1-aa2ba1afd38553e3880c267404e8d370',
|
||||
'NotificationPublisher': '1.0-51a09397d6c0687771fb5be9a999605d',
|
||||
|
||||
@@ -80,13 +80,18 @@ class TestPortgroupObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
|
||||
def test_create(self):
|
||||
portgroup = objects.Portgroup(self.context, **self.fake_portgroup)
|
||||
with mock.patch.object(self.dbapi, 'create_portgroup',
|
||||
autospec=True) as mock_create_portgroup:
|
||||
mock_create_portgroup.return_value = db_utils.get_test_portgroup()
|
||||
autospec=True) as mock_create_pg:
|
||||
with mock.patch.object(self.dbapi, 'get_portgroup_by_id',
|
||||
autospec=True) as mock_get_pg:
|
||||
test_pg = db_utils.get_test_portgroup()
|
||||
mock_create_pg.return_value = test_pg
|
||||
mock_get_pg.return_value = test_pg
|
||||
mock_create_pg.return_value = db_utils.get_test_portgroup()
|
||||
|
||||
portgroup.create()
|
||||
portgroup.create()
|
||||
|
||||
args, _kwargs = mock_create_portgroup.call_args
|
||||
self.assertEqual(objects.Portgroup.VERSION, args[0]['version'])
|
||||
args, _kwargs = mock_create_pg.call_args
|
||||
self.assertEqual(objects.Portgroup.VERSION, args[0]['version'])
|
||||
|
||||
def test_save(self):
|
||||
uuid = self.fake_portgroup['uuid']
|
||||
|
||||
Reference in New Issue
Block a user