diff --git a/neutron/plugins/nicira/dbexts/nicira_db.py b/neutron/plugins/nicira/dbexts/nicira_db.py index 10155145b9..15697cb7d0 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 accb6fd8e8..de0e745e92 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)