From a3113c56c2aee11755890e22026423cc5b43c811 Mon Sep 17 00:00:00 2001 From: John Davidge Date: Thu, 1 Oct 2015 18:32:53 +0100 Subject: [PATCH] Add new config option for IPv6 Prefix Delegation With the impending deprecation of the default subnetpool configuration options, IPv6 PD needs to be enabled with a new config option. This patch adds the 'ipv6_pd_enabled' option to neutron.conf, and makes all of the necessary changes for its use. DocImpact Change-Id: I43486c5a13ee2ff0097355afe7e1f3ef8794b185 Closes-Bug: 1501835 --- etc/neutron.conf | 12 +++++++++--- neutron/common/config.py | 3 +++ neutron/common/constants.py | 4 ++-- neutron/db/db_base_plugin_v2.py | 2 ++ neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py | 3 +-- neutron/tests/unit/db/test_db_base_plugin_v2.py | 5 +++-- neutron/tests/unit/db/test_ipam_pluggable_backend.py | 3 +-- 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/etc/neutron.conf b/etc/neutron.conf index 3ec158584a8..0575c03b6e4 100644 --- a/etc/neutron.conf +++ b/etc/neutron.conf @@ -166,11 +166,17 @@ # Default Subnet Pool to be used for IPv6 subnet-allocation. # Specifies by UUID the pool to be used in case of subnet-create being -# called without a subnet-pool ID. Set to "prefix_delegation" -# to enable IPv6 Prefix Delegation in a PD-capable environment. -# See the description for default_ipv4_subnet_pool for more information. +# called without a subnet-pool ID. See the description for +# default_ipv4_subnet_pool for more information. # default_ipv6_subnet_pool = +# Set to True to enable IPv6 Prefix Delegation for subnet-allocation in a +# PD-capable environment. Users making subnet-create requests for v6 subnets +# without providing a cidr or subnetpool ID will be given a cidr via the Prefix +# Delegation mechanism. Note that enabling PD will override the behavior of +# the default IPv6 subnetpool. +# ipv6_pd_enabled = + # =========== items for MTU selection and advertisement ============= # Advertise MTU. If True, effort is made to advertise MTU # settings to VMs via network methods (ie. DHCP and RA MTU options) diff --git a/neutron/common/config.py b/neutron/common/config.py index a598f73f427..1f07ba00a0d 100644 --- a/neutron/common/config.py +++ b/neutron/common/config.py @@ -78,6 +78,9 @@ core_opts = [ cfg.StrOpt('default_ipv6_subnet_pool', help=_("Default IPv6 subnet-pool to be used for automatic " "subnet CIDR allocation")), + cfg.BoolOpt('ipv6_pd_enabled', default=False, + help=_("Enables IPv6 Prefix Delegation for automatic subnet " + "CIDR allocation")), cfg.IntOpt('dhcp_lease_duration', default=86400, deprecated_name='dhcp_lease_time', help=_("DHCP lease duration (in seconds). Use -1 to tell " diff --git a/neutron/common/constants.py b/neutron/common/constants.py index a5f34ee9d2d..8d468d3b858 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -142,8 +142,8 @@ IPV6_MODES = [DHCPV6_STATEFUL, DHCPV6_STATELESS, IPV6_SLAAC] IPV6_LLA_PREFIX = 'fe80::/64' -# Human-readable ID to which default_ipv6_subnet_pool should be set to -# indicate that IPv6 Prefix Delegation should be used to allocate subnet CIDRs +# Human-readable ID to which the subnetpool ID should be set to +# indicate that IPv6 Prefix Delegation is enabled for a given subnet IPV6_PD_POOL_ID = 'prefix_delegation' # Special provisional prefix for IPv6 Prefix Delegation diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 5ea921c3489..bf032ada4c9 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -632,6 +632,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, if ip_version == 4: return cfg.CONF.default_ipv4_subnet_pool + if cfg.CONF.ipv6_pd_enabled: + return constants.IPV6_PD_POOL_ID return cfg.CONF.default_ipv6_subnet_pool def create_subnet(self, context, subnet): diff --git a/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py index 68ec79d141b..341436af045 100644 --- a/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py +++ b/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py @@ -30,8 +30,7 @@ class TestL3RpcCallback(testlib_api.SqlTestCase): self.setup_coreplugin(test_db_base_plugin_v2.DB_PLUGIN_KLASS) self.plugin = manager.NeutronManager.get_plugin() self.ctx = context.get_admin_context() - cfg.CONF.set_override('default_ipv6_subnet_pool', - constants.IPV6_PD_POOL_ID) + cfg.CONF.set_override('ipv6_pd_enabled', True) self.callbacks = l3_rpc.L3RpcCallback() self.network = self._prepare_network() diff --git a/neutron/tests/unit/db/test_db_base_plugin_v2.py b/neutron/tests/unit/db/test_db_base_plugin_v2.py index 6354c1274e0..cc87fc1bf0f 100644 --- a/neutron/tests/unit/db/test_db_base_plugin_v2.py +++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py @@ -1713,8 +1713,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s if ipv6_pd: cidr = None gateway = None - cfg.CONF.set_override('default_ipv6_subnet_pool', - constants.IPV6_PD_POOL_ID) + cfg.CONF.set_override('ipv6_pd_enabled', True) return (self._make_subnet(self.fmt, network, gateway=gateway, cidr=cidr, ip_version=6, ipv6_ra_mode=ra_addr_mode, @@ -2814,6 +2813,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_create_subnet_only_ip_version_v6_no_pool(self): with self.network() as network: tenant_id = network['network']['tenant_id'] + cfg.CONF.set_override('ipv6_pd_enabled', False) cfg.CONF.set_override('default_ipv6_subnet_pool', None) data = {'subnet': {'network_id': network['network']['id'], 'ip_version': '6', @@ -2856,6 +2856,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): tenant_id=tenant_id, min_prefixlen='64') as subnetpool: subnetpool_id = subnetpool['subnetpool']['id'] + cfg.CONF.set_override('ipv6_pd_enabled', False) cfg.CONF.set_override('default_ipv6_subnet_pool', subnetpool_id) data = {'subnet': {'network_id': network['network']['id'], diff --git a/neutron/tests/unit/db/test_ipam_pluggable_backend.py b/neutron/tests/unit/db/test_ipam_pluggable_backend.py index 97e79f561cf..5ca13cc0f05 100644 --- a/neutron/tests/unit/db/test_ipam_pluggable_backend.py +++ b/neutron/tests/unit/db/test_ipam_pluggable_backend.py @@ -290,8 +290,7 @@ class TestDbBasePluginIpam(test_db_base.NeutronDbPluginV2TestCase): @mock.patch('neutron.ipam.driver.Pool') def test_create_ipv6_pd_subnet_over_ipam(self, pool_mock): mocks = self._prepare_mocks_with_pool_mock(pool_mock) - cfg.CONF.set_override('default_ipv6_subnet_pool', - constants.IPV6_PD_POOL_ID) + cfg.CONF.set_override('ipv6_pd_enabled', True) cidr = constants.PROVISIONAL_IPV6_PD_PREFIX allocation_pools = [netaddr.IPRange('::2', '::ffff:ffff:ffff:ffff')] with self.subnet(cidr=None, ip_version=6,