Merge "Also retry inspection on HTTP CONFLICT"

This commit is contained in:
Zuul 2024-01-29 08:50:26 +00:00 committed by Gerrit Code Review
commit c3e3cf2aef
3 changed files with 12 additions and 4 deletions

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from http import client as http_client
import json import json
import os import os
import time import time
@ -165,7 +166,8 @@ def call_inspector(data, failures):
else: else:
break 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) raise requests.exceptions.HTTPError(response=inspector_resp)
return inspector_resp return inspector_resp

View File

@ -236,7 +236,7 @@ class TestCallInspector(base.IronicAgentTest):
@mock.patch.object(inspector, '_RETRY_ATTEMPTS', 3) @mock.patch.object(inspector, '_RETRY_ATTEMPTS', 3)
def test_inspector_retries_on_50X_error(self, mock_post): def test_inspector_retries_on_50X_error(self, mock_post):
mock_post.side_effect = [mock.Mock(status_code=500), mock_post.side_effect = [mock.Mock(status_code=500),
mock.Mock(status_code=501), mock.Mock(status_code=409),
mock.Mock(status_code=502)] mock.Mock(status_code=502)]
failures = utils.AccumulatedFailures() failures = utils.AccumulatedFailures()
data = collections.OrderedDict(data=42) 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', 0.01)
@mock.patch.object(inspector, '_RETRY_WAIT_MAX', 1) @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): def test_inspector_retry_on_50X_and_succeed(self, mock_post):
mock_post.side_effect = [mock.Mock(status_code=503), mock_post.side_effect = [mock.Mock(status_code=503),
mock.Mock(status_code=409),
mock.Mock(status_code=200)] mock.Mock(status_code=200)]
failures = utils.AccumulatedFailures() failures = utils.AccumulatedFailures()
data = collections.OrderedDict(data=42) data = collections.OrderedDict(data=42)
inspector.call_inspector(data, failures) 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', mock_post.assert_called_with('url',
cert=None, verify=True, cert=None, verify=True,
data='{"data": 42, "error": null}', data='{"data": 42, "error": null}',

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Inspection is now retried on HTTP 409 (conflict), which can be returned
by the new implementation in Ironic.