Skip to content

Commit

Permalink
Lazy-load instance attributes with read_deleted=yes
Browse files Browse the repository at this point in the history
If we're doing a lazy-load of a generic attribute on instance, we
should be using read_deleted=yes. Otherwise we just fail in the load
process which is confusing and not helpful to a cleanup routine that
needs to handle the deleted instance. This makes us load those things
with read_deleted=yes.

Change-Id: Ide6cc5bb1fce2c9aea9fa3efdf940e8308cd9ed0
Closes-Bug: #1745977
  • Loading branch information
kk7ds committed Feb 13, 2018
1 parent fba4161 commit 6ba8a35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions nova/objects/instance.py
Expand Up @@ -855,9 +855,10 @@ def refresh(self, use_slave=False):
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):
Expand Down
16 changes: 16 additions & 0 deletions nova/tests/unit/objects/test_instance.py
Expand Up @@ -220,6 +220,22 @@ def test_lazy_load_tags_on_deleted_instance(self):
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,
Expand Down

1 comment on commit 6ba8a35

@FionaLi1990
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kk7ds
This commit introduces a bug。Bug have been submmited at https://bugs.launchpad.net/nova/+bug/1941851。Please review,thank you!

Please sign in to comment.