Merge "Tweak the way plugin attributes are loaded"
This commit is contained in:
commit
67407b28bd
@ -139,10 +139,10 @@ class BaseLoader(object):
|
||||
:returns: An authentication Plugin.
|
||||
:rtype: :py:class:`keystoneauth1.plugin.BaseAuthPlugin`
|
||||
"""
|
||||
for opt in self.get_options():
|
||||
for opt in (o for o in self.get_options() if o.dest not in kwargs):
|
||||
val = getter(opt)
|
||||
if val is not None:
|
||||
val = opt.type(val)
|
||||
kwargs.setdefault(opt.dest, val)
|
||||
kwargs[opt.dest] = val
|
||||
|
||||
return self.load_from_options(**kwargs)
|
||||
|
@ -77,3 +77,26 @@ class LoadingTests(utils.TestCase):
|
||||
|
||||
# check that additional kwargs get passed through
|
||||
self.assertEqual(val, p['other'])
|
||||
|
||||
def test_loading_getter_with_kwargs(self):
|
||||
called_opts = set()
|
||||
|
||||
vals = {'a-bool': False,
|
||||
'a-float': 99.99}
|
||||
|
||||
def _getter(opt):
|
||||
called_opts.add(opt.name)
|
||||
# return str because oslo.config should convert them back
|
||||
return str(vals[opt.name])
|
||||
|
||||
p = utils.MockLoader().load_from_options_getter(_getter,
|
||||
a_int=66,
|
||||
a_str='another')
|
||||
|
||||
# only the options not passed by kwargs should get passed to getter
|
||||
self.assertEqual(set(('a-bool', 'a-float')), called_opts)
|
||||
|
||||
self.assertEqual(False, p['a_bool'])
|
||||
self.assertEqual(99.99, p['a_float'])
|
||||
self.assertEqual('another', p['a_str'])
|
||||
self.assertEqual(66, p['a_int'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user