summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2015-10-06 10:58:18 -0700
committerDan Smith <dansmith@redhat.com>2015-10-07 07:40:52 -0700
commiteda3029aa74932f421d2992ac24f5ac3c92f347c (patch)
tree4b03d56c551d7ff1789e84ad51f9b05107b6da6d
parent96b2236369dbb89faf2f3d39aadb3cba05c8f4f4 (diff)
downloadnova-eda3029aa74932f421d2992ac24f5ac3c92f347c.tar.gz
Fix InstanceV1 backports to use context
This fixes the InstanceV1 and InstanceListV1 backport code to properly initialize the temporary objects with a context. Without them, the objects are orphaned and can't do certain things. This should be backported to liberty Closes-Bug: #1503708 Change-Id: I537734c0f10110ac64799cc1232edbc18a16c794 (cherry picked from commit e571d88604353a0443ae4ca24e3ce72fb4c615f2)
-rw-r--r--nova/objects/instance.py6
-rw-r--r--nova/tests/unit/objects/test_instance.py13
2 files changed, 17 insertions, 2 deletions
diff --git a/nova/objects/instance.py b/nova/objects/instance.py
index ccdbd5f5ad..3169a945ae 100644
--- a/nova/objects/instance.py
+++ b/nova/objects/instance.py
@@ -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)
diff --git a/nova/tests/unit/objects/test_instance.py b/nova/tests/unit/objects/test_instance.py
index 8ab1c6925c..93b537ebda 100644
--- a/nova/tests/unit/objects/test_instance.py
+++ b/nova/tests/unit/objects/test_instance.py
@@ -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):