Skip to content

Commit

Permalink
Fix Nova's indirection fixture override
Browse files Browse the repository at this point in the history
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 1b3fbfb)
  • Loading branch information
kk7ds committed Nov 17, 2015
1 parent d3fe7e4 commit 0ff44c9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
5 changes: 3 additions & 2 deletions nova/tests/unit/objects/test_instance.py
Expand Up @@ -324,12 +324,13 @@ def _save_test_helper(self, cell_type, save_kwargs):
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())

Expand Down
41 changes: 35 additions & 6 deletions nova/tests/unit/objects/test_objects.py
Expand Up @@ -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(
Expand Down Expand Up @@ -348,6 +351,23 @@ def object_class_action(self, context, objname, objmethod, objver,
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):
Expand Down Expand Up @@ -892,13 +912,19 @@ def test_set_defaults_not_overwrite(self):


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)

Expand All @@ -907,8 +933,11 @@ def test_minor_version_less(self):
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)

Expand Down

0 comments on commit 0ff44c9

Please sign in to comment.