Sync the latest DB code from oslo-incubator
This sync contains the following commits from olso-incubator: 7959826 db: move all options into database group dda24eb Introduce mysql_sql_mode option, remove old warning 0b5af67 Introduce a method to set any MySQL session SQL mode 8dccc7b Handle ibm_db_sa DBDuplicateEntry integrity errors 0f24d82 Fix migration.db_version when no tables ac84a40 Update log translation domains c0d357b Add model_query() to db.sqlalchemy.utils module 84254fc Fix a small typo in api.py b8a676c Remove CONF.database.connection default value 86707cd Remove None for dict.get() 0545121 Fix duplicating of SQL queries in logs fcf517d Update oslo log messages with translation domains fa05b7c Restore the ability to load the DB backend lazily 630d395 Don't use cfg.CONF in oslo.db ce69e7f Don't store engine instances in oslo.db 35dc1d7 py3kcompat: remove b4f72b2 Don't raise MySQL 2013 'Lost connection' errors 271adfb Format sql in db.sqlalchemy.session docstring 0334cb3 Handle exception messages with six.text_type eff69ce Drop dependency on log from oslo db code 7a11a04 Automatic retry db.api query if db connection lost 11f2add Clean up docstring in db.sqlalchemy.session 1b5147f Only enable MySQL TRADITIONAL mode if we're running against MySQL 39e1c5c Move db tests base.py to common code 986dafd Fix parsing of UC errors in sqlite 3.7.16+/3.8.2+ bcf6d5e Small edits on help strings ae01e9a Transition from migrate to alembic Due to API changes in oslo.db code we have to change Nova code a bit in order to reuse oslo-incubator changes (oslo.db no longer stores SQLAlchemy Engine and sessionmaker instances globally and it's up to applications to create them). Change-Id: I4aaa7151f66e0292ff66c29330f93d78c6bf78a6
This commit is contained in:
committed by
Sean Dague
parent
5aff629c6e
commit
31613b3ab5
@@ -49,11 +49,14 @@ db_opts = [
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(db_opts)
|
||||
CONF.import_opt('backend', 'nova.openstack.common.db.options',
|
||||
group='database')
|
||||
|
||||
_BACKEND_MAPPING = {'sqlalchemy': 'nova.db.sqlalchemy.api'}
|
||||
|
||||
|
||||
IMPL = db_api.DBAPI(backend_mapping=_BACKEND_MAPPING)
|
||||
IMPL = db_api.DBAPI(CONF.database.backend, backend_mapping=_BACKEND_MAPPING,
|
||||
lazy=True)
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# The maximum value a signed INT type may have
|
||||
|
||||
@@ -70,21 +70,57 @@ db_opts = [
|
||||
'Should be empty, "project" or "global".'),
|
||||
]
|
||||
|
||||
connection_opts = [
|
||||
cfg.StrOpt('slave_connection',
|
||||
secret=True,
|
||||
help='The SQLAlchemy connection string used to connect to the '
|
||||
'slave database'),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(db_opts)
|
||||
CONF.register_opts(connection_opts, group='database')
|
||||
CONF.import_opt('compute_topic', 'nova.compute.rpcapi')
|
||||
CONF.import_opt('connection',
|
||||
'nova.openstack.common.db.sqlalchemy.session',
|
||||
'nova.openstack.common.db.options',
|
||||
group='database')
|
||||
CONF.import_opt('slave_connection',
|
||||
'nova.openstack.common.db.sqlalchemy.session',
|
||||
group='database')
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
get_engine = db_session.get_engine
|
||||
get_session = db_session.get_session
|
||||
|
||||
_MASTER_FACADE = None
|
||||
_SLAVE_FACADE = None
|
||||
|
||||
|
||||
def _create_facade_lazily(use_slave=False):
|
||||
global _MASTER_FACADE
|
||||
global _SLAVE_FACADE
|
||||
|
||||
return_slave = use_slave and CONF.database.slave_connection
|
||||
if not return_slave:
|
||||
if _MASTER_FACADE is None:
|
||||
_MASTER_FACADE = db_session.EngineFacade(
|
||||
CONF.database.connection,
|
||||
**dict(CONF.database.iteritems())
|
||||
)
|
||||
return _MASTER_FACADE
|
||||
else:
|
||||
if _SLAVE_FACADE is None:
|
||||
_SLAVE_FACADE = db_session.EngineFacade(
|
||||
CONF.database.slave_connection,
|
||||
**dict(CONF.database.iteritems())
|
||||
)
|
||||
return _SLAVE_FACADE
|
||||
|
||||
|
||||
def get_engine(use_slave=False):
|
||||
facade = _create_facade_lazily(use_slave)
|
||||
return facade.get_engine()
|
||||
|
||||
|
||||
def get_session(use_slave=False, **kwargs):
|
||||
facade = _create_facade_lazily(use_slave)
|
||||
return facade.get_session(**kwargs)
|
||||
|
||||
|
||||
_SHADOW_TABLE_PREFIX = 'shadow_'
|
||||
@@ -195,7 +231,7 @@ def model_query(context, model, *args, **kwargs):
|
||||
if CONF.database.slave_connection == '':
|
||||
use_slave = False
|
||||
|
||||
session = kwargs.get('session') or get_session(slave_session=use_slave)
|
||||
session = kwargs.get('session') or get_session(use_slave=use_slave)
|
||||
read_deleted = kwargs.get('read_deleted') or context.read_deleted
|
||||
project_only = kwargs.get('project_only', False)
|
||||
|
||||
@@ -1818,7 +1854,7 @@ def instance_get_all_by_filters(context, filters, sort_key, sort_dir,
|
||||
if CONF.database.slave_connection == '':
|
||||
use_slave = False
|
||||
|
||||
session = get_session(slave_session=use_slave)
|
||||
session = get_session(use_slave=use_slave)
|
||||
|
||||
if columns_to_join is None:
|
||||
columns_to_join = ['info_cache', 'security_groups']
|
||||
|
||||
@@ -21,8 +21,8 @@ from migrate.versioning import api as versioning_api
|
||||
from migrate.versioning.repository import Repository
|
||||
import sqlalchemy
|
||||
|
||||
from nova.db.sqlalchemy import api as db_session
|
||||
from nova import exception
|
||||
from nova.openstack.common.db.sqlalchemy import session as db_session
|
||||
from nova.openstack.common.gettextutils import _
|
||||
|
||||
INIT_VERSION = 215
|
||||
|
||||
@@ -39,9 +39,9 @@ import testtools
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova.db import migration
|
||||
from nova.db.sqlalchemy import api as session
|
||||
from nova.network import manager as network_manager
|
||||
from nova.objects import base as objects_base
|
||||
from nova.openstack.common.db.sqlalchemy import session
|
||||
from nova.openstack.common.fixture import logging as log_fixture
|
||||
from nova.openstack.common.fixture import moxstubout
|
||||
from nova.openstack.common import log as logging
|
||||
@@ -62,9 +62,10 @@ test_opts = [
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(test_opts)
|
||||
CONF.import_opt('connection',
|
||||
'nova.openstack.common.db.sqlalchemy.session',
|
||||
'nova.openstack.common.db.options',
|
||||
group='database')
|
||||
CONF.import_opt('sqlite_db', 'nova.openstack.common.db.options',
|
||||
group='database')
|
||||
CONF.import_opt('sqlite_db', 'nova.openstack.common.db.sqlalchemy.session')
|
||||
CONF.import_opt('enabled', 'nova.api.openstack', group='osapi_v3')
|
||||
CONF.set_override('use_stderr', False)
|
||||
|
||||
@@ -254,7 +255,7 @@ class TestCase(testtools.TestCase):
|
||||
if not _DB_CACHE:
|
||||
_DB_CACHE = Database(session, migration,
|
||||
sql_connection=CONF.database.connection,
|
||||
sqlite_db=CONF.sqlite_db,
|
||||
sqlite_db=CONF.database.sqlite_db,
|
||||
sqlite_clean_db=CONF.sqlite_clean_db)
|
||||
|
||||
self.useFixture(_DB_CACHE)
|
||||
|
||||
Reference in New Issue
Block a user