Retry 401 error from CTS

This could be a transient error caused by kerberos server instability.

JIRA: RHELCMP-11251
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
(cherry picked from commit 58036eab84)
This commit is contained in:
Lubomír Sedlář 2023-02-28 10:14:02 +01:00 committed by Stepan Oksanichenko
parent 9c4d3d496d
commit 2930a1cc54
Signed by: soksanichenko
GPG Key ID: AB9983172AB1E45B
1 changed files with 12 additions and 1 deletions

View File

@ -58,11 +58,22 @@ except ImportError:
SUPPORTED_MILESTONES = ["RC", "Update", "SecurityFix"]
def is_status_fatal(status_code):
"""Check if status code returned from CTS reports an error that is unlikely
to be fixed by retrying. Generally client errors (4XX) are fatal, with the
exception of 401 Unauthorized which could be caused by transient network
issue between compose host and KDC.
"""
if status_code == 401:
return False
return status_code >= 400 and status_code < 500
@retry(wait_on=RequestException)
def retry_request(method, url, data=None, auth=None):
request_method = getattr(requests, method)
rv = request_method(url, json=data, auth=auth)
if rv.status_code >= 400 and rv.status_code < 500:
if is_status_fatal(rv.status_code):
try:
error = rv.json()["message"]
except ValueError: