]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
improve UT coverage for nicira_db operations
authorarmando-migliaccio <armamig@gmail.com>
Tue, 14 Jan 2014 21:35:06 +0000 (13:35 -0800)
committerThomas Goirand <thomas@goirand.fr>
Thu, 13 Mar 2014 07:20:15 +0000 (15:20 +0800)
Also, ensure that a rollback is issued in the
event of any DB error.

Change-Id: I706db09f11fb5f6b369a1bd0cb1016df7d0359b5
Related-bug: #1265472

neutron/plugins/nicira/dbexts/nicira_db.py
neutron/tests/unit/nicira/test_nicira_db.py

index 10155145b91216c92bb377624b78ba6d1e157201..15697cb7d0c4bbb41970795dd79c823486fe868b 100644 (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
 
 
index accb6fd8e8f7941fdfe3fc2a3858d5df44f7c005..de0e745e92cf2b4387f190a3a49fc221414d9bbc 100644 (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)