From 04cd03840977bc32b2bcadcd185a8c4ae19b7159 Mon Sep 17 00:00:00 2001 From: Dane LeBlanc Date: Wed, 18 Mar 2015 12:41:25 -0400 Subject: [PATCH] No allocation needed for specific IPv6 SLAAC addr assignment (Patch set #7 for the multiple-ipv6-prefixes blueprint) On internal router ports, Neutron allows for an address to be assigned for an IPv6 SLAAC subnet that is not necessarily EUI-64. This makes it easier for subnet create, since a convenient address, e.g. one ending in ::1, can be used as the subnet gateway IP address. Currently, when an internal router port is created with a specific (non-EUI-64) address for a SLAAC subnet, the call flow includes a call to _allocate_specific_ip. This call is not necessary, since we're not allocating an address from a pool (and recalibrating availability ranges, etc.). This patch set prevents the call to _allocate_specific_ip for this scenario. Co-Authored-By: Baodong (Robert) Li Change-Id: I2533ee82980bb602faa663b875787ca50b268b34 Partially-implements: blueprint multiple-ipv6-prefixes --- neutron/db/db_base_plugin_v2.py | 13 +++++++------ neutron/tests/unit/test_db_plugin.py | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 586632641..ee07d62b7 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -447,18 +447,19 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, """Allocate IP addresses according to the configured fixed_ips.""" ips = [] for fixed in fixed_ips: + subnet = self._get_subnet(context, fixed['subnet_id']) + is_auto_addr = ipv6_utils.is_auto_address_subnet(subnet) if 'ip_address' in fixed: - # Remove the IP address from the allocation pool - NeutronDbPluginV2._allocate_specific_ip( - context, fixed['subnet_id'], fixed['ip_address']) + if not is_auto_addr: + # Remove the IP address from the allocation pool + NeutronDbPluginV2._allocate_specific_ip( + context, fixed['subnet_id'], fixed['ip_address']) ips.append({'ip_address': fixed['ip_address'], 'subnet_id': fixed['subnet_id']}) # Only subnet ID is specified => need to generate IP # from subnet else: - subnet = self._get_subnet(context, fixed['subnet_id']) - if (subnet['ip_version'] == 6 and - ipv6_utils.is_auto_address_subnet(subnet)): + if is_auto_addr: prefix = subnet['cidr'] ip_address = ipv6_utils.get_ipv6_addr_by_EUI64( prefix, mac_address) diff --git a/neutron/tests/unit/test_db_plugin.py b/neutron/tests/unit/test_db_plugin.py index 9daff9282..69450ffcd 100644 --- a/neutron/tests/unit/test_db_plugin.py +++ b/neutron/tests/unit/test_db_plugin.py @@ -1620,7 +1620,10 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s self.assertEqual(res.status_int, webob.exc.HTTPClientError.code) - def test_requested_fixed_ip_address_v6_slaac_router_iface(self): + @mock.patch.object(db_base_plugin_v2.NeutronDbPluginV2, + '_allocate_specific_ip') + def test_requested_fixed_ip_address_v6_slaac_router_iface( + self, alloc_specific_ip): with self.subnet(gateway_ip='fe80::1', cidr='fe80::/64', ip_version=6, @@ -1635,6 +1638,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s self.assertEqual(len(port['port']['fixed_ips']), 1) self.assertEqual(port['port']['fixed_ips'][0]['ip_address'], 'fe80::1') + self.assertFalse(alloc_specific_ip.called) def test_requested_subnet_id_v6_slaac(self): with self.subnet(gateway_ip='fe80::1', -- 2.45.2