Merge "Handle unregistered nested objects"
This commit is contained in:
commit
79b3d5bb5a
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue