Merge "Make instance.refresh() avoid recursion better" into stable/queens

This commit is contained in:
Zuul 2018-05-20 23:57:16 +00:00 committed by Gerrit Code Review
commit 445b9f8bfe
2 changed files with 15 additions and 6 deletions

View File

@ -847,11 +847,20 @@ class Instance(base.NovaPersistentObject, base.NovaObject,
current._context = None
for field in self.fields:
if self.obj_attr_is_set(field):
if field == 'info_cache':
self.info_cache.refresh()
elif self[field] != current[field]:
self[field] = current[field]
if field not in self:
continue
if field not in current:
# If the field isn't in current we should not
# touch it, triggering a likely-recursive lazy load.
# Log it so we can see it happening though, as it
# probably isn't expected in most cases.
LOG.debug('Field %s is set but not in refreshed '
'instance, skipping', field)
continue
if field == 'info_cache':
self.info_cache.refresh()
elif self[field] != current[field]:
self[field] = current[field]
self.obj_reset_changes()
def _load_generic(self, attrname):

View File

@ -380,7 +380,7 @@ class _TestInstanceObject(object):
mock_get.return_value = inst_copy
self.assertRaises(exception.OrphanedObjectError, inst.refresh)
inst.refresh()
mock_get.assert_called_once_with(self.context, uuid=inst.uuid,
expected_attrs=['metadata'], use_slave=False)