pci: add safe-guard to __eq__ of PciDevice

We want to only compare a PciDevice object with an other PCIDevice
object. This patch adds that condition to avoid any exceptions raised
if we compare it for example with a NULL value.

Change-Id: I67f0ccb1e931ed327bc844eefc684754302d74d2
This commit is contained in:
Sahid Orentino Ferdjaoui 2016-05-18 10:56:24 -04:00
parent c477f14205
commit 7268006a2f
2 changed files with 9 additions and 0 deletions

View File

@ -30,6 +30,8 @@ LOG = logging.getLogger(__name__)
def compare_pci_device_attributes(obj_a, obj_b):
if not isinstance(obj_b, PciDevice):
return False
pci_ignore_fields = base.NovaPersistentObject.fields.keys()
for name in obj_a.obj_fields:
if name in pci_ignore_fields:

View File

@ -347,6 +347,13 @@ class _TestPciDeviceObject(object):
pci_device2.instance_uuid = None
self.assertNotEqual(pci_device1, pci_device2)
def test_pci_device_not_equivalent_with_not_pci_device(self):
pci_device1 = pci_device.PciDevice.create(None, dev_dict)
self.assertNotEqual(pci_device1, None)
self.assertNotEqual(pci_device1, 'foo')
self.assertNotEqual(pci_device1, 1)
self.assertNotEqual(pci_device1, objects.PciDeviceList())
def test_claim_device(self):
self._create_fake_instance()
devobj = pci_device.PciDevice.create(None, dev_dict)