]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move more snat code to dvr class that does snat
authorCarl Baldwin <carl.baldwin@hp.com>
Thu, 9 Jul 2015 21:08:19 +0000 (21:08 +0000)
committerCarl Baldwin <carl.baldwin@hp.com>
Fri, 10 Jul 2015 17:26:11 +0000 (17:26 +0000)
A few methods were left in the wrong class when splitting up the dvr
classes.  This commit reduces the amount of dependency between the
two.

Change-Id: Id1b4f4e99a5c51576eddadd5eb0c973c0d5b46b8

neutron/agent/l3/dvr_edge_router.py
neutron/agent/l3/dvr_local_router.py
neutron/tests/unit/agent/l3/test_agent.py

index 167df080a1107c7306e71752290278b62ca81b12..dd128dc888e0ef7c21a9a1bb96374fe00eb309e1 100644 (file)
@@ -28,6 +28,7 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
     def __init__(self, agent, host, *args, **kwargs):
         super(DvrEdgeRouter, self).__init__(agent, host, *args, **kwargs)
         self.snat_namespace = None
+        self.snat_iptables_manager = None
 
     def external_gateway_added(self, ex_gw_port, interface_name):
         super(DvrEdgeRouter, self).external_gateway_added(
@@ -145,4 +146,34 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
         return long_name[:self.driver.DEV_NAME_LEN]
 
     def _is_this_snat_host(self):
-        return self.get_gw_port_host() == self.host
+        return self._get_gw_port_host() == self.host
+
+    def _get_gw_port_host(self):
+        host = self.router.get('gw_port_host')
+        if not host:
+            LOG.debug("gw_port_host missing from router: %s",
+                      self.router['id'])
+        return host
+
+    def _handle_router_snat_rules(self, ex_gw_port,
+                                  interface_name, action):
+        if not self.snat_iptables_manager:
+            LOG.debug("DVR router: no snat rules to be handled")
+            return
+
+        with self.snat_iptables_manager.defer_apply():
+            self._empty_snat_chains(self.snat_iptables_manager)
+
+            # NOTE DVR doesn't add the jump to float snat like the super class.
+
+            self._add_snat_rules(ex_gw_port, self.snat_iptables_manager,
+                                 interface_name, action)
+
+    def perform_snat_action(self, snat_callback, *args):
+        # NOTE DVR skips this step in a few cases...
+        if not self.get_ex_gw_port():
+            return
+        if self._get_gw_port_host() != self.host:
+            return
+
+        super(DvrEdgeRouter, self).perform_snat_action(snat_callback, *args)
index e306c7c91f0b8b0e4f043d59b5306ba9158ac8cb..ca72d0d95c5479bf68426e74af3991d735cbc085 100755 (executable)
@@ -39,7 +39,6 @@ class DvrLocalRouter(router.RouterInfo):
         self.host = host
 
         self.floating_ips_dict = {}
-        self.snat_iptables_manager = None
         # Linklocal subnet for router and floating IP namespace link
         self.rtr_fip_subnet = None
         self.dist_fip_count = None
@@ -291,13 +290,6 @@ class DvrLocalRouter(router.RouterInfo):
         """Removes rules and routes for SNAT redirection."""
         self._snat_redirect_modify(gateway, sn_port, sn_int, is_add=False)
 
-    def get_gw_port_host(self):
-        host = self.router.get('gw_port_host')
-        if not host:
-            LOG.debug("gw_port_host missing from router: %s",
-                      self.router['id'])
-        return host
-
     def internal_network_added(self, port):
         super(DvrLocalRouter, self).internal_network_added(port)
 
@@ -387,27 +379,7 @@ class DvrLocalRouter(router.RouterInfo):
 
     def _handle_router_snat_rules(self, ex_gw_port,
                                   interface_name, action):
-        if not self.snat_iptables_manager:
-            LOG.debug("DVR router: no snat rules to be handled")
-            return
-
-        with self.snat_iptables_manager.defer_apply():
-            self._empty_snat_chains(self.snat_iptables_manager)
-
-            # NOTE DVR doesn't add the jump to float snat like the super class.
-
-            self._add_snat_rules(ex_gw_port, self.snat_iptables_manager,
-                                 interface_name, action)
-
-    def perform_snat_action(self, snat_callback, *args):
-        # NOTE DVR skips this step in a few cases...
-        if not self.get_ex_gw_port():
-            return
-        if self.get_gw_port_host() != self.host:
-            return
-
-        super(DvrLocalRouter,
-              self).perform_snat_action(snat_callback, *args)
+        pass
 
     def process_external(self, agent):
         ex_gw_port = self.get_ex_gw_port()
index b683727fdb59d2ff41a0f2985d74cea9995cb0c3..73dcd42dbc2c1d25655f6d6366fb13f0e0b327bc 100644 (file)
@@ -29,7 +29,6 @@ from neutron.agent.common import config as agent_config
 from neutron.agent.l3 import agent as l3_agent
 from neutron.agent.l3 import config as l3_config
 from neutron.agent.l3 import dvr_edge_router as dvr_router
-from neutron.agent.l3 import dvr_local_router
 from neutron.agent.l3 import dvr_snat_ns
 from neutron.agent.l3 import ha
 from neutron.agent.l3 import legacy_router
@@ -1488,7 +1487,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
             **self.ri_kwargs)
         ri.iptables_manager = mock.Mock()
 
-        with mock.patch.object(dvr_local_router.LOG,
+        with mock.patch.object(dvr_router.LOG,
                                'debug') as log_debug:
             ri._handle_router_snat_rules(mock.ANY, mock.ANY, mock.ANY)
         self.assertIsNone(ri.snat_iptables_manager)