From 81ebefe3d2f0404d628921153c9a3624dc9284de Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Fri, 22 Aug 2014 16:29:49 +0400 Subject: [PATCH] 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 --- neutron/db/db_base_plugin_v2.py | 6 ++++++ .../tests/unit/oneconvergence/test_nvsd_plugin.py | 3 +++ neutron/tests/unit/test_db_plugin.py | 14 ++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 910e3e7f98..3beda98c67 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 d186f1a4d0..06d9cdaca1 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 0145a34b86..a81c9f4809 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: