Allow setting retry counts for Adapter via configuration options

Change-Id: I67ba69bfff69676ceb28b8a7515f10f5eff21c4c
This commit is contained in:
Dmitry Tantsur 2019-06-19 15:24:11 +02:00
parent 96559d6009
commit 92921c6016
3 changed files with 67 additions and 27 deletions

View File

@ -135,6 +135,16 @@ class Adapter(base.BaseLoader):
'intended to be used as the upper bound of a '
'range with min_version. Mutually exclusive '
'with version.'),
cfg.IntOpt('connect-retries',
deprecated_opts=deprecated_opts.get(
'connect-retries'),
help='The maximum number of retries that should be '
'attempted for connection errors.'),
cfg.IntOpt('status-code-retries',
deprecated_opts=deprecated_opts.get(
'status-code-retries'),
help='The maximum number of retries that should be '
'attempted for retriable HTTP status codes.'),
]
if include_deprecated:
opts += [
@ -154,29 +164,33 @@ class Adapter(base.BaseLoader):
"""Register the oslo_config options that are needed for an Adapter.
The options that are set are:
:service_type: The default service_type for URL discovery.
:service_name: The default service_name for URL discovery.
:interface: The default interface for URL discovery.
(deprecated)
:valid_interfaces: List of acceptable interfaces for URL
discovery. Can be a list of any of
'public', 'internal' or 'admin'.
:region_name: The default region_name for URL discovery.
:endpoint_override: Always use this endpoint URL for requests
for this client.
:version: The minimum version restricted to a given Major
API. Mutually exclusive with min_version and
max_version.
:min_version: The minimum major version of a given API,
intended to be used as the lower bound of a
range with max_version. Mutually exclusive with
version. If min_version is given with no
max_version it is as if max version is
'latest'.
:max_version: The maximum major version of a given API,
intended to be used as the upper bound of a
range with min_version. Mutually exclusive with
version.
:service_type: The default service_type for URL discovery.
:service_name: The default service_name for URL discovery.
:interface: The default interface for URL discovery.
(deprecated)
:valid_interfaces: List of acceptable interfaces for URL
discovery. Can be a list of any of
'public', 'internal' or 'admin'.
:region_name: The default region_name for URL discovery.
:endpoint_override: Always use this endpoint URL for requests
for this client.
:version: The minimum version restricted to a given
Major API. Mutually exclusive with
min_version and max_version.
:min_version: The minimum major version of a given API,
intended to be used as the lower bound of a
range with max_version. Mutually exclusive
with version. If min_version is given with no
max_version it is as if max version is
'latest'.
:max_version: The maximum major version of a given API,
intended to be used as the upper bound of a
range with min_version. Mutually exclusive
with version.
:connect_retries: The maximum number of retries that should be
attempted for connection errors.
:status_code_retries: The maximum number of retries that should be
attempted for retriable HTTP status codes.
:param oslo_config.Cfg conf: config object to register with.
:param string group: The ini group to register options in.
@ -256,6 +270,8 @@ def process_conf_options(confgrp, kwargs):
raise TypeError(
"version is mutually exclusive with min_version and"
" max_version")
kwargs.setdefault('connect_retries', confgrp.connect_retries)
kwargs.setdefault('status_code_retries', confgrp.status_code_retries)
def register_argparse_arguments(*args, **kwargs):

View File

@ -154,29 +154,47 @@ class ConfLoadingTests(utils.TestCase):
loading.load_adapter_from_conf_options,
self.conf_fx.conf, self.GROUP, session='session', auth='auth')
def test_load_retries(self):
self.conf_fx.config(
service_type='type', service_name='name',
connect_retries=3, status_code_retries=5,
group=self.GROUP)
adap = loading.load_adapter_from_conf_options(
self.conf_fx.conf, self.GROUP, session='session', auth='auth')
self.assertEqual('type', adap.service_type)
self.assertEqual('name', adap.service_name)
self.assertEqual(3, adap.connect_retries)
self.assertEqual(5, adap.status_code_retries)
def test_get_conf_options(self):
opts = loading.get_adapter_conf_options()
for opt in opts:
if opt.name != 'valid-interfaces':
if opt.name.endswith('-retries'):
self.assertIsInstance(opt, cfg.IntOpt)
elif opt.name != 'valid-interfaces':
self.assertIsInstance(opt, cfg.StrOpt)
else:
self.assertIsInstance(opt, cfg.ListOpt)
self.assertEqual({'service-type', 'service-name',
'interface', 'valid-interfaces',
'region-name', 'endpoint-override', 'version',
'min-version', 'max-version'},
'min-version', 'max-version', 'connect-retries',
'status-code-retries'},
{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':
if opt.name.endswith('-retries'):
self.assertIsInstance(opt, cfg.IntOpt)
elif 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'},
'min-version', 'max-version', 'connect-retries',
'status-code-retries'},
{opt.name for opt in opts})
def test_deprecated(self):

View File

@ -0,0 +1,6 @@
---
features:
- |
The Adapter parameters ``connect_retries`` and ``status_code_retries`` can
now be set via configuration options ``connect-retries`` and
``status-code-retries`` accordingly.