Merge "Enable ra on gateway when add gateway to HA router"
This commit is contained in:
commit
0f3008dd32
@ -134,15 +134,13 @@ class AgentMixin(object):
|
||||
# include any IPv6 subnet, enable the gateway interface to accept
|
||||
# Router Advts from upstream router for default route.
|
||||
ex_gw_port_id = ri.ex_gw_port and ri.ex_gw_port['id']
|
||||
if state == 'master' and ex_gw_port_id and ri.use_ipv6:
|
||||
gateway_ips = ri._get_external_gw_ips(ri.ex_gw_port)
|
||||
if not ri.is_v6_gateway_set(gateway_ips):
|
||||
interface_name = ri.get_external_device_name(ex_gw_port_id)
|
||||
if ri.router.get('distributed', False):
|
||||
namespace = ri.ha_namespace
|
||||
else:
|
||||
namespace = ri.ns_name
|
||||
ri.driver.configure_ipv6_ra(namespace, interface_name)
|
||||
if state == 'master' and ex_gw_port_id:
|
||||
interface_name = ri.get_external_device_name(ex_gw_port_id)
|
||||
if ri.router.get('distributed', False):
|
||||
namespace = ri.ha_namespace
|
||||
else:
|
||||
namespace = ri.ns_name
|
||||
ri._enable_ra_on_gw(ri.ex_gw_port, namespace, interface_name)
|
||||
|
||||
def _update_metadata_proxy(self, ri, router_id, state):
|
||||
if state == 'master':
|
||||
|
@ -352,6 +352,8 @@ class HaRouter(router.RouterInfo):
|
||||
self._plug_external_gateway(ex_gw_port, interface_name, self.ns_name)
|
||||
self._add_gateway_vip(ex_gw_port, interface_name)
|
||||
self._disable_ipv6_addressing_on_interface(interface_name)
|
||||
if self.ha_state == 'master':
|
||||
self._enable_ra_on_gw(ex_gw_port, self.ns_name, interface_name)
|
||||
|
||||
def external_gateway_updated(self, ex_gw_port, interface_name):
|
||||
self._plug_external_gateway(
|
||||
|
@ -599,6 +599,14 @@ class RouterInfo(object):
|
||||
device = ip_lib.IPDevice(device_name, namespace=namespace)
|
||||
device.route.add_route(subnet['gateway_ip'], scope='link')
|
||||
|
||||
def _enable_ra_on_gw(self, ex_gw_port, ns_name, interface_name):
|
||||
gateway_ips = self._get_external_gw_ips(ex_gw_port)
|
||||
if not self.use_ipv6 or self.is_v6_gateway_set(gateway_ips):
|
||||
return
|
||||
|
||||
# There is no IPv6 gw_ip, use RouterAdvt for default route.
|
||||
self.driver.configure_ipv6_ra(ns_name, interface_name)
|
||||
|
||||
def _external_gateway_added(self, ex_gw_port, interface_name,
|
||||
ns_name, preserve_ips):
|
||||
LOG.debug("External gateway added: port(%s), interface(%s), ns(%s)",
|
||||
@ -610,10 +618,6 @@ class RouterInfo(object):
|
||||
ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips'])
|
||||
|
||||
gateway_ips = self._get_external_gw_ips(ex_gw_port)
|
||||
enable_ra_on_gw = False
|
||||
if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips):
|
||||
# There is no IPv6 gw_ip, use RouterAdvt for default route.
|
||||
enable_ra_on_gw = True
|
||||
|
||||
self._add_route_to_gw(ex_gw_port, device_name=interface_name,
|
||||
namespace=ns_name, preserve_ips=preserve_ips)
|
||||
@ -637,8 +641,7 @@ class RouterInfo(object):
|
||||
for ip in gateway_ips:
|
||||
device.route.add_gateway(ip)
|
||||
|
||||
if enable_ra_on_gw:
|
||||
self.driver.configure_ipv6_ra(ns_name, interface_name)
|
||||
self._enable_ra_on_gw(ex_gw_port, ns_name, interface_name)
|
||||
|
||||
for fixed_ip in ex_gw_port['fixed_ips']:
|
||||
ip_lib.send_ip_addr_adv_notif(ns_name,
|
||||
|
@ -209,6 +209,15 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
|
||||
external_port, router.get_external_device_name,
|
||||
router.ns_name))
|
||||
|
||||
def _assert_ipv6_accept_ra(self, router):
|
||||
external_port = router.get_ex_gw_port()
|
||||
external_device_name = router.get_external_device_name(
|
||||
external_port['id'])
|
||||
ip_wrapper = ip_lib.IPWrapper(namespace=router.ns_name)
|
||||
ra_state = ip_wrapper.netns.execute(['sysctl', '-b',
|
||||
'net.ipv6.conf.%s.accept_ra' % external_device_name])
|
||||
self.assertEqual('2', ra_state)
|
||||
|
||||
def _router_lifecycle(self, enable_ha, ip_version=4,
|
||||
dual_stack=False, v6_ext_gw_with_sub=True):
|
||||
router_info = self.generate_router_info(enable_ha, ip_version,
|
||||
@ -270,13 +279,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
|
||||
# when IPv6 is enabled and no IPv6 gateway is configured.
|
||||
if router.use_ipv6 and not v6_ext_gw_with_sub:
|
||||
if not self.agent.conf.ipv6_gateway:
|
||||
external_port = router.get_ex_gw_port()
|
||||
external_device_name = router.get_external_device_name(
|
||||
external_port['id'])
|
||||
ip_wrapper = ip_lib.IPWrapper(namespace=router.ns_name)
|
||||
ra_state = ip_wrapper.netns.execute(['sysctl', '-b',
|
||||
'net.ipv6.conf.%s.accept_ra' % external_device_name])
|
||||
self.assertEqual('2', ra_state)
|
||||
self._assert_ipv6_accept_ra(router)
|
||||
|
||||
if enable_ha:
|
||||
self._assert_ha_device(router)
|
||||
|
@ -18,11 +18,13 @@ import copy
|
||||
import mock
|
||||
from neutron_lib import constants as l3_constants
|
||||
import six
|
||||
import testtools
|
||||
|
||||
from neutron.agent.l3 import agent as neutron_l3_agent
|
||||
from neutron.agent.l3 import namespaces
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.common import constants
|
||||
from neutron.common import ipv6_utils
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.tests.common import l3_test_common
|
||||
from neutron.tests.common import net_helpers
|
||||
@ -97,6 +99,20 @@ class L3HATestCase(framework.L3AgentTestFramework):
|
||||
self._router_lifecycle(enable_ha=True, dual_stack=True,
|
||||
v6_ext_gw_with_sub=False)
|
||||
|
||||
@testtools.skipUnless(ipv6_utils.is_enabled(), "IPv6 is not enabled")
|
||||
def test_ipv6_router_advts_after_router_state_change(self):
|
||||
# Schedule router to l3 agent, and then add router gateway. Verify
|
||||
# that router gw interface is configured to receive Router Advts.
|
||||
router_info = l3_test_common.prepare_router_data(
|
||||
enable_snat=True, enable_ha=True, dual_stack=True, enable_gw=False)
|
||||
router = self.manage_router(self.agent, router_info)
|
||||
common_utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
_ext_dev_name, ex_port = l3_test_common.prepare_ext_gw_test(
|
||||
mock.Mock(), router)
|
||||
router_info['gw_port'] = ex_port
|
||||
router.process(self.agent)
|
||||
self._assert_ipv6_accept_ra(router)
|
||||
|
||||
def test_keepalived_configuration(self):
|
||||
router_info = self.generate_router_info(enable_ha=True)
|
||||
router = self.manage_router(self.agent, router_info)
|
||||
|
Loading…
Reference in New Issue
Block a user