From: Russell Bryant Date: Wed, 21 Jan 2015 20:50:21 +0000 (-0500) Subject: sriovnicagent: untangle SecurityGroupAgentRpcMixin X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e6592f74021fbb4a1d577733292233f0a3f7be5f;p=openstack-build%2Fneutron-build.git sriovnicagent: 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 PluginApi instance includes SecurityGroupServerRpcApiMixin. Part of blueprint rpc-docs-and-namespaces. Change-Id: I46bdf2132bfed582df85bb302f55b1840e7a7a18 --- diff --git a/neutron/plugins/sriovnicagent/sriov_nic_agent.py b/neutron/plugins/sriovnicagent/sriov_nic_agent.py index 33abde34d..751e1c445 100644 --- a/neutron/plugins/sriovnicagent/sriov_nic_agent.py +++ b/neutron/plugins/sriovnicagent/sriov_nic_agent.py @@ -49,11 +49,11 @@ class SriovNicSwitchRpcCallbacks(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(SriovNicSwitchRpcCallbacks, self).__init__() self.context = context self.agent = agent - self.sg_agent = agent + self.sg_agent = sg_agent def port_update(self, context, **kwargs): LOG.debug("port_update received") @@ -71,7 +71,15 @@ class SriovNicSwitchPluginApi(agent_rpc.PluginApi, pass -class SriovNicSwitchAgent(sg_rpc.SecurityGroupAgentRpcMixin): +class SriovNicSwitchSecurityGroupAgent(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 SriovNicSwitchAgent(object): def __init__(self, physical_devices_mappings, exclude_devices, polling_interval, root_helper): @@ -90,8 +98,12 @@ class SriovNicSwitchAgent(sg_rpc.SecurityGroupAgentRpcMixin): # Stores port update notifications for processing in the main loop self.updated_devices = set() + + self.context = context.get_admin_context_without_session() + self.plugin_rpc = SriovNicSwitchPluginApi(topics.PLUGIN) + self.sg_agent = SriovNicSwitchSecurityGroupAgent(self.context, + self.plugin_rpc, self.root_helper) self._setup_rpc() - self.init_firewall() # Initialize iteration counter self.iter_num = 0 @@ -100,12 +112,11 @@ class SriovNicSwitchAgent(sg_rpc.SecurityGroupAgentRpcMixin): LOG.info(_LI("RPC agent_id: %s"), self.agent_id) self.topic = topics.AGENT - self.plugin_rpc = SriovNicSwitchPluginApi(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 = [SriovNicSwitchRpcCallbacks(self.context, self)] + self.endpoints = [SriovNicSwitchRpcCallbacks(self.context, self, + self.sg_agent)] # Define the listening consumers for the agent consumers = [[topics.PORT, topics.UPDATE], [topics.NETWORK, topics.DELETE], @@ -155,10 +166,10 @@ class SriovNicSwitchAgent(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 # work when a device is new and updated in the same polling iteration. diff --git a/neutron/tests/unit/sriovnicagent/test_sriov_neutron_agent.py b/neutron/tests/unit/sriovnicagent/test_sriov_neutron_agent.py index 3a422ce8e..f492f4440 100644 --- a/neutron/tests/unit/sriovnicagent/test_sriov_neutron_agent.py +++ b/neutron/tests/unit/sriovnicagent/test_sriov_neutron_agent.py @@ -154,15 +154,16 @@ class TestSriovAgent(base.BaseTestCase): 'added': set(['mac3', 'mac4']), 'updated': set(['mac2', 'mac3']), 'removed': set(['mac1'])} - 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(['mac3', 'mac4'])) - self.assertTrue(agent.refresh_firewall.called) + agent.sg_agent.prepare_devices_filter.assert_called_with( + set(['mac3', 'mac4'])) + self.assertTrue(agent.sg_agent.refresh_firewall.called) agent.treat_devices_added_updated.assert_called_with(set(['mac2', 'mac3', 'mac4']))