Merge "Handle unregistered nested objects"

This commit is contained in:
Zuul 2020-03-07 20:58:38 +00:00 committed by Gerrit Code Review
commit 79b3d5bb5a
3 changed files with 26 additions and 1 deletions

View File

@ -1147,7 +1147,11 @@ def obj_tree_get_versions(objname, tree=None):
else: else:
continue continue
obj_tree_get_versions(child_cls, tree=tree) try:
obj_tree_get_versions(child_cls, tree=tree)
except IndexError:
raise exception.UnregisteredSubobject(
child_objname=child_cls, parent_objname=objname)
return tree return tree

View File

@ -186,3 +186,8 @@ class InvalidTargetVersion(VersionedObjectsException):
class TargetBeforeSubobjectExistedException(VersionedObjectsException): class TargetBeforeSubobjectExistedException(VersionedObjectsException):
msg_fmt = _("No subobject existed at version %(target_version)s") msg_fmt = _("No subobject existed at version %(target_version)s")
class UnregisteredSubobject(VersionedObjectsException):
msg_fmt = _("%(child_objname)s is referenced by %(parent_objname)s but "
"is not registered")

View File

@ -2341,6 +2341,22 @@ class TestUtilityMethods(test.TestCase):
'TestChildTwo': '4.56'}, 'TestChildTwo': '4.56'},
tree) tree)
def test_missing_referenced(self):
"""Ensure a missing child object is highlighted."""
@base.VersionedObjectRegistry.register
class TestObjectFoo(base.VersionedObject):
VERSION = '1.23'
fields = {
# note that this object does not exist
'child': fields.ObjectField('TestChildBar'),
}
exc = self.assertRaises(exception.UnregisteredSubobject,
base.obj_tree_get_versions,
'TestObjectFoo')
self.assertIn('TestChildBar is referenced by TestObjectFoo',
exc.format_message())
class TestListObjectConcat(test.TestCase): class TestListObjectConcat(test.TestCase):
def test_list_object_concat(self): def test_list_object_concat(self):