Make MySQL regexes generic across MySQL drivers
Note that mysqlconnector raises InternalError whereas mysqldb raises OperationalError when a deadlock is found. The reported error codes and messages are identical, however. Change-Id: Iac9167e0777e0bf4361bcf6a8722923cce052b90
This commit is contained in:
@@ -57,7 +57,8 @@ def filters(dbname, exception_type, regex):
|
||||
# psycopg2.extensions.TransactionRollbackError(OperationalError),
|
||||
# as well as sqlalchemy.exc.DBAPIError, as SQLAlchemy will reraise it
|
||||
# as this until issue #3075 is fixed.
|
||||
@filters("mysql", sqla_exc.OperationalError, r"^.*\(1213, 'Deadlock.*")
|
||||
@filters("mysql", sqla_exc.OperationalError, r"^.*\b1213\b.*Deadlock found.*")
|
||||
@filters("mysql", sqla_exc.InternalError, r"^.*\b1213\b.*Deadlock found.*")
|
||||
@filters("postgresql", sqla_exc.OperationalError, r"^.*deadlock detected.*")
|
||||
@filters("postgresql", sqla_exc.DBAPIError, r"^.*deadlock detected.*")
|
||||
@filters("ibm_db_sa", sqla_exc.DBAPIError, r"^.*SQL0911N.*")
|
||||
@@ -67,10 +68,14 @@ def _deadlock_error(operational_error, match, engine_name, is_disconnect):
|
||||
NOTE(comstud): In current versions of DB backends, Deadlock violation
|
||||
messages follow the structure:
|
||||
|
||||
mysql:
|
||||
mysql+mysqldb:
|
||||
(OperationalError) (1213, 'Deadlock found when trying to get lock; try '
|
||||
'restarting transaction') <query_str> <query_args>
|
||||
|
||||
mysql+mysqlconnector:
|
||||
(InternalError) 1213 (40001): Deadlock found when trying to get lock; try
|
||||
restarting transaction
|
||||
|
||||
postgresql:
|
||||
(TransactionRollbackError) deadlock detected <deadlock_details>
|
||||
|
||||
@@ -174,7 +179,7 @@ def _db2_dupe_key_error(integrity_error, match, engine_name, is_disconnect):
|
||||
raise exception.DBDuplicateEntry([], integrity_error)
|
||||
|
||||
|
||||
@filters("mysql", sqla_exc.DBAPIError, r".*\(1146")
|
||||
@filters("mysql", sqla_exc.DBAPIError, r".*\b1146\b")
|
||||
def _raise_mysql_table_doesnt_exist_asis(
|
||||
error, match, engine_name, is_disconnect):
|
||||
"""Raise MySQL error 1146 as is, so that it does not conflict with
|
||||
|
||||
@@ -41,6 +41,9 @@ class TestsExceptionFilter(test_base.DbTestCase):
|
||||
class InterfaceError(Error):
|
||||
pass
|
||||
|
||||
class InternalError(Error):
|
||||
pass
|
||||
|
||||
class IntegrityError(Error):
|
||||
pass
|
||||
|
||||
@@ -287,7 +290,7 @@ class TestDeadlock(TestsExceptionFilter):
|
||||
str(matched)
|
||||
)
|
||||
|
||||
def test_mysql_deadlock(self):
|
||||
def test_mysql_mysqldb_deadlock(self):
|
||||
self._run_deadlock_detect_test(
|
||||
"mysql",
|
||||
"(1213, 'Deadlock found when trying "
|
||||
@@ -295,6 +298,14 @@ class TestDeadlock(TestsExceptionFilter):
|
||||
"transaction')"
|
||||
)
|
||||
|
||||
def test_mysql_mysqlconnector_deadlock(self):
|
||||
self._run_deadlock_detect_test(
|
||||
"mysql",
|
||||
"1213 (40001): Deadlock found when trying to get lock; try "
|
||||
"restarting transaction",
|
||||
orig_exception_cls=self.InternalError
|
||||
)
|
||||
|
||||
def test_mysql_not_deadlock(self):
|
||||
self._not_deadlock_test(
|
||||
"mysql",
|
||||
|
||||
Reference in New Issue
Block a user