Merge "Allow saving empty pci_device_pools in ComputeNode object"
This commit is contained in:
commit
4045934e75
@ -219,7 +219,9 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject,
|
||||
compute['supported_hv_specs'] = hv_specs
|
||||
|
||||
pci_stats = db_compute.get('pci_stats')
|
||||
compute.pci_device_pools = pci_device_pool.from_pci_stats(pci_stats)
|
||||
if pci_stats is not None:
|
||||
pci_stats = pci_device_pool.from_pci_stats(pci_stats)
|
||||
compute.pci_device_pools = pci_stats
|
||||
compute._context = context
|
||||
|
||||
# Make sure that we correctly set the host field depending on either
|
||||
@ -299,9 +301,11 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject,
|
||||
|
||||
@staticmethod
|
||||
def _convert_pci_stats_to_db_format(updates):
|
||||
pools = updates.pop('pci_device_pools', None)
|
||||
if pools:
|
||||
updates['pci_stats'] = jsonutils.dumps(pools.obj_to_primitive())
|
||||
if 'pci_device_pools' in updates:
|
||||
pools = updates.pop('pci_device_pools')
|
||||
if pools is not None:
|
||||
pools = jsonutils.dumps(pools.obj_to_primitive())
|
||||
updates['pci_stats'] = pools
|
||||
|
||||
@base.remotable
|
||||
def create(self):
|
||||
|
@ -135,8 +135,11 @@ class _TestComputeNodeObject(object):
|
||||
self.assertJsonEqual(expected, obj_val)
|
||||
|
||||
def pci_device_pools_comparator(self, expected, obj_val):
|
||||
if obj_val is not None:
|
||||
obj_val = obj_val.obj_to_primitive()
|
||||
self.assertJsonEqual(expected, obj_val)
|
||||
else:
|
||||
self.assertEqual(expected, obj_val)
|
||||
|
||||
def comparators(self):
|
||||
return {'stats': self.assertJsonEqual,
|
||||
@ -314,6 +317,44 @@ class _TestComputeNodeObject(object):
|
||||
self.assertEqual(uuidsentinel.fake_compute_node, obj.uuid)
|
||||
self.assertFalse(mock_gu.called)
|
||||
|
||||
def test_save_pci_device_pools_empty(self):
|
||||
fake_pci = jsonutils.dumps(
|
||||
objects.PciDevicePoolList(objects=[]).obj_to_primitive())
|
||||
compute_dict = fake_compute_node.copy()
|
||||
compute_dict['pci_stats'] = fake_pci
|
||||
|
||||
with mock.patch.object(
|
||||
db, 'compute_node_update',
|
||||
return_value=compute_dict) as mock_compute_node_update:
|
||||
compute = compute_node.ComputeNode(context=self.context)
|
||||
compute.id = 123
|
||||
compute.pci_device_pools = objects.PciDevicePoolList(objects=[])
|
||||
compute.save()
|
||||
self.compare_obj(compute, compute_dict,
|
||||
subs=self.subs(),
|
||||
comparators=self.comparators())
|
||||
|
||||
mock_compute_node_update.assert_called_once_with(
|
||||
self.context, 123, {'pci_stats': fake_pci})
|
||||
|
||||
def test_save_pci_device_pools_null(self):
|
||||
compute_dict = fake_compute_node.copy()
|
||||
compute_dict['pci_stats'] = None
|
||||
|
||||
with mock.patch.object(
|
||||
db, 'compute_node_update',
|
||||
return_value=compute_dict) as mock_compute_node_update:
|
||||
compute = compute_node.ComputeNode(context=self.context)
|
||||
compute.id = 123
|
||||
compute.pci_device_pools = None
|
||||
compute.save()
|
||||
self.compare_obj(compute, compute_dict,
|
||||
subs=self.subs(),
|
||||
comparators=self.comparators())
|
||||
|
||||
mock_compute_node_update.assert_called_once_with(
|
||||
self.context, 123, {'pci_stats': None})
|
||||
|
||||
@mock.patch.object(db, 'compute_node_create',
|
||||
return_value=fake_compute_node)
|
||||
def test_set_id_failure(self, db_mock):
|
||||
|
Loading…
Reference in New Issue
Block a user