From: Russell Bryant Date: Wed, 21 Jan 2015 19:44:23 +0000 (-0500) Subject: mlnx: untangle SecurityGroupAgentRpcMixin X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=fe4a82254d54750082c3a6d909c6643aa9d2bce7;p=openstack-build%2Fneutron-build.git mlnx: 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: Ie850a262bc7e4b697003cf6d91780dc819c688e0 --- diff --git a/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py b/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py index 0acaf6e1a..7f463c5aa 100644 --- a/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py +++ b/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py @@ -151,12 +151,12 @@ class MlnxEswitchRpcCallbacks(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(MlnxEswitchRpcCallbacks, self).__init__() self.context = context self.agent = agent self.eswitch = agent.eswitch - self.sg_agent = agent + self.sg_agent = sg_agent def network_delete(self, context, **kwargs): LOG.debug("network_delete received") @@ -179,9 +179,17 @@ class MlnxEswitchPluginApi(agent_rpc.PluginApi, pass -class MlnxEswitchNeutronAgent(sg_rpc.SecurityGroupAgentRpcMixin): +class MlnxEswitchSecurityGroupAgent(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() + - def __init__(self, interface_mapping): +class MlnxEswitchNeutronAgent(object): + + def __init__(self, interface_mapping, root_helper): self._polling_interval = cfg.CONF.AGENT.polling_interval self._setup_eswitches(interface_mapping) configurations = {'interface_mappings': interface_mapping} @@ -194,8 +202,11 @@ class MlnxEswitchNeutronAgent(sg_rpc.SecurityGroupAgentRpcMixin): 'start_flag': True} # Stores port update notifications for processing in main rpc loop self.updated_ports = set() + self.context = context.get_admin_context_without_session() + self.plugin_rpc = MlnxEswitchPluginApi(topics.PLUGIN) + self.sg_agent = MlnxEswitchSecurityGroupAgent(self.context, + self.plugin_rpc, root_helper) self._setup_rpc() - self.init_firewall() def _setup_eswitches(self, interface_mapping): daemon = cfg.CONF.ESWITCH.daemon_endpoint @@ -217,12 +228,11 @@ class MlnxEswitchNeutronAgent(sg_rpc.SecurityGroupAgentRpcMixin): LOG.info(_LI("RPC agent_id: %s"), self.agent_id) self.topic = topics.AGENT - self.plugin_rpc = MlnxEswitchPluginApi(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 = [MlnxEswitchRpcCallbacks(self.context, self)] + self.endpoints = [MlnxEswitchRpcCallbacks(self.context, self, + self.sg_agent)] # Define the listening consumers for the agent consumers = [[topics.PORT, topics.UPDATE], [topics.NETWORK, topics.DELETE], @@ -406,8 +416,9 @@ def main(): sys.exit(1) LOG.info(_LI("Interface mappings: %s"), interface_mappings) + root_helper = cfg.CONF.AGENT.root_helper try: - agent = MlnxEswitchNeutronAgent(interface_mappings) + agent = MlnxEswitchNeutronAgent(interface_mappings, root_helper) except Exception as e: LOG.error(_LE("Failed on Agent initialisation : %s. " "Agent terminated!"), e) diff --git a/neutron/tests/unit/mlnx/test_mlnx_neutron_agent.py b/neutron/tests/unit/mlnx/test_mlnx_neutron_agent.py index fafbd5c56..e149af231 100644 --- a/neutron/tests/unit/mlnx/test_mlnx_neutron_agent.py +++ b/neutron/tests/unit/mlnx/test_mlnx_neutron_agent.py @@ -52,6 +52,7 @@ class TestMlnxEswitchRpcCallbacks(base.BaseTestCase): agent = mock.Mock() self.rpc_callbacks = eswitch_neutron_agent.MlnxEswitchRpcCallbacks( 'context', + agent, agent ) @@ -82,7 +83,7 @@ class TestEswitchAgent(base.BaseTestCase): new=MockFixedIntervalLoopingCall) with mock.patch.object(utils, 'zmq'): - self.agent = eswitch_neutron_agent.MlnxEswitchNeutronAgent({}) + self.agent = eswitch_neutron_agent.MlnxEswitchNeutronAgent({}, {}) self.agent.plugin_rpc = mock.Mock() self.agent.context = mock.Mock() self.agent.agent_id = mock.Mock()