objects: update the old location parent_addr only if it has value
Do not update extra_update['phys_function'] in case parent_addr field is None. Updating it leads to an exception as extra_update is a dictionary of non-nullable fields. Partially implements blueprint sriov-physical-function-passthrough Change-Id: I8b091432f76af117d0f8d303d8b6d53ad2ca8ba3
This commit is contained in:
parent
6248dd0ae5
commit
365bd8619f
@ -218,7 +218,7 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject):
|
|||||||
# NOTE(ndipanov): If we are not migrating data yet, make sure
|
# NOTE(ndipanov): If we are not migrating data yet, make sure
|
||||||
# that any changes to parent_addr are also in the old location
|
# that any changes to parent_addr are also in the old location
|
||||||
# in extra_info
|
# in extra_info
|
||||||
if 'parent_addr' in updates:
|
if 'parent_addr' in updates and updates['parent_addr']:
|
||||||
extra_update = updates.get('extra_info', {})
|
extra_update = updates.get('extra_info', {})
|
||||||
if not extra_update and self.obj_attr_is_set('extra_info'):
|
if not extra_update and self.obj_attr_is_set('extra_info'):
|
||||||
extra_update = self.extra_info
|
extra_update = self.extra_info
|
||||||
|
@ -180,6 +180,17 @@ class _TestPciDeviceObject(object):
|
|||||||
self.assertEqual('blah', dev.parent_addr)
|
self.assertEqual('blah', dev.parent_addr)
|
||||||
self.assertEqual({'phys_function': 'blah'}, dev.extra_info)
|
self.assertEqual({'phys_function': 'blah'}, dev.extra_info)
|
||||||
|
|
||||||
|
def test_save_empty_parent_addr(self):
|
||||||
|
ctxt = context.get_admin_context()
|
||||||
|
dev = pci_device.PciDevice._from_db_object(
|
||||||
|
ctxt, pci_device.PciDevice(), fake_db_dev)
|
||||||
|
dev.parent_addr = None
|
||||||
|
with mock.patch.object(db, 'pci_device_update',
|
||||||
|
return_value=fake_db_dev):
|
||||||
|
dev.save()
|
||||||
|
self.assertIsNone(dev.parent_addr)
|
||||||
|
self.assertEqual({}, dev.extra_info)
|
||||||
|
|
||||||
def test_save(self):
|
def test_save(self):
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
self._create_fake_pci_device(ctxt=ctxt)
|
self._create_fake_pci_device(ctxt=ctxt)
|
||||||
|
Loading…
Reference in New Issue
Block a user