Fix get_location for opts in groups
get_location defines the type of its ``group`` parameter as a str, but it then passes that directly into _do_get, which expects an OptGroup for its parameter. When it tries to reference group.name it blows up because a str doesn't have a .name attr. In the interest of not changing either API, this change coerces the group str into an OptGroup. Closes-Bug: 1807230 Change-Id: Iae547cbd63059fa19691a7f7fe398b148effd177
This commit is contained in:
parent
b5df53543f
commit
03f91cfd67
@ -3095,7 +3095,8 @@ class ConfigOpts(collections.Mapping):
|
||||
|
||||
.. versionadded:: 5.3.0
|
||||
"""
|
||||
value, loc = self._do_get(name, group, None)
|
||||
opt_group = OptGroup(group) if group is not None else None
|
||||
value, loc = self._do_get(name, opt_group, None)
|
||||
return loc
|
||||
|
||||
class GroupAttr(collections.Mapping):
|
||||
|
@ -68,6 +68,11 @@ class GetLocationTestCase(base.BaseTestCase):
|
||||
default='cli_opt_default',
|
||||
)
|
||||
self.conf.register_cli_opt(self.cli_opt)
|
||||
self.group_opt = cfg.StrOpt(
|
||||
'group_opt',
|
||||
default='group_opt_default',
|
||||
)
|
||||
self.conf.register_opt(self.group_opt, group='group')
|
||||
|
||||
def test_opt_default(self):
|
||||
self.conf([])
|
||||
@ -189,3 +194,12 @@ class GetLocationTestCase(base.BaseTestCase):
|
||||
# We expect register_opt() to return False to indicate that
|
||||
# the option was already registered.
|
||||
self.assertFalse(self.conf.register_opt(dupe_opt))
|
||||
|
||||
def test_group_opt(self):
|
||||
self.conf([])
|
||||
loc = self.conf.get_location('group_opt', 'group')
|
||||
self.assertEqual(
|
||||
cfg.Locations.opt_default,
|
||||
loc.location,
|
||||
)
|
||||
self.assertIn('test_get_location.py', loc.detail)
|
||||
|
Loading…
x
Reference in New Issue
Block a user