1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-03-22 13:19:13 +00:00

[PR #11561/7436c0c9 backport][stable-12] replace literal HTTP codes with http.HTTPStatus (#11568)

replace literal HTTP codes with `http.HTTPStatus` (#11561)

* replace literal HTTP codes with http.HTTPStatus

* add changelog frag

(cherry picked from commit 7436c0c9ba)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2026-03-10 22:14:27 +01:00 committed by GitHub
parent b3782a76e0
commit 25c475a7ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 135 additions and 78 deletions

View file

@ -9,6 +9,7 @@ import json
import os
import typing as t
import uuid
from http import HTTPStatus
from urllib.error import HTTPError, URLError
from urllib.parse import urlparse
@ -91,7 +92,7 @@ class OcapiUtils:
use_proxy=True,
timeout=self.timeout,
)
if resp.status != 204:
if resp.status != HTTPStatus.NO_CONTENT:
data = json.loads(resp.read())
else:
data = ""
@ -390,7 +391,7 @@ class OcapiUtils:
job_uri = self.get_uri_with_slot_number_query_param(job_uri)
response = self.get_request(job_uri)
if response["ret"] is False:
if response.get("status") == 404:
if response.get("status") == HTTPStatus.NOT_FOUND:
# Job not found -- assume 0%
return {
"ret": True,
@ -436,7 +437,7 @@ class OcapiUtils:
return {"ret": False, "changed": False, "msg": "Cannot delete job because it is in progress."}
if response["ret"] is False:
if response["status"] == 404:
if response["status"] == HTTPStatus.NOT_FOUND:
return {"ret": True, "changed": False, "msg": "Job already deleted."}
return response
if self.module.check_mode:
@ -445,9 +446,9 @@ class OcapiUtils:
# Do the DELETE (unless we are in check mode)
response = self.delete_request(job_uri, etag)
if response["ret"] is False:
if response["status"] == 404:
if response["status"] == HTTPStatus.NOT_FOUND:
return {"ret": True, "changed": False}
elif response["status"] == 409:
elif response["status"] == HTTPStatus.CONFLICT:
return {"ret": False, "changed": False, "msg": "Cannot delete job because it is in progress."}
return response
return {"ret": True, "changed": True}