From: Jay S. Bryant Date: Sun, 9 Jun 2013 13:43:55 +0000 (-0500) Subject: Allow non-root ip in subnet CIDR X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=af91fe1e179effcbb89fee0b9fa037290585a444;p=openstack-build%2Fneutron-build.git Allow non-root ip in subnet CIDR If a subnet is created using an IP that isn't a root IP (doesn't end with .0) the code that handles IP checking for fixed IPs fails. This fix changes the check for a valid IP to use the net.network IP address to avoid problems in subnets created with the non-root CIDR. (fixes bug 1188845) Change-Id: I89df64261d0f2741668576e45dc8f026857f20b0 --- diff --git a/quantum/db/db_base_plugin_v2.py b/quantum/db/db_base_plugin_v2.py index 3860a5b6c..dff54f99d 100644 --- a/quantum/db/db_base_plugin_v2.py +++ b/quantum/db/db_base_plugin_v2.py @@ -554,7 +554,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2, # network or the broadcast address if (ip != net.network and ip != net.broadcast and - net.netmask & ip == net.ip): + net.netmask & ip == net.network): return True return False diff --git a/quantum/tests/unit/test_db_plugin.py b/quantum/tests/unit/test_db_plugin.py index 6122de51d..729dfe28f 100644 --- a/quantum/tests/unit/test_db_plugin.py +++ b/quantum/tests/unit/test_db_plugin.py @@ -1543,6 +1543,26 @@ 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, 400) + def test_fixed_ip_valid_ip_non_root_cidr(self): + with self.subnet(cidr='10.0.0.254/24') as subnet: + # Allocate specific IP + kwargs = {"fixed_ips": [{'subnet_id': subnet['subnet']['id'], + 'ip_address': '10.0.0.2'}]} + net_id = subnet['subnet']['network_id'] + res = self._create_port(self.fmt, net_id=net_id, **kwargs) + self.assertEqual(res.status_int, 201) + port = self.deserialize(self.fmt, res) + self._delete('ports', port['port']['id']) + + def test_fixed_ip_invalid_ip_non_root_cidr(self): + with self.subnet(cidr='10.0.0.254/24') as subnet: + # Allocate specific IP + kwargs = {"fixed_ips": [{'subnet_id': subnet['subnet']['id'], + 'ip_address': '10.0.1.2'}]} + net_id = subnet['subnet']['network_id'] + res = self._create_port(self.fmt, net_id=net_id, **kwargs) + self.assertEqual(res.status_int, 400) + def test_requested_ips_only(self): with self.subnet() as subnet: with self.port(subnet=subnet) as port: