Skip to content

Commit

Permalink
get_conf_options can exclude deprecated opts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Eric Fried committed Jul 26, 2017
1 parent 5268d00 commit 81363ec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
32 changes: 20 additions & 12 deletions keystoneauth1/loading/adapter.py
Expand Up @@ -32,7 +32,7 @@ def get_options(self):
return []

@staticmethod
def get_conf_options():
def get_conf_options(include_deprecated=True):
"""Get oslo_config options that are needed for a :py:class:`.Adapter`.
These may be useful without being registered for config file generation
Expand Down Expand Up @@ -63,24 +63,20 @@ def get_conf_options():
range with min_version. Mutually exclusive with
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.
"""
cfg = _utils.get_oslo_config()

return [cfg.StrOpt('service-type',
opts = [cfg.StrOpt('service-type',
help='The default service_type for endpoint URL '
'discovery.'),
cfg.StrOpt('service-name',
help='The default service_name for endpoint URL '
'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',
help='List of interfaces, in order of preference, '
'for endpoint URL.'),
Expand Down Expand Up @@ -108,6 +104,18 @@ def get_conf_options():
'range with min_version. Mutually exclusive '
'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):
"""Register the oslo_config options that are needed for an Adapter.
Expand Down Expand Up @@ -205,5 +213,5 @@ def load_from_conf_options(*args, **kwargs):
return Adapter().load_from_conf_options(*args, **kwargs)


def get_conf_options():
return Adapter.get_conf_options()
def get_conf_options(*args, **kwargs):
return Adapter.get_conf_options(*args, **kwargs)
12 changes: 12 additions & 0 deletions keystoneauth1/tests/unit/loading/test_adapter.py
Expand Up @@ -170,3 +170,15 @@ def test_get_conf_options(self):
'region-name', 'endpoint-override', 'version',
'min-version', 'max-version'},
{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})

0 comments on commit 81363ec

Please sign in to comment.