Fix crashing during guest config with pci_devices=None

The Instance.pci_devices field is nullable, but the get_instance_pci_devs()
function does not account for that. If it is passed an instance (from an
older deployment) with no pci_devices, it will crash trying to iterate
None as a list.

Change-Id: I3d535e01ac31db7804347c3938c0d88a28ba67f5
Closes-Bug: #1648887
This commit is contained in:
Dan Smith 2016-12-09 13:23:44 -08:00
parent 4728c3e4fd
commit 15564eb355
2 changed files with 6 additions and 0 deletions

View File

@ -353,5 +353,7 @@ def get_instance_pci_devs(inst, request_id=None):
soft_reboot and hard_boot of 'xen' instances.
"""
pci_devices = inst.pci_devices
if pci_devices is None:
return []
return [device for device in pci_devices if
device.request_id == request_id or request_id == 'all']

View File

@ -509,3 +509,7 @@ class PciGetInstanceDevs(test.NoDBTestCase):
self.load_attr_called = False
manager.get_instance_pci_devs(objects.Instance())
self.assertTrue(self.load_attr_called)
def test_get_devs_no_pci_devices(self):
inst = objects.Instance(pci_devices=None)
self.assertEqual([], manager.get_instance_pci_devs(inst))