From cfbe5c56340c0e4a3b18902d7e55bb18a45857ec Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 7 Jan 2015 17:43:30 -0500 Subject: 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 --- oslo_db/tests/sqlalchemy/test_sqlalchemy.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'oslo_db/tests/sqlalchemy/test_sqlalchemy.py') diff --git a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py index 26cda61..28ae411 100644 --- a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py +++ b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py @@ -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) -- cgit v1.2.1