]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Ensures port is not created when database exception occurs
authorGary Kotton <gkotton@redhat.com>
Mon, 8 Oct 2012 04:18:11 +0000 (04:18 +0000)
committerGary Kotton <gkotton@redhat.com>
Mon, 8 Oct 2012 04:31:42 +0000 (04:31 +0000)
Fixes bug 1064261

The port creation code did not correctly treat a database error. That is,
if there was an exception the port would be created and an error returned
to the client.

Change-Id: I6cf36d1c641b46716afb16f228b8daa631099a5d

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

index 3326f73c5bc006e51359e7bce3e168dc9d7bc465..36da230afa819acab1707e47defcb1776aab4719 100644 (file)
@@ -1159,9 +1159,8 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
                                   device_owner=p['device_owner'])
             context.session.add(port)
 
-        # Update the allocated IP's
-        if ips:
-            with context.session.begin(subtransactions=True):
+            # Update the allocated IP's
+            if ips:
                 for ip in ips:
                     LOG.debug("Allocated IP %s (%s/%s/%s)", ip['ip_address'],
                               port['network_id'], ip['subnet_id'], port.id)
index dd8c1a4bfa8c149e0a36ba246ba3f6d03c66bf96..8c9377387eb3252788c7c9f8216fd81c0600887d 100644 (file)
@@ -1193,6 +1193,19 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
                 for p in ports_to_delete:
                     self._delete('ports', p['port']['id'])
 
+    def test_duplicate_ips(self):
+        fmt = 'json'
+        with self.subnet() as subnet:
+            # Allocate specific IP
+            kwargs = {"fixed_ips": [{'subnet_id': subnet['subnet']['id'],
+                                     'ip_address': '10.0.0.5'},
+                                    {'subnet_id': subnet['subnet']['id'],
+                                     'ip_address': '10.0.0.5'}]}
+            net_id = subnet['subnet']['network_id']
+            res = self._create_port(fmt, net_id=net_id, **kwargs)
+            port2 = self.deserialize(fmt, res)
+            self.assertEquals(res.status_int, 500)
+
     def test_requested_ips_only(self):
         fmt = 'json'
         with self.subnet() as subnet: