Merge "Lazy-load instance attributes with read_deleted=yes" into stable/queens

This commit is contained in:
Zuul 2018-02-22 08:18:23 +00:00 committed by Gerrit Code Review
commit 6a4b07826e
2 changed files with 20 additions and 3 deletions

View File

@ -855,9 +855,10 @@ class Instance(base.NovaPersistentObject, base.NovaObject,
self.obj_reset_changes()
def _load_generic(self, attrname):
instance = self.__class__.get_by_uuid(self._context,
uuid=self.uuid,
expected_attrs=[attrname])
with utils.temporary_mutation(self._context, read_deleted='yes'):
instance = self.__class__.get_by_uuid(self._context,
uuid=self.uuid,
expected_attrs=[attrname])
# NOTE(danms): Never allow us to recursively-load
if instance.obj_attr_is_set(attrname):

View File

@ -220,6 +220,22 @@ class _TestInstanceObject(object):
deleted=True)
self.assertEqual(0, len(instance.tags))
def test_lazy_load_generic_on_deleted_instance(self):
# For generic fields, we try to load the deleted record from the
# database.
instance = objects.Instance(self.context, uuid=uuids.instance,
user_id=self.context.user_id,
project_id=self.context.project_id)
instance.create()
instance.destroy()
# Re-create our local object to make sure it doesn't have sysmeta
# filled in by create()
instance = objects.Instance(self.context, uuid=uuids.instance,
user_id=self.context.user_id,
project_id=self.context.project_id)
self.assertNotIn('system_metadata', instance)
self.assertEqual(0, len(instance.system_metadata))
def test_lazy_load_tags(self):
instance = objects.Instance(self.context, uuid=uuids.instance,
user_id=self.context.user_id,