Don't replace instance.info_cache on each save
If we are working on an Instance that came from an older client, we should not replace an older nested .info_cache object with a newer one for no reason during a save(). Related-Bug: #1258256 Change-Id: I8cf4a629d454de1a5de16ea4032f39e36aab505a
This commit is contained in:
parent
8c004201fe
commit
28bd2298ba
|
@ -240,12 +240,14 @@ class Instance(base.NovaPersistentObject, base.NovaObject):
|
|||
instance['pci_devices'] = pci_devices
|
||||
if 'info_cache' in expected_attrs:
|
||||
if db_inst['info_cache'] is None:
|
||||
info_cache = None
|
||||
else:
|
||||
info_cache = instance_info_cache.InstanceInfoCache()
|
||||
instance.info_cache = None
|
||||
elif not instance.obj_attr_is_set('info_cache'):
|
||||
# TODO(danms): If this ever happens on a backlevel instance
|
||||
# passed to us by a backlevel service, things will break
|
||||
instance.info_cache = instance_info_cache.InstanceInfoCache()
|
||||
if instance.info_cache is not None:
|
||||
instance_info_cache.InstanceInfoCache._from_db_object(
|
||||
context, info_cache, db_inst['info_cache'])
|
||||
instance['info_cache'] = info_cache
|
||||
context, instance.info_cache, db_inst['info_cache'])
|
||||
if 'security_groups' in expected_attrs:
|
||||
sec_groups = security_group._make_secgroup_list(
|
||||
context, security_group.SecurityGroupList(),
|
||||
|
|
|
@ -693,6 +693,17 @@ class _TestInstanceObject(object):
|
|||
self.assertEqual('foo-%s' % db_inst['uuid'], inst.name)
|
||||
self.assertFalse(inst.obj_attr_is_set('fault'))
|
||||
|
||||
def test_from_db_object_not_overwrite_info_cache(self):
|
||||
info_cache = instance_info_cache.InstanceInfoCache()
|
||||
inst = instance.Instance(context=self.context,
|
||||
info_cache=info_cache)
|
||||
db_inst = fake_instance.fake_db_instance()
|
||||
db_inst['info_cache'] = dict(
|
||||
test_instance_info_cache.fake_info_cache)
|
||||
inst._from_db_object(self.context, inst, db_inst,
|
||||
expected_attrs=['info_cache'])
|
||||
self.assertIs(info_cache, inst.info_cache)
|
||||
|
||||
|
||||
class TestInstanceObject(test_objects._LocalTest,
|
||||
_TestInstanceObject):
|
||||
|
|
Loading…
Reference in New Issue