]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Drop old code from SecurityGroupAgentRpcApiMixin
authorRussell Bryant <rbryant@redhat.com>
Mon, 1 Dec 2014 19:15:58 +0000 (19:15 +0000)
committerRussell Bryant <rbryant@redhat.com>
Mon, 1 Dec 2014 19:15:58 +0000 (19:15 +0000)
The SecurityGroupAgentRpcApiMixin class temporarily had support for
both RpcProxy and new oslo.messaging style rpc client interfaces.  Now
that all users of this mixin have been converted to direct usage of
oslo.messaging APIs, the old compatibility code can be removed.

Part of blueprint drop-rpc-compat.

Change-Id: I18dc65e7f14a8ae42e3c2bc81d1d73f61c12c1fc

neutron/agent/securitygroups_rpc.py
neutron/tests/unit/test_security_groups_rpc.py

index ad986e4c84dd41a57d9bc4c7183609c7972253a6..7681b31ead22d818a759e101061505820ee5d4c7 100644 (file)
@@ -356,10 +356,6 @@ class SecurityGroupAgentRpcMixin(object):
                 self.refresh_firewall(updated_devices)
 
 
-# NOTE(russellb) This class has been conditionally converted to use the
-# oslo.messaging APIs because it's a mix-in used in different places.  The
-# conditional usage is temporary until the whole code base has been converted
-# to stop using the RpcProxy compatibility class.
 class SecurityGroupAgentRpcApiMixin(object):
 
     def _get_security_group_topic(self):
@@ -371,45 +367,25 @@ class SecurityGroupAgentRpcApiMixin(object):
         """Notify rule updated security groups."""
         if not security_groups:
             return
-        if hasattr(self, 'client'):
-            cctxt = self.client.prepare(version=SG_RPC_VERSION,
-                                        topic=self._get_security_group_topic(),
-                                        fanout=True)
-            cctxt.cast(context, 'security_groups_rule_updated',
-                       security_groups=security_groups)
-        else:
-            self.fanout_cast(context,
-                             self.make_msg('security_groups_rule_updated',
-                                           security_groups=security_groups),
-                             version=SG_RPC_VERSION,
-                             topic=self._get_security_group_topic())
+        cctxt = self.client.prepare(version=SG_RPC_VERSION,
+                                    topic=self._get_security_group_topic(),
+                                    fanout=True)
+        cctxt.cast(context, 'security_groups_rule_updated',
+                   security_groups=security_groups)
 
     def security_groups_member_updated(self, context, security_groups):
         """Notify member updated security groups."""
         if not security_groups:
             return
-        if hasattr(self, 'client'):
-            cctxt = self.client.prepare(version=SG_RPC_VERSION,
-                                        topic=self._get_security_group_topic(),
-                                        fanout=True)
-            cctxt.cast(context, 'security_groups_member_updated',
-                       security_groups=security_groups)
-        else:
-            self.fanout_cast(context,
-                             self.make_msg('security_groups_member_updated',
-                                           security_groups=security_groups),
-                             version=SG_RPC_VERSION,
-                             topic=self._get_security_group_topic())
+        cctxt = self.client.prepare(version=SG_RPC_VERSION,
+                                    topic=self._get_security_group_topic(),
+                                    fanout=True)
+        cctxt.cast(context, 'security_groups_member_updated',
+                   security_groups=security_groups)
 
     def security_groups_provider_updated(self, context):
         """Notify provider updated security groups."""
-        if hasattr(self, 'client'):
-            cctxt = self.client.prepare(version=SG_RPC_VERSION,
-                                        topic=self._get_security_group_topic(),
-                                        fanout=True)
-            cctxt.cast(context, 'security_groups_member_updated')
-        else:
-            self.fanout_cast(context,
-                             self.make_msg('security_groups_provider_updated'),
-                             version=SG_RPC_VERSION,
-                             topic=self._get_security_group_topic())
+        cctxt = self.client.prepare(version=SG_RPC_VERSION,
+                                    topic=self._get_security_group_topic(),
+                                    fanout=True)
+        cctxt.cast(context, 'security_groups_member_updated')
index 24b4a9a3b0137883d06a7c41fc746c221efd404f..fb141486ce20c3aa0d8af74255ffb5e508048c95 100644 (file)
@@ -1565,51 +1565,45 @@ class SecurityGroupServerRpcApiTestCase(base.BaseTestCase):
                 devices=['fake_device'])
 
 
-class FakeSGNotifierAPI(n_rpc.RpcProxy,
-                        sg_rpc.SecurityGroupAgentRpcApiMixin):
-    pass
+class FakeSGNotifierAPI(sg_rpc.SecurityGroupAgentRpcApiMixin):
+    def __init__(self):
+        self.topic = 'fake'
+        target = messaging.Target(topic=self.topic, version='1.0')
+        self.client = n_rpc.get_client(target)
 
 
 class SecurityGroupAgentRpcApiTestCase(base.BaseTestCase):
     def setUp(self):
         super(SecurityGroupAgentRpcApiTestCase, self).setUp()
-        self.notifier = FakeSGNotifierAPI(topic='fake',
-                                          default_version='1.0')
-        self.notifier.fanout_cast = mock.Mock()
+        self.notifier = FakeSGNotifierAPI()
+        self.mock_prepare = mock.patch.object(self.notifier.client, 'prepare',
+                return_value=self.notifier.client).start()
+        self.mock_cast = mock.patch.object(self.notifier.client,
+                'cast').start()
 
     def test_security_groups_rule_updated(self):
         self.notifier.security_groups_rule_updated(
             None, security_groups=['fake_sgid'])
-        self.notifier.fanout_cast.assert_has_calls(
-            [mock.call(None,
-                       {'args':
-                           {'security_groups': ['fake_sgid']},
-                           'method': 'security_groups_rule_updated',
-                           'namespace': None},
-                       version=sg_rpc.SG_RPC_VERSION,
-                       topic='fake-security_group-update')])
+        self.mock_cast.assert_has_calls(
+            [mock.call(None, 'security_groups_rule_updated',
+                       security_groups=['fake_sgid'])])
 
     def test_security_groups_member_updated(self):
         self.notifier.security_groups_member_updated(
             None, security_groups=['fake_sgid'])
-        self.notifier.fanout_cast.assert_has_calls(
-            [mock.call(None,
-                       {'args':
-                           {'security_groups': ['fake_sgid']},
-                           'method': 'security_groups_member_updated',
-                           'namespace': None},
-                       version=sg_rpc.SG_RPC_VERSION,
-                       topic='fake-security_group-update')])
+        self.mock_cast.assert_has_calls(
+            [mock.call(None, 'security_groups_member_updated',
+                       security_groups=['fake_sgid'])])
 
     def test_security_groups_rule_not_updated(self):
         self.notifier.security_groups_rule_updated(
             None, security_groups=[])
-        self.assertEqual(False, self.notifier.fanout_cast.called)
+        self.assertEqual(False, self.mock_cast.called)
 
     def test_security_groups_member_not_updated(self):
         self.notifier.security_groups_member_updated(
             None, security_groups=[])
-        self.assertEqual(False, self.notifier.fanout_cast.called)
+        self.assertEqual(False, self.mock_cast.called)
 
 #Note(nati) bn -> binary_name
 # id -> device_id