Ensure mysql_sql_mode is set for MySQLOpportunisticTests
The default setting for oslo.db is TRADITIONAL for mysql_sql_mode; this is set up in oslo_db/options.py as well as in EngineFacade; however, the provisioning system currently does not use these options or EngineFacade, and the default for mysql_sql_mode in the base session.create_engine() is None. For a MySQL/MariaDB database where this is not established in my.cnf, tests will run without TRADITIONAL SQL mode and some tests will fail, including some Nova migration tests that rely upon this. This patch resolves that as well as the warning we see in tests regarding the empty SQL mode. Change-Id: I3acdc0fb30327f56a76ee299cc6bade7c5a7e312
This commit is contained in:
1 parent
98b434db7d
commit
cfbe5c5634
3 files changed
+26
-3
No files matched your search
@@ -244,6 +244,8 @@ class BackendImpl(object):
|
||||
|
||||
"""
|
||||
|
||||
default_engine_kwargs = {}
|
||||
|
||||
@classmethod
|
||||
def all_impls(cls):
|
||||
"""Return an iterator of all possible BackendImpl objects.
|
||||
@@ -314,11 +316,16 @@ class BackendImpl(object):
|
||||
url.database = ident
|
||||
return session.create_engine(
|
||||
url,
|
||||
logging_name="%s@%s" % (self.drivername, ident))
|
||||
logging_name="%s@%s" % (self.drivername, ident),
|
||||
**self.default_engine_kwargs
|
||||
)
|
||||
|
||||
|
||||
@BackendImpl.impl.dispatch_for("mysql")
|
||||
class MySQLBackendImpl(BackendImpl):
|
||||
|
||||
default_engine_kwargs = {'mysql_sql_mode': 'TRADITIONAL'}
|
||||
|
||||
def create_opportunistic_driver_url(self):
|
||||
return "mysql://openstack_citest:openstack_citest@localhost/"
|
||||
|
||||
|
||||
@@ -441,8 +441,11 @@ class MysqlConnectTest(test_base.MySQLOpportunisticTestCase):
|
||||
# If _mysql_set_mode_callback is called with sql_mode=None, then
|
||||
# the SQL mode is NOT set on the connection.
|
||||
|
||||
# get the GLOBAL sql_mode, not the @@SESSION, so that
|
||||
# we get what is configured for the MySQL database, as opposed
|
||||
# to what our own session.create_engine() has set it to.
|
||||
expected = self.engine.execute(
|
||||
"SHOW VARIABLES LIKE 'sql_mode'").fetchone()[1]
|
||||
"SELECT @@GLOBAL.sql_mode").scalar()
|
||||
|
||||
engine = self._fixture(sql_mode=None)
|
||||
self._assert_sql_mode(engine, expected, None)
|
||||
|
||||
@@ -209,6 +209,16 @@ class FakeDB2Engine(object):
|
||||
pass
|
||||
|
||||
|
||||
class MySQLDefaultModeTestCase(test_base.MySQLOpportunisticTestCase):
|
||||
def test_default_is_traditional(self):
|
||||
with self.engine.connect() as conn:
|
||||
sql_mode = conn.execute(
|
||||
"SHOW VARIABLES LIKE 'sql_mode'"
|
||||
).first()[1]
|
||||
|
||||
self.assertTrue("TRADITIONAL" in sql_mode)
|
||||
|
||||
|
||||
class MySQLModeTestCase(test_base.MySQLOpportunisticTestCase):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -441,8 +451,11 @@ class MysqlConnectTest(test_base.MySQLOpportunisticTestCase):
|
||||
# If _mysql_set_mode_callback is called with sql_mode=None, then
|
||||
# the SQL mode is NOT set on the connection.
|
||||
|
||||
# get the GLOBAL sql_mode, not the @@SESSION, so that
|
||||
# we get what is configured for the MySQL database, as opposed
|
||||
# to what our own session.create_engine() has set it to.
|
||||
expected = self.engine.execute(
|
||||
"SHOW VARIABLES LIKE 'sql_mode'").fetchone()[1]
|
||||
"SELECT @@GLOBAL.sql_mode").scalar()
|
||||
|
||||
engine = self._fixture(sql_mode=None)
|
||||
self._assert_sql_mode(engine, expected, None)
|
||||
|
||||
Reference in new issue
Block a user