From: Russell Bryant Date: Wed, 21 Jan 2015 19:34:12 +0000 (-0500) Subject: linuxbridge: untangle SecurityGroupAgentRpcMixin X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f5629f04b1b7fe2220dbb808dff3556157c3c385;p=openstack-build%2Fneutron-build.git linuxbridge: untangle SecurityGroupAgentRpcMixin This patch separates the use of SecurityGroupAgentRpcMixin out to its own class. This matches most of the rest of the code base. This separation is needed to be able to eventually move this rpc API into its own messaging namespace. Now that it's separate, a future change can pass the new class an instance of SecurityGroupServerRpcApi instead of assuming that the LinuxBridgePluginApi includes SecurityGroupServerRpcApiMixin. Part of blueprint rpc-docs-and-namespaces. Change-Id: I913ef0e2f981b258ea03a519f53a55b4afe80daa --- diff --git a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py index 872db5109..9b2e2a5a7 100755 --- a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -640,11 +640,11 @@ class LinuxBridgeRpcCallbacks(sg_rpc.SecurityGroupAgentRpcCallbackMixin, # 1.1 Support Security Group RPC target = messaging.Target(version='1.1') - def __init__(self, context, agent): + def __init__(self, context, agent, sg_agent): super(LinuxBridgeRpcCallbacks, self).__init__() self.context = context self.agent = agent - self.sg_agent = agent + self.sg_agent = sg_agent def network_delete(self, context, **kwargs): LOG.debug("network_delete received") @@ -747,7 +747,15 @@ class LinuxBridgePluginApi(agent_rpc.PluginApi, pass -class LinuxBridgeNeutronAgentRPC(sg_rpc.SecurityGroupAgentRpcMixin): +class LinuxBridgeSecurityGroupAgent(sg_rpc.SecurityGroupAgentRpcMixin): + def __init__(self, context, plugin_rpc, root_helper): + self.context = context + self.plugin_rpc = plugin_rpc + self.root_helper = root_helper + self.init_firewall() + + +class LinuxBridgeNeutronAgentRPC(object): def __init__(self, interface_mappings, polling_interval, root_helper): @@ -769,8 +777,11 @@ class LinuxBridgeNeutronAgentRPC(sg_rpc.SecurityGroupAgentRpcMixin): # stores received port_updates for processing by the main loop self.updated_devices = set() + self.context = context.get_admin_context_without_session() + self.plugin_rpc = LinuxBridgePluginApi(topics.PLUGIN) + self.sg_agent = LinuxBridgeSecurityGroupAgent(self.context, + self.plugin_rpc, self.root_helper) self.setup_rpc(interface_mappings.values()) - self.init_firewall() def _report_state(self): try: @@ -797,12 +808,11 @@ class LinuxBridgeNeutronAgentRPC(sg_rpc.SecurityGroupAgentRpcMixin): LOG.info(_LI("RPC agent_id: %s"), self.agent_id) self.topic = topics.AGENT - self.plugin_rpc = LinuxBridgePluginApi(topics.PLUGIN) self.state_rpc = agent_rpc.PluginReportStateAPI(topics.PLUGIN) # RPC network init - self.context = context.get_admin_context_without_session() # Handle updates from service - self.endpoints = [LinuxBridgeRpcCallbacks(self.context, self)] + self.endpoints = [LinuxBridgeRpcCallbacks(self.context, self, + self.sg_agent)] # Define the listening consumers for the agent consumers = [[topics.PORT, topics.UPDATE], [topics.NETWORK, topics.DELETE], @@ -831,10 +841,10 @@ class LinuxBridgeNeutronAgentRPC(sg_rpc.SecurityGroupAgentRpcMixin): resync_a = False resync_b = False - self.prepare_devices_filter(device_info.get('added')) + self.sg_agent.prepare_devices_filter(device_info.get('added')) if device_info.get('updated'): - self.refresh_firewall() + self.sg_agent.refresh_firewall() # Updated devices are processed the same as new ones, as their # admin_state_up may have changed. The set union prevents duplicating @@ -903,7 +913,7 @@ class LinuxBridgeNeutronAgentRPC(sg_rpc.SecurityGroupAgentRpcMixin): def treat_devices_removed(self, devices): resync = False - self.remove_devices_filter(devices) + self.sg_agent.remove_devices_filter(devices) for device in devices: LOG.info(_LI("Attachment %s removed"), device) details = None diff --git a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py index 09a5d78cf..bba566c98 100644 --- a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py +++ b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py @@ -116,7 +116,7 @@ class TestLinuxBridgeAgent(base.BaseTestCase): devices = [DEVICE_1] with contextlib.nested( mock.patch.object(agent.plugin_rpc, "update_device_down"), - mock.patch.object(agent, "remove_devices_filter") + mock.patch.object(agent.sg_agent, "remove_devices_filter") ) as (fn_udd, fn_rdf): fn_udd.return_value = {'device': DEVICE_1, 'exists': True} @@ -135,7 +135,7 @@ class TestLinuxBridgeAgent(base.BaseTestCase): devices = [DEVICE_1] with contextlib.nested( mock.patch.object(agent.plugin_rpc, "update_device_down"), - mock.patch.object(agent, "remove_devices_filter") + mock.patch.object(agent.sg_agent, "remove_devices_filter") ) as (fn_udd, fn_rdf): fn_udd.return_value = {'device': DEVICE_1, 'exists': False} @@ -154,7 +154,7 @@ class TestLinuxBridgeAgent(base.BaseTestCase): devices = [DEVICE_1] with contextlib.nested( mock.patch.object(agent.plugin_rpc, "update_device_down"), - mock.patch.object(agent, "remove_devices_filter") + mock.patch.object(agent.sg_agent, "remove_devices_filter") ) as (fn_udd, fn_rdf): fn_udd.side_effect = Exception() with mock.patch.object(linuxbridge_neutron_agent.LOG, @@ -287,15 +287,16 @@ class TestLinuxBridgeAgent(base.BaseTestCase): 'added': set(['tap3', 'tap4']), 'updated': set(['tap2', 'tap3']), 'removed': set(['tap1'])} - agent.prepare_devices_filter = mock.Mock() - agent.refresh_firewall = mock.Mock() + agent.sg_agent.prepare_devices_filter = mock.Mock() + agent.sg_agent.refresh_firewall = mock.Mock() agent.treat_devices_added_updated = mock.Mock(return_value=False) agent.treat_devices_removed = mock.Mock(return_value=False) agent.process_network_devices(device_info) - agent.prepare_devices_filter.assert_called_with(set(['tap3', 'tap4'])) - self.assertTrue(agent.refresh_firewall.called) + agent.sg_agent.prepare_devices_filter.assert_called_with( + set(['tap3', 'tap4'])) + self.assertTrue(agent.sg_agent.refresh_firewall.called) agent.treat_devices_added_updated.assert_called_with(set(['tap2', 'tap3', 'tap4'])) @@ -935,7 +936,8 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): self.lb_rpc = linuxbridge_neutron_agent.LinuxBridgeRpcCallbacks( object(), - FakeLBAgent() + FakeLBAgent(), + object() ) self.root_helper = cfg.CONF.AGENT.root_helper