diff --git a/quantum/db/db_base_plugin_v2.py b/quantum/db/db_base_plugin_v2.py index 64de1b1530d..27d44f59ba8 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 6122de51d00..729dfe28fef 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: