Merge "Instance object incorrectly handles None info_cache"

This commit is contained in:
Jenkins 2013-09-24 03:01:48 +00:00 committed by Gerrit Code Review
commit f6197c4c11
2 changed files with 23 additions and 8 deletions

View File

@ -221,6 +221,8 @@ class Instance(base.NovaPersistentObject, base.NovaObject):
_attr_terminated_at_from_primitive = obj_utils.dt_deserializer
def _attr_info_cache_from_primitive(self, val):
if val is None:
return val
return base.NovaObject.obj_from_primitive(val)
def _attr_security_groups_from_primitive(self, val):
@ -265,14 +267,14 @@ class Instance(base.NovaPersistentObject, base.NovaObject):
context, pci_device.PciDeviceList(),
db_inst['pci_devices'])
instance['pci_devices'] = pci_devices
# NOTE(danms): info_cache and security_groups are almost
# always joined in the DB layer right now, so check to see if
# they are asked for and are present in the resulting object
if 'info_cache' in expected_attrs and db_inst.get('info_cache'):
instance['info_cache'] = instance_info_cache.InstanceInfoCache()
instance_info_cache.InstanceInfoCache._from_db_object(
context, instance['info_cache'], db_inst['info_cache'])
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.InstanceInfoCache._from_db_object(
context, info_cache, db_inst['info_cache'])
instance['info_cache'] = info_cache
if 'security_groups' in expected_attrs:
sec_groups = security_group._make_secgroup_list(
context, security_group.SecurityGroupList(),

View File

@ -366,6 +366,19 @@ class _TestInstanceObject(object):
inst.info_cache.network_info = nwinfo2
inst.save()
def test_with_info_cache_none(self):
fake_inst = dict(self.fake_instance, info_cache=None)
fake_uuid = fake_inst['uuid']
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
# NOTE(comstud): info_cache is always joined right now
db.instance_get_by_uuid(self.context, fake_uuid,
columns_to_join=[]
).AndReturn(fake_inst)
self.mox.ReplayAll()
inst = instance.Instance.get_by_uuid(self.context, fake_uuid,
['info_cache'])
self.assertEqual(None, inst.info_cache)
def test_with_security_groups(self):
fake_inst = dict(self.fake_instance)
fake_uuid = fake_inst['uuid']