get_conf_options can exclude deprecated opts

Add the ability to exclude deprecated conf options from
Adapter.get_conf_options via a new kwarg, include_deprecated, which (for
backward compatibility) defaults to True.

Closes-Bug: #1706775
Change-Id: I9245d2b983482154959ba05d7d8496a947f1c701
This commit is contained in:
Eric Fried 2017-07-26 16:04:05 -05:00
parent 5268d00218
commit 81363eca79
2 changed files with 32 additions and 12 deletions

View File

@ -32,7 +32,7 @@ class Adapter(base.BaseLoader):
return [] return []
@staticmethod @staticmethod
def get_conf_options(): def get_conf_options(include_deprecated=True):
"""Get oslo_config options that are needed for a :py:class:`.Adapter`. """Get oslo_config options that are needed for a :py:class:`.Adapter`.
These may be useful without being registered for config file generation These may be useful without being registered for config file generation
@ -63,24 +63,20 @@ class Adapter(base.BaseLoader):
range with min_version. Mutually exclusive with range with min_version. Mutually exclusive with
version. version.
:param include_deprecated: If True (the default, for backward
compatibility), deprecated options are
included in the result. If False, they are
excluded.
:returns: A list of oslo_config options. :returns: A list of oslo_config options.
""" """
cfg = _utils.get_oslo_config() cfg = _utils.get_oslo_config()
return [cfg.StrOpt('service-type', opts = [cfg.StrOpt('service-type',
help='The default service_type for endpoint URL ' help='The default service_type for endpoint URL '
'discovery.'), 'discovery.'),
cfg.StrOpt('service-name', cfg.StrOpt('service-name',
help='The default service_name for endpoint URL ' help='The default service_name for endpoint URL '
'discovery.'), 'discovery.'),
cfg.StrOpt('interface',
help='The default interface for endpoint URL '
'discovery.',
deprecated_for_removal=True,
deprecated_reason='Using valid-interfaces is'
' preferrable because it is'
' capable of accepting a list of'
' possible interfaces.'),
cfg.ListOpt('valid-interfaces', cfg.ListOpt('valid-interfaces',
help='List of interfaces, in order of preference, ' help='List of interfaces, in order of preference, '
'for endpoint URL.'), 'for endpoint URL.'),
@ -108,6 +104,18 @@ class Adapter(base.BaseLoader):
'range with min_version. Mutually exclusive ' 'range with min_version. Mutually exclusive '
'with version.'), 'with version.'),
] ]
if include_deprecated:
opts += [
cfg.StrOpt('interface',
help='The default interface for endpoint URL '
'discovery.',
deprecated_for_removal=True,
deprecated_reason='Using valid-interfaces is'
' preferrable because it is'
' capable of accepting a list of'
' possible interfaces.'),
]
return opts
def register_conf_options(self, conf, group): def register_conf_options(self, conf, group):
"""Register the oslo_config options that are needed for an Adapter. """Register the oslo_config options that are needed for an Adapter.
@ -205,5 +213,5 @@ def load_from_conf_options(*args, **kwargs):
return Adapter().load_from_conf_options(*args, **kwargs) return Adapter().load_from_conf_options(*args, **kwargs)
def get_conf_options(): def get_conf_options(*args, **kwargs):
return Adapter.get_conf_options() return Adapter.get_conf_options(*args, **kwargs)

View File

@ -170,3 +170,15 @@ class ConfLoadingTests(utils.TestCase):
'region-name', 'endpoint-override', 'version', 'region-name', 'endpoint-override', 'version',
'min-version', 'max-version'}, 'min-version', 'max-version'},
{opt.name for opt in opts}) {opt.name for opt in opts})
def test_get_conf_options_undeprecated(self):
opts = loading.get_adapter_conf_options(include_deprecated=False)
for opt in opts:
if opt.name != 'valid-interfaces':
self.assertIsInstance(opt, cfg.StrOpt)
else:
self.assertIsInstance(opt, cfg.ListOpt)
self.assertEqual({'service-type', 'service-name', 'valid-interfaces',
'region-name', 'endpoint-override', 'version',
'min-version', 'max-version'},
{opt.name for opt in opts})