Reduce the duration of retries in the inspector tests

Currently the test takes 5*5=25 seconds. Re-arrange the code so
that it's possible to change the retry delay in tests.

Change-Id: Ia559dad4bc656f8ad6b2cb8cb0137a97e2614db7
This commit is contained in:
Dmitry Tantsur 2020-10-07 12:37:37 +02:00
parent abd9f91813
commit 62672de131
2 changed files with 15 additions and 12 deletions

View File

@ -116,15 +116,8 @@ def inspect():
return resp.get('uuid')
@tenacity.retry(
retry=tenacity.retry_if_exception_type(
requests.exceptions.ConnectionError),
stop=tenacity.stop_after_attempt(5),
wait=tenacity.wait_fixed(5),
reraise=True)
def _post_to_inspector(url, data, verify, cert):
return requests.post(CONF.inspection_callback_url, data=data,
verify=verify, cert=cert)
_RETRY_WAIT = 5
_RETRY_ATTEMPTS = 5
def call_inspector(data, failures):
@ -137,10 +130,19 @@ def call_inspector(data, failures):
encoder = encoding.RESTJSONEncoder()
data = encoder.encode(data)
verify, cert = utils.get_ssl_client_options(CONF)
resp = _post_to_inspector(CONF.inspection_callback_url, data=data,
verify=verify, cert=cert)
@tenacity.retry(
retry=tenacity.retry_if_exception_type(
requests.exceptions.ConnectionError),
stop=tenacity.stop_after_attempt(_RETRY_ATTEMPTS),
wait=tenacity.wait_fixed(_RETRY_WAIT),
reraise=True)
def _post_to_inspector():
return requests.post(CONF.inspection_callback_url, data=data,
verify=verify, cert=cert)
resp = _post_to_inspector()
if resp.status_code >= 400:
LOG.error('inspector %s error %d: %s, proceeding with lookup',
CONF.inspection_callback_url,

View File

@ -191,6 +191,7 @@ class TestCallInspector(base.IronicAgentTest):
data='{"data": 42, "error": null}')
self.assertIsNone(res)
@mock.patch.object(inspector, '_RETRY_WAIT', 0.01)
def test_inspector_retries(self, mock_post):
mock_post.side_effect = requests.exceptions.ConnectionError
failures = utils.AccumulatedFailures()