summaryrefslogtreecommitdiff
path: root/keystone/common/sql/upgrades.py
diff options
context:
space:
mode:
Diffstat (limited to 'keystone/common/sql/upgrades.py')
-rw-r--r--keystone/common/sql/upgrades.py102
1 files changed, 51 insertions, 51 deletions
diff --git a/keystone/common/sql/upgrades.py b/keystone/common/sql/upgrades.py
index f0657e01a..f463771f2 100644
--- a/keystone/common/sql/upgrades.py
+++ b/keystone/common/sql/upgrades.py
@@ -28,17 +28,17 @@ from keystone.i18n import _
INITIAL_VERSION = 72
LATEST_VERSION = 79
-EXPAND_REPO = 'expand_repo'
-DATA_MIGRATION_REPO = 'data_migration_repo'
-CONTRACT_REPO = 'contract_repo'
+EXPAND_BRANCH = 'expand'
+DATA_MIGRATION_BRANCH = 'data_migration'
+CONTRACT_BRANCH = 'contract'
-def _get_migrate_repo_path(repo_name):
+def _get_migrate_repo_path(branch):
abs_path = os.path.abspath(
os.path.join(
os.path.dirname(sql.__file__),
'legacy_migrations',
- repo_name,
+ f'{branch}_repo',
)
)
@@ -142,8 +142,18 @@ def _migrate_db_sync(engine, abs_path, version=None, init_version=0):
return migrate_api.downgrade(engine, repository, version)
-def _sync_repo(repo_name):
- abs_path = _get_migrate_repo_path(repo_name)
+def get_db_version(branch=EXPAND_BRANCH):
+ abs_path = _get_migrate_repo_path(branch)
+ with sql.session_for_read() as session:
+ return _migrate_db_version(
+ session.get_bind(),
+ abs_path,
+ INITIAL_VERSION,
+ )
+
+
+def _db_sync(branch):
+ abs_path = _get_migrate_repo_path(branch)
with sql.session_for_write() as session:
engine = session.get_bind()
_migrate_db_sync(
@@ -153,37 +163,7 @@ def _sync_repo(repo_name):
)
-def offline_sync_database_to_version(version=None):
- """Perform and off-line sync of the database.
-
- Migrate the database up to the latest version, doing the equivalent of
- the cycle of --expand, --migrate and --contract, for when an offline
- upgrade is being performed.
-
- If a version is specified then only migrate the database up to that
- version. Downgrading is not supported. If version is specified, then only
- the main database migration is carried out - and the expand, migration and
- contract phases will NOT be run.
- """
- if version:
- raise Exception('Specifying a version is no longer supported')
-
- expand_schema()
- migrate_data()
- contract_schema()
-
-
-def get_db_version(repo=EXPAND_REPO):
- abs_path = _get_migrate_repo_path(repo)
- with sql.session_for_read() as session:
- return _migrate_db_version(
- session.get_bind(),
- abs_path,
- INITIAL_VERSION,
- )
-
-
-def validate_upgrade_order(repo_name, target_repo_version=None):
+def _validate_upgrade_order(branch, target_repo_version=None):
"""Validate the state of the migration repositories.
This is run before allowing the db_sync command to execute. Ensure the
@@ -191,7 +171,7 @@ def validate_upgrade_order(repo_name, target_repo_version=None):
the upgrade process. I.e. expand's version is greater or equal to
migrate's, migrate's version is greater or equal to contract's.
- :param repo_name: The name of the repository that the user is trying to
+ :param branch: The name of the repository that the user is trying to
upgrade.
:param target_repo_version: The version to upgrade the repo. Otherwise, the
version will be upgraded to the latest version
@@ -200,22 +180,22 @@ def validate_upgrade_order(repo_name, target_repo_version=None):
# Initialize a dict to have each key assigned a repo with their value being
# the repo that comes before.
db_sync_order = {
- DATA_MIGRATION_REPO: EXPAND_REPO,
- CONTRACT_REPO: DATA_MIGRATION_REPO,
+ DATA_MIGRATION_BRANCH: EXPAND_BRANCH,
+ CONTRACT_BRANCH: DATA_MIGRATION_BRANCH,
}
- if repo_name == EXPAND_REPO:
+ if branch == EXPAND_BRANCH:
return
# find the latest version that the current command will upgrade to if there
# wasn't a version specified for upgrade.
if not target_repo_version:
- abs_path = _get_migrate_repo_path(repo_name)
+ abs_path = _get_migrate_repo_path(branch)
repo = _find_migrate_repo(abs_path)
target_repo_version = int(repo.latest)
# get current version of the command that runs before the current command.
- dependency_repo_version = get_db_version(repo=db_sync_order[repo_name])
+ dependency_repo_version = get_db_version(branch=db_sync_order[branch])
if dependency_repo_version < target_repo_version:
raise db_exception.DBMigrationError(
@@ -223,7 +203,7 @@ def validate_upgrade_order(repo_name, target_repo_version=None):
'https://docs.openstack.org/keystone/latest/admin/'
'identity-upgrading.html '
'to see the proper steps for rolling upgrades.' % (
- repo_name, db_sync_order[repo_name]))
+ branch, db_sync_order[branch]))
def expand_schema():
@@ -232,8 +212,8 @@ def expand_schema():
This is run manually by the keystone-manage command before the first
keystone node is migrated to the latest release.
"""
- validate_upgrade_order(EXPAND_REPO)
- _sync_repo(repo_name=EXPAND_REPO)
+ _validate_upgrade_order(EXPAND_BRANCH)
+ _db_sync(branch=EXPAND_BRANCH)
def migrate_data():
@@ -242,8 +222,8 @@ def migrate_data():
This is run manually by the keystone-manage command once the keystone
schema has been expanded for the new release.
"""
- validate_upgrade_order(DATA_MIGRATION_REPO)
- _sync_repo(repo_name=DATA_MIGRATION_REPO)
+ _validate_upgrade_order(DATA_MIGRATION_BRANCH)
+ _db_sync(branch=DATA_MIGRATION_BRANCH)
def contract_schema():
@@ -253,5 +233,25 @@ def contract_schema():
nodes have been upgraded to the latest release and will remove any old
tables/columns that are no longer required.
"""
- validate_upgrade_order(CONTRACT_REPO)
- _sync_repo(repo_name=CONTRACT_REPO)
+ _validate_upgrade_order(CONTRACT_BRANCH)
+ _db_sync(branch=CONTRACT_BRANCH)
+
+
+def offline_sync_database_to_version(version=None):
+ """Perform and off-line sync of the database.
+
+ Migrate the database up to the latest version, doing the equivalent of
+ the cycle of --expand, --migrate and --contract, for when an offline
+ upgrade is being performed.
+
+ If a version is specified then only migrate the database up to that
+ version. Downgrading is not supported. If version is specified, then only
+ the main database migration is carried out - and the expand, migration and
+ contract phases will NOT be run.
+ """
+ if version:
+ raise Exception('Specifying a version is no longer supported')
+
+ expand_schema()
+ migrate_data()
+ contract_schema()