From: Wei Hu Date: Thu, 13 Nov 2014 10:19:39 +0000 (+0800) Subject: Remove DBDuplicateEntry columns check X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a7eead2f1fa71466c5734413165752dc9386ca89;p=openstack-build%2Fneutron-build.git Remove DBDuplicateEntry columns check 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 --- diff --git a/neutron/db/agents_db.py b/neutron/db/agents_db.py index ffcfed37f..c147a0f3f 100644 --- a/neutron/db/agents_db.py +++ b/neutron/db/agents_db.py @@ -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): diff --git a/neutron/tests/unit/db/test_agent_db.py b/neutron/tests/unit/db/test_agent_db.py index b0a1daef3..9f6c18ca2 100644 --- a/neutron/tests/unit/db/test_agent_db.py +++ b/neutron/tests/unit/db/test_agent_db.py @@ -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 ]