]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Drop RpcProxy usage from PluginReportStateAPI
authorRussell Bryant <rbryant@redhat.com>
Tue, 11 Nov 2014 19:23:15 +0000 (14:23 -0500)
committerRussell Bryant <rbryant@redhat.com>
Wed, 19 Nov 2014 17:18:34 +0000 (17:18 +0000)
Drop the usage of the RpcProxy compatibility class from the
PluginReportStateAPI rpc client class.  It now uses the appropriate
oslo.messaging APIs directly, instead.

Part of blueprint drop-rpc-compat.

Change-Id: I7101331a556bd0a5c8f782ae6cb4103151e6c45c

neutron/agent/rpc.py
neutron/tests/unit/test_agent_rpc.py

index 7039c21cd5daa5e28e2c77cacfb703e71d880b0b..06e3ae6d42b605deb7ee631f03b7534859b7fb45 100644 (file)
@@ -54,22 +54,19 @@ def create_consumers(endpoints, prefix, topic_details):
     return connection
 
 
-class PluginReportStateAPI(n_rpc.RpcProxy):
-    BASE_RPC_API_VERSION = '1.0'
-
+class PluginReportStateAPI(object):
     def __init__(self, topic):
-        super(PluginReportStateAPI, self).__init__(
-            topic=topic, default_version=self.BASE_RPC_API_VERSION)
+        target = messaging.Target(topic=topic, version='1.0')
+        self.client = n_rpc.get_client(target)
 
     def report_state(self, context, agent_state, use_call=False):
-        msg = self.make_msg('report_state',
-                            agent_state={'agent_state':
-                                         agent_state},
-                            time=timeutils.strtime())
-        if use_call:
-            return self.call(context, msg)
-        else:
-            return self.cast(context, msg)
+        cctxt = self.client.prepare()
+        kwargs = {
+            'agent_state': {'agent_state': agent_state},
+            'time': timeutils.strtime(),
+        }
+        method = cctxt.call if use_call else cctxt.cast
+        return method(context, 'report_state', **kwargs)
 
 
 class PluginApi(n_rpc.RpcProxy):
index c0f7e0ddd700cdd66d9a245f8870f575097f5168..e30f636b50c4792a5df10b9bf330999defb7d4a7 100644 (file)
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import contextlib
 import mock
 from oslo import messaging
 
@@ -65,32 +66,42 @@ class AgentPluginReportState(base.BaseTestCase):
         topic = 'test'
         reportStateAPI = rpc.PluginReportStateAPI(topic)
         expected_agent_state = {'agent': 'test'}
-        with mock.patch.object(reportStateAPI, 'call') as call:
+        with contextlib.nested(
+            mock.patch.object(reportStateAPI.client, 'call'),
+            mock.patch.object(reportStateAPI.client, 'cast'),
+            mock.patch.object(reportStateAPI.client, 'prepare'),
+        ) as (
+            mock_call, mock_cast, mock_prepare
+        ):
+            mock_prepare.return_value = reportStateAPI.client
             ctxt = context.RequestContext('fake_user', 'fake_project')
             reportStateAPI.report_state(ctxt, expected_agent_state,
                                         use_call=True)
-            self.assertEqual(call.call_args[0][0], ctxt)
-            self.assertEqual(call.call_args[0][1]['method'],
-                             'report_state')
-            self.assertEqual(call.call_args[0][1]['args']['agent_state'],
+            self.assertEqual(mock_call.call_args[0][0], ctxt)
+            self.assertEqual(mock_call.call_args[0][1], 'report_state')
+            self.assertEqual(mock_call.call_args[1]['agent_state'],
                              {'agent_state': expected_agent_state})
-            self.assertIsInstance(call.call_args[0][1]['args']['time'],
-                                  str)
+            self.assertIsInstance(mock_call.call_args[1]['time'], str)
 
     def test_plugin_report_state_cast(self):
         topic = 'test'
         reportStateAPI = rpc.PluginReportStateAPI(topic)
         expected_agent_state = {'agent': 'test'}
-        with mock.patch.object(reportStateAPI, 'cast') as cast:
+        with contextlib.nested(
+            mock.patch.object(reportStateAPI.client, 'call'),
+            mock.patch.object(reportStateAPI.client, 'cast'),
+            mock.patch.object(reportStateAPI.client, 'prepare'),
+        ) as (
+            mock_call, mock_cast, mock_prepare
+        ):
+            mock_prepare.return_value = reportStateAPI.client
             ctxt = context.RequestContext('fake_user', 'fake_project')
             reportStateAPI.report_state(ctxt, expected_agent_state)
-            self.assertEqual(cast.call_args[0][0], ctxt)
-            self.assertEqual(cast.call_args[0][1]['method'],
-                             'report_state')
-            self.assertEqual(cast.call_args[0][1]['args']['agent_state'],
+            self.assertEqual(mock_cast.call_args[0][0], ctxt)
+            self.assertEqual(mock_cast.call_args[0][1], 'report_state')
+            self.assertEqual(mock_cast.call_args[1]['agent_state'],
                              {'agent_state': expected_agent_state})
-            self.assertIsInstance(cast.call_args[0][1]['args']['time'],
-                                  str)
+            self.assertIsInstance(mock_cast.call_args[1]['time'], str)
 
 
 class AgentRPCMethods(base.BaseTestCase):