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