From: Eugene Nikanorov Date: Fri, 22 Aug 2014 12:29:49 +0000 (+0400) Subject: Raise proper exception in case duplicate ipv6 address is allocated X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=eb3be39521659d0d5a0ddfdc33b08f6d0c24db39;p=openstack-build%2Fneutron-build.git Raise proper exception in case duplicate ipv6 address is allocated 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 --- diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 910e3e7f9..3beda98c6 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -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) diff --git a/neutron/tests/unit/oneconvergence/test_nvsd_plugin.py b/neutron/tests/unit/oneconvergence/test_nvsd_plugin.py index d186f1a4d..06d9cdaca 100644 --- a/neutron/tests/unit/oneconvergence/test_nvsd_plugin.py +++ b/neutron/tests/unit/oneconvergence/test_nvsd_plugin.py @@ -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): diff --git a/neutron/tests/unit/test_db_plugin.py b/neutron/tests/unit/test_db_plugin.py index 0145a34b8..a81c9f480 100644 --- a/neutron/tests/unit/test_db_plugin.py +++ b/neutron/tests/unit/test_db_plugin.py @@ -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: