Browse Source

Merge "Do not initialize snat-ns twice"

changes/66/677166/14
Zuul 2 weeks ago
parent
commit
418be00155
3 changed files with 24 additions and 7 deletions
  1. +0
    -4
      neutron/agent/l3/dvr_edge_ha_router.py
  2. +7
    -3
      neutron/agent/l3/dvr_edge_router.py
  3. +17
    -0
      neutron/tests/unit/agent/l3/test_dvr_local_router.py

+ 0
- 4
neutron/agent/l3/dvr_edge_ha_router.py View File

@@ -112,10 +112,6 @@ class DvrEdgeHaRouter(dvr_edge_router.DvrEdgeRouter,
ha_router.HaRouter.external_gateway_updated(self, ex_gw_port,
interface_name)

def initialize(self, process_monitor):
self._create_snat_namespace()
super(DvrEdgeHaRouter, self).initialize(process_monitor)

def _external_gateway_added(self, ex_gw_port, interface_name,
ns_name, preserve_ips):
self._plug_external_gateway(ex_gw_port, interface_name, ns_name)

+ 7
- 3
neutron/agent/l3/dvr_edge_router.py View File

@@ -156,15 +156,19 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
lib_constants.SNAT_INT_DEV_PREFIX,
mtu=port.get('mtu'))

def initialize(self, process_monitor):
self._create_snat_namespace()
super(DvrEdgeRouter, self).initialize(process_monitor)

def _create_dvr_gateway(self, ex_gw_port, gw_interface_name):
snat_ns = self._create_snat_namespace()
# connect snat_ports to br_int from SNAT namespace
for port in self.get_snat_interfaces():
self._plug_snat_port(port)
self._external_gateway_added(ex_gw_port, gw_interface_name,
snat_ns.name, preserve_ips=[])
self.snat_namespace.name,
preserve_ips=[])
self.snat_iptables_manager = iptables_manager.IptablesManager(
namespace=snat_ns.name,
namespace=self.snat_namespace.name,
use_ipv6=self.use_ipv6)

self._initialize_address_scope_iptables(self.snat_iptables_manager)

+ 17
- 0
neutron/tests/unit/agent/l3/test_dvr_local_router.py View File

@@ -888,3 +888,20 @@ class TestDvrRouterOperations(base.BaseTestCase):
ri1.remove_centralized_floatingip(fip_cidr)
ri1._remove_vip.assert_called_once_with(fip_cidr)
super_remove_centralized_floatingip.assert_called_once_with(fip_cidr)

def test_initialize_dvr_ha_router_snat_ns_once(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
agent.conf.agent_mode = lib_constants.L3_AGENT_MODE_DVR_SNAT
router = l3_test_common.prepare_router_data(
num_internal_ports=2, enable_ha=True)
router['gw_port_host'] = HOSTNAME
router[lib_constants.HA_INTERFACE_KEY]['status'] = 'ACTIVE'
self.mock_driver.unplug.reset_mock()
self._set_ri_kwargs(agent, router['id'], router)
ri = dvr_edge_ha_rtr.DvrEdgeHaRouter(HOSTNAME, [], **self.ri_kwargs)
ri._create_snat_namespace = mock.Mock()
ri.update_initial_state = mock.Mock()
ri._plug_external_gateway = mock.Mock()
ri.initialize(mock.Mock())
ri._create_dvr_gateway(mock.Mock(), mock.Mock())
ri._create_snat_namespace.assert_called_once_with()

Loading…
Cancel
Save