Lazy-load instance attributes with read_deleted=yes
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
This commit is contained in:
parent
fba4161f71
commit
6ba8a35825
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue