From 365bd8619fed7a40c4cca8846932e06d03be86d5 Mon Sep 17 00:00:00 2001 From: Vladik Romanovsky Date: Tue, 12 Jan 2016 13:42:56 -0500 Subject: [PATCH] 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 --- nova/objects/pci_device.py | 2 +- nova/tests/unit/objects/test_pci_device.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/nova/objects/pci_device.py b/nova/objects/pci_device.py index 01e478c1696e..bd4a5ccfbedf 100644 --- a/nova/objects/pci_device.py +++ b/nova/objects/pci_device.py @@ -218,7 +218,7 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject): # NOTE(ndipanov): If we are not migrating data yet, make sure # that any changes to parent_addr are also in the old location # in extra_info - if 'parent_addr' in updates: + if 'parent_addr' in updates and updates['parent_addr']: extra_update = updates.get('extra_info', {}) if not extra_update and self.obj_attr_is_set('extra_info'): extra_update = self.extra_info diff --git a/nova/tests/unit/objects/test_pci_device.py b/nova/tests/unit/objects/test_pci_device.py index 431e421a3fc8..16b2870533c6 100644 --- a/nova/tests/unit/objects/test_pci_device.py +++ b/nova/tests/unit/objects/test_pci_device.py @@ -180,6 +180,17 @@ class _TestPciDeviceObject(object): self.assertEqual('blah', dev.parent_addr) 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): ctxt = context.get_admin_context() self._create_fake_pci_device(ctxt=ctxt)