]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
linuxbridge: untangle SecurityGroupAgentRpcMixin
authorRussell Bryant <rbryant@redhat.com>
Wed, 21 Jan 2015 19:34:12 +0000 (14:34 -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 LinuxBridgePluginApi includes
SecurityGroupServerRpcApiMixin.

Part of blueprint rpc-docs-and-namespaces.

Change-Id: I913ef0e2f981b258ea03a519f53a55b4afe80daa

neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py
neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py

index 872db510933f7096757b42eaaac5e63bcd9696fd..9b2e2a5a71868081f9450724392dae3914dcd56f 100755 (executable)
@@ -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
index 09a5d78cf85c090478e9a95fbfd463959079a6dd..bba566c987ff76e692b7eee0ffd4e593edcd4fea 100644 (file)
@@ -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