Merge "Fix InstanceV1 backports to use context" into stable/liberty

This commit is contained in:
Jenkins 2015-10-08 16:16:40 +00:00 committed by Gerrit Code Review
commit ba6fccc794
2 changed files with 17 additions and 2 deletions

View File

@ -1074,7 +1074,8 @@ class InstanceV2(_BaseInstance):
# FIXME(danms): Remove this when we drop v1.x compatibility
my_prim = self.obj_to_primitive()
my_prim['nova_object.version'] = InstanceV1.VERSION
instv1 = InstanceV1.obj_from_primitive(my_prim)
instv1 = InstanceV1.obj_from_primitive(my_prim,
context=self._context)
return instv1.obj_make_compatible(primitive, target_version)
super(InstanceV2, self).obj_make_compatible(primitive, target_version)
@ -1317,7 +1318,8 @@ class InstanceListV2(_BaseInstanceList):
if target_version.startswith('1.'):
my_prim = self.obj_to_primitive()
my_prim['nova_object.version'] = InstanceListV1.VERSION
instv1 = InstanceListV1.obj_from_primitive(my_prim)
instv1 = InstanceListV1.obj_from_primitive(my_prim,
context=self._context)
return instv1.obj_make_compatible(primitive, target_version)
super(InstanceListV2, self).obj_make_compatible(primitive,
target_version)

View File

@ -1394,6 +1394,19 @@ class TestInstanceV1RemoteObject(test_objects._RemoteTest,
self.assertIsInstance(list1[0], instance.InstanceV1)
self.assertEqual(list2[0].uuid, list1[0].uuid)
def test_backport_v2_to_v1_uses_context(self):
inst2 = instance.InstanceV2(context=self.context)
with mock.patch.object(instance.InstanceV1, 'obj_from_primitive') as m:
inst2.obj_make_compatible({}, '1.0')
m.assert_called_once_with(mock.ANY, context=self.context)
def test_backport_list_v2_to_v1_uses_context(self):
list2 = instance.InstanceListV2(context=self.context)
with mock.patch.object(instance.InstanceListV1,
'obj_from_primitive') as m:
list2.obj_make_compatible({}, '1.0')
m.assert_called_once_with(mock.ANY, context=self.context)
class _TestInstanceListObject(object):
def fake_instance(self, id, updates=None):