Move more snat code to dvr class that does snat
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
This commit is contained in:
parent
c499fe5019
commit
3fc52dee3c
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue