From 03f91cfd67e0f67d5e626e653ddb897799cb6dc8 Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Thu, 6 Dec 2018 16:22:50 +0000 Subject: [PATCH] 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 --- oslo_config/cfg.py | 3 ++- oslo_config/tests/test_get_location.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/oslo_config/cfg.py b/oslo_config/cfg.py index 69ee547d..b151cff2 100644 --- a/oslo_config/cfg.py +++ b/oslo_config/cfg.py @@ -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): diff --git a/oslo_config/tests/test_get_location.py b/oslo_config/tests/test_get_location.py index d8aef48a..9541708c 100644 --- a/oslo_config/tests/test_get_location.py +++ b/oslo_config/tests/test_get_location.py @@ -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)