diff options
author | Adam Young <ayoung@redhat.com> | 2013-07-11 16:42:46 -0400 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2013-08-06 20:21:52 -0400 |
commit | 10ef682f46e34e4e19d467c9b0e45f4f8838a134 (patch) | |
tree | 9a0ce53f380b1898893912c0455c7ca4342645d3 /keystone/cli.py | |
parent | 60e98a12cbee0b9fb8aa91a08e7f3a11fd4182e7 (diff) | |
download | keystone-10ef682f46e34e4e19d467c9b0e45f4f8838a134.tar.gz keystone-10ef682f46e34e4e19d467c9b0e45f4f8838a134.tar.xz keystone-10ef682f46e34e4e19d467c9b0e45f4f8838a134.zip |
extension migrations
Allow each of the extensions to have their own
sql migration repository instead of mixing them into
the common repo. db_sync must be called explicitly on the extension.
In the past, it was assumed that only migrations for backends backed in
sql would be run. In practice, however, all of the migrations were run
every time. The code has been modified to reflect this.
Adds parameter --extension to the cli for db_sync and db_version
to test out the migrations
bin/keystone-manage db_sync --extension example
will migrate to version 1 and
bin/keystone-manage db_sync --extension example 0
will migrate it back to 0
to check the version
bin/keystone-manage db_version --extension example
blueprint multiple-sql-migrate-repos
DocImpact
Change-Id: I6852d75bde6506c535fa3d74537e3c1bbd6578d8
Diffstat (limited to 'keystone/cli.py')
-rw-r--r-- | keystone/cli.py | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/keystone/cli.py b/keystone/cli.py index 21d2ad40..18c095ce 100644 --- a/keystone/cli.py +++ b/keystone/cli.py @@ -20,12 +20,15 @@ import grp import os import pwd +from migrate import exceptions + from oslo.config import cfg import pbr.version from keystone.common import openssl from keystone.common.sql import migration from keystone import config +from keystone import contrib from keystone.openstack.common import importutils from keystone.openstack.common import jsonutils from keystone import token @@ -57,14 +60,35 @@ class DbSync(BaseApp): 'version. If not provided, db_sync will ' 'migrate the database to the latest known ' 'version.')) + parser.add_argument('--extension', default=None, + help=('Migrate the database for the specified ' + 'extension. If not provided, db_sync will ' + 'migrate the common repository.')) + return parser @staticmethod def main(): - for k in ['identity', 'catalog', 'policy', 'token', 'credential']: - driver = importutils.import_object(getattr(CONF, k).driver) - if hasattr(driver, 'db_sync'): - driver.db_sync(CONF.command.version) + version = CONF.command.version + extension = CONF.command.extension + if not extension: + migration.db_sync(version=version) + else: + package_name = "%s.%s.migrate_repo" % (contrib.__name__, extension) + try: + package = importutils.import_module(package_name) + repo_path = os.path.abspath(os.path.dirname(package.__file__)) + except ImportError: + print _("This extension does not provide migrations.") + exit(0) + try: + # Register the repo with the version control API + # If it already knows about the repo, it will throw + # an exception that we can safely ignore + migration.db_version_control(version=None, repo_path=repo_path) + except exceptions.DatabaseAlreadyControlledError: + pass + migration.db_sync(version=None, repo_path=repo_path) class DbVersion(BaseApp): @@ -72,9 +96,29 @@ class DbVersion(BaseApp): name = 'db_version' + @classmethod + def add_argument_parser(cls, subparsers): + parser = super(DbVersion, cls).add_argument_parser(subparsers) + parser.add_argument('--extension', default=None, + help=('Migrate the database for the specified ' + 'extension. If not provided, db_sync will ' + 'migrate the common repository.')) + @staticmethod def main(): - print(migration.db_version()) + extension = CONF.command.extension + if extension: + try: + package_name = ("%s.%s.migrate_repo" % + (contrib.__name__, extension)) + package = importutils.import_module(package_name) + repo_path = os.path.abspath(os.path.dirname(package.__file__)) + print(migration.db_version(repo_path)) + except ImportError: + print _("This extension does not provide migrations.") + exit(1) + else: + print(migration.db_version()) class BaseCertificateSetup(BaseApp): |