From 6210d28424b6fad5aae24f68484b9430f4d140c9 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Wed, 30 Sep 2015 16:00:21 +0200 Subject: [PATCH] Support new mitaka directory with revisions Also, don't initialize a new 'per-release' directory with new revisions that have branch labels because we don't maintain per release labels anymore. Change-Id: I3a875e239602147d82d28994788c3409d64d6992 --- neutron/db/migration/__init__.py | 2 ++ neutron/db/migration/autogen.py | 3 ++- neutron/db/migration/cli.py | 29 ++++++++++++++++--------- neutron/tests/unit/db/test_migration.py | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/neutron/db/migration/__init__.py b/neutron/db/migration/__init__.py index 81b491083..e69b8ab6b 100644 --- a/neutron/db/migration/__init__.py +++ b/neutron/db/migration/__init__.py @@ -23,10 +23,12 @@ from sqlalchemy.engine import reflection # Neutron milestones for upgrade aliases LIBERTY = 'liberty' +MITAKA = 'mitaka' NEUTRON_MILESTONES = [ # earlier milestones were not tagged LIBERTY, + MITAKA, ] CREATION_OPERATIONS = (sa.sql.ddl.CreateIndex, diff --git a/neutron/db/migration/autogen.py b/neutron/db/migration/autogen.py index 68257e44e..daa3aaa80 100644 --- a/neutron/db/migration/autogen.py +++ b/neutron/db/migration/autogen.py @@ -52,7 +52,8 @@ def _migration_script_ops(context, directive, phase): the correct branch labels/depends_on/head revision are set up. """ - version_path = cli._get_version_branch_path(context.config, phase) + version_path = cli._get_version_branch_path( + context.config, release=cli.CURRENT_RELEASE, branch=phase) autogen_kwargs = {} cli._check_bootstrap_new_branch(phase, version_path, autogen_kwargs) diff --git a/neutron/db/migration/cli.py b/neutron/db/migration/cli.py index b998a082c..9dbb457d2 100644 --- a/neutron/db/migration/cli.py +++ b/neutron/db/migration/cli.py @@ -31,7 +31,12 @@ from neutron.db import migration HEAD_FILENAME = 'HEAD' HEADS_FILENAME = 'HEADS' -CURRENT_RELEASE = migration.LIBERTY + +CURRENT_RELEASE = migration.MITAKA +RELEASES = ( + migration.LIBERTY, + migration.MITAKA, +) EXPAND_BRANCH = 'expand' CONTRACT_BRANCH = 'contract' @@ -216,7 +221,6 @@ def _check_bootstrap_new_branch(branch, version_path, addn_kwargs): if not os.path.exists(version_path): # Bootstrap initial directory structure utils.ensure_dir(version_path) - addn_kwargs['branch_label'] = branch def do_revision(config, cmd): @@ -231,7 +235,9 @@ def do_revision(config, cmd): def _get_release_labels(labels): result = set() for label in labels: - result.add('%s_%s' % (CURRENT_RELEASE, label)) + # release labels were introduced Liberty for a short time and dropped + # in that same release cycle + result.add('%s_%s' % (migration.LIBERTY, label)) return result @@ -453,10 +459,10 @@ def _get_heads_file_path(config): HEADS_FILENAME) -def _get_version_branch_path(config, branch=None): +def _get_version_branch_path(config, release=None, branch=None): version_path = _get_root_versions_dir(config) - if branch: - return os.path.join(version_path, CURRENT_RELEASE, branch) + if branch and release: + return os.path.join(version_path, release, branch) return version_path @@ -474,11 +480,14 @@ def _use_separate_migration_branches(config): def _set_version_locations(config): '''Make alembic see all revisions in all migration branches.''' + split_branches = False version_paths = [_get_version_branch_path(config)] - for branch in MIGRATION_BRANCHES: - version_path = _get_version_branch_path(config, branch) - if os.path.exists(version_path): - version_paths.append(version_path) + for release in RELEASES: + for branch in MIGRATION_BRANCHES: + version_path = _get_version_branch_path(config, release, branch) + if split_branches or os.path.exists(version_path): + split_branches = True + version_paths.append(version_path) config.set_main_option('version_locations', ' '.join(version_paths)) diff --git a/neutron/tests/unit/db/test_migration.py b/neutron/tests/unit/db/test_migration.py index d5e0eda75..3c149ea87 100644 --- a/neutron/tests/unit/db/test_migration.py +++ b/neutron/tests/unit/db/test_migration.py @@ -531,7 +531,7 @@ class TestCli(base.BaseTestCase): use_separate_migration_branches): use_separate_migration_branches.return_value = True - get_version_branch_path.side_effect = lambda cfg, branch: ( + get_version_branch_path.side_effect = lambda cfg, release, branch: ( "/foo/expand" if branch == 'expand' else "/foo/contract") migration_script = alembic_ops.MigrationScript( -- 2.45.2