]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
mlnx: untangle SecurityGroupAgentRpcMixin
authorRussell Bryant <rbryant@redhat.com>
Wed, 21 Jan 2015 19:44:23 +0000 (14:44 -0500)
committerRussell Bryant <rbryant@redhat.com>
Thu, 22 Jan 2015 20:39:07 +0000 (15:39 -0500)
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

neutron/plugins/mlnx/agent/eswitch_neutron_agent.py
neutron/tests/unit/mlnx/test_mlnx_neutron_agent.py

index 0acaf6e1aded2d7fd90d3e669872d37f6df9f5f9..7f463c5aa1ac9950a9da7d1d742a8029e177716f 100644 (file)
@@ -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)
index fafbd5c56d743efc1610ae203be58e6ea0b27382..e149af2311376d8d3ec12ab795f0eb911b0a6f0c 100644 (file)
@@ -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()