Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions podman/domain/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -751,16 +753,17 @@ def wait(self, **kwargs) -> int:
condition = [condition]

interval = kwargs.get("interval")
timeout = kwargs.get("timeout")

params = {}
if condition != []:
params["condition"] = condition
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()
20 changes: 19 additions & 1 deletion podman/tests/unit/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down