Merge "Adapter.get_conf_options(deprecated_opts)"
This commit is contained in:
commit
2c5df20f80
|
@ -32,7 +32,7 @@ class Adapter(base.BaseLoader):
|
|||
return []
|
||||
|
||||
@staticmethod
|
||||
def get_conf_options(include_deprecated=True):
|
||||
def get_conf_options(include_deprecated=True, deprecated_opts=None):
|
||||
"""Get oslo_config options that are needed for a :py:class:`.Adapter`.
|
||||
|
||||
These may be useful without being registered for config file generation
|
||||
|
@ -67,31 +67,58 @@ class Adapter(base.BaseLoader):
|
|||
compatibility), deprecated options are
|
||||
included in the result. If False, they are
|
||||
excluded.
|
||||
:param dict deprecated_opts: Deprecated options that should be included
|
||||
in the definition of new options. This should be a dict from the
|
||||
name of the new option to a list of oslo.DeprecatedOpts that
|
||||
correspond to the new option. (optional)
|
||||
|
||||
For example, to support the ``api_endpoint`` option pointing to
|
||||
the new ``endpoint_override`` option name::
|
||||
|
||||
old_opt = oslo_cfg.DeprecatedOpt('api_endpoint', 'old_group')
|
||||
deprecated_opts={'endpoint_override': [old_opt]}
|
||||
|
||||
:returns: A list of oslo_config options.
|
||||
"""
|
||||
cfg = _utils.get_oslo_config()
|
||||
|
||||
if deprecated_opts is None:
|
||||
deprecated_opts = {}
|
||||
|
||||
# This is goofy, but need to support hyphens *or* underscores
|
||||
deprecated_opts = {name.replace('_', '-'): opt
|
||||
for name, opt in deprecated_opts.items()}
|
||||
|
||||
opts = [cfg.StrOpt('service-type',
|
||||
deprecated_opts=deprecated_opts.get('service-type'),
|
||||
help='The default service_type for endpoint URL '
|
||||
'discovery.'),
|
||||
cfg.StrOpt('service-name',
|
||||
deprecated_opts=deprecated_opts.get('service-name'),
|
||||
help='The default service_name for endpoint URL '
|
||||
'discovery.'),
|
||||
cfg.ListOpt('valid-interfaces',
|
||||
deprecated_opts=deprecated_opts.get(
|
||||
'valid-interfaces'),
|
||||
help='List of interfaces, in order of preference, '
|
||||
'for endpoint URL.'),
|
||||
cfg.StrOpt('region-name',
|
||||
deprecated_opts=deprecated_opts.get('region-name'),
|
||||
help='The default region_name for endpoint URL '
|
||||
'discovery.'),
|
||||
cfg.StrOpt('endpoint-override',
|
||||
deprecated_opts=deprecated_opts.get(
|
||||
'endpoint-override'),
|
||||
help='Always use this endpoint URL for requests '
|
||||
'for this client.'),
|
||||
cfg.StrOpt('version',
|
||||
deprecated_opts=deprecated_opts.get('version'),
|
||||
help='Minimum Major API version within a given '
|
||||
'Major API version for endpoint URL '
|
||||
'discovery. Mutually exclusive with '
|
||||
'min_version and max_version'),
|
||||
cfg.StrOpt('min-version',
|
||||
deprecated_opts=deprecated_opts.get('min-version'),
|
||||
help='The minimum major version of a given API, '
|
||||
'intended to be used as the lower bound of a '
|
||||
'range with max_version. Mutually exclusive '
|
||||
|
@ -99,6 +126,7 @@ class Adapter(base.BaseLoader):
|
|||
'no max_version it is as if max version is '
|
||||
'"latest".'),
|
||||
cfg.StrOpt('max-version',
|
||||
deprecated_opts=deprecated_opts.get('max-version'),
|
||||
help='The maximum major version of a given API, '
|
||||
'intended to be used as the upper bound of a '
|
||||
'range with min_version. Mutually exclusive '
|
||||
|
@ -117,7 +145,8 @@ class Adapter(base.BaseLoader):
|
|||
]
|
||||
return opts
|
||||
|
||||
def register_conf_options(self, conf, group):
|
||||
def register_conf_options(self, conf, group, include_deprecated=True,
|
||||
deprecated_opts=None):
|
||||
"""Register the oslo_config options that are needed for an Adapter.
|
||||
|
||||
The options that are set are:
|
||||
|
@ -147,9 +176,24 @@ class Adapter(base.BaseLoader):
|
|||
|
||||
:param oslo_config.Cfg conf: config object to register with.
|
||||
:param string group: The ini group to register options in.
|
||||
:param include_deprecated: If True (the default, for backward
|
||||
compatibility), deprecated options are
|
||||
registered. If False, they are excluded.
|
||||
:param dict deprecated_opts: Deprecated options that should be included
|
||||
in the definition of new options. This should be a dict from the
|
||||
name of the new option to a list of oslo.DeprecatedOpts that
|
||||
correspond to the new option. (optional)
|
||||
|
||||
For example, to support the ``api_endpoint`` option pointing to
|
||||
the new ``endpoint_override`` option name::
|
||||
|
||||
old_opt = oslo_cfg.DeprecatedOpt('api_endpoint', 'old_group')
|
||||
deprecated_opts={'endpoint_override': [old_opt]}
|
||||
|
||||
:returns: The list of options that was registered.
|
||||
"""
|
||||
opts = self.get_conf_options()
|
||||
opts = self.get_conf_options(include_deprecated=include_deprecated,
|
||||
deprecated_opts=deprecated_opts)
|
||||
conf.register_group(_utils.get_oslo_config().OptGroup(group))
|
||||
conf.register_opts(opts, group=group)
|
||||
return opts
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import uuid
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as config
|
||||
|
||||
|
@ -182,3 +184,15 @@ class ConfLoadingTests(utils.TestCase):
|
|||
'region-name', 'endpoint-override', 'version',
|
||||
'min-version', 'max-version'},
|
||||
{opt.name for opt in opts})
|
||||
|
||||
def test_deprecated(self):
|
||||
def new_deprecated():
|
||||
return cfg.DeprecatedOpt(uuid.uuid4().hex, group=uuid.uuid4().hex)
|
||||
|
||||
opt_names = ['service-type', 'valid-interfaces', 'endpoint-override']
|
||||
depr = dict([(n, [new_deprecated()]) for n in opt_names])
|
||||
opts = loading.get_adapter_conf_options(deprecated_opts=depr)
|
||||
|
||||
for opt in opts:
|
||||
if opt.name in opt_names:
|
||||
self.assertIn(depr[opt.name][0], opt.deprecated_opts)
|
||||
|
|
Loading…
Reference in New Issue