]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Raise proper exception in case duplicate ipv6 address is allocated
authorEugene Nikanorov <enikanorov@mirantis.com>
Fri, 22 Aug 2014 12:29:49 +0000 (16:29 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Mon, 25 Aug 2014 12:27:44 +0000 (16:27 +0400)
In case neutron tries to generate ipv6 address for slaac subnet,
it doesn't check that generated ip is unique and throws DB exception
that results in 500 HTTP error.

The fix throws proper IpAddressInUse exception.

Closes-Bug: #1358731
Change-Id: I66aed81b8d31d1eff6c87a77c4c4a813179ba458

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

index 910e3e7f9823442638798da572c1786fb9d3221a..3beda98c674ad5d15b69a4eef1e87af9fd0b63b3 100644 (file)
@@ -522,6 +522,12 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
                     prefix = subnet['cidr']
                     ip_address = ipv6_utils.get_ipv6_addr_by_EUI64(
                         prefix, mac)
+                    if not self._check_unique_ip(
+                        context, p['network_id'],
+                        subnet['id'], ip_address.format()):
+                        raise n_exc.IpAddressInUse(
+                            net_id=p['network_id'],
+                            ip_address=ip_address.format())
                     ips.append({'ip_address': ip_address.format(),
                                 'subnet_id': subnet['id']})
                     v6.remove(subnet)
index d186f1a4d0c210567bf4501234c9022e58797e68..06d9cdaca13b428699acebe15930b71bd83754da 100644 (file)
@@ -124,6 +124,9 @@ class TestOneConvergencePluginPortsV2(test_plugin.TestPortsV2,
     def test_ip_allocation_for_ipv6_subnet_slaac_adddress_mode(self):
         self.skipTest("NVSD Plugin does not support IPV6.")
 
+    def test_generated_duplicate_ip_ipv6(self):
+        self.skipTest("NVSD Plugin does not support IPV6.")
+
 
 class TestOneConvergenceBasicGet(test_plugin.TestBasicGet,
                                  OneConvergencePluginV2TestCase):
index 0145a34b86ed69d18d68c6163146eab9d486d27c..a81c9f48090c917966b8d55588914c1ba839ced5 100644 (file)
@@ -1302,6 +1302,20 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
                 res = self._create_port(self.fmt, net_id=net_id, **kwargs)
                 self.assertEqual(res.status_int, webob.exc.HTTPConflict.code)
 
+    def test_generated_duplicate_ip_ipv6(self):
+        with self.subnet(ip_version=6,
+                         cidr="2014::/64",
+                         ipv6_address_mode=constants.IPV6_SLAAC) as subnet:
+            with self.port(subnet=subnet,
+                           fixed_ips=[{'subnet_id': subnet['subnet']['id'],
+                                       'ip_address':
+                                       "2014::1322:33ff:fe44:5566"}]) as port:
+                # Check configuring of duplicate IP
+                kwargs = {"mac_address": "11:22:33:44:55:66"}
+                net_id = port['port']['network_id']
+                res = self._create_port(self.fmt, net_id=net_id, **kwargs)
+                self.assertEqual(res.status_int, webob.exc.HTTPConflict.code)
+
     def test_requested_subnet_delete(self):
         with self.subnet() as subnet:
             with self.port(subnet=subnet) as port: