diff options
-rw-r--r-- | oslo_db/options.py | 1 | ||||
-rw-r--r-- | oslo_db/sqlalchemy/enginefacade.py | 14 | ||||
-rw-r--r-- | oslo_db/sqlalchemy/engines.py | 2 | ||||
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_enginefacade.py | 43 | ||||
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_sqlalchemy.py | 4 | ||||
-rw-r--r-- | releasenotes/notes/connection_debug_min_max-bf6d53d49be7ca52.yaml | 7 | ||||
-rw-r--r-- | requirements.txt | 6 | ||||
-rw-r--r-- | setup.cfg | 1 |
8 files changed, 72 insertions, 6 deletions
diff --git a/oslo_db/options.py b/oslo_db/options.py index 4ec1a33..a02dad5 100644 --- a/oslo_db/options.py +++ b/oslo_db/options.py @@ -102,6 +102,7 @@ database_opts = [ 'SQLAlchemy.'), cfg.IntOpt('connection_debug', default=0, + min=0, max=100, deprecated_opts=[cfg.DeprecatedOpt('sql_connection_debug', group='DEFAULT')], help='Verbosity of SQL debugging information: 0=None, ' diff --git a/oslo_db/sqlalchemy/enginefacade.py b/oslo_db/sqlalchemy/enginefacade.py index c935602..cd6745b 100644 --- a/oslo_db/sqlalchemy/enginefacade.py +++ b/oslo_db/sqlalchemy/enginefacade.py @@ -308,6 +308,16 @@ class _TransactionFactory(object): def _maker_args_for_conf(self, conf): return self._args_for_conf(self._maker_cfg, conf) + def dispose_pool(self): + """Call engine.pool.dispose() on underlying Engine objects.""" + with self._start_lock: + if not self._started: + return + + self._writer_engine.pool.dispose() + if self._reader_engine is not self._writer_engine: + self._reader_engine.pool.dispose() + def _start(self, conf=False, connection=None, slave_connection=None): with self._start_lock: # self._started has been checked on the outside @@ -638,6 +648,10 @@ class _TransactionContextManager(object): return self._factory.get_legacy_facade() + def dispose_pool(self): + """Call engine.pool.dispose() on underlying Engine objects.""" + self._factory.dispose_pool() + @property def replace(self): """Modifier to replace the global transaction factory with this one.""" diff --git a/oslo_db/sqlalchemy/engines.py b/oslo_db/sqlalchemy/engines.py index 54852b4..3e8bb0a 100644 --- a/oslo_db/sqlalchemy/engines.py +++ b/oslo_db/sqlalchemy/engines.py @@ -93,7 +93,7 @@ def _setup_logging(connection_debug=0): """ if connection_debug >= 0: logger = logging.getLogger('sqlalchemy.engine') - if connection_debug >= 100: + if connection_debug == 100: logger.setLevel(logging.DEBUG) elif connection_debug >= 50: logger.setLevel(logging.INFO) diff --git a/oslo_db/tests/sqlalchemy/test_enginefacade.py b/oslo_db/tests/sqlalchemy/test_enginefacade.py index d27f7bf..1365f1c 100644 --- a/oslo_db/tests/sqlalchemy/test_enginefacade.py +++ b/oslo_db/tests/sqlalchemy/test_enginefacade.py @@ -62,6 +62,7 @@ class SingletonEngine(SingletonOnName): super(SingletonEngine, self).__init__( "engine", connect=mock.Mock(return_value=connection), + pool=mock.Mock(), url=connection, _assert_connection=connection, **kw @@ -417,6 +418,48 @@ class MockFacadeTest(oslo_test_base.BaseTestCase): session.mock_calls, self.sessions.element_for_writer(writer).mock_calls) + def test_dispose_pool(self): + facade = enginefacade.transaction_context() + + facade.configure( + connection=self.engine_uri, + ) + + facade.dispose_pool() + self.assertFalse(hasattr(facade._factory, '_writer_engine')) + + facade._factory._start() + facade.dispose_pool() + + self.assertEqual( + facade._factory._writer_engine.pool.mock_calls, + [mock.call.dispose()] + ) + + def test_dispose_pool_w_reader(self): + facade = enginefacade.transaction_context() + + facade.configure( + connection=self.engine_uri, + slave_connection=self.slave_uri + ) + + facade.dispose_pool() + self.assertFalse(hasattr(facade._factory, '_writer_engine')) + self.assertFalse(hasattr(facade._factory, '_reader_engine')) + + facade._factory._start() + facade.dispose_pool() + + self.assertEqual( + facade._factory._writer_engine.pool.mock_calls, + [mock.call.dispose()] + ) + self.assertEqual( + facade._factory._reader_engine.pool.mock_calls, + [mock.call.dispose()] + ) + def test_session_reader_decorator(self): context = oslo_context.RequestContext() diff --git a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py index ceb2afe..6f327d6 100644 --- a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py +++ b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py @@ -18,6 +18,7 @@ """Unit tests for SQLAlchemy specific code.""" import logging +import os import fixtures import mock @@ -719,4 +720,5 @@ class PatchStacktraceTest(test_base.DbTestCase): call = mock_exec.mock_calls[0] # we're the caller, see that we're in there - self.assertIn("tests/sqlalchemy/test_sqlalchemy.py", call[1][1]) + caller = os.path.join("tests", "sqlalchemy", "test_sqlalchemy.py") + self.assertIn(caller, call[1][1]) diff --git a/releasenotes/notes/connection_debug_min_max-bf6d53d49be7ca52.yaml b/releasenotes/notes/connection_debug_min_max-bf6d53d49be7ca52.yaml new file mode 100644 index 0000000..7b0713b --- /dev/null +++ b/releasenotes/notes/connection_debug_min_max-bf6d53d49be7ca52.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - The allowed values for the ``connection_debug`` option are now restricted to + the range between 0 and 100 (inclusive). Previously a number lower than 0 + or higher than 100 could be given without error. But now, a + ``ConfigFileValueError`` will be raised when the option value is outside this + range. diff --git a/requirements.txt b/requirements.txt index 8da6b1a..3b7898d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,10 +6,10 @@ pbr>=1.6 # Apache-2.0 alembic>=0.8.4 # MIT debtcollector>=1.2.0 # Apache-2.0 oslo.i18n>=2.1.0 # Apache-2.0 -oslo.config>=3.10.0 # Apache-2.0 +oslo.config>=3.12.0 # Apache-2.0 oslo.context>=2.4.0 # Apache-2.0 -oslo.utils>=3.14.0 # Apache-2.0 +oslo.utils>=3.15.0 # Apache-2.0 SQLAlchemy<1.1.0,>=1.0.10 # MIT sqlalchemy-migrate>=0.9.6 # Apache-2.0 -stevedore>=1.10.0 # Apache-2.0 +stevedore>=1.16.0 # Apache-2.0 six>=1.9.0 # MIT @@ -32,7 +32,6 @@ postgresql = test = hacking<0.11,>=0.10.0 coverage>=3.6 # Apache-2.0 - discover # BSD doc8 # Apache-2.0 eventlet!=0.18.3,>=0.18.2 # MIT fixtures>=3.0.0 # Apache-2.0/BSD |