From 8707b1859fc2f3ef9171c851f0f0a5402de69ebd Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Mon, 1 Feb 2016 14:37:58 -0600 Subject: [PATCH] Manage db sync command for cell0 Add the ability to sync the cell0 database using nova-manage. The `db sync` command will be used to sync the cell0 database. This ensures that operators will only have two db sync commands to perform in the single cell case. blueprint cells-cell0 Change-Id: I21ae13a6c029e8ac89484faa212434911160fd51 --- nova/db/migration.py | 8 ++++---- nova/db/sqlalchemy/migration.py | 36 +++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/nova/db/migration.py b/nova/db/migration.py index 0575b4528..4765e457c 100644 --- a/nova/db/migration.py +++ b/nova/db/migration.py @@ -21,14 +21,14 @@ from nova.db.sqlalchemy import migration IMPL = migration -def db_sync(version=None, database='main'): +def db_sync(version=None, database='main', context=None): """Migrate the database to `version` or the most recent version.""" - return IMPL.db_sync(version=version, database=database) + return IMPL.db_sync(version=version, database=database, context=context) -def db_version(database='main'): +def db_version(database='main', context=None): """Display the current database version.""" - return IMPL.db_version(database=database) + return IMPL.db_version(database=database, context=context) def db_initial_version(database='main'): diff --git a/nova/db/sqlalchemy/migration.py b/nova/db/sqlalchemy/migration.py index 3c8d3d793..f457186ac 100644 --- a/nova/db/sqlalchemy/migration.py +++ b/nova/db/sqlalchemy/migration.py @@ -37,44 +37,48 @@ _REPOSITORY = {} LOG = logging.getLogger(__name__) -def get_engine(database='main'): +def get_engine(database='main', context=None): if database == 'main': - return db_session.get_engine() + return db_session.get_engine(context=context) if database == 'api': return db_session.get_api_engine() if database == 'placement': return db_session.get_placement_engine() -def db_sync(version=None, database='main'): +def db_sync(version=None, database='main', context=None): if version is not None: try: version = int(version) except ValueError: raise exception.NovaException(_("version should be an integer")) - current_version = db_version(database) + current_version = db_version(database, context=context) repository = _find_migrate_repo(database) if version is None or version > current_version: - return versioning_api.upgrade(get_engine(database), repository, - version) + return versioning_api.upgrade(get_engine(database, context=context), + repository, version) else: - return versioning_api.downgrade(get_engine(database), repository, - version) + return versioning_api.downgrade(get_engine(database, context=context), + repository, version) -def db_version(database='main'): +def db_version(database='main', context=None): repository = _find_migrate_repo(database) try: - return versioning_api.db_version(get_engine(database), repository) + return versioning_api.db_version(get_engine(database, context=context), + repository) except versioning_exceptions.DatabaseNotControlledError as exc: meta = sqlalchemy.MetaData() - engine = get_engine(database) + engine = get_engine(database, context=context) meta.reflect(bind=engine) tables = meta.tables if len(tables) == 0: - db_version_control(INIT_VERSION[database], database) - return versioning_api.db_version(get_engine(database), repository) + db_version_control(INIT_VERSION[database], + database, + context=context) + return versioning_api.db_version( + get_engine(database, context=context), repository) else: LOG.exception(exc) # Some pre-Essex DB's may not be version controlled. @@ -156,9 +160,11 @@ def db_null_instance_uuid_scan(delete=False): return processed -def db_version_control(version=None, database='main'): +def db_version_control(version=None, database='main', context=None): repository = _find_migrate_repo(database) - versioning_api.version_control(get_engine(database), repository, version) + versioning_api.version_control(get_engine(database, context=context), + repository, + version) return version