Enable SNAT by default in L3 agents
If ext-gw-mode extension isn't supported by plugin, it won't return enable_snat param in router info. Agent will currently default to enable_snat = false, which changes from expected default behaviour prior to ext-gw-mode introduction. This patch changes L3 agent to enable SNAT by default if plugin doesn't support ext-gw-mode extension. Change-Id: I35e8f8c20392bff9ac2f875f2c9a1038ab06ad7b Closes-Bug: #1212868
This commit is contained in:
parent
253da3b88e
commit
4b7342797f
@ -116,15 +116,15 @@ class RouterInfo(object):
|
|||||||
self._router = value
|
self._router = value
|
||||||
if not self._router:
|
if not self._router:
|
||||||
return
|
return
|
||||||
|
# enable_snat by default if it wasn't specified by plugin
|
||||||
|
self._snat_enabled = self._router.get('enable_snat', True)
|
||||||
# Set a SNAT action for the router
|
# Set a SNAT action for the router
|
||||||
if self._router.get('gw_port'):
|
if self._router.get('gw_port'):
|
||||||
self._snat_action = (
|
self._snat_action = ('add_rules' if self._snat_enabled
|
||||||
'add_rules' if self._router.get('enable_snat')
|
else 'remove_rules')
|
||||||
else 'remove_rules')
|
|
||||||
elif self.ex_gw_port:
|
elif self.ex_gw_port:
|
||||||
# Gateway port was removed, remove rules
|
# Gateway port was removed, remove rules
|
||||||
self._snat_action = 'remove_rules'
|
self._snat_action = 'remove_rules'
|
||||||
self._snat_enabled = self._router.get('enable_snat')
|
|
||||||
|
|
||||||
def ns_name(self):
|
def ns_name(self):
|
||||||
if self.use_namespaces:
|
if self.use_namespaces:
|
||||||
|
@ -352,7 +352,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
|
|||||||
else:
|
else:
|
||||||
self.assertIn(r.rule, expected_rules)
|
self.assertIn(r.rule, expected_rules)
|
||||||
|
|
||||||
def _prepare_router_data(self, enable_snat=True, num_internal_ports=1):
|
def _prepare_router_data(self, enable_snat=None, num_internal_ports=1):
|
||||||
router_id = _uuid()
|
router_id = _uuid()
|
||||||
ex_gw_port = {'id': _uuid(),
|
ex_gw_port = {'id': _uuid(),
|
||||||
'network_id': _uuid(),
|
'network_id': _uuid(),
|
||||||
@ -374,9 +374,10 @@ class TestBasicRouterOperations(base.BaseTestCase):
|
|||||||
router = {
|
router = {
|
||||||
'id': router_id,
|
'id': router_id,
|
||||||
l3_constants.INTERFACE_KEY: int_ports,
|
l3_constants.INTERFACE_KEY: int_ports,
|
||||||
'enable_snat': enable_snat,
|
|
||||||
'routes': [],
|
'routes': [],
|
||||||
'gw_port': ex_gw_port}
|
'gw_port': ex_gw_port}
|
||||||
|
if enable_snat is not None:
|
||||||
|
router['enable_snat'] = enable_snat
|
||||||
return router
|
return router
|
||||||
|
|
||||||
def testProcessRouter(self):
|
def testProcessRouter(self):
|
||||||
@ -409,7 +410,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
|
|||||||
|
|
||||||
def test_process_router_snat_disabled(self):
|
def test_process_router_snat_disabled(self):
|
||||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||||
router = self._prepare_router_data()
|
router = self._prepare_router_data(enable_snat=True)
|
||||||
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
|
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
|
||||||
self.conf.use_namespaces, router=router)
|
self.conf.use_namespaces, router=router)
|
||||||
# Process with NAT
|
# Process with NAT
|
||||||
@ -432,10 +433,10 @@ class TestBasicRouterOperations(base.BaseTestCase):
|
|||||||
router = self._prepare_router_data(enable_snat=False)
|
router = self._prepare_router_data(enable_snat=False)
|
||||||
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
|
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
|
||||||
self.conf.use_namespaces, router=router)
|
self.conf.use_namespaces, router=router)
|
||||||
# Process with NAT
|
# Process without NAT
|
||||||
agent.process_router(ri)
|
agent.process_router(ri)
|
||||||
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
|
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
|
||||||
# Reprocess without NAT
|
# Reprocess with NAT
|
||||||
router['enable_snat'] = True
|
router['enable_snat'] = True
|
||||||
# Reassign the router object to RouterInfo
|
# Reassign the router object to RouterInfo
|
||||||
ri.router = router
|
ri.router = router
|
||||||
|
Loading…
Reference in New Issue
Block a user