Browse Source

Merge "Handle unregistered nested objects"

tags/2.0.1^0
Zuul 4 months ago
committed by Gerrit Code Review
parent
commit
79b3d5bb5a
3 changed files with 26 additions and 1 deletions
  1. +5
    -1
      oslo_versionedobjects/base.py
  2. +5
    -0
      oslo_versionedobjects/exception.py
  3. +16
    -0
      oslo_versionedobjects/tests/test_objects.py

+ 5
- 1
oslo_versionedobjects/base.py View File

@@ -1147,7 +1147,11 @@ def obj_tree_get_versions(objname, tree=None):
else:
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




+ 5
- 0
oslo_versionedobjects/exception.py View File

@@ -186,3 +186,8 @@ class InvalidTargetVersion(VersionedObjectsException):

class TargetBeforeSubobjectExistedException(VersionedObjectsException):
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")

+ 16
- 0
oslo_versionedobjects/tests/test_objects.py View File

@@ -2341,6 +2341,22 @@ class TestUtilityMethods(test.TestCase):
'TestChildTwo': '4.56'},
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):
def test_list_object_concat(self):


Loading…
Cancel
Save