Merge "Sync up bare minimum from neutron.db.api into lib"
This commit is contained in:
commit
292ec4c901
@ -10,37 +10,17 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
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
|
||||
from oslo_db.sqlalchemy import enginefacade
|
||||
|
||||
|
||||
def _create_facade_lazily():
|
||||
global _FACADE
|
||||
|
||||
# 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()
|
||||
context_manager = enginefacade.transaction_context()
|
||||
context_manager.configure(sqlite_fk=True)
|
||||
|
||||
|
||||
# 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):
|
||||
"""Helper method to grab session."""
|
||||
facade = _create_facade_lazily()
|
||||
return facade.get_session(autocommit=autocommit,
|
||||
expire_on_commit=expire_on_commit,
|
||||
use_slave=use_slave)
|
||||
return context_manager.get_legacy_facade().get_session(
|
||||
autocommit=autocommit, expire_on_commit=expire_on_commit,
|
||||
use_slave=use_slave)
|
||||
|
@ -30,7 +30,7 @@ class SqlFixture(fixtures.Fixture):
|
||||
|
||||
def _setUp(self):
|
||||
# Register all data models
|
||||
engine = db_api.get_engine()
|
||||
engine = db_api.context_manager.get_legacy_facade().get_engine()
|
||||
if not SqlFixture._TABLES_ESTABLISHED:
|
||||
model_base.BASEV2.metadata.create_all(engine)
|
||||
SqlFixture._TABLES_ESTABLISHED = True
|
||||
|
Loading…
x
Reference in New Issue
Block a user