[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:
Gauvain Pocentek 2017-04-28 21:47:20 +02:00
parent 53de7deb1c
commit 1b404be30a
1 changed files with 20 additions and 0 deletions

View File

@ -30,6 +30,7 @@ import sys
import jinja2
import stevedore
from oslo_config import generator
try:
from sqlalchemy import exc
except Exception:
@ -677,6 +678,25 @@ 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)
if args.verbose > 0:
print("%s options imported from package %s." % (len(options),
str(package_name)))