Don't convert ValueError to NoSuchOptError in ConfigOpts

Bug #1471149 reported by ChangBo Guo(gcb)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.config
Fix Released
Low
ChangBo Guo(gcb)

Bug Description

In method __getattr__ of ConfigOpts, we catch all exceptions and convert it to NoSuchOptError, this is wrong.

This is code example and output should raise ValueError , but showing NoSuchOptError.

[gcb@localhost my_code]$ cat test_oslo_config.py
import sys
from oslo_config import cfg

if __name__ == '__main__':
    opts = [
        cfg.StrOpt('type',
                   default='kvm-x',
                   choices=('kvm', 'lxc', 'qemu', 'uml', 'xen', 'parallels'),
                   help='Libvirt domain type'),
           ]

    cfg.CONF.register_opts(opts)
    cfg.CONF(sys.argv[1:], project='test', version='0.1', default_config_files=None)
    virt_type = cfg.CONF.type
    print(virt_type)

[gcb@localhost my_code]$ python test_oslo_config.py
> /usr/lib/python2.7/site-packages/oslo_config/types.py(57)__call__()
-> if self.quotes and value:
(Pdb) c
Traceback (most recent call last):
  File "test_oslo_config.py", line 14, in <module>
    virt_type = cfg.CONF.type
  File "/usr/lib/python2.7/site-packages/oslo_config/cfg.py", line 1870, in __getattr__
    raise NoSuchOptError(name)
oslo_config.cfg.NoSuchOptError: no such option: type

expected output like:

[gcb@localhost my_code]$ python test_oslo_config.py
Traceback (most recent call last):
  File "test_oslo_config.py", line 14, in <module>
    virt_type = cfg.CONF.type
  File "/usr/lib/python2.7/site-packages/oslo_config/cfg.py", line 1868, in __getattr__
    return self._get(name)
  File "/usr/lib/python2.7/site-packages/oslo_config/cfg.py", line 2240, in _get
    value = self._do_get(name, group, namespace)
  File "/usr/lib/python2.7/site-packages/oslo_config/cfg.py", line 2296, in _do_get
    return convert(opt.default)
  File "/usr/lib/python2.7/site-packages/oslo_config/cfg.py", line 2272, in convert
    self._substitute(value, group, namespace), opt)
  File "/usr/lib/python2.7/site-packages/oslo_config/cfg.py", line 2341, in _convert_value
    return opt.type(value)
  File "/usr/lib/python2.7/site-packages/oslo_config/types.py", line 68, in __call__
    repr(value)))
ValueError: Valid values are [kvm, lxc, qemu, uml, xen, parallels], but found 'kvm-x'

Changed in oslo.config:
assignee: nobody → ChangBo Guo(gcb) (glongwave)
importance: Undecided → Low
Changed in oslo.config:
status: New → In Progress
Changed in oslo.config:
status: In Progress → Fix Committed
Changed in oslo.config:
milestone: none → 1.15.0
status: Fix Committed → Fix Released
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.