From 28941f919e61cf238a9b0976826c9cc6091db069 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Sat, 28 Feb 2026 01:47:41 +0100 Subject: [PATCH] Adding timeout parameter to container.wait() and fixing interval type When calling wait() on a container it was impossible to set a timeout for waiting on the container. This adds the timeout parameter and sets it accordingly when doing the request. Also the interval parameter was described to be an integer, but the API documentation states it to be a string, e.g. '5s'. Signed-off-by: Florian Streibelt --- podman/domain/containers.py | 9 ++++++--- podman/tests/unit/test_container.py | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/podman/domain/containers.py b/podman/domain/containers.py index 66ceb65f..2f1e888f 100644 --- a/podman/domain/containers.py +++ b/podman/domain/containers.py @@ -736,10 +736,12 @@ def wait(self, **kwargs) -> int: condition (Union[str, list[str]]): Container state on which to release. One or more of: "configured", "created", "running", "stopped", "paused", "exited", "removing", "stopping". - interval (int): Time interval to wait before polling for completion. + interval (str): Time interval to wait before polling for completion, e.g. '5s' + timeout (int): API call timeout in seconds. Returns: "Error" key has a dictionary value with the key "Message". + On success: exit code of the container process. Raises: NotFound: when Container not found @@ -751,6 +753,7 @@ def wait(self, **kwargs) -> int: condition = [condition] interval = kwargs.get("interval") + timeout = kwargs.get("timeout") params = {} if condition != []: @@ -758,9 +761,9 @@ def wait(self, **kwargs) -> int: if interval != "": params["interval"] = interval - # This API endpoint responds with a JSON encoded integer. + # This API endpoint responds with a JSON encoded integer, the exit code of the container. # See: # https://docs.podman.io/en/latest/_static/api.html#tag/containers/operation/ContainerWaitLibpod - response = self.client.post(f"/containers/{self.id}/wait", params=params) + response = self.client.post(f"/containers/{self.id}/wait", params=params, timeout=timeout) response.raise_for_status() return response.json() diff --git a/podman/tests/unit/test_container.py b/podman/tests/unit/test_container.py index b38ea483..adb8a5a7 100644 --- a/podman/tests/unit/test_container.py +++ b/podman/tests/unit/test_container.py @@ -225,8 +225,26 @@ def test_wait_condition_interval(self, mock): json={"StatusCode": 0}, ) container = Container(attrs=FIRST_CONTAINER, client=self.client.api) - container.wait(condition="exited", interval=1) + container.wait(condition="exited", interval="23s") self.assertTrue(adapter.called_once) + self.maxDiff = None + self.assertEqual(adapter.last_request.qs['interval'], ['23s']) + + @requests_mock.Mocker() + def test_wait_timeout(self, mock): + adapter = mock.post( + tests.LIBPOD_URL + + "/containers/87e1325c82424e49a00abdd4de08009eb76c7de8d228426a9b8af9318ced5ecd/wait", + status_code=200, + json={"StatusCode": 0}, + ) + container = Container(attrs=FIRST_CONTAINER, client=self.client.api) + container.wait(timeout=42) + self.assertTrue(adapter.called_once) + self.assertEqual(adapter.last_request.timeout, 42) + + container.wait() + self.assertIsNone(adapter.last_request.timeout) @requests_mock.Mocker() def test_diff(self, mock):