summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-07-13 16:08:33 +0000
committerGerrit Code Review <review@openstack.org>2018-07-13 16:08:33 +0000
commit6ddee6d29ae5035e63c7a4d32bbf2a120933e74b (patch)
tree4dab18f04fd7b1a5217f0a861eaf45f4b7bb0c8c
parent084ac31f4c0ac9d2a7960658b9a8dbde6765492b (diff)
parent8b1a0ff4177f0e78ec37c2f29f61711f5b525d49 (diff)
downloadoslo-config-6ddee6d29ae5035e63c7a4d32bbf2a120933e74b.tar.gz
Merge "Add example group for the URI driver"
-rw-r--r--oslo_config/_list_opts.py17
-rw-r--r--oslo_config/cfg.py4
-rw-r--r--oslo_config/sources/__init__.py13
-rw-r--r--oslo_config/sources/_uri.py52
-rw-r--r--oslo_config/tests/test_sources.py15
5 files changed, 86 insertions, 15 deletions
diff --git a/oslo_config/_list_opts.py b/oslo_config/_list_opts.py
index 701ff18..2a318c4 100644
--- a/oslo_config/_list_opts.py
+++ b/oslo_config/_list_opts.py
@@ -12,6 +12,8 @@
from oslo_config import cfg
+import stevedore
+
def list_opts():
default_config_files = [
@@ -26,8 +28,17 @@ def list_opts():
'/etc/project/project.conf.d/',
'/etc/project.conf.d/',
]
- options = cfg.ConfigOpts._list_options_for_discovery(
+ options = [(None, cfg.ConfigOpts._list_options_for_discovery(
default_config_files,
default_config_dirs,
- )
- return [(None, options)]
+ ))]
+
+ ext_mgr = stevedore.ExtensionManager(
+ "oslo.config.driver",
+ invoke_on_load=True)
+
+ for driver in ext_mgr.names():
+ options.append(('sample_%s_source' % driver,
+ ext_mgr[driver].obj.list_options_for_discovery()))
+
+ return options
diff --git a/oslo_config/cfg.py b/oslo_config/cfg.py
index 6d6eb87..e797829 100644
--- a/oslo_config/cfg.py
+++ b/oslo_config/cfg.py
@@ -510,7 +510,7 @@ from oslo_config import iniparser
from oslo_config import sources
from oslo_config import types
-from stevedore.extension import ExtensionManager
+import stevedore
LOG = logging.getLogger(__name__)
@@ -2570,7 +2570,7 @@ class ConfigOpts(collections.Mapping):
def _open_source_from_opt_group(self, group_name):
if not self._ext_mgr:
- self._ext_mgr = ExtensionManager(
+ self._ext_mgr = stevedore.ExtensionManager(
"oslo.config.driver",
invoke_on_load=True)
diff --git a/oslo_config/sources/__init__.py b/oslo_config/sources/__init__.py
index e338d26..47565fa 100644
--- a/oslo_config/sources/__init__.py
+++ b/oslo_config/sources/__init__.py
@@ -46,6 +46,19 @@ class ConfigurationSourceDriver(object):
:returns: an instance of a subclass of ConfigurationSource
"""
+ @abc.abstractmethod
+ def list_options_for_discovery(self):
+ """Return a list of options used by the driver to create the source.
+
+ Drivers should advertise all supported options in this method for the
+ purpose of sample generation by oslo-config-generator.
+
+ For an example on how to implement this method you can check the URI
+ driver at oslo_config.sources._uri.URIConfigurationSourceDriver.
+
+ :returns: a list of supported options of a ConfigurationSource.
+ """
+
@six.add_metaclass(abc.ABCMeta)
class ConfigurationSource(object):
diff --git a/oslo_config/sources/_uri.py b/oslo_config/sources/_uri.py
index 8e19cf0..f868824 100644
--- a/oslo_config/sources/_uri.py
+++ b/oslo_config/sources/_uri.py
@@ -35,17 +35,49 @@ class URIConfigurationSourceDriver(sources.ConfigurationSourceDriver):
specified but does not includes the private key.
"""
- def open_source_from_opt_group(self, conf, group_name):
- group = cfg.OptGroup(group_name)
-
- conf.register_opt(cfg.URIOpt("uri",
- schemes=["http", "https"],
- required=True),
- group)
+ _uri_driver_opts = [
+ cfg.URIOpt(
+ 'uri',
+ schemes=['http', 'https'],
+ required=True,
+ help=('Required option with the URI of the '
+ 'extra configuration file\'s location.'),
+ ),
+ cfg.StrOpt(
+ 'ca_path',
+ help=('The path to a CA_BUNDLE file or directory '
+ 'with certificates of trusted CAs.'),
+ ),
+ cfg.StrOpt(
+ 'client_cert',
+ help=('Client side certificate, as a single file path '
+ 'containing either the certificate only or the '
+ 'private key and the certificate.'),
+ ),
+ cfg.StrOpt(
+ 'client_key',
+ help=('Client side private key, in case client_cert is '
+ 'specified but does not includes the private key.'),
+ ),
+ ]
+
+ def list_options_for_discovery(self):
+ # NOTE(moguimar): This option is only used to provide a better
+ # description of the driver option registered
+ # by ConfigOpts._open_source_from_opt_group().
+ driver_opt = cfg.StrOpt(
+ 'driver',
+ default='remote_file',
+ help=('Required option and value for this group to be '
+ 'parsed as an extra source by the URI driver. '
+ 'This group\'s name must be set as one of the '
+ 'config_source\'s values in the [DEFAULT] group.'),
+ )
+
+ return [driver_opt] + self._uri_driver_opts
- conf.register_opt(cfg.StrOpt("ca_path"), group)
- conf.register_opt(cfg.StrOpt("client_cert"), group)
- conf.register_opt(cfg.StrOpt("client_key"), group)
+ def open_source_from_opt_group(self, conf, group_name):
+ conf.register_opts(self._uri_driver_opts, group_name)
return URIConfigurationSource(
conf[group_name].uri,
diff --git a/oslo_config/tests/test_sources.py b/oslo_config/tests/test_sources.py
index 69ba645..0ca389c 100644
--- a/oslo_config/tests/test_sources.py
+++ b/oslo_config/tests/test_sources.py
@@ -12,6 +12,7 @@
from requests import HTTPError
+from oslo_config import _list_opts
from oslo_config import cfg
from oslo_config import fixture
from oslo_config import sources
@@ -279,3 +280,17 @@ class URISourceTestCase(base.BaseTestCase):
# the option name and option value will match correctly
for option in _extra_configs[uri]["data"]["DEFAULT"]:
self.assertEqual(option, self.conf[option])
+
+ def test_list_opts(self):
+ expected_group = None
+ for group in _list_opts.list_opts():
+ if group[0] == "sample_remote_file_source":
+ expected_group = group
+ break
+
+ self.assertIsNotNone(expected_group)
+
+ self.assertEqual(
+ expected_group[1],
+ _uri.URIConfigurationSourceDriver().list_options_for_discovery()
+ )