Skip to content

Commit 9e84562

Browse files
committed
Add debug logging when Instance raises OrphanedObjectError
This logging would be helpful in debugging issues when OrphanedObjectError is raised by an instance. Currently, there is not a way to identify which instance is attempting to lazy-load a field while orphaned. Being able to locate the instance in the database could also help with recovery/cleanup when a problematic record is disrupting operation of a deployment. Change-Id: I093de2839c1bb7c949a0812e07b63de4cc5ed167 (cherry picked from commit e0fbb6f) (cherry picked from commit f32deaa)
1 parent 77db642 commit 9e84562

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
@@ -1090,6 +1090,11 @@ def clear_numa_topology(self):
10901090
def obj_load_attr(self, attrname):
10911091
# NOTE(danms): We can't lazy-load anything without a context and a uuid
10921092
if not self._context:
1093+
if 'uuid' in self:
1094+
LOG.debug(
1095+
"Lazy-load of '%s' attempted by orphaned instance",
1096+
attrname, instance=self
1097+
)
10931098
raise exception.OrphanedObjectError(method='obj_load_attr',
10941099
objtype=self.obj_name())
10951100
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
@@ -1633,6 +1633,21 @@ def test_save_objectfield_reraises_if_not_instance_related(self):
16331633
self._test_save_objectfield_fk_constraint_fails(
16341634
'other_foreign_key', db_exc.DBReferenceError)
16351635

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

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

0 commit comments

Comments
 (0)