Sync latest cfg from oslo-incubator

Main cfg change is:

  c5984ba Move logging config options into the log module

Change-Id: I3913ea54465658d93dc56e014dfe5d911b0541d6
This commit is contained in:
Mark McLoughlin 2013-01-21 16:53:51 +00:00
parent 46e5c83c88
commit a01a8d88db
8 changed files with 81 additions and 93 deletions

View File

@ -27,7 +27,7 @@ def setup_conf():
help=_('Top-level directory for maintaining dhcp state')), help=_('Top-level directory for maintaining dhcp state')),
] ]
conf = cfg.CommonConfigOpts() conf = cfg.ConfigOpts()
conf.register_opts(bind_opts) conf.register_opts(bind_opts)
return conf return conf

View File

@ -68,7 +68,7 @@ def setup_conf():
default=False, default=False,
help=_('Delete the namespace by removing all devices.')), help=_('Delete the namespace by removing all devices.')),
] ]
conf = cfg.CommonConfigOpts() conf = cfg.ConfigOpts()
conf.register_opts(opts) conf.register_opts(opts)
conf.register_opts(dhcp.OPTS) conf.register_opts(dhcp.OPTS)
config.setup_logging(conf) config.setup_logging(conf)

View File

@ -47,7 +47,7 @@ def setup_conf():
help=_("Root helper application.")), help=_("Root helper application.")),
] ]
conf = cfg.CommonConfigOpts() conf = cfg.ConfigOpts()
conf.register_cli_opts(opts) conf.register_cli_opts(opts)
conf.register_opts(l3_agent.L3NATAgent.OPTS) conf.register_opts(l3_agent.L3NATAgent.OPTS)
conf.register_opts(interface.OPTS) conf.register_opts(interface.OPTS)

View File

@ -44,7 +44,7 @@ _db_opts = [
help=_('URL to database')), help=_('URL to database')),
] ]
CONF = cfg.CommonConfigOpts() CONF = cfg.ConfigOpts()
CONF.register_opts(_core_opts) CONF.register_opts(_core_opts)
CONF.register_opts(_db_opts, 'DATABASE') CONF.register_opts(_db_opts, 'DATABASE')
CONF.register_opts(_quota_opts, 'QUOTAS') CONF.register_opts(_quota_opts, 'QUOTAS')

View File

@ -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:: in order to support a common usage pattern in OpenStack::
from quantum.openstack.common import cfg 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 Positional command line arguments are supported via a 'positional' Opt
constructor argument:: constructor argument::
>>> CONF.register_cli_opt(MultiStrOpt('bar', positional=True)) >>> conf = ConfigOpts()
>>> conf.register_cli_opt(MultiStrOpt('bar', positional=True))
True True
>>> CONF(['a', 'b']) >>> conf(['a', 'b'])
>>> CONF.bar >>> conf.bar
['a', 'b'] ['a', 'b']
It is also possible to use argparse "sub-parsers" to parse additional 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 = subparsers.add_parser('list')
... list_action.add_argument('id') ... 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 True
>>> CONF(['list', '10']) >>> conf(args=['list', '10'])
>>> CONF.action.name, CONF.action.id >>> conf.action.name, conf.action.id
('list', '10') ('list', '10')
""" """
@ -1726,64 +1728,4 @@ class ConfigOpts(collections.Mapping):
return value return value
class CommonConfigOpts(ConfigOpts): CONF = 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()

View File

@ -47,6 +47,67 @@ from quantum.openstack.common import local
from quantum.openstack.common import notifier 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 = [ log_opts = [
cfg.StrOpt('logging_context_format_string', cfg.StrOpt('logging_context_format_string',
default='%(asctime)s.%(msecs)03d %(levelname)s %(name)s ' default='%(asctime)s.%(msecs)03d %(levelname)s %(name)s '
@ -94,24 +155,9 @@ log_opts = [
'format it like this'), '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 = 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(generic_log_opts)
CONF.register_opts(log_opts) CONF.register_opts(log_opts)
@ -149,8 +195,8 @@ def _get_binary_name():
def _get_log_file_path(binary=None): def _get_log_file_path(binary=None):
logfile = CONF.log_file or CONF.logfile logfile = CONF.log_file
logdir = CONF.log_dir or CONF.logdir logdir = CONF.log_dir
if logfile and not logdir: if logfile and not logdir:
return logfile return logfile

View File

@ -56,7 +56,7 @@ cluster_opts = [
cfg.CONF.register_opts(nvp_opts, "NVP") cfg.CONF.register_opts(nvp_opts, "NVP")
class ClusterConfigOptions(cfg.CommonConfigOpts): class ClusterConfigOptions(cfg.ConfigOpts):
def __init__(self, config_options): def __init__(self, config_options):
super(ClusterConfigOptions, self).__init__() super(ClusterConfigOptions, self).__init__()

View File

@ -35,7 +35,7 @@ HOSTNAME = 'myhost'
class TestBasicRouterOperations(unittest2.TestCase): class TestBasicRouterOperations(unittest2.TestCase):
def setUp(self): def setUp(self):
self.conf = cfg.CommonConfigOpts() self.conf = cfg.ConfigOpts()
self.conf.register_opts(base_config.core_opts) self.conf.register_opts(base_config.core_opts)
self.conf.register_opts(l3_agent.L3NATAgent.OPTS) self.conf.register_opts(l3_agent.L3NATAgent.OPTS)
self.conf.register_opts(interface.OPTS) self.conf.register_opts(interface.OPTS)