Files
placement/placement/db_api.py
EdLeafe c8ab9ff906 Added alembic environment
Added alembic, and created an initial database revision.

For the sake of testing with real databases, tools/test-setup.sh is added
so that CI can start up a mysql and/or postgresql database on which to
test migrations. The OpportunisticDBMixin from oslo_db was originally
used for this, but because of the way placement configures the database
this proved hard to debug and get correct, so we've used something
that leverages the available oslo_db tools, but with more visibility.

Because these tests mix sqlite, mysql and postgresql settings in the
potentially the same process we need a way to insure that global
settings for databases do not leak into other tests. This is done with
a reset() on the placement db fixture, called by the msyql and
postgresql tests before and after they run. We also need careful
management of that cleanup when these tests are skipped (because db
server or database is not there).

Those tests will confirm that the models match the migrations so we also
need to remove model files that no longer matter.

Since we no longer need to distinguish among multiple database files, we
can simplify the naming of these files.

Co-Authored-By: Chris Dent <cdent@anticdent.org>
Change-Id: I51ed1e4e7dbb76a3eab23af7d0d106f716059112
2018-11-14 15:26:13 +00:00

41 lines
1.3 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Database context manager for placement database connection."""
from oslo_db.sqlalchemy import enginefacade
from oslo_log import log as logging
from placement.util import run_once
LOG = logging.getLogger(__name__)
placement_context_manager = enginefacade.transaction_context()
def _get_db_conf(conf_group):
return dict(conf_group.items())
@run_once("TransactionFactory already started, not reconfiguring.",
LOG.warning)
def configure(conf):
placement_context_manager.configure(
**_get_db_conf(conf.placement_database))
def get_placement_engine():
return placement_context_manager.writer.get_engine()
@enginefacade.transaction_context_provider
class DbContext(object):
"""Stub class for db session handling outside of web requests."""