Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Support lookup of value using "group.key"
Browse files Browse the repository at this point in the history
Let us check if the opt_name has a '.', if it does then split it
into a group/key and try lookup using that combination. Since
LazyPluggable uses "CONF[self.__pivot]" if we just add this
capability to cfg, we get "LazyPluggable doesn't support
option groups" for free.

Fixes LP #1093043

Change-Id: I9cedcf22014038e9fe4ed5e66ca5427aa99b5091
  • Loading branch information
Davanum Srinivas authored and openstack-gerrit committed Jan 2, 2013
1 parent ffeb085 commit 525ac47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion openstack/common/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,11 @@ def _get_opt_info(self, opt_name, group=None):
opts = group._opts

if not opt_name in opts:
raise NoSuchOptError(opt_name, group)
if group is None and '.' in opt_name:
group, opt_name = opt_name.split('.')
return self._get_opt_info(opt_name, group)
else:
raise NoSuchOptError(opt_name, group)

return opts[opt_name]

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,12 @@ def test_group_override(self):
self.conf.clear_override('foo', group='blaa')
self.assertEquals(self.conf.blaa.foo, None)

def test_group_get_group_option(self):
self.conf.register_group(OptGroup('blaa'))
self.conf.register_opt(StrOpt('foo', default='foo2'), group='blaa')
self.conf([])
self.assertEquals(self.conf['blaa.foo'], 'foo2')

def test_cli_bool_default(self):
self.conf.register_cli_opt(BoolOpt('foo'))
self.conf.set_default('foo', True)
Expand Down

0 comments on commit 525ac47

Please sign in to comment.