Fix PCIDevice ignoring missing DB attributes
Right now, the PCIDevice _from_db_object() method ignores missing attributes on the DB object by using get(). This prevents the strict typechecking from doing it's job, and differs from every other object model currently in the tree. As a result, non-nullable attributes such as dev_type are string-converted to "None" in the object, which is definitely not the intent. This is convention, not something we test for, but it was wrong, and ended up breaking the next patch which introduces a scenario where this gets checked in the unit tests more strictly. Thus, the test is in the next aptch Change-Id: Id6e1f444ceae13ee9fa1a9518db5a239a1d9fbe3 Closes-bug: 1221360
This commit is contained in:
@@ -143,7 +143,7 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject):
|
||||
def _from_db_object(context, pci_device, db_dev):
|
||||
for key in pci_device.fields:
|
||||
if key != 'extra_info':
|
||||
pci_device[key] = db_dev.get(key)
|
||||
pci_device[key] = db_dev[key]
|
||||
else:
|
||||
extra_info = db_dev.get("extra_info")
|
||||
pci_device.extra_info = jsonutils.loads(extra_info)
|
||||
|
||||
@@ -413,9 +413,12 @@ class _TestInstanceObject(object):
|
||||
'id': 2,
|
||||
'compute_node_id': 1,
|
||||
'address': 'a1',
|
||||
'product_id': 'p1',
|
||||
'vendor_id': 'v1',
|
||||
'product_id': 'p1',
|
||||
'dev_type': 't',
|
||||
'status': 'allocated',
|
||||
'dev_id': 'i',
|
||||
'label': 'l',
|
||||
'instance_uuid': fake_uuid,
|
||||
'extra_info': '{}'},
|
||||
{
|
||||
@@ -426,9 +429,12 @@ class _TestInstanceObject(object):
|
||||
'id': 1,
|
||||
'compute_node_id': 1,
|
||||
'address': 'a',
|
||||
'product_id': 'p',
|
||||
'vendor_id': 'v',
|
||||
'product_id': 'p',
|
||||
'dev_type': 't',
|
||||
'status': 'allocated',
|
||||
'dev_id': 'i',
|
||||
'label': 'l',
|
||||
'instance_uuid': fake_uuid,
|
||||
'extra_info': '{}'},
|
||||
]
|
||||
|
||||
@@ -40,9 +40,13 @@ fake_db_dev = {
|
||||
'id': 1,
|
||||
'compute_node_id': 1,
|
||||
'address': 'a',
|
||||
'product_id': 'p',
|
||||
'vendor_id': 'v',
|
||||
'product_id': 'p',
|
||||
'dev_type': 't',
|
||||
'status': 'available',
|
||||
'dev_id': 'i',
|
||||
'label': 'l',
|
||||
'instance_uuid': None,
|
||||
'extra_info': '{}',
|
||||
}
|
||||
|
||||
@@ -55,9 +59,13 @@ fake_db_dev_1 = {
|
||||
'id': 2,
|
||||
'compute_node_id': 1,
|
||||
'address': 'a1',
|
||||
'product_id': 'p1',
|
||||
'vendor_id': 'v1',
|
||||
'product_id': 'p1',
|
||||
'dev_type': 't',
|
||||
'status': 'available',
|
||||
'dev_id': 'i',
|
||||
'label': 'l',
|
||||
'instance_uuid': None,
|
||||
'extra_info': '{}',
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,13 @@ fake_db_dev = {
|
||||
'id': 1,
|
||||
'compute_node_id': 1,
|
||||
'address': '0000:00:00.1',
|
||||
'product_id': 'p',
|
||||
'vendor_id': 'v',
|
||||
'product_id': 'p',
|
||||
'dev_type': 't',
|
||||
'status': 'available',
|
||||
'dev_id': 'i',
|
||||
'label': 'l',
|
||||
'instance_uuid': None,
|
||||
'extra_info': '{}',
|
||||
}
|
||||
fake_db_dev_1 = dict(fake_db_dev, vendor_id='v1',
|
||||
|
||||
@@ -52,6 +52,7 @@ from nova import test
|
||||
from nova.tests import fake_network
|
||||
import nova.tests.image.fake
|
||||
from nova.tests import matchers
|
||||
from nova.tests.objects import test_pci_device
|
||||
from nova.tests.virt.libvirt import fake_libvirt_utils
|
||||
from nova import utils
|
||||
from nova import version
|
||||
@@ -1079,15 +1080,14 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
service_ref, compute_ref = self._create_fake_service_compute()
|
||||
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
pci_device_info = {
|
||||
'compute_node_id': 1,
|
||||
'label': 'fake',
|
||||
'status': 'allocated',
|
||||
'address': '0000:00:00.1',
|
||||
'compute_id': compute_ref['id'],
|
||||
'instance_uuid': instance_ref['uuid'],
|
||||
'extra_info': jsonutils.dumps({}),
|
||||
}
|
||||
pci_device_info = dict(test_pci_device.fake_db_dev)
|
||||
pci_device_info.update(compute_node_id=1,
|
||||
label='fake',
|
||||
status='allocated',
|
||||
address='0000:00:00.1',
|
||||
compute_id=compute_ref['id'],
|
||||
instance_uuid=instance_ref['uuid'],
|
||||
extra_info=jsonutils.dumps({}))
|
||||
db.pci_device_update(self.context, pci_device_info['compute_node_id'],
|
||||
pci_device_info['address'], pci_device_info)
|
||||
|
||||
@@ -1118,15 +1118,14 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
service_ref, compute_ref = self._create_fake_service_compute()
|
||||
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
pci_device_info = {
|
||||
'compute_node_id': 1,
|
||||
'label': 'fake',
|
||||
'status': 'allocated',
|
||||
'address': '0000:00:00.2',
|
||||
'compute_id': compute_ref['id'],
|
||||
'instance_uuid': instance_ref['uuid'],
|
||||
'extra_info': jsonutils.dumps({}),
|
||||
}
|
||||
pci_device_info = dict(test_pci_device.fake_db_dev)
|
||||
pci_device_info.update(compute_node_id=1,
|
||||
label='fake',
|
||||
status='allocated',
|
||||
address='0000:00:00.2',
|
||||
compute_id=compute_ref['id'],
|
||||
instance_uuid=instance_ref['uuid'],
|
||||
extra_info=jsonutils.dumps({}))
|
||||
db.pci_device_update(self.context, pci_device_info['compute_node_id'],
|
||||
pci_device_info['address'], pci_device_info)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user