Return empty PciDevicePoolList obj instead of None
If a ComputeNode object has its pci_device_pools field set to an empty PciDevicePoolList object and then that node object is saved via the save() method, the pci_device_pools field of the same object is changed to None due to the from_pci_stats() returning None if pci_stats is None. The fix is to return an empty PciDevicePoolList instead of None, ensuring that calling save() does not have this unintended side effect. Closes-Bug: #1492342 Change-Id: I7b5a3ed24d137646579fc4534c71a2bc6baa8ca6
This commit is contained in:
parent
69f1a7a1fa
commit
8df3810ca0
@ -87,7 +87,7 @@ def from_pci_stats(pci_stats):
|
||||
which can be either the serialized object, or, prior to the creation of the
|
||||
device pool objects, a simple dict or a list of such dicts.
|
||||
"""
|
||||
pools = None
|
||||
pools = []
|
||||
if isinstance(pci_stats, six.string_types):
|
||||
try:
|
||||
pci_stats = jsonutils.loads(pci_stats)
|
||||
@ -96,13 +96,12 @@ def from_pci_stats(pci_stats):
|
||||
if pci_stats:
|
||||
# Check for object-ness, or old-style storage format.
|
||||
if 'nova_object.namespace' in pci_stats:
|
||||
pools = objects.PciDevicePoolList.obj_from_primitive(pci_stats)
|
||||
return objects.PciDevicePoolList.obj_from_primitive(pci_stats)
|
||||
else:
|
||||
# This can be either a dict or a list of dicts
|
||||
if isinstance(pci_stats, list):
|
||||
pool_list = [objects.PciDevicePool.from_dict(stat)
|
||||
for stat in pci_stats]
|
||||
pools = [objects.PciDevicePool.from_dict(stat)
|
||||
for stat in pci_stats]
|
||||
else:
|
||||
pool_list = [objects.PciDevicePool.from_dict(pci_stats)]
|
||||
pools = objects.PciDevicePoolList(objects=pool_list)
|
||||
return pools
|
||||
pools = [objects.PciDevicePool.from_dict(pci_stats)]
|
||||
return objects.PciDevicePoolList(objects=pools)
|
||||
|
@ -708,8 +708,11 @@ class TrackerTestCase(BaseTrackerTestCase):
|
||||
self.assertFalse(self.tracker.disabled)
|
||||
self.assertEqual(0, self.tracker.compute_node.current_workload)
|
||||
expected = pci_device_pool.from_pci_stats(driver.pci_stats)
|
||||
self.assertEqual(expected,
|
||||
self.tracker.compute_node.pci_device_pools)
|
||||
self.assertEqual(len(expected),
|
||||
len(self.tracker.compute_node.pci_device_pools))
|
||||
for expected_pool, actual_pool in zip(
|
||||
expected, self.tracker.compute_node.pci_device_pools):
|
||||
self.assertEqual(expected_pool, actual_pool)
|
||||
|
||||
def test_set_instance_host_and_node(self):
|
||||
inst = objects.Instance()
|
||||
|
@ -109,4 +109,4 @@ class TestConvertPciStats(test.NoDBTestCase):
|
||||
def test_from_pci_stats_bad(self):
|
||||
prim = "not a valid json string for an object"
|
||||
pools = pci_device_pool.from_pci_stats(prim)
|
||||
self.assertIsNone(pools)
|
||||
self.assertEqual(len(pools), 0)
|
||||
|
Loading…
Reference in New Issue
Block a user