Ensures port is not created when database exception occurs

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
This commit is contained in:
Gary Kotton 2012-10-08 04:18:11 +00:00
parent d7a440abc9
commit 6d2bfa49e8
2 changed files with 15 additions and 3 deletions

View 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)

View 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: