From 5af0918e429f3dc3cd6bc2e5351b0ee625e654e8 Mon Sep 17 00:00:00 2001 From: Jaroslav Henner <1187265+jarovo@users.noreply.github.com> Date: Fri, 23 May 2025 07:27:43 +0200 Subject: [PATCH 1/4] Add test for Don't try to parse the response json when not_modified #550 Signed-off-by: Jaroslav Henner <1187265+jarovo@users.noreply.github.com> --- podman/tests/integration/test_containers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/podman/tests/integration/test_containers.py b/podman/tests/integration/test_containers.py index cd32f1ef..2b1f786f 100644 --- a/podman/tests/integration/test_containers.py +++ b/podman/tests/integration/test_containers.py @@ -139,6 +139,11 @@ def test_container_crud(self): self.assertIn("/usr/bin/top", report["Processes"][0][-1]) top_ctnr.stop() + + # Try stopping the already stopped. + # See https://github.com/containers/podman-py/pull/550 for more info. + top_ctnr.stop() + top_ctnr.reload() self.assertIn(top_ctnr.status, ("exited", "stopped")) From 98a341bd90a425bdfb8940745e652fac9f4f76e5 Mon Sep 17 00:00:00 2001 From: Jaroslav Henner <1187265+jarovo@users.noreply.github.com> Date: Sun, 18 May 2025 15:51:24 +0200 Subject: [PATCH 2/4] Don't try to parse the response json when not_modified In case of not_modified (HTTP 304), there is no json in the response body. Json parsing fails like: ```python if response.status_code == requests.codes.not_modified: if kwargs.get("ignore", False): return body = response > raise APIError(body["cause"], response=response, explanation=body) E TypeError: 'APIResponse' object is not subscriptable .venv/lib/python3.12/site-packages/podman/domain/containers.py:477: TypeError ``` This patch fixes this in the way that APIError is rised with content from the text of the requests response Signed-off-by: Jaroslav Henner <1187265+jarovo@users.noreply.github.com> --- podman/domain/containers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/podman/domain/containers.py b/podman/domain/containers.py index 66ceb65f..7d6305fd 100644 --- a/podman/domain/containers.py +++ b/podman/domain/containers.py @@ -472,6 +472,10 @@ def stop(self, **kwargs) -> None: if response.status_code == requests.codes.not_modified: if kwargs.get("ignore", False): return + else: + raise APIError( + response.text, response=response, explanation="Container already stopped." + ) body = response.json() raise APIError(body["cause"], response=response, explanation=body["message"]) From a0652cf58e2539d489d55051e286f61723b37f7b Mon Sep 17 00:00:00 2001 From: Jaroslav Henner <1187265+jarovo@users.noreply.github.com> Date: Fri, 23 May 2025 07:27:43 +0200 Subject: [PATCH 3/4] Add test for Don't try to parse the response json when not_modified #550 Signed-off-by: Jaroslav Henner <1187265+jarovo@users.noreply.github.com> --- podman/tests/integration/test_containers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/podman/tests/integration/test_containers.py b/podman/tests/integration/test_containers.py index 2b1f786f..bdfa8a67 100644 --- a/podman/tests/integration/test_containers.py +++ b/podman/tests/integration/test_containers.py @@ -142,7 +142,8 @@ def test_container_crud(self): # Try stopping the already stopped. # See https://github.com/containers/podman-py/pull/550 for more info. - top_ctnr.stop() + with self.assertRaises(APIError): + top_ctnr.stop() top_ctnr.reload() self.assertIn(top_ctnr.status, ("exited", "stopped")) From b06e5e76aa228d19185ee9ff9b89c17f0d3429fb Mon Sep 17 00:00:00 2001 From: Jaroslav Henner <1187265+jarovo@users.noreply.github.com> Date: Fri, 23 May 2025 09:23:34 +0200 Subject: [PATCH 4/4] Add missing APIError Signed-off-by: Jaroslav Henner <1187265+jarovo@users.noreply.github.com> --- podman/tests/integration/test_containers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/podman/tests/integration/test_containers.py b/podman/tests/integration/test_containers.py index bdfa8a67..a9c877c6 100644 --- a/podman/tests/integration/test_containers.py +++ b/podman/tests/integration/test_containers.py @@ -15,7 +15,7 @@ from podman import PodmanClient from podman.domain.containers import Container from podman.domain.images import Image -from podman.errors import NotFound +from podman.errors import NotFound, APIError # @unittest.skipIf(os.geteuid() != 0, 'Skipping, not running as root')