summaryrefslogtreecommitdiff
path: root/oslo_config
diff options
context:
space:
mode:
authorMoises Guimaraes de Medeiros <moguimar@redhat.com>2018-06-25 10:32:15 +0200
committerMoises Guimaraes de Medeiros <moguimar@redhat.com>2018-06-25 10:38:54 +0200
commit8b1a0ff4177f0e78ec37c2f29f61711f5b525d49 (patch)
tree7489d1ff38c0b04c53b796065de3b14ea1280683 /oslo_config
parente233fc58da51303fa4be3d27935ab29485985bd8 (diff)
downloadoslo-config-8b1a0ff4177f0e78ec37c2f29f61711f5b525d49.tar.gz
Add example group for the URI driver
Ensure the sample generator emits an example group with instructions on how to define extra URI sources. Change-Id: Ica556771d8dd37cb02d9ca69c04e888d187041ee Blueprint: oslo-config-drivers Signed-off-by: Moises Guimaraes de Medeiros <moguimar@redhat.com>
Diffstat (limited to 'oslo_config')
-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 0f89e49..ea33b26 100644
--- a/oslo_config/cfg.py
+++ b/oslo_config/cfg.py
@@ -503,7 +503,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__)
@@ -2544,7 +2544,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()
+ )