Skip to content

Commit

Permalink
Ensures port is not created when database exception occurs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Gary Kotton committed Oct 20, 2012
1 parent 4946d4b commit 51c8799
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions quantum/db/db_base_plugin_v2.py
Expand Up @@ -1160,9 +1160,8 @@ def create_port(self, context, port):
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)
Expand Down
13 changes: 13 additions & 0 deletions quantum/tests/unit/test_db_plugin.py
Expand Up @@ -1196,6 +1196,19 @@ def test_requested_split(self):
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:
Expand Down

0 comments on commit 51c8799

Please sign in to comment.