config sample generator cannot recognize DictOpt type options

Bug #1276859 reported by Xinyuan Huang
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
oslo-incubator
Fix Released
Medium
Xinyuan Huang

Bug Description

Class DictOpt is defined in oslo.config.cfg
If we register a DictOpt type config option in nova, then the following error will be given when running tools/config/generate_sample.sh to generate nova.conf.sample:

'NoneType' object has no attribute 'group'

The tools/config/generate_sample.sh calls openstack.common.config.generator to execute the generation of config sample, and in openstack.common.config.generator there doesn't exist a way to process DictOpt type options:

STROPT = "StrOpt"
BOOLOPT = "BoolOpt"
INTOPT = "IntOpt"
FLOATOPT = "FloatOpt"
LISTOPT = "ListOpt"
MULTISTROPT = "MultiStrOpt"

OPT_TYPES = {
    STROPT: 'string value',
    BOOLOPT: 'boolean value',
    INTOPT: 'integer value',
    FLOATOPT: 'floating point value',
    LISTOPT: 'list value',
    MULTISTROPT: 'multi valued',
}

OPTION_REGEX = re.compile(r"(%s)" % "|".join([STROPT, BOOLOPT, INTOPT,
                                              FLOATOPT, LISTOPT,
                                              MULTISTROPT]))

def _print_opt(opt):
    opt_name, opt_default, opt_help = opt.dest, opt.default, opt.help
    if not opt_help:
        sys.stderr.write('WARNING: "%s" is missing help string.\n' % opt_name)
        opt_help = ""
    opt_type = None
    try:
        opt_type = OPTION_REGEX.search(str(type(opt))).group(0)
    except (ValueError, AttributeError) as err:
        sys.stderr.write("%s\n" % str(err))
        sys.exit(1)
    opt_help += ' (' + OPT_TYPES[opt_type] + ')'
    print('#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH)))
    if opt.deprecated_opts:
        for deprecated_opt in opt.deprecated_opts:
            if deprecated_opt.name:
                deprecated_group = (deprecated_opt.group if
                                    deprecated_opt.group else "DEFAULT")
                print('# Deprecated group/name - [%s]/%s' %
                      (deprecated_group,
                       deprecated_opt.name))
    try:
        if opt_default is None:
            print('#%s=<None>' % opt_name)
        elif opt_type == STROPT:
            assert(isinstance(opt_default, six.string_types))
            print('#%s=%s' % (opt_name, _sanitize_default(opt_name,
                                                          opt_default)))
        elif opt_type == BOOLOPT:
            assert(isinstance(opt_default, bool))
            print('#%s=%s' % (opt_name, str(opt_default).lower()))
        elif opt_type == INTOPT:
            assert(isinstance(opt_default, int) and
                   not isinstance(opt_default, bool))
            print('#%s=%s' % (opt_name, opt_default))
        elif opt_type == FLOATOPT:
            assert(isinstance(opt_default, float))
            print('#%s=%s' % (opt_name, opt_default))
        elif opt_type == LISTOPT:
            assert(isinstance(opt_default, list))
            print('#%s=%s' % (opt_name, ','.join(opt_default)))
        elif opt_type == MULTISTROPT:
            assert(isinstance(opt_default, list))
            if not opt_default:
                opt_default = ['']
            for default in opt_default:
                print('#%s=%s' % (opt_name, default))
        print('')
    except Exception:
        sys.stderr.write('Error in option "%s"\n' % opt_name)
        sys.exit(1)

Since the DictOpt value is not recognized , the code exits with an exception.
This problem will also affect tools/config/check_uptodate.sh because that also depend on the same module to process config sample generation.

Tags: oslo
Xinyuan Huang (xyhuang)
Changed in oslo:
assignee: nobody → Xinyuan Huang (xyhuang)
Xinyuan Huang (xyhuang)
Changed in nova:
assignee: nobody → Xinyuan Huang (xyhuang)
Xinyuan Huang (xyhuang)
description: updated
Matt Riedemann (mriedem)
tags: added: oslo
Xinyuan Huang (xyhuang)
description: updated
Changed in oslo:
status: New → Triaged
importance: Undecided → Medium
Chuck Short (zulcss)
Changed in nova:
status: New → Triaged
Xinyuan Huang (xyhuang)
Changed in oslo:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo-incubator (master)

Fix proposed to branch: master
Review: https://review.openstack.org/71863

Joe Gordon (jogo)
no longer affects: nova
Changed in oslo:
milestone: none → icehouse-3
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo-incubator (master)

Reviewed: https://review.openstack.org/71863
Committed: https://git.openstack.org/cgit/openstack/oslo-incubator/commit/?id=763eedff66a2281ad54c9e1768f499f1b148037e
Submitter: Jenkins
Branch: master

commit 763eedff66a2281ad54c9e1768f499f1b148037e
Author: Xinyuan Huang <email address hidden>
Date: Fri Feb 7 02:59:01 2014 -0800

    Fix DictOpt support in config sample generator

    Class DictOpt was defined in oslo.config.cfg .
    The config sample generator cannot recognize DictOpt type config options,
    and will exit with exception when generating config sample files from codes
    that contain DictOpt type options. This will result in unexpected output
    of tools/config/generate_sample.sh and tools/config/check_uptodate.sh.
    This problem is fixed by adding DictOpt support to config sample generator.

    Change-Id: Ia360dbfae8446ddaa563e94f51900071e95cdf6d
    Closes: bug #1276859

Changed in oslo:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in oslo:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in oslo:
milestone: icehouse-3 → 2014.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.