From 0ff44c9d50bbe01e23bc9699e1aaab3ddfaaa0eb Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 16 Nov 2015 14:46:16 -0800 Subject: [PATCH] Fix Nova's indirection fixture override This mirrors the indirection fixture override that we have for object_class_action() while we transition fully to the base VersionedObjectRegistry. This prevents us from breaking with current oslo.versionedobjects. This also caused a few other tests to get run with manifest calls, which needed to be converted to continue to work. Also, because liberty still has both InstanceV1 and InstanceV2, this tickled another case where we need to use the instance base class for a mox.IsA() check. Change-Id: I2aaa42784b2cc5c6898a3fac0c951dd57dd4f4c6 Closes-Bug: #1516805 (cherry picked from commit 1b3fbfb087998633ea66db223c0f7c201f69e49a) --- nova/tests/unit/objects/test_instance.py | 5 +-- nova/tests/unit/objects/test_objects.py | 41 ++++++++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/nova/tests/unit/objects/test_instance.py b/nova/tests/unit/objects/test_instance.py index 93b537ebdadb..08a98c27b404 100644 --- a/nova/tests/unit/objects/test_instance.py +++ b/nova/tests/unit/objects/test_instance.py @@ -324,12 +324,13 @@ class _TestInstanceObject(object): if cell_type == 'api': cells_rpcapi.CellsAPI().AndReturn(cells_api_mock) cells_api_mock.instance_update_from_api( - self.context, mox.IsA(objects.Instance), + self.context, mox.IsA(instance._BaseInstance), exp_vm_state, exp_task_state, admin_reset) elif cell_type == 'compute': cells_rpcapi.CellsAPI().AndReturn(cells_api_mock) cells_api_mock.instance_update_at_top(self.context, - mox.IsA(objects.Instance)) + mox.IsA( + instance._BaseInstance)) notifications.send_update(self.context, mox.IgnoreArg(), mox.IgnoreArg()) diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py index 8284cf9fc144..fe3182631d07 100644 --- a/nova/tests/unit/objects/test_objects.py +++ b/nova/tests/unit/objects/test_objects.py @@ -310,6 +310,9 @@ def things_temporarily_local(): base.NovaObject.indirection_api = _api +# FIXME(danms): We shouldn't be overriding any of this, but need to +# for the moment because of the mocks in the base fixture that don't +# hit our registry subclass. class FakeIndirectionHack(fixture.FakeIndirectionAPI): def object_action(self, context, objinst, objmethod, args, kwargs): objinst = self._ser.deserialize_entity( @@ -348,6 +351,23 @@ class FakeIndirectionHack(fixture.FakeIndirectionAPI): context=context) if isinstance(result, base.NovaObject) else result) + def object_class_action_versions(self, context, objname, objmethod, + object_versions, args, kwargs): + objname = six.text_type(objname) + objmethod = six.text_type(objmethod) + object_versions = {six.text_type(o): six.text_type(v) + for o, v in object_versions.items()} + args, kwargs = self._canonicalize_args(context, args, kwargs) + objver = object_versions[objname] + cls = base.NovaObject.obj_class_from_name(objname, objver) + with mock.patch('nova.objects.base.NovaObject.' + 'indirection_api', new=None): + result = getattr(cls, objmethod)(context, *args, **kwargs) + return (base.NovaObject.obj_from_primitive( + result.obj_to_primitive(target_version=objver), + context=context) + if isinstance(result, base.NovaObject) else result) + class IndirectionFixture(fixtures.Fixture): def setUp(self): @@ -892,13 +912,19 @@ class TestObject(_LocalTest, _TestObject): class TestRemoteObject(_RemoteTest, _TestObject): - def test_major_version_mismatch(self): - MyObj2.VERSION = '2.0' + @mock.patch('oslo_versionedobjects.base.obj_tree_get_versions') + def test_major_version_mismatch(self, mock_otgv): + mock_otgv.return_value = { + 'MyObj': '2.0', + } self.assertRaises(ovo_exc.IncompatibleObjectVersion, MyObj2.query, self.context) - def test_minor_version_greater(self): - MyObj2.VERSION = '1.7' + @mock.patch('oslo_versionedobjects.base.obj_tree_get_versions') + def test_minor_version_greater(self, mock_otgv): + mock_otgv.return_value = { + 'MyObj': '1.7', + } self.assertRaises(ovo_exc.IncompatibleObjectVersion, MyObj2.query, self.context) @@ -907,8 +933,11 @@ class TestRemoteObject(_RemoteTest, _TestObject): obj = MyObj2.query(self.context) self.assertEqual(obj.bar, 'bar') - def test_compat(self): - MyObj2.VERSION = '1.1' + @mock.patch('oslo_versionedobjects.base.obj_tree_get_versions') + def test_compat(self, mock_otgv): + mock_otgv.return_value = { + 'MyObj': '1.1', + } obj = MyObj2.query(self.context) self.assertEqual('oldbar', obj.bar)