Skip to content

Commit fa77480

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add debug logging when Instance raises OrphanedObjectError" into stable/yoga
2 parents de928ad + 8aa6723 commit fa77480

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

nova/objects/instance.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,11 @@ def clear_numa_topology(self):
10891089
def obj_load_attr(self, attrname):
10901090
# NOTE(danms): We can't lazy-load anything without a context and a uuid
10911091
if not self._context:
1092+
if 'uuid' in self:
1093+
LOG.debug(
1094+
"Lazy-load of '%s' attempted by orphaned instance",
1095+
attrname, instance=self
1096+
)
10921097
raise exception.OrphanedObjectError(method='obj_load_attr',
10931098
objtype=self.obj_name())
10941099
if 'uuid' not in self:

nova/tests/unit/objects/test_instance.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,21 @@ def test_save_objectfield_reraises_if_not_instance_related(self):
16321632
self._test_save_objectfield_fk_constraint_fails(
16331633
'other_foreign_key', db_exc.DBReferenceError)
16341634

1635+
@mock.patch('nova.objects.instance.LOG.debug')
1636+
def test_obj_load_attr_log(self, mock_log_debug):
1637+
# Instance with no UUID should not log.
1638+
instance = objects.Instance()
1639+
self.assertRaises(
1640+
exception.OrphanedObjectError, instance.obj_load_attr, 'foo')
1641+
mock_log_debug.assert_not_called()
1642+
# Instance with UUID should log.
1643+
instance = objects.Instance(
1644+
uuid='127a0d59-b88c-422b-b9a1-2dc7cc51fb9a')
1645+
self.assertRaises(
1646+
exception.OrphanedObjectError, instance.obj_load_attr, 'foo')
1647+
msg = "Lazy-load of '%s' attempted by orphaned instance"
1648+
mock_log_debug.assert_called_once_with(msg, 'foo', instance=instance)
1649+
16351650

16361651
class TestRemoteInstanceObject(test_objects._RemoteTest,
16371652
_TestInstanceObject):

0 commit comments

Comments
 (0)