Browse Source

HA-non-DVR router don't need manually add static route

When a router set as HA mode, The keepalived process will take over
the route entry's generation. So, the codes that add static route
is redundant.

But, for DVR-HA router, in dvr_snat node the keepalived process run
in snat-namespace and don't take over qrouter-namespace, so the
manually add static route codes still need be called.

Closes-Bug: #1927849
Change-Id: Id09de6c43c0fab4009336e253c88f54219398053
(cherry picked from commit f192153b44)
changes/75/792875/2
yangjianfeng 3 months ago
committed by Bernard Cafarelli
parent
commit
531cb5bef7
  1. 4
      neutron/agent/l3/ha_router.py
  2. 25
      neutron/tests/unit/agent/l3/test_ha_router.py

4
neutron/agent/l3/ha_router.py

@ -271,7 +271,9 @@ class HaRouter(router.RouterInfo):
keepalived.KeepalivedVirtualRoute(
route['destination'], route['nexthop'])
for route in new_routes]
super(HaRouter, self).routes_updated(old_routes, new_routes)
if self.router.get('distributed', False):
super(HaRouter, self).routes_updated(old_routes, new_routes)
self.keepalived_manager.get_process().reload_cfg()
def _add_default_gw_virtual_route(self, ex_gw_port, interface_name):
gateway_ips = self._get_external_gw_ips(ex_gw_port)

25
neutron/tests/unit/agent/l3/test_ha_router.py

@ -55,6 +55,31 @@ class TestBasicRouterOperations(base.BaseTestCase):
ri._get_cidrs_from_keepalived = mock.MagicMock(return_value=addresses)
self.assertEqual(set(addresses), ri.get_router_cidrs(device))
def test_routes_updated_with_dvr(self):
ri = self._create_router(router={'distributed': True})
ri.keepalived_manager = mock.Mock()
base_routes_updated = mock.patch(
'neutron.agent.l3.router_info.'
'RouterInfo.routes_updated').start()
mock_instance = mock.Mock()
mock_instance.virtual_routes.gateway_routes = []
ri._get_keepalived_instance = mock.Mock(
return_value=mock_instance)
ri.routes_updated([], [])
self.assertTrue(base_routes_updated.called)
def test_routes_updated_with_non_dvr(self):
ri = self._create_router(router={'distributed': False})
ri.keepalived_manager = mock.Mock()
base_routes_updated = mock.patch(
'neutron.agent.l3.router_info.'
'RouterInfo.routes_updated').start()
mock_instance = mock.Mock()
mock_instance.virtual_routes.gateway_routes = []
ri._get_keepalived_instance = mock.Mock(return_value=mock_instance)
ri.routes_updated([], [])
self.assertFalse(base_routes_updated.called)
def test__add_default_gw_virtual_route(self):
ri = self._create_router()
mock_instance = mock.Mock()

Loading…
Cancel
Save