Do not initialize snat-ns twice
If the DVR+HA router has external gateway, the snat-namespace will be
initialized twice during agent restart. And that ns initialization
function will run many external resource processing actions which will
definitely increase the starting time of L3 agent. This patch addresses
this issue.
Change-Id: I7719491275fa1ebfa7e881366e5cb066e3d4185c
Closes-Bug: #1850779
(cherry picked from commit 7a9d6d2641
)
This commit is contained in:
parent
dad3dc704e
commit
9d5e80e935
|
@ -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)
|
||||
|
|
|
@ -158,15 +158,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)
|
||||
|
|
|
@ -889,3 +889,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…
Reference in New Issue