Merge "report the correct location for an option updated with set_defaults()"

This commit is contained in:
Zuul 2018-03-01 12:26:12 +00:00 committed by Gerrit Code Review
commit 6b7bea1746
2 changed files with 13 additions and 2 deletions

View File

@ -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)

View File

@ -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([])