Allow calling obj_to_primitive() with version_manifest

When we call obj_to_primitive() on an object, we need to be able to
pass in the version_manifest so that the backport happens according
to those versions. This merely adds an optional argument which, if
present, calls the new interface.

Change-Id: I016a8061825507751168b6a59e092c9db5b0b19f
This commit is contained in:
Dan Smith
2015-08-26 07:26:44 -07:00
parent aba1089fab
commit 00c503efbb
2 changed files with 11 additions and 2 deletions

View File

@@ -502,7 +502,7 @@ class VersionedObject(object):
finally:
delattr(self, '_obj_version_manifest')
def obj_to_primitive(self, target_version=None):
def obj_to_primitive(self, target_version=None, version_manifest=None):
"""Simple base-case dehydration.
This calls to_primitive() for each item in fields.
@@ -518,7 +518,9 @@ class VersionedObject(object):
primitive[name] = field.to_primitive(self, name,
getattr(self, name))
if target_version != self.VERSION:
self.obj_make_compatible(primitive, target_version)
self.obj_make_compatible_from_manifest(primitive,
target_version,
version_manifest)
obj = {self._obj_primitive_key('name'): self.obj_name(),
self._obj_primitive_key('namespace'): (
self.OBJ_PROJECT_NAMESPACE),

View File

@@ -417,6 +417,13 @@ class TestDoSubobjectBackport(test.TestCase):
"have been called because the subobject is "
"None.")
def test_to_primitive_calls_make_compatible_manifest(self):
obj = self.ParentObj()
with mock.patch.object(obj, 'obj_make_compatible_from_manifest') as m:
obj.obj_to_primitive(target_version='1.0',
version_manifest=mock.sentinel.manifest)
m.assert_called_once_with(mock.ANY, '1.0', mock.sentinel.manifest)
def compare_obj(test, obj, db_obj, subs=None, allow_missing=None,
comparators=None):