[autohelp] Use oslo_config.generator if possible
Options discovery is 1) complex and 2) partly broken at the moment. This patch adds the ability to use the oslo.config generator to discover options. This is a quick fix to restore some missing options but is porbably not a definitive solution. Ways to improve things: - get rid of all the discovery code and only use the oslo generator - make use of the YAML output from oslo.config (WIP): . https://review.openstack.org/#/c/451081/ . https://review.openstack.org/#/c/458556/ Change-Id: Iaabb5418b103f20bb13c6843482277579e77b51b Partial-Bug: #1668202
This commit is contained in:
parent
53de7deb1c
commit
61466223c6
|
@ -30,6 +30,7 @@ import sys
|
|||
import jinja2
|
||||
import stevedore
|
||||
|
||||
from oslo_config import generator
|
||||
try:
|
||||
from sqlalchemy import exc
|
||||
except Exception:
|
||||
|
@ -274,16 +275,17 @@ class OptionsCache(object):
|
|||
opt = cfg.CONF._opts[optname]['opt']
|
||||
# We ignore some CLI opts by excluding SubCommandOpt objects
|
||||
if not isinstance(opt, cfg.SubCommandOpt):
|
||||
self._add_opt(optname, 'DEFAULT', opt)
|
||||
self.add_opt(optname, 'DEFAULT', opt)
|
||||
|
||||
for group in cfg.CONF._groups:
|
||||
for optname in cfg.CONF._groups[group]._opts:
|
||||
self._add_opt(group + '/' + optname, group,
|
||||
cfg.CONF._groups[group]._opts[optname]['opt'])
|
||||
self.add_opt(group + '/' + optname, group,
|
||||
cfg.CONF._groups[group]._opts[optname]['opt'])
|
||||
|
||||
def sort(self):
|
||||
self._opt_names.sort(OptionsCache._cmpopts)
|
||||
|
||||
def _add_opt(self, optname, group, opt):
|
||||
def add_opt(self, optname, group, opt):
|
||||
if optname in self._opts_by_name:
|
||||
if self._verbose >= 2:
|
||||
print("Duplicate option name %s" % optname)
|
||||
|
@ -327,9 +329,9 @@ class OptionsCache(object):
|
|||
for group, opts in ext.plugin():
|
||||
for opt in opts:
|
||||
if group is None:
|
||||
self._add_opt(opt.dest, 'DEFAULT', opt)
|
||||
self.add_opt(opt.dest, 'DEFAULT', opt)
|
||||
else:
|
||||
self._add_opt(group + '/' + opt.dest, group, opt)
|
||||
self.add_opt(group + '/' + opt.dest, group, opt)
|
||||
|
||||
self._opt_names.sort(OptionsCache._cmpopts)
|
||||
|
||||
|
@ -677,6 +679,26 @@ def main():
|
|||
options = OptionsCache(overrides, verbose=args.verbose)
|
||||
options.maybe_load_extensions(args.repos)
|
||||
|
||||
# NOTE(gpocentek): most projects have moved to oslo_config.generator to
|
||||
# handle their opt files. We try to use it and add the new options.
|
||||
# We should probably only use this at some point (here or in a sphinx
|
||||
# extension).
|
||||
try:
|
||||
generator_opts = generator._list_opts(package_name)[0][1]
|
||||
except Exception as e:
|
||||
generator_opts = None
|
||||
|
||||
if generator_opts is not None:
|
||||
for grouped_opts in generator_opts:
|
||||
group = grouped_opts[0]
|
||||
for opt in grouped_opts[1]:
|
||||
if group in ('DEFAULT', None):
|
||||
optname = opt.name
|
||||
else:
|
||||
optname = '%s/%s' % (group, opt.name)
|
||||
options.add_opt(optname, group, opt)
|
||||
options.sort()
|
||||
|
||||
if args.verbose > 0:
|
||||
print("%s options imported from package %s." % (len(options),
|
||||
str(package_name)))
|
||||
|
|
Loading…
Reference in New Issue