]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove DBDuplicateEntry columns check
authorWei Hu <hwhu@cn.ibm.com>
Thu, 13 Nov 2014 10:19:39 +0000 (18:19 +0800)
committerWeiHu <hwhu@cn.ibm.com>
Fri, 9 Jan 2015 03:41:29 +0000 (11:41 +0800)
DBDuplicateEntry exception does not provide columns for db2.
we have to remove this exception columns check in neutron/
db/agents_db.py. It is safe to remove columns check here, since
only the duplication of host and agent_type can raise this
exception.

Change-Id: I00d7b7c64de2912dda9fa57c08d90b1ef1c3aed7
Closes-bug: #1391766

neutron/db/agents_db.py
neutron/tests/unit/db/test_agent_db.py

index ffcfed37f8a3ed410557f6cd4d5618bafb403a52..c147a0f3fe1e5196dea5a849178b485abd9ccd04 100644 (file)
@@ -19,7 +19,6 @@ from oslo.config import cfg
 from oslo.db import exception as db_exc
 from oslo import messaging
 from oslo.serialization import jsonutils
-from oslo.utils import excutils
 from oslo.utils import timeutils
 import sqlalchemy as sa
 from sqlalchemy.orm import exc
@@ -196,23 +195,20 @@ class AgentDbMixin(ext_agent.AgentPluginBase):
 
         try:
             return self._create_or_update_agent(context, agent)
-        except db_exc.DBDuplicateEntry as e:
-            with excutils.save_and_reraise_exception() as ctxt:
-                if e.columns == ['agent_type', 'host']:
-                    # It might happen that two or more concurrent transactions
-                    # are trying to insert new rows having the same value of
-                    # (agent_type, host) pair at the same time (if there has
-                    # been no such entry in the table and multiple agent status
-                    # updates are being processed at the moment). In this case
-                    # having a unique constraint on (agent_type, host) columns
-                    # guarantees that only one transaction will succeed and
-                    # insert a new agent entry, others will fail and be rolled
-                    # back. That means we must retry them one more time: no
-                    # INSERTs will be issued, because
-                    # _get_agent_by_type_and_host() will return the existing
-                    # agent entry, which will be updated multiple times
-                    ctxt.reraise = False
-                    return self._create_or_update_agent(context, agent)
+        except db_exc.DBDuplicateEntry:
+            # It might happen that two or more concurrent transactions
+            # are trying to insert new rows having the same value of
+            # (agent_type, host) pair at the same time (if there has
+            # been no such entry in the table and multiple agent status
+            # updates are being processed at the moment). In this case
+            # having a unique constraint on (agent_type, host) columns
+            # guarantees that only one transaction will succeed and
+            # insert a new agent entry, others will fail and be rolled
+            # back. That means we must retry them one more time: no
+            # INSERTs will be issued, because
+            # _get_agent_by_type_and_host() will return the existing
+            # agent entry, which will be updated multiple times
+            return self._create_or_update_agent(context, agent)
 
 
 class AgentExtRpcCallback(object):
index b0a1daef35bc7e17995590f54d0c602345013afe..9f6c18ca2afe240b2c88b20abd715ec4642f4393 100644 (file)
@@ -103,7 +103,7 @@ class TestAgentsDbMixin(testlib_api.SqlTestCase):
         #                   attempt on fail
         with mock.patch('sqlalchemy.orm.Session.add') as add_mock:
             add_mock.side_effect = [
-                exc.DBDuplicateEntry(columns=['agent_type', 'host']),
+                exc.DBDuplicateEntry(),
                 None
             ]