]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Allow non-root ip in subnet CIDR
authorJay S. Bryant <jsbryant@us.ibm.com>
Sun, 9 Jun 2013 13:43:55 +0000 (08:43 -0500)
committerJay S. Bryant <jsbryant@us.ibm.com>
Mon, 1 Jul 2013 20:18:47 +0000 (15:18 -0500)
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

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

index 3860a5b6cf3a373d943edaf578ab6a7597e27052..dff54f99d8cd25430791cdaa86b48376652651e9 100644 (file)
@@ -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
 
index 6122de51d000cb9cfb02edfb6699730d2c1c6195..729dfe28fefa12a3e2118c4044bacf5b23252343 100644 (file)
@@ -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: