From a01a8d88dbaf1b669f2b72d1ef7a7c4194da3ec1 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 21 Jan 2013 16:53:51 +0000 Subject: [PATCH] Sync latest cfg from oslo-incubator Main cfg change is: c5984ba Move logging config options into the log module Change-Id: I3913ea54465658d93dc56e014dfe5d911b0541d6 --- quantum/agent/common/config.py | 2 +- quantum/agent/netns_cleanup_util.py | 2 +- quantum/agent/ovs_cleanup_util.py | 2 +- quantum/db/migration/cli.py | 2 +- quantum/openstack/common/cfg.py | 78 +++-------------- quantum/openstack/common/log.py | 84 ++++++++++++++----- .../nicira/nicira_nvp_plugin/common/config.py | 2 +- quantum/tests/unit/test_l3_agent.py | 2 +- 8 files changed, 81 insertions(+), 93 deletions(-) diff --git a/quantum/agent/common/config.py b/quantum/agent/common/config.py index 7faf3cd47e..de58ee26b5 100644 --- a/quantum/agent/common/config.py +++ b/quantum/agent/common/config.py @@ -27,7 +27,7 @@ def setup_conf(): help=_('Top-level directory for maintaining dhcp state')), ] - conf = cfg.CommonConfigOpts() + conf = cfg.ConfigOpts() conf.register_opts(bind_opts) return conf diff --git a/quantum/agent/netns_cleanup_util.py b/quantum/agent/netns_cleanup_util.py index 73f64c3158..c4d93f8936 100644 --- a/quantum/agent/netns_cleanup_util.py +++ b/quantum/agent/netns_cleanup_util.py @@ -68,7 +68,7 @@ def setup_conf(): default=False, help=_('Delete the namespace by removing all devices.')), ] - conf = cfg.CommonConfigOpts() + conf = cfg.ConfigOpts() conf.register_opts(opts) conf.register_opts(dhcp.OPTS) config.setup_logging(conf) diff --git a/quantum/agent/ovs_cleanup_util.py b/quantum/agent/ovs_cleanup_util.py index 3e820d2814..31d1f4b041 100644 --- a/quantum/agent/ovs_cleanup_util.py +++ b/quantum/agent/ovs_cleanup_util.py @@ -47,7 +47,7 @@ def setup_conf(): help=_("Root helper application.")), ] - conf = cfg.CommonConfigOpts() + conf = cfg.ConfigOpts() conf.register_cli_opts(opts) conf.register_opts(l3_agent.L3NATAgent.OPTS) conf.register_opts(interface.OPTS) diff --git a/quantum/db/migration/cli.py b/quantum/db/migration/cli.py index ba115ee1fb..dc9ec18178 100644 --- a/quantum/db/migration/cli.py +++ b/quantum/db/migration/cli.py @@ -44,7 +44,7 @@ _db_opts = [ help=_('URL to database')), ] -CONF = cfg.CommonConfigOpts() +CONF = cfg.ConfigOpts() CONF.register_opts(_core_opts) CONF.register_opts(_db_opts, 'DATABASE') CONF.register_opts(_quota_opts, 'QUOTAS') diff --git a/quantum/openstack/common/cfg.py b/quantum/openstack/common/cfg.py index 4aad78adc0..c26191c339 100644 --- a/quantum/openstack/common/cfg.py +++ b/quantum/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 quantum.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') """ @@ -1726,64 +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 (set logging level to ' - 'DEBUG instead of default WARNING level).'), - BoolOpt('verbose', - short='v', - default=False, - help='Print more verbose output (set logging level to ' - 'INFO instead of default WARNING level).'), - ] - - 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', - deprecated_name='logfile', - help='(Optional) Name of log file to output to. ' - 'If not set, logging will go to stdout.'), - StrOpt('log-dir', - deprecated_name='logdir', - help='(Optional) The directory to keep log files in ' - '(will be prepended to --log-file)'), - 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/quantum/openstack/common/log.py b/quantum/openstack/common/log.py index 9ef5441112..e6e8414c39 100644 --- a/quantum/openstack/common/log.py +++ b/quantum/openstack/common/log.py @@ -47,6 +47,67 @@ from quantum.openstack.common import local from quantum.openstack.common import notifier +_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-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'), + 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.StrOpt('log-file', + metavar='PATH', + deprecated_name='logfile', + help='(Optional) Name of log file to output to. ' + 'If not set, logging will go to stdout.'), + cfg.StrOpt('log-dir', + deprecated_name='logdir', + help='(Optional) The directory to keep log files in ' + '(will be prepended to --log-file)'), + 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') +] + +generic_log_opts = [ + cfg.BoolOpt('use_stderr', + default=True, + help='Log output to standard error'), + cfg.StrOpt('logfile_mode', + default='0644', + help='Default file mode used when creating log files'), +] + log_opts = [ cfg.StrOpt('logging_context_format_string', default='%(asctime)s.%(msecs)03d %(levelname)s %(name)s ' @@ -94,24 +155,9 @@ log_opts = [ 'format it like this'), ] - -generic_log_opts = [ - cfg.StrOpt('logdir', - default=None, - help='Log output to a per-service log file in named directory'), - cfg.StrOpt('logfile', - default=None, - help='Log output to a named file'), - cfg.BoolOpt('use_stderr', - default=True, - help='Log output to standard error'), - cfg.StrOpt('logfile_mode', - default='0644', - help='Default file mode used when creating log files'), -] - - CONF = cfg.CONF +CONF.register_cli_opts(common_cli_opts) +CONF.register_cli_opts(logging_cli_opts) CONF.register_opts(generic_log_opts) CONF.register_opts(log_opts) @@ -149,8 +195,8 @@ def _get_binary_name(): def _get_log_file_path(binary=None): - logfile = CONF.log_file or CONF.logfile - logdir = CONF.log_dir or CONF.logdir + logfile = CONF.log_file + logdir = CONF.log_dir if logfile and not logdir: return logfile diff --git a/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py b/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py index 7a26bc04f5..c1fa6851f4 100644 --- a/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py +++ b/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py @@ -56,7 +56,7 @@ cluster_opts = [ cfg.CONF.register_opts(nvp_opts, "NVP") -class ClusterConfigOptions(cfg.CommonConfigOpts): +class ClusterConfigOptions(cfg.ConfigOpts): def __init__(self, config_options): super(ClusterConfigOptions, self).__init__() diff --git a/quantum/tests/unit/test_l3_agent.py b/quantum/tests/unit/test_l3_agent.py index a7356323d7..1088489f04 100644 --- a/quantum/tests/unit/test_l3_agent.py +++ b/quantum/tests/unit/test_l3_agent.py @@ -35,7 +35,7 @@ HOSTNAME = 'myhost' class TestBasicRouterOperations(unittest2.TestCase): def setUp(self): - self.conf = cfg.CommonConfigOpts() + self.conf = cfg.ConfigOpts() self.conf.register_opts(base_config.core_opts) self.conf.register_opts(l3_agent.L3NATAgent.OPTS) self.conf.register_opts(interface.OPTS)