Allow fetching oslo.config Opts from plugins
At the moment we only have access to the loading.Opts for a plugin, which is fine most of the time but in places like auth_token middleware we sometimes need to manually register a plugin options. Extend the existing function to get the options from a Loader directly if one is passed. Change-Id: I3fd0cead78d5cc8ee2a3d19f056b5eff15208f84
This commit is contained in:
parent
3915102963
commit
45a95b6e9b
@ -42,15 +42,25 @@ def get_common_conf_options():
|
||||
return [_AUTH_TYPE_OPT._to_oslo_opt(), _AUTH_SECTION_OPT._to_oslo_opt()]
|
||||
|
||||
|
||||
def get_plugin_conf_options(name):
|
||||
def get_plugin_conf_options(plugin):
|
||||
"""Get the oslo_config options for a specific plugin.
|
||||
|
||||
This will be the list of config options that is registered and loaded by
|
||||
the specified plugin.
|
||||
|
||||
:param plugin: The name of the plugin loader or a plugin loader object
|
||||
:type plugin: str or keystoneauth1._loading.BaseLoader
|
||||
|
||||
:returns: A list of oslo_config options.
|
||||
"""
|
||||
return [o._to_oslo_opt() for o in base.get_plugin_options(name)]
|
||||
try:
|
||||
getter = plugin.get_options
|
||||
except AttributeError:
|
||||
opts = base.get_plugin_options(plugin)
|
||||
else:
|
||||
opts = getter()
|
||||
|
||||
return [o._to_oslo_opt() for o in opts]
|
||||
|
||||
|
||||
def register_conf_options(conf, group):
|
||||
|
@ -24,10 +24,6 @@ from keystoneauth1.loading._plugins.identity import v3
|
||||
from keystoneauth1.tests.unit.loading import utils
|
||||
|
||||
|
||||
def to_oslo_opts(opts):
|
||||
return [o._to_oslo_opt() for o in opts]
|
||||
|
||||
|
||||
class ConfTests(utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -53,9 +49,8 @@ class ConfTests(utils.TestCase):
|
||||
loading.register_auth_conf_options(self.conf_fixture.conf,
|
||||
group=self.GROUP)
|
||||
|
||||
self.conf_fixture.register_opts(
|
||||
to_oslo_opts(v2.Password().get_options()),
|
||||
group=section)
|
||||
opts = loading.get_auth_plugin_conf_options(v2.Password())
|
||||
self.conf_fixture.register_opts(opts, group=section)
|
||||
|
||||
self.conf_fixture.config(auth_type=self.V2PASS,
|
||||
auth_url=auth_url,
|
||||
@ -86,8 +81,8 @@ class ConfTests(utils.TestCase):
|
||||
loading.register_auth_conf_options(self.conf_fixture.conf,
|
||||
group=self.GROUP)
|
||||
|
||||
self.conf_fixture.register_opts(to_oslo_opts(v3.Token().get_options()),
|
||||
group=section)
|
||||
opts = loading.get_auth_plugin_conf_options(v3.Token())
|
||||
self.conf_fixture.register_opts(opts, group=section)
|
||||
|
||||
self.conf_fixture.config(auth_type=self.V3TOKEN,
|
||||
auth_url=auth_url,
|
||||
@ -127,9 +122,8 @@ class ConfTests(utils.TestCase):
|
||||
m.return_value = utils.MockManager(utils.MockLoader())
|
||||
driver_name = uuid.uuid4().hex
|
||||
|
||||
self.conf_fixture.register_opts(
|
||||
to_oslo_opts(utils.MockLoader().get_options()),
|
||||
group=self.GROUP)
|
||||
opts = loading.get_auth_plugin_conf_options(utils.MockLoader())
|
||||
self.conf_fixture.register_opts(opts, group=self.GROUP)
|
||||
self.conf_fixture.config(auth_type=driver_name,
|
||||
group=self.GROUP,
|
||||
**self.TEST_VALS)
|
||||
@ -144,9 +138,8 @@ class ConfTests(utils.TestCase):
|
||||
|
||||
@utils.mock_plugin()
|
||||
def test_same_section(self, m):
|
||||
self.conf_fixture.register_opts(
|
||||
to_oslo_opts(utils.MockLoader().get_options()),
|
||||
group=self.GROUP)
|
||||
opts = loading.get_auth_plugin_conf_options(utils.MockLoader())
|
||||
self.conf_fixture.register_opts(opts, group=self.GROUP)
|
||||
|
||||
loading.register_auth_conf_options(self.conf_fixture.conf,
|
||||
group=self.GROUP)
|
||||
@ -166,9 +159,8 @@ class ConfTests(utils.TestCase):
|
||||
loading.register_auth_conf_options(self.conf_fixture.conf,
|
||||
group=self.GROUP)
|
||||
|
||||
self.conf_fixture.register_opts(to_oslo_opts(
|
||||
utils.MockLoader().get_options()),
|
||||
group=section)
|
||||
opts = loading.get_auth_plugin_conf_options(utils.MockLoader())
|
||||
self.conf_fixture.register_opts(opts, group=section)
|
||||
self.conf_fixture.config(group=section,
|
||||
auth_type=uuid.uuid4().hex,
|
||||
**self.TEST_VALS)
|
||||
|
Loading…
Reference in New Issue
Block a user