From: armando-migliaccio Date: Tue, 14 Jan 2014 21:35:06 +0000 (-0800) Subject: improve UT coverage for nicira_db operations X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=da77203c92664e860047c01064d62dd1a985a166;p=openstack-build%2Fneutron-build.git 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 --- diff --git a/neutron/plugins/nicira/dbexts/nicira_db.py b/neutron/plugins/nicira/dbexts/nicira_db.py index 10155145b..15697cb7d 100644 --- a/neutron/plugins/nicira/dbexts/nicira_db.py +++ b/neutron/plugins/nicira/dbexts/nicira_db.py @@ -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 diff --git a/neutron/tests/unit/nicira/test_nicira_db.py b/neutron/tests/unit/nicira/test_nicira_db.py index accb6fd8e..de0e745e9 100644 --- a/neutron/tests/unit/nicira/test_nicira_db.py +++ b/neutron/tests/unit/nicira/test_nicira_db.py @@ -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)