improve UT coverage for nicira_db operations

Also, ensure that a rollback is issued in the
event of any DB error.

Change-Id: I706db09f11fb5f6b369a1bd0cb1016df7d0359b5
Related-bug: #1265472
This commit is contained in:
armando-migliaccio
2014-01-14 13:35:06 -08:00
committed by Gerrit Code Review
parent 3d851a7e44
commit e447211094
2 changed files with 13 additions and 0 deletions

View File

@@ -67,6 +67,10 @@ def add_neutron_nsx_port_mapping(session, neutron_id,
LOG.debug(_("Port mapping for %s already available"), neutron_id)
else:
raise
except d_exc.DBError:
# rollback for any other db error
session.rollback()
raise
return mapping

View File

@@ -77,3 +77,12 @@ class NiciraDBTestCase(base.BaseTestCase):
nicira_db.add_neutron_nsx_port_mapping,
self.ctx.session, neutron_port_id,
nsx_switch_id, nsx_port_id_2)
def test_add_neutron_nsx_port_mapping_raise_integrity_constraint(self):
neutron_port_id = 'foo_neutron_port_id'
nsx_port_id = 'foo_nsx_port_id'
nsx_switch_id = 'foo_nsx_switch_id'
self.assertRaises(d_exc.DBError,
nicira_db.add_neutron_nsx_port_mapping,
self.ctx.session, neutron_port_id,
nsx_switch_id, nsx_port_id)