From 0010f5c11ac50526a768cee5917fa10048b6ec7a Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Fri, 26 Jan 2024 16:19:16 +0100 Subject: [PATCH] Also retry inspection on HTTP CONFLICT The new implementation can return it when unable to lock the node. Other possible errors are 400 and 404 (should not be retried), as well as 5xx (already retried). Change-Id: I74c2f54a624dc47e8e2d1e67ae4c6a6078e01d2f --- ironic_python_agent/inspector.py | 4 +++- ironic_python_agent/tests/unit/test_inspector.py | 7 ++++--- releasenotes/notes/inspection-409-69d5bd6c2a49d2ec.yaml | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/inspection-409-69d5bd6c2a49d2ec.yaml diff --git a/ironic_python_agent/inspector.py b/ironic_python_agent/inspector.py index 7d9dc0733..485795aa1 100644 --- a/ironic_python_agent/inspector.py +++ b/ironic_python_agent/inspector.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from http import client as http_client import json import os import time @@ -165,7 +166,8 @@ def call_inspector(data, failures): else: break - if inspector_resp.status_code >= 500: + if (inspector_resp.status_code >= 500 + or inspector_resp.status_code == http_client.CONFLICT): raise requests.exceptions.HTTPError(response=inspector_resp) return inspector_resp diff --git a/ironic_python_agent/tests/unit/test_inspector.py b/ironic_python_agent/tests/unit/test_inspector.py index 5f05fed79..a0611c9af 100644 --- a/ironic_python_agent/tests/unit/test_inspector.py +++ b/ironic_python_agent/tests/unit/test_inspector.py @@ -236,7 +236,7 @@ class TestCallInspector(base.IronicAgentTest): @mock.patch.object(inspector, '_RETRY_ATTEMPTS', 3) def test_inspector_retries_on_50X_error(self, mock_post): mock_post.side_effect = [mock.Mock(status_code=500), - mock.Mock(status_code=501), + mock.Mock(status_code=409), mock.Mock(status_code=502)] failures = utils.AccumulatedFailures() data = collections.OrderedDict(data=42) @@ -247,15 +247,16 @@ class TestCallInspector(base.IronicAgentTest): @mock.patch.object(inspector, '_RETRY_WAIT', 0.01) @mock.patch.object(inspector, '_RETRY_WAIT_MAX', 1) - @mock.patch.object(inspector, '_RETRY_ATTEMPTS', 2) + @mock.patch.object(inspector, '_RETRY_ATTEMPTS', 3) def test_inspector_retry_on_50X_and_succeed(self, mock_post): mock_post.side_effect = [mock.Mock(status_code=503), + mock.Mock(status_code=409), mock.Mock(status_code=200)] failures = utils.AccumulatedFailures() data = collections.OrderedDict(data=42) inspector.call_inspector(data, failures) - self.assertEqual(2, mock_post.call_count) + self.assertEqual(3, mock_post.call_count) mock_post.assert_called_with('url', cert=None, verify=True, data='{"data": 42, "error": null}', diff --git a/releasenotes/notes/inspection-409-69d5bd6c2a49d2ec.yaml b/releasenotes/notes/inspection-409-69d5bd6c2a49d2ec.yaml new file mode 100644 index 000000000..8673be075 --- /dev/null +++ b/releasenotes/notes/inspection-409-69d5bd6c2a49d2ec.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Inspection is now retried on HTTP 409 (conflict), which can be returned + by the new implementation in Ironic.