From 1171e25d1d80ee02cb1a86fa4d9e442e3633115d Mon Sep 17 00:00:00 2001 From: Lin Tan Date: Fri, 4 Dec 2015 15:45:48 +0800 Subject: [PATCH] Correct NotImplemented to NotImplementedError in rpcapi.py NotImplemented will not return any useful info to end-user. This should be NotImplementedError. Change-Id: I4402a1f4f5fd47fd7230359a5c2eb03123f993fa Close-Bug: #1524163 --- ironic/conductor/rpcapi.py | 24 +++++++++------ ironic/tests/unit/conductor/test_rpcapi.py | 29 +++++++++++++++++++ ...mentederror-misspell-276a181afd652cf6.yaml | 7 +++++ 3 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/notimplementederror-misspell-276a181afd652cf6.yaml diff --git a/ironic/conductor/rpcapi.py b/ironic/conductor/rpcapi.py index fbd1105800..9f7d8f3f03 100644 --- a/ironic/conductor/rpcapi.py +++ b/ironic/conductor/rpcapi.py @@ -606,13 +606,15 @@ class ConductorAPI(object): :param object_versions: A dict of {objname: version} mappings :param args: The positional arguments to the action method :param kwargs: The keyword arguments to the action method - :raises: NotImplemented when an operator makes an error during upgrade + :raises: NotImplementedError when an operator makes an error during + upgrade :returns: The result of the action method, which may (or may not) be an instance of the implementing VersionedObject class. """ if not self.client.can_send_version('1.31'): - raise NotImplemented(_('Incompatible conductor version - ' - 'please upgrade ironic-conductor first')) + raise NotImplementedError(_('Incompatible conductor version - ' + 'please upgrade ironic-conductor ' + 'first')) cctxt = self.client.prepare(topic=self.topic, version='1.31') return cctxt.call(context, 'object_class_action_versions', objname=objname, objmethod=objmethod, @@ -630,13 +632,15 @@ class ConductorAPI(object): :param objmethod: The name of the action method to call :param args: The positional arguments to the action method :param kwargs: The keyword arguments to the action method - :raises: NotImplemented when an operator makes an error during upgrade + :raises: NotImplementedError when an operator makes an error during + upgrade :returns: A tuple with the updates made to the object and the result of the action method """ if not self.client.can_send_version('1.31'): - raise NotImplemented(_('Incompatible conductor version - ' - 'please upgrade ironic-conductor first')) + raise NotImplementedError(_('Incompatible conductor version - ' + 'please upgrade ironic-conductor ' + 'first')) cctxt = self.client.prepare(topic=self.topic, version='1.31') return cctxt.call(context, 'object_action', objinst=objinst, objmethod=objmethod, args=args, kwargs=kwargs) @@ -654,12 +658,14 @@ class ConductorAPI(object): :param context: The context within which to perform the backport :param objinst: An instance of a VersionedObject to be backported :param object_versions: A dict of {objname: version} mappings - :raises: NotImplemented when an operator makes an error during upgrade + :raises: NotImplementedError when an operator makes an error during + upgrade :returns: The downgraded instance of objinst """ if not self.client.can_send_version('1.31'): - raise NotImplemented(_('Incompatible conductor version - ' - 'please upgrade ironic-conductor first')) + raise NotImplementedError(_('Incompatible conductor version - ' + 'please upgrade ironic-conductor ' + 'first')) cctxt = self.client.prepare(topic=self.topic, version='1.31') return cctxt.call(context, 'object_backport_versions', objinst=objinst, object_versions=object_versions) diff --git a/ironic/tests/unit/conductor/test_rpcapi.py b/ironic/tests/unit/conductor/test_rpcapi.py index cc993f3656..0362ef4386 100644 --- a/ironic/tests/unit/conductor/test_rpcapi.py +++ b/ironic/tests/unit/conductor/test_rpcapi.py @@ -22,6 +22,7 @@ import copy import mock from oslo_config import cfg +import oslo_messaging as messaging from oslo_messaging import _utils as messaging_utils from ironic.common import boot_devices @@ -342,3 +343,31 @@ class RPCAPITestCase(base.DbTestCase): version='1.31', objinst='fake-object', object_versions={'fake-object': '1.0'}) + + @mock.patch.object(messaging.RPCClient, 'can_send_version', autospec=True) + def test_object_action_invalid_version(self, mock_send): + rpcapi = conductor_rpcapi.ConductorAPI(topic='fake-topic') + mock_send.return_value = False + self.assertRaises(NotImplementedError, + rpcapi.object_action, self.context, + objinst='fake-object', objmethod='foo', + args=tuple(), kwargs=dict()) + + @mock.patch.object(messaging.RPCClient, 'can_send_version', autospec=True) + def test_object_class_action_versions_invalid_version(self, mock_send): + rpcapi = conductor_rpcapi.ConductorAPI(topic='fake-topic') + mock_send.return_value = False + self.assertRaises(NotImplementedError, + rpcapi.object_class_action_versions, self.context, + objname='fake-object', objmethod='foo', + object_versions={'fake-object': '1.0'}, + args=tuple(), kwargs=dict()) + + @mock.patch.object(messaging.RPCClient, 'can_send_version', autospec=True) + def test_object_backport_versions_invalid_version(self, mock_send): + rpcapi = conductor_rpcapi.ConductorAPI(topic='fake-topic') + mock_send.return_value = False + self.assertRaises(NotImplementedError, + rpcapi.object_backport_versions, self.context, + objinst='fake-object', + object_versions={'fake-object': '1.0'}) diff --git a/releasenotes/notes/notimplementederror-misspell-276a181afd652cf6.yaml b/releasenotes/notes/notimplementederror-misspell-276a181afd652cf6.yaml new file mode 100644 index 0000000000..b31a937a76 --- /dev/null +++ b/releasenotes/notes/notimplementederror-misspell-276a181afd652cf6.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - In conductor/rpcapi.py, object_backport_version(), + object_action() and object_class_action_versions() + misspell NotImplementedError with NotImplemented + which returns nothing useful to users. + See https://bugs.launchpad.net/ironic/+bug/1524163.