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

View File

@ -154,29 +154,47 @@ class ConfLoadingTests(utils.TestCase):
loading.load_adapter_from_conf_options, loading.load_adapter_from_conf_options,
self.conf_fx.conf, self.GROUP, session='session', auth='auth') 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): def test_get_conf_options(self):
opts = loading.get_adapter_conf_options() opts = loading.get_adapter_conf_options()
for opt in opts: 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) self.assertIsInstance(opt, cfg.StrOpt)
else: else:
self.assertIsInstance(opt, cfg.ListOpt) self.assertIsInstance(opt, cfg.ListOpt)
self.assertEqual({'service-type', 'service-name', self.assertEqual({'service-type', 'service-name',
'interface', 'valid-interfaces', 'interface', 'valid-interfaces',
'region-name', 'endpoint-override', 'version', 'region-name', 'endpoint-override', 'version',
'min-version', 'max-version'}, 'min-version', 'max-version', 'connect-retries',
'status-code-retries'},
{opt.name for opt in opts}) {opt.name for opt in opts})
def test_get_conf_options_undeprecated(self): def test_get_conf_options_undeprecated(self):
opts = loading.get_adapter_conf_options(include_deprecated=False) opts = loading.get_adapter_conf_options(include_deprecated=False)
for opt in opts: 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) self.assertIsInstance(opt, cfg.StrOpt)
else: else:
self.assertIsInstance(opt, cfg.ListOpt) self.assertIsInstance(opt, cfg.ListOpt)
self.assertEqual({'service-type', 'service-name', 'valid-interfaces', self.assertEqual({'service-type', 'service-name', 'valid-interfaces',
'region-name', 'endpoint-override', 'version', 'region-name', 'endpoint-override', 'version',
'min-version', 'max-version'}, 'min-version', 'max-version', 'connect-retries',
'status-code-retries'},
{opt.name for opt in opts}) {opt.name for opt in opts})
def test_deprecated(self): 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.