Comment 1 for bug 1471168

Revision history for this message
ChangBo Guo(gcb) (glongwave) wrote :

an example the usage of choices:
[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

I'm also fixing bug https://bugs.launchpad.net/bugs/1471149 , that will result 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'