diff options
-rw-r--r-- | etc/keystone.conf.sample | 6 | ||||
-rw-r--r-- | keystone/config.py | 38 | ||||
-rw-r--r-- | keystone/openstack/common/cfg.py | 83 | ||||
-rw-r--r-- | keystone/openstack/common/iniparser.py | 2 | ||||
-rw-r--r-- | tests/test_exception.py | 12 |
5 files changed, 66 insertions, 75 deletions
diff --git a/etc/keystone.conf.sample b/etc/keystone.conf.sample index 13a78475..d866890b 100644 --- a/etc/keystone.conf.sample +++ b/etc/keystone.conf.sample @@ -24,12 +24,12 @@ # === Logging Options === # Print debugging output -# verbose = False - -# Print more verbose output # (includes plaintext request logging, potentially including passwords) # debug = False +# Print more verbose output +# verbose = False + # Name of log file to output to. If not set, logging will go to stdout. # log_file = keystone.log diff --git a/keystone/config.py b/keystone/config.py index c26a518c..34ab2b99 100644 --- a/keystone/config.py +++ b/keystone/config.py @@ -24,8 +24,46 @@ from keystone.openstack.common import cfg gettext.install('keystone', unicode=1) +_DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s" +_DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" + +common_cli_opts = [ + cfg.BoolOpt('debug', + short='d', + default=False, + help='Print debugging output (set logging level to ' + 'DEBUG instead of default WARNING level).'), + cfg.BoolOpt('verbose', + short='v', + default=False, + help='Print more verbose output (set logging level to ' + 'INFO instead of default WARNING level).'), +] + +logging_cli_opts = [ + cfg.StrOpt('log-config', + metavar='PATH', + help='If this option is specified, the logging configuration ' + 'file specified is used and overrides any other logging ' + 'options specified. Please see the Python logging module ' + 'documentation for details on logging configuration ' + 'files.'), + cfg.StrOpt('log-date-format', + default=_DEFAULT_LOG_DATE_FORMAT, + metavar='DATE_FORMAT', + help='Format string for %%(asctime)s in log records. ' + 'Default: %(default)s'), + cfg.BoolOpt('use-syslog', + default=False, + help='Use syslog for logging.'), + cfg.StrOpt('syslog-log-facility', + default='LOG_USER', + help='syslog facility to receive log lines') +] CONF = cfg.CONF +CONF.register_cli_opts(common_cli_opts) +CONF.register_cli_opts(logging_cli_opts) def setup_logging(conf): diff --git a/keystone/openstack/common/cfg.py b/keystone/openstack/common/cfg.py index 256bfea7..0f35080c 100644 --- a/keystone/openstack/common/cfg.py +++ b/keystone/openstack/common/cfg.py @@ -217,7 +217,7 @@ log files:: ... ] -This module also contains a global instance of the CommonConfigOpts class +This module also contains a global instance of the ConfigOpts class in order to support a common usage pattern in OpenStack:: from keystone.openstack.common import cfg @@ -236,10 +236,11 @@ in order to support a common usage pattern in OpenStack:: Positional command line arguments are supported via a 'positional' Opt constructor argument:: - >>> CONF.register_cli_opt(MultiStrOpt('bar', positional=True)) + >>> conf = ConfigOpts() + >>> conf.register_cli_opt(MultiStrOpt('bar', positional=True)) True - >>> CONF(['a', 'b']) - >>> CONF.bar + >>> conf(['a', 'b']) + >>> conf.bar ['a', 'b'] It is also possible to use argparse "sub-parsers" to parse additional @@ -249,10 +250,11 @@ command line arguments using the SubCommandOpt class: ... list_action = subparsers.add_parser('list') ... list_action.add_argument('id') ... - >>> CONF.register_cli_opt(SubCommandOpt('action', handler=add_parsers)) + >>> conf = ConfigOpts() + >>> conf.register_cli_opt(SubCommandOpt('action', handler=add_parsers)) True - >>> CONF(['list', '10']) - >>> CONF.action.name, CONF.action.id + >>> conf(args=['list', '10']) + >>> conf.action.name, conf.action.id ('list', '10') """ @@ -480,6 +482,13 @@ def _is_opt_registered(opts, opt): return False +def set_defaults(opts, **kwargs): + for opt in opts: + if opt.dest in kwargs: + opt.default = kwargs[opt.dest] + break + + class Opt(object): """Base class for all configuration options. @@ -771,7 +780,7 @@ class ListOpt(Opt): def _get_from_config_parser(self, cparser, section): """Retrieve the opt value as a list from ConfigParser.""" - return [v.split(',') for v in + return [[a.strip() for a in v.split(',')] for v in self._cparser_get_with_deprecated(cparser, section)] def _get_argparse_kwargs(self, group, **kwargs): @@ -1719,60 +1728,4 @@ class ConfigOpts(collections.Mapping): return value -class CommonConfigOpts(ConfigOpts): - - DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s" - DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" - - common_cli_opts = [ - BoolOpt('debug', - short='d', - default=False, - help='Print debugging output'), - BoolOpt('verbose', - short='v', - default=False, - help='Print more verbose output'), - ] - - logging_cli_opts = [ - StrOpt('log-config', - metavar='PATH', - help='If this option is specified, the logging configuration ' - 'file specified is used and overrides any other logging ' - 'options specified. Please see the Python logging module ' - 'documentation for details on logging configuration ' - 'files.'), - StrOpt('log-format', - default=DEFAULT_LOG_FORMAT, - metavar='FORMAT', - help='A logging.Formatter log message format string which may ' - 'use any of the available logging.LogRecord attributes. ' - 'Default: %(default)s'), - StrOpt('log-date-format', - default=DEFAULT_LOG_DATE_FORMAT, - metavar='DATE_FORMAT', - help='Format string for %%(asctime)s in log records. ' - 'Default: %(default)s'), - StrOpt('log-file', - metavar='PATH', - help='(Optional) Name of log file to output to. ' - 'If not set, logging will go to stdout.'), - StrOpt('log-dir', - help='(Optional) The directory to keep log files in ' - '(will be prepended to --logfile)'), - BoolOpt('use-syslog', - default=False, - help='Use syslog for logging.'), - StrOpt('syslog-log-facility', - default='LOG_USER', - help='syslog facility to receive log lines') - ] - - def __init__(self): - super(CommonConfigOpts, self).__init__() - self.register_cli_opts(self.common_cli_opts) - self.register_cli_opts(self.logging_cli_opts) - - -CONF = CommonConfigOpts() +CONF = ConfigOpts() diff --git a/keystone/openstack/common/iniparser.py b/keystone/openstack/common/iniparser.py index 24128444..9bf399f0 100644 --- a/keystone/openstack/common/iniparser.py +++ b/keystone/openstack/common/iniparser.py @@ -54,7 +54,7 @@ class BaseParser(object): value = value.strip() if ((value and value[0] == value[-1]) and - (value[0] == "\"" or value[0] == "'")): + (value[0] == "\"" or value[0] == "'")): value = value[1:-1] return key.strip(), [value] diff --git a/tests/test_exception.py b/tests/test_exception.py index a13e3982..13f626a0 100644 --- a/tests/test_exception.py +++ b/tests/test_exception.py @@ -79,7 +79,7 @@ class ExceptionTestCase(test.TestCase): class SecurityErrorTestCase(ExceptionTestCase): """Tests whether security-related info is exposed to the API user.""" def test_unauthorized_exposure(self): - CONF.debug = False + self.opt(debug=False) risky_info = uuid.uuid4().hex e = exception.Unauthorized(message=risky_info) @@ -87,7 +87,7 @@ class SecurityErrorTestCase(ExceptionTestCase): self.assertNotIn(risky_info, str(e)) def test_unauthorized_exposure_in_debug(self): - CONF.debug = True + self.opt(debug=True) risky_info = uuid.uuid4().hex e = exception.Unauthorized(message=risky_info) @@ -95,7 +95,7 @@ class SecurityErrorTestCase(ExceptionTestCase): self.assertIn(risky_info, str(e)) def test_forbidden_exposure(self): - CONF.debug = False + self.opt(debug=False) risky_info = uuid.uuid4().hex e = exception.Forbidden(message=risky_info) @@ -103,7 +103,7 @@ class SecurityErrorTestCase(ExceptionTestCase): self.assertNotIn(risky_info, str(e)) def test_forbidden_exposure_in_debug(self): - CONF.debug = True + self.opt(debug=True) risky_info = uuid.uuid4().hex e = exception.Forbidden(message=risky_info) @@ -111,7 +111,7 @@ class SecurityErrorTestCase(ExceptionTestCase): self.assertIn(risky_info, str(e)) def test_forbidden_action_exposure(self): - CONF.debug = False + self.opt(debug=False) risky_info = uuid.uuid4().hex action = uuid.uuid4().hex @@ -125,7 +125,7 @@ class SecurityErrorTestCase(ExceptionTestCase): self.assertIn(risky_info, str(e)) def test_forbidden_action_exposure_in_debug(self): - CONF.debug = True + self.opt(debug=True) risky_info = uuid.uuid4().hex |