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. Change-Id: I2aaa42784b2cc5c6898a3fac0c951dd57dd4f4c6 Closes-Bug: #1516805
This commit is contained in:
@@ -307,6 +307,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(
|
||||
@@ -345,6 +348,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):
|
||||
@@ -889,13 +909,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)
|
||||
|
||||
@@ -904,8 +930,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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user