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
This commit is contained in:
Russell Bryant 2014-12-01 19:15:58 +00:00
parent 3bb80a0333
commit a7aabe1d1f
2 changed files with 32 additions and 62 deletions

View File

@ -356,10 +356,6 @@ class SecurityGroupAgentRpcMixin(object):
self.refresh_firewall(updated_devices) 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): class SecurityGroupAgentRpcApiMixin(object):
def _get_security_group_topic(self): def _get_security_group_topic(self):
@ -371,45 +367,25 @@ class SecurityGroupAgentRpcApiMixin(object):
"""Notify rule updated security groups.""" """Notify rule updated security groups."""
if not security_groups: if not security_groups:
return return
if hasattr(self, 'client'):
cctxt = self.client.prepare(version=SG_RPC_VERSION, cctxt = self.client.prepare(version=SG_RPC_VERSION,
topic=self._get_security_group_topic(), topic=self._get_security_group_topic(),
fanout=True) fanout=True)
cctxt.cast(context, 'security_groups_rule_updated', cctxt.cast(context, 'security_groups_rule_updated',
security_groups=security_groups) 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())
def security_groups_member_updated(self, context, security_groups): def security_groups_member_updated(self, context, security_groups):
"""Notify member updated security groups.""" """Notify member updated security groups."""
if not security_groups: if not security_groups:
return return
if hasattr(self, 'client'):
cctxt = self.client.prepare(version=SG_RPC_VERSION, cctxt = self.client.prepare(version=SG_RPC_VERSION,
topic=self._get_security_group_topic(), topic=self._get_security_group_topic(),
fanout=True) fanout=True)
cctxt.cast(context, 'security_groups_member_updated', cctxt.cast(context, 'security_groups_member_updated',
security_groups=security_groups) 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())
def security_groups_provider_updated(self, context): def security_groups_provider_updated(self, context):
"""Notify provider updated security groups.""" """Notify provider updated security groups."""
if hasattr(self, 'client'):
cctxt = self.client.prepare(version=SG_RPC_VERSION, cctxt = self.client.prepare(version=SG_RPC_VERSION,
topic=self._get_security_group_topic(), topic=self._get_security_group_topic(),
fanout=True) fanout=True)
cctxt.cast(context, 'security_groups_member_updated') 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())

View File

@ -1565,51 +1565,45 @@ class SecurityGroupServerRpcApiTestCase(base.BaseTestCase):
devices=['fake_device']) devices=['fake_device'])
class FakeSGNotifierAPI(n_rpc.RpcProxy, class FakeSGNotifierAPI(sg_rpc.SecurityGroupAgentRpcApiMixin):
sg_rpc.SecurityGroupAgentRpcApiMixin): def __init__(self):
pass self.topic = 'fake'
target = messaging.Target(topic=self.topic, version='1.0')
self.client = n_rpc.get_client(target)
class SecurityGroupAgentRpcApiTestCase(base.BaseTestCase): class SecurityGroupAgentRpcApiTestCase(base.BaseTestCase):
def setUp(self): def setUp(self):
super(SecurityGroupAgentRpcApiTestCase, self).setUp() super(SecurityGroupAgentRpcApiTestCase, self).setUp()
self.notifier = FakeSGNotifierAPI(topic='fake', self.notifier = FakeSGNotifierAPI()
default_version='1.0') self.mock_prepare = mock.patch.object(self.notifier.client, 'prepare',
self.notifier.fanout_cast = mock.Mock() return_value=self.notifier.client).start()
self.mock_cast = mock.patch.object(self.notifier.client,
'cast').start()
def test_security_groups_rule_updated(self): def test_security_groups_rule_updated(self):
self.notifier.security_groups_rule_updated( self.notifier.security_groups_rule_updated(
None, security_groups=['fake_sgid']) None, security_groups=['fake_sgid'])
self.notifier.fanout_cast.assert_has_calls( self.mock_cast.assert_has_calls(
[mock.call(None, [mock.call(None, 'security_groups_rule_updated',
{'args': security_groups=['fake_sgid'])])
{'security_groups': ['fake_sgid']},
'method': 'security_groups_rule_updated',
'namespace': None},
version=sg_rpc.SG_RPC_VERSION,
topic='fake-security_group-update')])
def test_security_groups_member_updated(self): def test_security_groups_member_updated(self):
self.notifier.security_groups_member_updated( self.notifier.security_groups_member_updated(
None, security_groups=['fake_sgid']) None, security_groups=['fake_sgid'])
self.notifier.fanout_cast.assert_has_calls( self.mock_cast.assert_has_calls(
[mock.call(None, [mock.call(None, 'security_groups_member_updated',
{'args': security_groups=['fake_sgid'])])
{'security_groups': ['fake_sgid']},
'method': 'security_groups_member_updated',
'namespace': None},
version=sg_rpc.SG_RPC_VERSION,
topic='fake-security_group-update')])
def test_security_groups_rule_not_updated(self): def test_security_groups_rule_not_updated(self):
self.notifier.security_groups_rule_updated( self.notifier.security_groups_rule_updated(
None, security_groups=[]) 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): def test_security_groups_member_not_updated(self):
self.notifier.security_groups_member_updated( self.notifier.security_groups_member_updated(
None, security_groups=[]) None, security_groups=[])
self.assertEqual(False, self.notifier.fanout_cast.called) self.assertEqual(False, self.mock_cast.called)
#Note(nati) bn -> binary_name #Note(nati) bn -> binary_name
# id -> device_id # id -> device_id