From 4010c4b0023a92ed3bb299f041994c80a2767ae2 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Tue, 23 Jan 2018 16:19:48 -0500 Subject: [PATCH] report the correct location for an option updated with set_defaults() Change-Id: Ida9259b56f3f293d9f3cc6848051ab6895310c25 Signed-off-by: Doug Hellmann --- oslo_config/cfg.py | 6 ++++-- oslo_config/tests/test_get_location.py | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/oslo_config/cfg.py b/oslo_config/cfg.py index 81545fa2..ad985b1d 100644 --- a/oslo_config/cfg.py +++ b/oslo_config/cfg.py @@ -808,6 +808,7 @@ def set_defaults(opts, **kwargs): for opt in opts: if opt.dest in kwargs: opt.default = kwargs[opt.dest] + opt._set_location = LocationInfo(Locations.set_default, '') def _normalize_group_name(group_name): @@ -957,6 +958,7 @@ class Opt(object): self.deprecated_reason = deprecated_reason self.deprecated_since = deprecated_since self._logged_deprecation = False + self._set_location = LocationInfo(Locations.opt_default, '') self.deprecated_opts = copy.deepcopy(deprecated_opts) or [] for o in self.deprecated_opts: @@ -2972,6 +2974,7 @@ class ConfigOpts(collections.Mapping): info = self._get_opt_info(name, group) opt = info['opt'] + loc = opt._set_location if isinstance(opt, SubCommandOpt): return (self.SubCommandAttr(self, group, opt.dest), None) @@ -3016,8 +3019,7 @@ class ConfigOpts(collections.Mapping): % (opt.name, str(e))) if opt.default is not None: - return (convert(opt.default), - LocationInfo(Locations.opt_default, '')) + return (convert(opt.default), loc) return (None, None) diff --git a/oslo_config/tests/test_get_location.py b/oslo_config/tests/test_get_location.py index 77e6682b..c220a91d 100644 --- a/oslo_config/tests/test_get_location.py +++ b/oslo_config/tests/test_get_location.py @@ -75,6 +75,15 @@ class GetLocationTestCase(base.BaseTestCase): loc.location, ) + def test_set_defaults_func(self): + cfg.set_defaults([self.normal_opt], normal_opt=self.id()) + self.conf([]) + loc = self.conf.get_location('normal_opt') + self.assertEqual( + cfg.Locations.set_default, + loc.location, + ) + def test_set_override(self): self.conf.set_override('normal_opt', self.id()) self.conf([])