Merge "ProviderTree.has_inventory_changed for new fields"

This commit is contained in:
Zuul 2018-05-19 01:38:30 +00:00 committed by Gerrit Code Review
commit f594003ddd
2 changed files with 15 additions and 4 deletions

View File

@ -128,12 +128,17 @@ class _Provider(object):
return True
for key, cur_rec in cur.items():
new_rec = new[key]
# If the new record contains new fields (e.g. we're adding on
# `reserved` or `allocation_ratio`) we want to make sure to pick
# them up
if set(new_rec) - set(cur_rec):
return True
for rec_key, cur_val in cur_rec.items():
if rec_key not in new_rec:
# Deliberately don't want to compare missing keys in the
# inventory record. For instance, we will be passing in
# fields like allocation_ratio in the current dict but the
# resource tracker may only pass in the total field. We
# *new* inventory record. For instance, we will be passing
# in fields like allocation_ratio in the current dict but
# the resource tracker may only pass in the total field. We
# want to return that inventory didn't change when the
# total field values are the same even if the
# allocation_ratio field is missing from the new record.

View File

@ -440,7 +440,6 @@ class TestProviderTree(test.NoDBTestCase):
cn_inv = {
'VCPU': {
'total': 8,
'reserved': 0,
'min_unit': 1,
'max_unit': 8,
'step_size': 1,
@ -500,6 +499,13 @@ class TestProviderTree(test.NoDBTestCase):
self.assertTrue(pt.update_inventory(cn.uuid, cn_inv,
generation=rp_gen))
# ...but *adding* a key in the new record *should* result in changes
# being recorded
cn_inv['VCPU']['reserved'] = 0
self.assertTrue(pt.has_inventory_changed(cn.uuid, cn_inv))
self.assertTrue(pt.update_inventory(cn.uuid, cn_inv,
generation=rp_gen))
def test_have_traits_changed_no_existing_rp(self):
pt = self._pt_with_cns()
self.assertRaises(