From 4407f43af4693a4f0d2394e0630fe457537af532 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Mon, 1 Dec 2014 19:15:58 +0000 Subject: [PATCH] Drop old code from SecurityGroupAgentRpcApiMixin 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 | 52 +++++-------------- .../tests/unit/test_security_groups_rpc.py | 42 +++++++-------- 2 files changed, 32 insertions(+), 62 deletions(-) diff --git a/neutron/agent/securitygroups_rpc.py b/neutron/agent/securitygroups_rpc.py index ad986e4c8..7681b31ea 100644 --- a/neutron/agent/securitygroups_rpc.py +++ b/neutron/agent/securitygroups_rpc.py @@ -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') diff --git a/neutron/tests/unit/test_security_groups_rpc.py b/neutron/tests/unit/test_security_groups_rpc.py index 24b4a9a3b..fb141486c 100644 --- a/neutron/tests/unit/test_security_groups_rpc.py +++ b/neutron/tests/unit/test_security_groups_rpc.py @@ -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 -- 2.45.2