summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Podoliaka <rpodolyaka@mirantis.com>2014-06-16 12:48:48 +0300
committerRoman Podoliaka <rpodolyaka@mirantis.com>2014-06-16 13:03:27 +0300
commit5c1d5c81c98ab9ea3d598041868fa8036a864556 (patch)
treef507dff7a1b2abb8f2c63697234d23ba84c52236
parent2ed2f6085a397fa2a406bfeebb3d1d8476fd50be (diff)
downloadoslo-db-5c1d5c81c98ab9ea3d598041868fa8036a864556.tar.gz
Fix kwarg passed twice error in EngineFacade.from_config()juno-a20.2.0
slave_connection keyword argument is passed to EngineFacade init twice: the first time in code explicitly, and the second time when CONF.database options are unpacked. Actually, it's better to pass all the arguments explicitly rather than rely on the fact that argument names correspond to database options names (now they are tightly coupled). Closes-Bug: #1330426 Change-Id: Ic0aaf26e76f68adc48f7ed58fd4c7e9e87648005
-rw-r--r--oslo/db/sqlalchemy/session.py11
-rw-r--r--tests/sqlalchemy/test_sqlalchemy.py23
2 files changed, 24 insertions, 10 deletions
diff --git a/oslo/db/sqlalchemy/session.py b/oslo/db/sqlalchemy/session.py
index 90e544b..31d1fd0 100644
--- a/oslo/db/sqlalchemy/session.py
+++ b/oslo/db/sqlalchemy/session.py
@@ -945,4 +945,13 @@ class EngineFacade(object):
sqlite_fk=sqlite_fk,
autocommit=autocommit,
expire_on_commit=expire_on_commit,
- **dict(conf.database.items()))
+ mysql_sql_mode=conf.database.mysql_sql_mode,
+ idle_timeout=conf.database.idle_timeout,
+ connection_debug=conf.database.connection_debug,
+ max_pool_size=conf.database.max_pool_size,
+ max_overflow=conf.database.max_overflow,
+ pool_timeout=conf.database.pool_timeout,
+ sqlite_synchronous=conf.database.sqlite_synchronous,
+ connection_trace=conf.database.connection_trace,
+ max_retries=conf.database.max_retries,
+ retry_interval=conf.database.retry_interval)
diff --git a/tests/sqlalchemy/test_sqlalchemy.py b/tests/sqlalchemy/test_sqlalchemy.py
index d526004..2036e13 100644
--- a/tests/sqlalchemy/test_sqlalchemy.py
+++ b/tests/sqlalchemy/test_sqlalchemy.py
@@ -17,6 +17,7 @@
"""Unit tests for SQLAlchemy specific code."""
import logging
+from oslo.config import cfg
import _mysql_exceptions
import fixtures
@@ -30,6 +31,7 @@ from sqlalchemy.exc import DataError
from sqlalchemy.ext.declarative import declarative_base
from oslo.db import exception as db_exc
+from oslo.db import options as db_options
from oslo.db.sqlalchemy import models
from oslo.db.sqlalchemy import session
from oslo.db.sqlalchemy import test_base
@@ -351,20 +353,23 @@ class EngineFacadeTestCase(oslo_test.BaseTestCase):
@mock.patch('oslo.db.sqlalchemy.session.get_maker')
@mock.patch('oslo.db.sqlalchemy.session.create_engine')
def test_creation_from_config(self, create_engine, get_maker):
- conf = mock.MagicMock()
- conf.database.connection = 'sqlite:///:memory:'
- conf.database.slave_connection = None
- conf.database.items.return_value = [
- ('connection_debug', 100),
- ('max_pool_size', 10),
- ('mysql_sql_mode', 'TRADITIONAL'),
- ]
+ conf = cfg.ConfigOpts()
+ conf.register_opts(db_options.database_opts, group='database')
+
+ overrides = {
+ 'connection': 'sqlite:///:memory:',
+ 'slave_connection': None,
+ 'connection_debug': 100,
+ 'max_pool_size': 10,
+ 'mysql_sql_mode': 'TRADITIONAL',
+ }
+ for optname, optvalue in overrides.items():
+ conf.set_override(optname, optvalue, group='database')
session.EngineFacade.from_config(conf,
autocommit=False,
expire_on_commit=True)
- conf.database.items.assert_called_once_with()
create_engine.assert_called_once_with(
sql_connection='sqlite:///:memory:',
connection_debug=100,