From ac0f86858dfb09e6db42ffbe74b355b632aeb8c8 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Mon, 2 Feb 2015 15:35:37 -0800 Subject: [PATCH] Switch from mysql-python to PyMySQL mysql-python undesireable over PyMySQL for a few reasons. Mainly, it does not support Py3* and does not work well with eventlet. There is also a bug in using oslo.db with PyMySQL where reference errors are not properly detected. This fixed in oslo.db ab20754db71e55b79b9e71e36ad86d9befc89a92 but we should still work around this unless global-requirements are bumped for oslo.db. Also adding pymysql to requirements since it is a pure python library and having a codebase that can 'just work' is awesome. Change-Id: I0058193c7cbd329731ade37108614fa6eb19d0f7 --- etc/storyboard.conf.sample | 2 +- requirements-py3.txt | 1 + requirements.txt | 1 + storyboard/db/api/base.py | 24 ++++++++++++------- storyboard/tests/base.py | 4 ++-- .../tests/db/migration/test_migrations.conf | 4 ++-- .../db/migration/test_migrations_base.py | 2 +- test-requirements.txt | 3 --- 8 files changed, 23 insertions(+), 18 deletions(-) diff --git a/etc/storyboard.conf.sample b/etc/storyboard.conf.sample index d9cd3a12..f31f2ccf 100644 --- a/etc/storyboard.conf.sample +++ b/etc/storyboard.conf.sample @@ -110,7 +110,7 @@ lock_path = $state_path/lock [database] # This line MUST be changed to actually run storyboard # Example: -# connection = mysql://root:pass@127.0.0.1:3306/storyboard +# connection = mysql+pymysql://root:pass@127.0.0.1:3306/storyboard # Replace 127.0.0.1 above with the IP address of the database used by the # main storyboard server. (Leave it as is if the database runs on this host.) # connection=sqlite:// diff --git a/requirements-py3.txt b/requirements-py3.txt index a3758fbc..85ddecfa 100644 --- a/requirements-py3.txt +++ b/requirements-py3.txt @@ -26,3 +26,4 @@ python-crontab>=1.8.1 tzlocal>=1.1.2 rfc3987>=1.3.4 Jinja2>=2.7.3 +PyMySQL>=0.6.2 diff --git a/requirements.txt b/requirements.txt index d57ddd8d..2fd7be60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,3 +27,4 @@ tzlocal>=1.1.2 rfc3987>=1.3.4 email>=4.0.2 Jinja2>=2.7.3 +PyMySQL>=0.6.2 diff --git a/storyboard/db/api/base.py b/storyboard/db/api/base.py index 13394444..b0728ef8 100644 --- a/storyboard/db/api/base.py +++ b/storyboard/db/api/base.py @@ -266,9 +266,6 @@ def entity_create(kls, values): except db_exc.DBDuplicateEntry as de: raise exc.DBDuplicateEntry(object_name=kls.__name__, value=de.value) - except db_exc.DBReferenceError as re: - raise exc.DBReferenceError(object_name=kls.__name__, - value=re.constraint, key=re.key) except db_exc.DBConnectionError: raise exc.DBConnectionError() except db_exc.ColumnError: @@ -277,6 +274,11 @@ def entity_create(kls, values): raise exc.DBDeadLock() except db_exc.DBInvalidUnicodeParameter: raise exc.DBInvalidUnicodeParameter + # XXX(greghaynes) Due to a bug in oslo.db + PyMySQL reference errors + # are not properly raised. + except db_exc.DBError: + raise exc.DBReferenceError(object_name=kls.__name__, + value='unknown', key='unknown') return entity @@ -299,9 +301,6 @@ def entity_update(kls, entity_id, values): except db_exc.DBDuplicateEntry as de: raise exc.DBDuplicateEntry(object_name=kls.__name__, value=de.value) - except db_exc.DBReferenceError as re: - raise exc.DBReferenceError(object_name=kls.__name__, - value=re.constraint, key=re.key) except db_exc.DBConnectionError: raise exc.DBConnectionError() except db_exc.ColumnError: @@ -310,6 +309,11 @@ def entity_update(kls, entity_id, values): raise exc.DBDeadLock() except db_exc.DBInvalidUnicodeParameter: raise exc.DBInvalidUnicodeParameter + # XXX(greghaynes) Due to a bug in oslo.db + PyMySQL reference errors + # are not properly raised. + except db_exc.DBError: + raise exc.DBReferenceError(object_name=kls.__name__, + value='error', key='error') session = get_session() entity = __entity_get(kls, entity_id, session) @@ -330,9 +334,6 @@ def entity_hard_delete(kls, entity_id): session.delete(entity) - except db_exc.DBReferenceError as re: - raise exc.DBReferenceError(object_name=kls.__name__, - value=re.constraint, key=re.key) except db_exc.DBConnectionError: raise exc.DBConnectionError() except db_exc.ColumnError: @@ -341,3 +342,8 @@ def entity_hard_delete(kls, entity_id): raise exc.DBDeadLock() except db_exc.DBInvalidUnicodeParameter: raise exc.DBInvalidUnicodeParameter() + # XXX(greghaynes) Due to a bug in oslo.db + PyMySQL reference errors + # are not properly raised. + except db_exc.DBError: + raise exc.DBReferenceError(object_name=kls.__name__, + value='unkonwn', key='unknonwn') diff --git a/storyboard/tests/base.py b/storyboard/tests/base.py index e7048640..133f9086 100644 --- a/storyboard/tests/base.py +++ b/storyboard/tests/base.py @@ -69,8 +69,8 @@ class TestCase(testtools.TestCase): if env_test_db is not None: self.test_connection = env_test_db else: - self.test_connection = ("mysql://openstack_citest:openstack_citest" - "@127.0.0.1:3306") + self.test_connection = ("mysql+pymysql://openstack_citest:" + "openstack_citest@127.0.0.1:3306") self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) diff --git a/storyboard/tests/db/migration/test_migrations.conf b/storyboard/tests/db/migration/test_migrations.conf index 4e5948ef..11e498c2 100644 --- a/storyboard/tests/db/migration/test_migrations.conf +++ b/storyboard/tests/db/migration/test_migrations.conf @@ -6,7 +6,7 @@ #sqlite=sqlite:// #sqlitefile=sqlite:///test_migrations_utils.db -mysql=mysql+mysqldb://storyboard:storyboard@localhost/test_migrations_utils +mysql=mysql+pymysql://storyboard:storyboard@localhost/test_migrations_utils [migration_dbs] # Migration DB details are listed separately as they can't be connected to @@ -17,7 +17,7 @@ mysql=mysql+mysqldb://storyboard:storyboard@localhost/test_migrations_utils #sqlite=sqlite:// #sqlitefile=sqlite:///test_migrations.db -#mysql=mysql+mysqldb://user:pass@localhost/test_migrations +#mysql=mysql+pymysql://user:pass@localhost/test_migrations [walk_style] snake_walk=yes diff --git a/storyboard/tests/db/migration/test_migrations_base.py b/storyboard/tests/db/migration/test_migrations_base.py index 20bc5815..0c85dbfe 100644 --- a/storyboard/tests/db/migration/test_migrations_base.py +++ b/storyboard/tests/db/migration/test_migrations_base.py @@ -53,7 +53,7 @@ def _get_connect_string(backend, user, passwd, database): """ if backend == "mysql": - backend = "mysql+mysqldb" + backend = "mysql+pymysql" else: raise Exception("Unrecognized backend: '%s'" % backend) diff --git a/test-requirements.txt b/test-requirements.txt index dd418d85..857c4185 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -14,9 +14,6 @@ testtools>=0.9.34 posix_ipc>=0.9.8 -# Some of the tests use real MySQL and Postgres databases -MySQL-python - # Doc requirements sphinx>=1.1.2,<1.2 sphinxcontrib-pecanwsme>=0.5