From 8c6e606110e26415f81e4177f433528e659182cb Mon Sep 17 00:00:00 2001 From: Dolph Mathews Date: Tue, 24 Jan 2012 19:03:58 -0600 Subject: Updated bp keystone-configuration for bp keystone-manage2 - Centralized sql_connection method - Avoided initializing commands that weren't being called Change-Id: I8231ed4ee4c384f948703b5620acef9f27265f55 --- keystone/manage2/__init__.py | 3 +-- keystone/manage2/base.py | 11 +++++++---- keystone/manage2/commands/downgrade_database.py | 6 ------ keystone/manage2/commands/goto_database.py | 6 ------ keystone/manage2/commands/sync_database.py | 6 ------ keystone/manage2/commands/upgrade_database.py | 6 ------ keystone/manage2/commands/version.py | 6 ------ keystone/manage2/commands/version_control_database.py | 6 ------ keystone/manage2/common.py | 2 +- keystone/test/client/test_keystone_manage.py | 2 +- 10 files changed, 10 insertions(+), 44 deletions(-) diff --git a/keystone/manage2/__init__.py b/keystone/manage2/__init__.py index 9b5af47e..8e86fb7a 100644 --- a/keystone/manage2/__init__.py +++ b/keystone/manage2/__init__.py @@ -44,8 +44,7 @@ def main(): subparser = subparsers.add_parser(module_name, help=module.Command.__doc__) - cmd = module.Command() - cmd.append_parser(subparser) + module.Command.append_parser(subparser) # actually parse the command line args or print help args = parser.parse_args() diff --git a/keystone/manage2/base.py b/keystone/manage2/base.py index f964bf36..85088a58 100644 --- a/keystone/manage2/base.py +++ b/keystone/manage2/base.py @@ -1,5 +1,6 @@ import argparse +from keystone import config from keystone.manage2 import common @@ -8,9 +9,6 @@ class BaseCommand(object): # pylint: disable=W0613 def __init__(self, *args, **kwargs): - if not hasattr(self.__class__, '_args'): - self.__class__._args = {} - self.parser = argparse.ArgumentParser(prog=self.__module__, description=self.__doc__) self.append_parser(self.parser) @@ -35,7 +33,7 @@ class BaseCommand(object): :param parser: argparse.ArgumentParser """ - args = cls._args + args = getattr(cls, '_args', {}) for name in args.keys(): try: @@ -59,6 +57,11 @@ class BaseSqlalchemyCommand(BaseCommand): def __init__(self, *args, **kwargs): super(BaseSqlalchemyCommand, self).__init__(*args, **kwargs) + @staticmethod + def _get_connection_string(): + sqla = config.CONF['keystone.backends.sqlalchemy'] + return sqla.sql_connection + # pylint: disable=E1101,W0223 class BaseBackendCommand(BaseCommand): diff --git a/keystone/manage2/commands/downgrade_database.py b/keystone/manage2/commands/downgrade_database.py index cab545a3..3bfbcc20 100644 --- a/keystone/manage2/commands/downgrade_database.py +++ b/keystone/manage2/commands/downgrade_database.py @@ -1,5 +1,4 @@ from keystone.backends.sqlalchemy import migration -from keystone import config from keystone.manage2 import base from keystone.manage2 import common @@ -10,11 +9,6 @@ from keystone.manage2 import common class Command(base.BaseSqlalchemyCommand): """Downgrades the database to the specified version""" - @staticmethod - def _get_connection_string(): - sqla = config.CONF['keystone.backends.sqlalchemy'] - return sqla.sql_connection - @staticmethod def downgrade_database(version): """Downgrade database to the specified version""" diff --git a/keystone/manage2/commands/goto_database.py b/keystone/manage2/commands/goto_database.py index 8d53fb8c..d419c1c7 100644 --- a/keystone/manage2/commands/goto_database.py +++ b/keystone/manage2/commands/goto_database.py @@ -1,5 +1,4 @@ from keystone.backends.sqlalchemy import migration -from keystone import config from keystone.manage2 import base from keystone.manage2 import common @@ -15,11 +14,6 @@ class Command(base.BaseSqlalchemyCommand): """ - @staticmethod - def _get_connection_string(): - sqla = config.CONF['keystone.backends.sqlalchemy'] - return sqla.sql_connection - @staticmethod def goto_database_version(version): """Override database's current migration level""" diff --git a/keystone/manage2/commands/sync_database.py b/keystone/manage2/commands/sync_database.py index 464654c5..62092d50 100644 --- a/keystone/manage2/commands/sync_database.py +++ b/keystone/manage2/commands/sync_database.py @@ -1,5 +1,4 @@ from keystone.backends.sqlalchemy import migration -from keystone import config from keystone.manage2 import base from keystone.manage2 import common @@ -10,11 +9,6 @@ from keystone.manage2 import common class Command(base.BaseSqlalchemyCommand): """Upgrades the database to the latest schema.""" - @staticmethod - def _get_connection_string(): - sqla = config.CONF['keystone.backends.sqlalchemy'] - return sqla.sql_connection - @staticmethod def sync_database(version=None): """Place database under migration control & automatically upgrade""" diff --git a/keystone/manage2/commands/upgrade_database.py b/keystone/manage2/commands/upgrade_database.py index 3eee19b8..94884442 100644 --- a/keystone/manage2/commands/upgrade_database.py +++ b/keystone/manage2/commands/upgrade_database.py @@ -1,5 +1,4 @@ from keystone.backends.sqlalchemy import migration -from keystone import config from keystone.manage2 import base from keystone.manage2 import common @@ -10,11 +9,6 @@ from keystone.manage2 import common class Command(base.BaseSqlalchemyCommand): """Upgrades the database to the specified version.""" - @staticmethod - def _get_connection_string(): - sqla = config.CONF['keystone.backends.sqlalchemy'] - return sqla.sql_connection - @staticmethod def upgrade_database(version): """Upgrade database to the specified version""" diff --git a/keystone/manage2/commands/version.py b/keystone/manage2/commands/version.py index 410711ad..8e97346f 100644 --- a/keystone/manage2/commands/version.py +++ b/keystone/manage2/commands/version.py @@ -1,5 +1,4 @@ from keystone.backends.sqlalchemy import migration -from keystone import config from keystone import version from keystone.manage2 import base from keystone.manage2 import common @@ -27,11 +26,6 @@ class Command(base.BaseSqlalchemyCommand): """Returns a complete API version string""" return ' '.join([version.API_VERSION, version.API_VERSION_STATUS]) - @staticmethod - def _get_connection_string(): - sqla = config.CONF['keystone.backends.sqlalchemy'] - return sqla.sql_connection - @staticmethod def get_implementation_version(): """Returns a complete implementation version string""" diff --git a/keystone/manage2/commands/version_control_database.py b/keystone/manage2/commands/version_control_database.py index 464e4ff5..f69e206c 100644 --- a/keystone/manage2/commands/version_control_database.py +++ b/keystone/manage2/commands/version_control_database.py @@ -1,16 +1,10 @@ from keystone.backends.sqlalchemy import migration -from keystone import config from keystone.manage2 import base class Command(base.BaseSqlalchemyCommand): """Places an existing database under version control.""" - @staticmethod - def _get_connection_string(): - sqla = config.CONF['keystone.backends.sqlalchemy'] - return sqla.sql_connection - @staticmethod def version_control_database(): """Place database under migration control""" diff --git a/keystone/manage2/common.py b/keystone/manage2/common.py index 4eb582ba..55624109 100644 --- a/keystone/manage2/common.py +++ b/keystone/manage2/common.py @@ -30,7 +30,7 @@ def arg(name, **kwargs): def get_options(): # Initialize a parser for our configuration paramaters - parser = optparse.OptionParser("usage", version='%%prog %s' + parser = optparse.OptionParser("Usage", version='%%prog %s' % version.version()) config.add_common_options(parser) config.add_log_options(parser) diff --git a/keystone/test/client/test_keystone_manage.py b/keystone/test/client/test_keystone_manage.py index 05a06fa3..d60e8a5c 100644 --- a/keystone/test/client/test_keystone_manage.py +++ b/keystone/test/client/test_keystone_manage.py @@ -30,7 +30,7 @@ class TestKeystoneManage(unittest.TestCase): ] process = subprocess.Popen(cmd, stdout=subprocess.PIPE) result = process.communicate()[0] - self.assertIn('Usage', result) + self.assertIn('usage', result.lower()) def test_keystone_manage_calls(self): """ -- cgit