commit 62672de131ca0ae2246b48b5215cbdfb32cd7485 Author: Dmitry Tantsur Date: Wed Oct 7 12:37:37 2020 +0200 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 diff --git a/ironic_python_agent/inspector.py b/ironic_python_agent/inspector.py index f4076c5..31ca0a9 100644 --- a/ironic_python_agent/inspector.py +++ b/ironic_python_agent/inspector.py @@ -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, diff --git a/ironic_python_agent/tests/unit/test_inspector.py b/ironic_python_agent/tests/unit/test_inspector.py index f3f6f13..b5861c7 100644 --- a/ironic_python_agent/tests/unit/test_inspector.py +++ b/ironic_python_agent/tests/unit/test_inspector.py @@ -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()