Merge "Sync up bare minimum from neutron.db.api into lib"

This commit is contained in:
Jenkins 2016-12-28 14:11:04 +00:00 committed by Gerrit Code Review
commit 292ec4c901
2 changed files with 9 additions and 29 deletions

View File

@ -10,37 +10,17 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
""" from oslo_db.sqlalchemy import enginefacade
TEMPORARY: use the old EngineFacade and lazy init.
TODO(HenryG): replace this file with the new db/api.py from neutron.
"""
from oslo_config import cfg
from oslo_db.sqlalchemy import session
_FACADE = None
def _create_facade_lazily(): context_manager = enginefacade.transaction_context()
global _FACADE context_manager.configure(sqlite_fk=True)
# NOTE: This is going to change with bug 1520719
if _FACADE is None:
_FACADE = session.EngineFacade.from_config(cfg.CONF, sqlite_fk=True)
return _FACADE
def get_engine():
"""Helper method to grab engine."""
facade = _create_facade_lazily()
return facade.get_engine()
# TODO(akamyshnikova): when all places in the code, which use sessions/
# connections will be updated, this won't be needed
def get_session(autocommit=True, expire_on_commit=False, use_slave=False): def get_session(autocommit=True, expire_on_commit=False, use_slave=False):
"""Helper method to grab session.""" """Helper method to grab session."""
facade = _create_facade_lazily() return context_manager.get_legacy_facade().get_session(
return facade.get_session(autocommit=autocommit, autocommit=autocommit, expire_on_commit=expire_on_commit,
expire_on_commit=expire_on_commit, use_slave=use_slave)
use_slave=use_slave)

View File

@ -30,7 +30,7 @@ class SqlFixture(fixtures.Fixture):
def _setUp(self): def _setUp(self):
# Register all data models # Register all data models
engine = db_api.get_engine() engine = db_api.context_manager.get_legacy_facade().get_engine()
if not SqlFixture._TABLES_ESTABLISHED: if not SqlFixture._TABLES_ESTABLISHED:
model_base.BASEV2.metadata.create_all(engine) model_base.BASEV2.metadata.create_all(engine)
SqlFixture._TABLES_ESTABLISHED = True SqlFixture._TABLES_ESTABLISHED = True