Merge "Allow fetching oslo.config Opts from plugins"

This commit is contained in:
Jenkins 2015-10-16 02:27:21 +00:00 committed by Gerrit Code Review
commit 79104aa0fe
2 changed files with 22 additions and 20 deletions

View File

@ -42,15 +42,25 @@ def get_common_conf_options():
return [_AUTH_TYPE_OPT._to_oslo_opt(), _AUTH_SECTION_OPT._to_oslo_opt()] 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. """Get the oslo_config options for a specific plugin.
This will be the list of config options that is registered and loaded by This will be the list of config options that is registered and loaded by
the specified plugin. 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. :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): def register_conf_options(conf, group):

View File

@ -24,10 +24,6 @@ from keystoneauth1.loading._plugins.identity import v3
from keystoneauth1.tests.unit.loading import utils 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): class ConfTests(utils.TestCase):
def setUp(self): def setUp(self):
@ -53,9 +49,8 @@ class ConfTests(utils.TestCase):
loading.register_auth_conf_options(self.conf_fixture.conf, loading.register_auth_conf_options(self.conf_fixture.conf,
group=self.GROUP) group=self.GROUP)
self.conf_fixture.register_opts( opts = loading.get_auth_plugin_conf_options(v2.Password())
to_oslo_opts(v2.Password().get_options()), self.conf_fixture.register_opts(opts, group=section)
group=section)
self.conf_fixture.config(auth_type=self.V2PASS, self.conf_fixture.config(auth_type=self.V2PASS,
auth_url=auth_url, auth_url=auth_url,
@ -86,8 +81,8 @@ class ConfTests(utils.TestCase):
loading.register_auth_conf_options(self.conf_fixture.conf, loading.register_auth_conf_options(self.conf_fixture.conf,
group=self.GROUP) group=self.GROUP)
self.conf_fixture.register_opts(to_oslo_opts(v3.Token().get_options()), opts = loading.get_auth_plugin_conf_options(v3.Token())
group=section) self.conf_fixture.register_opts(opts, group=section)
self.conf_fixture.config(auth_type=self.V3TOKEN, self.conf_fixture.config(auth_type=self.V3TOKEN,
auth_url=auth_url, auth_url=auth_url,
@ -127,9 +122,8 @@ class ConfTests(utils.TestCase):
m.return_value = utils.MockManager(utils.MockLoader()) m.return_value = utils.MockManager(utils.MockLoader())
driver_name = uuid.uuid4().hex driver_name = uuid.uuid4().hex
self.conf_fixture.register_opts( opts = loading.get_auth_plugin_conf_options(utils.MockLoader())
to_oslo_opts(utils.MockLoader().get_options()), self.conf_fixture.register_opts(opts, group=self.GROUP)
group=self.GROUP)
self.conf_fixture.config(auth_type=driver_name, self.conf_fixture.config(auth_type=driver_name,
group=self.GROUP, group=self.GROUP,
**self.TEST_VALS) **self.TEST_VALS)
@ -144,9 +138,8 @@ class ConfTests(utils.TestCase):
@utils.mock_plugin() @utils.mock_plugin()
def test_same_section(self, m): def test_same_section(self, m):
self.conf_fixture.register_opts( opts = loading.get_auth_plugin_conf_options(utils.MockLoader())
to_oslo_opts(utils.MockLoader().get_options()), self.conf_fixture.register_opts(opts, group=self.GROUP)
group=self.GROUP)
loading.register_auth_conf_options(self.conf_fixture.conf, loading.register_auth_conf_options(self.conf_fixture.conf,
group=self.GROUP) group=self.GROUP)
@ -166,9 +159,8 @@ class ConfTests(utils.TestCase):
loading.register_auth_conf_options(self.conf_fixture.conf, loading.register_auth_conf_options(self.conf_fixture.conf,
group=self.GROUP) group=self.GROUP)
self.conf_fixture.register_opts(to_oslo_opts( opts = loading.get_auth_plugin_conf_options(utils.MockLoader())
utils.MockLoader().get_options()), self.conf_fixture.register_opts(opts, group=section)
group=section)
self.conf_fixture.config(group=section, self.conf_fixture.config(group=section,
auth_type=uuid.uuid4().hex, auth_type=uuid.uuid4().hex,
**self.TEST_VALS) **self.TEST_VALS)