]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Drop RpcProxy usage from FWaaS code
authorRussell Bryant <rbryant@redhat.com>
Tue, 18 Nov 2014 14:46:06 +0000 (14:46 +0000)
committerRussell Bryant <rbryant@redhat.com>
Wed, 19 Nov 2014 17:18:34 +0000 (17:18 +0000)
This patch removes the usage of the RpcProxy compatibility class from
the FWaaS code.  The equivalent direct usage of oslo.messaging APIs
are now used instead.

Part of blueprint drop-rpc-compat.

Change-Id: I1bab4dcd376d4e9684fee1edc97fd29a61ba38de

neutron/services/firewall/agents/firewall_agent_api.py
neutron/services/firewall/fwaas_plugin.py
neutron/tests/unit/services/firewall/agents/test_firewall_agent_api.py
neutron/tests/unit/services/firewall/test_fwaas_plugin.py

index 71caca8c65d0ff9abfb31852be7b565250464357..85be6e6a41699456689356672a6a332207eed31b 100644 (file)
@@ -14,6 +14,7 @@
 #    under the License.
 
 from oslo.config import cfg
+from oslo import messaging
 
 from neutron.common import rpc as n_rpc
 from neutron.openstack.common import log as logging
@@ -33,28 +34,25 @@ FWaaSOpts = [
 cfg.CONF.register_opts(FWaaSOpts, 'fwaas')
 
 
-class FWaaSPluginApiMixin(n_rpc.RpcProxy):
+class FWaaSPluginApiMixin(object):
     """Agent side of the FWaaS agent to FWaaS Plugin RPC API."""
 
-    RPC_API_VERSION = '1.0'
-
     def __init__(self, topic, host):
-        super(FWaaSPluginApiMixin,
-              self).__init__(topic=topic,
-                             default_version=self.RPC_API_VERSION)
         self.host = host
+        target = messaging.Target(topic=topic, version='1.0')
+        self.client = n_rpc.get_client(target)
 
     def set_firewall_status(self, context, firewall_id, status):
         """Make a RPC to set the status of a firewall."""
-        return self.call(context,
-                         self.make_msg('set_firewall_status', host=self.host,
-                                       firewall_id=firewall_id, status=status))
+        cctxt = self.client.prepare()
+        return cctxt.call(context, 'set_firewall_status', host=self.host,
+                          firewall_id=firewall_id, status=status)
 
     def firewall_deleted(self, context, firewall_id):
         """Make a RPC to indicate that the firewall resources are deleted."""
-        return self.call(context,
-                         self.make_msg('firewall_deleted', host=self.host,
-                                       firewall_id=firewall_id))
+        cctxt = self.client.prepare()
+        return cctxt.call(context, 'firewall_deleted', host=self.host,
+                          firewall_id=firewall_id)
 
 
 class FWaaSAgentRpcCallbackMixin(object):
index 15179f4df2295b994d6e728c80c65a26d38ebbce..e67d75aa52f07440dd232e6e1af36e0d85da99dc 100644 (file)
@@ -97,35 +97,28 @@ class FirewallCallbacks(object):
         return fw_tenant_list
 
 
-class FirewallAgentApi(n_rpc.RpcProxy):
+class FirewallAgentApi(object):
     """Plugin side of plugin to agent RPC API."""
 
-    API_VERSION = '1.0'
-
     def __init__(self, topic, host):
-        super(FirewallAgentApi, self).__init__(topic, self.API_VERSION)
         self.host = host
+        target = messaging.Target(topic=topic, version='1.0')
+        self.client = n_rpc.get_client(target)
 
     def create_firewall(self, context, firewall):
-        return self.fanout_cast(
-            context,
-            self.make_msg('create_firewall', firewall=firewall,
-                          host=self.host)
-        )
+        cctxt = self.client.prepare(fanout=True)
+        cctxt.cast(context, 'create_firewall', firewall=firewall,
+                   host=self.host)
 
     def update_firewall(self, context, firewall):
-        return self.fanout_cast(
-            context,
-            self.make_msg('update_firewall', firewall=firewall,
-                          host=self.host)
-        )
+        cctxt = self.client.prepare(fanout=True)
+        cctxt.cast(context, 'update_firewall', firewall=firewall,
+                   host=self.host)
 
     def delete_firewall(self, context, firewall):
-        return self.fanout_cast(
-            context,
-            self.make_msg('delete_firewall', firewall=firewall,
-                          host=self.host)
-        )
+        cctxt = self.client.prepare(fanout=True)
+        cctxt.cast(context, 'delete_firewall', firewall=firewall,
+                   host=self.host)
 
 
 class FirewallCountExceeded(n_exception.Conflict):
index e2891d328cfb1daee0904aa8137bb648f0499841..63266d9b0ed1aa4a45281b2646f8f101039b3075 100644 (file)
@@ -52,46 +52,26 @@ class TestFWaaSAgentApi(base.BaseTestCase):
     def test_init(self):
         self.assertEqual(self.api.host, 'host')
 
-    def test_set_firewall_status(self):
+    def _test_firewall_method(self, method_name, **kwargs):
         with contextlib.nested(
-            mock.patch.object(self.api, 'make_msg'),
-            mock.patch.object(self.api, 'call')
-        ) as (mock_make_msg, mock_call):
-
-            self.assertEqual(
-                self.api.set_firewall_status(
-                    mock.sentinel.context,
-                    'firewall_id',
-                    'status'),
-                mock_call.return_value)
-
-            mock_make_msg.assert_called_once_with(
-                'set_firewall_status',
-                host='host',
-                firewall_id='firewall_id',
-                status='status')
-
-            mock_call.assert_called_once_with(
-                mock.sentinel.context,
-                mock_make_msg.return_value)
+            mock.patch.object(self.api.client, 'call'),
+            mock.patch.object(self.api.client, 'prepare'),
+        ) as (
+            rpc_mock, prepare_mock
+        ):
+            prepare_mock.return_value = self.api.client
+            getattr(self.api, method_name)(mock.sentinel.context, 'test',
+                                           **kwargs)
+
+        prepare_args = {}
+        prepare_mock.assert_called_once_with(**prepare_args)
+
+        rpc_mock.assert_called_once_with(mock.sentinel.context, method_name,
+                                         firewall_id='test', host='host',
+                                         **kwargs)
+
+    def test_set_firewall_status(self):
+        self._test_firewall_method('set_firewall_status', status='fake_status')
 
     def test_firewall_deleted(self):
-        with contextlib.nested(
-            mock.patch.object(self.api, 'make_msg'),
-            mock.patch.object(self.api, 'call')
-        ) as (mock_make_msg, mock_call):
-
-            self.assertEqual(
-                self.api.firewall_deleted(
-                    mock.sentinel.context,
-                    'firewall_id'),
-                mock_call.return_value)
-
-            mock_make_msg.assert_called_once_with(
-                'firewall_deleted',
-                host='host',
-                firewall_id='firewall_id')
-
-            mock_call.assert_called_once_with(
-                mock.sentinel.context,
-                mock_make_msg.return_value)
+        self._test_firewall_method('firewall_deleted')
index a9f8e67298c3b02ab60ee87a75d1760bfac8ad21..dd162f04471d7e5508ece2565bf014c091943279 100644 (file)
@@ -171,27 +171,26 @@ class TestFirewallAgentApi(base.BaseTestCase):
         super(TestFirewallAgentApi, self).setUp()
 
         self.api = fwaas_plugin.FirewallAgentApi('topic', 'host')
-        self.mock_fanoutcast = mock.patch.object(self.api,
-                                                 'fanout_cast').start()
-        self.mock_msg = mock.patch.object(self.api, 'make_msg').start()
 
     def test_init(self):
-        self.assertEqual(self.api.topic, 'topic')
+        self.assertEqual(self.api.client.target.topic, 'topic')
         self.assertEqual(self.api.host, 'host')
 
     def _call_test_helper(self, method_name):
-        rv = getattr(self.api, method_name)(mock.sentinel.context, 'test')
-        self.assertEqual(rv, self.mock_fanoutcast.return_value)
-        self.mock_fanoutcast.assert_called_once_with(
-            mock.sentinel.context,
-            self.mock_msg.return_value
-        )
-
-        self.mock_msg.assert_called_once_with(
-            method_name,
-            firewall='test',
-            host='host'
-        )
+        with contextlib.nested(
+            mock.patch.object(self.api.client, 'cast'),
+            mock.patch.object(self.api.client, 'prepare'),
+        ) as (
+            rpc_mock, prepare_mock
+        ):
+            prepare_mock.return_value = self.api.client
+            getattr(self.api, method_name)(mock.sentinel.context, 'test')
+
+        prepare_args = {'fanout': True}
+        prepare_mock.assert_called_once_with(**prepare_args)
+
+        rpc_mock.assert_called_once_with(mock.sentinel.context, method_name,
+                                         firewall='test', host='host')
 
     def test_create_firewall(self):
         self._call_test_helper('create_firewall')