]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Ensure that subnet_id is on correct network.
authorGary Kotton <gkotton@redhat.com>
Sun, 1 Jul 2012 10:46:29 +0000 (06:46 -0400)
committerGary Kotton <gkotton@redhat.com>
Mon, 2 Jul 2012 13:50:52 +0000 (09:50 -0400)
Fixes bug 1019759.

Change-Id: I7a732ebf404c6fddaf6f06798411adbadd8ebb3f

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

index 55f98fd180e2844ccfdc633098acc1060e49728f..ab4da90905385513fbc95abba022321cff7abd5d 100644 (file)
@@ -344,6 +344,11 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
                     raise q_exc.InvalidInput(error_message=msg)
             else:
                 subnet = self._get_subnet(context, fixed['subnet_id'])
+                if subnet['network_id'] != network_id:
+                    msg = _('Failed to create port on network %s, '
+                            'because fixed_ips included invalid subnet '
+                            '%s') % (network_id, fixed['subnet_id'])
+                    raise q_exc.InvalidInput(error_message=msg)
                 subnet_id = subnet['id']
 
             if 'ip_address' in fixed:
index cdfa42ecd0cd66f8969feedf28145ee304a2fc38..c0808b5403b8477cd5bdce9f7abefc7aa5a01982 100644 (file)
@@ -425,6 +425,24 @@ class TestPortsV2(QuantumDbPluginV2TestCase):
                 self.assertEquals(ips[0]['ip_address'], '10.0.0.3')
                 self.assertEquals(ips[0]['subnet_id'], subnet['subnet']['id'])
 
+    def test_requested_subnet_id_not_on_network(self):
+        fmt = 'json'
+        with self.subnet() as subnet:
+            with self.port(subnet=subnet) as port:
+                # Create new network
+                res = self._create_network(fmt=fmt, name='net2',
+                                           admin_status_up=True)
+                network2 = self.deserialize(fmt, res)
+                subnet2 = self._make_subnet(fmt, network2, "1.1.1.1",
+                                            "1.1.1.0/24", 4)
+                net_id = port['port']['network_id']
+                # Request a IP from specific subnet
+                kwargs = {"fixed_ips": [{'subnet_id':
+                                         subnet2['subnet']['id']}]}
+                net_id = port['port']['network_id']
+                res = self._create_port(fmt, net_id=net_id, **kwargs)
+                self.assertEquals(res.status_int, 400)
+
     def test_requested_subnet_id_v4_and_v6(self):
         fmt = 'json'
         with self.subnet() as subnet: