summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Podoliaka <rpodolyaka@mirantis.com>2016-11-03 15:20:50 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2016-11-25 15:31:33 -0500
commitd4000aa2c8f45da5526e9de4bdf2731ba1795d09 (patch)
tree0139dcfd06f7ea5d5a50441a2f4314394135f77c
parentf4d58257b636b097875cf99f945decc948062c2b (diff)
downloadoslo-db-d4000aa2c8f45da5526e9de4bdf2731ba1795d09.tar.gz
Backport fix exc_filters for mysql-python
In order to backport changes to Newton, mysql-python tests need to pass, since it seems that tox.ini is still forcing MySQL tests to use MySQL-Python (not pymysql or mysqlclient at least). The change here re: libmysqlclient is impacting Newton, so backport. Something changed in mysql-python / libmysqlclient or mysql and now exceptions that used to be InternalError's have become OperationalError's. Update filters accordingly to wrap those into oslo.db exceptions properly. OperationalError's are kind of special, as we re-raise them as is due to historical reasons: we need to make sure that at least SAVEPOINT errors are wrapped, as that's what oslo.db and neutron unit tests expect. Closes-Bug: #1630899 Change-Id: I39ea8c4a0dc9d43992f00da7b1ff502595b4dc13 (cherry picked from commit 699933ca01884efe39cfed44946c3d570b5ebbfe)
-rw-r--r--oslo_db/sqlalchemy/exc_filters.py13
-rw-r--r--oslo_db/tests/sqlalchemy/test_exc_filters.py6
2 files changed, 17 insertions, 2 deletions
diff --git a/oslo_db/sqlalchemy/exc_filters.py b/oslo_db/sqlalchemy/exc_filters.py
index 9e5a2e5..fb46440 100644
--- a/oslo_db/sqlalchemy/exc_filters.py
+++ b/oslo_db/sqlalchemy/exc_filters.py
@@ -252,6 +252,9 @@ def _check_constraint_error(
@filters("mysql", sqla_exc.InternalError,
r".*1091,.*Can't DROP '(?P<constraint>.+)'; "
"check that column/key exists")
+@filters("mysql", sqla_exc.OperationalError,
+ r".*1091,.*Can't DROP '(?P<constraint>.+)'; "
+ "check that column/key exists")
@filters("mysql", sqla_exc.InternalError,
r".*1025,.*Error on rename of '.+/(?P<relation>.+)' to ")
def _check_constraint_non_existing(
@@ -277,6 +280,8 @@ def _check_constraint_non_existing(
r".* no such table: (?P<table>.+)")
@filters("mysql", sqla_exc.InternalError,
r".*1051,.*Unknown table '(.+\.)?(?P<table>.+)'\"")
+@filters("mysql", sqla_exc.OperationalError,
+ r".*1051,.*Unknown table '(.+\.)?(?P<table>.+)'\"")
@filters("postgresql", sqla_exc.ProgrammingError,
r".* table \"(?P<table>.+)\" does not exist")
def _check_table_non_existing(
@@ -331,6 +336,14 @@ def _raise_data_error(error, match, engine_name, is_disconnect):
raise exception.DBDataError(error)
+@filters("mysql", sqla_exc.OperationalError,
+ r".*\(1305,\s+\'SAVEPOINT\s+(.+)\s+does not exist\'\)")
+def _raise_savepoints_as_dberrors(error, match, engine_name, is_disconnect):
+ # NOTE(rpodolyaka): this is a special case of an OperationalError that used
+ # to be an InternalError. It's expected to be wrapped into oslo.db error.
+ raise exception.DBError(error)
+
+
@filters("*", sqla_exc.OperationalError, r".*")
def _raise_operational_errors_directly_filter(operational_error,
match, engine_name,
diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py
index e31f8dd..101b2eb 100644
--- a/oslo_db/tests/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py
@@ -305,7 +305,8 @@ class TestNonExistentConstraintMySQL(
# NOTE(jd) Cannot check precisely with assertInnerException since MySQL
# error are not the same depending on its version…
self.assertIsInstance(matched.inner_exception,
- sqlalchemy.exc.InternalError)
+ (sqlalchemy.exc.InternalError,
+ sqlalchemy.exc.OperationalError))
if matched.table is not None:
self.assertEqual("resource_foo", matched.table)
if matched.constraint is not None:
@@ -375,7 +376,8 @@ class TestNonExistentTableMySQL(
# NOTE(jd) Cannot check precisely with assertInnerException since MySQL
# error are not the same depending on its version…
self.assertIsInstance(matched.inner_exception,
- sqlalchemy.exc.InternalError)
+ (sqlalchemy.exc.InternalError,
+ sqlalchemy.exc.OperationalError))
self.assertEqual("foo", matched.table)