diff options
Diffstat (limited to 'keystone/cli.py')
-rw-r--r-- | keystone/cli.py | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/keystone/cli.py b/keystone/cli.py index 8e41f2264..257b4a517 100644 --- a/keystone/cli.py +++ b/keystone/cli.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 OpenStack Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -25,10 +23,12 @@ import pbr.version from keystone.common import openssl from keystone.common import sql -from keystone.common.sql import migration +from keystone.common.sql import migration_helpers from keystone.common import utils from keystone import config from keystone import contrib +from keystone import exception +from keystone.openstack.common.db.sqlalchemy import migration from keystone.openstack.common import importutils from keystone import token @@ -71,23 +71,27 @@ class DbSync(BaseApp): version = CONF.command.version extension = CONF.command.extension if not extension: - migration.db_sync(version=version) + abs_path = migration_helpers.find_migrate_repo() else: - package_name = "%s.%s.migrate_repo" % (contrib.__name__, extension) try: + package_name = '.'.join((contrib.__name__, extension)) 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) + raise ImportError(_("%s extension does not exist.") + % package_name) try: + abs_path = migration_helpers.find_migrate_repo(package) + try: + migration.db_version_control(abs_path) # 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=version, repo_path=repo_path) + except exceptions.DatabaseAlreadyControlledError: + pass + except exception.MigrationNotProvided as e: + print(e) + exit(0) + migration.db_sync(abs_path, version=version) class DbVersion(BaseApp): @@ -108,16 +112,20 @@ class DbVersion(BaseApp): extension = CONF.command.extension if extension: try: - package_name = ("%s.%s.migrate_repo" % - (contrib.__name__, extension)) + package_name = '.'.join((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) + raise ImportError(_("%s extension does not exist.") + % package_name) + try: + print(migration.db_version( + migration_helpers.find_migrate_repo(package)), 0) + except exception.MigrationNotProvided as e: + print(e) + exit(0) else: - print(migration.db_version()) + print(migration.db_version( + migration_helpers.find_migrate_repo()), 0) class BaseCertificateSetup(BaseApp): @@ -214,6 +222,7 @@ def main(argv=None, config_files=None): config.configure() sql.initialize() + config.set_default_for_default_log_levels() CONF(args=argv[1:], project='keystone', |