]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
No allocation needed for specific IPv6 SLAAC addr assignment
authorDane LeBlanc <leblancd@cisco.com>
Wed, 18 Mar 2015 16:41:25 +0000 (12:41 -0400)
committerDane LeBlanc <leblancd@cisco.com>
Fri, 27 Mar 2015 20:46:03 +0000 (16:46 -0400)
(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 <baoli@cisco.com>
Change-Id: I2533ee82980bb602faa663b875787ca50b268b34
Partially-implements: blueprint multiple-ipv6-prefixes

neutron/db/db_base_plugin_v2.py
neutron/tests/unit/test_db_plugin.py

index 5866326414c4a29e16248a49841b00b87e86dec6..ee07d62b7412cf9ed265c38740c05179c9bfaa5a 100644 (file)
@@ -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)
index 9daff92822e22fb06090f48e11d31bde30d7593e..69450ffcd375f792ddd3e026f8f24d5b859621d9 100644 (file)
@@ -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',