Skip to content

Commit

Permalink
Podman Spawner: update method of detecting container running
Browse files Browse the repository at this point in the history
This updates the method that is used to detect if the container is
running, adding a (by default, one time) timeout between the "created"
and "running" state.

Signed-off-by: Cleber Rosa <[email protected]>
  • Loading branch information
clebergnu committed Oct 20, 2023
1 parent 061873c commit 021660d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions avocado/plugins/spawners/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import subprocess
import time
import uuid

from avocado.core.dependencies.requirements import cache
Expand Down Expand Up @@ -122,7 +123,7 @@ def podman(self):
LOG.error(ex)
return self._podman

def is_task_alive(self, runtime_task): # pylint: disable=W0221
def _get_podman_state(self, runtime_task):
if runtime_task.spawner_handle is None:
return False
podman_bin = self.config.get("spawner.podman.bin")
Expand All @@ -140,8 +141,17 @@ def is_task_alive(self, runtime_task): # pylint: disable=W0221
stderr=subprocess.DEVNULL,
)
out, _ = process.communicate()
# FIXME: check how podman 2.x is reporting valid "OK" states
return out.startswith(b"Up ")
return out

def is_task_alive(self, runtime_task, timeout_until_running=0.1): # pylint: disable=W0221
out = self._get_podman_state(runtime_task)
if out == b"running\n":
return True
if out == b"created\n":
if timeout is None:
return False
time.sleep(timeout_until_running)
return self.is_task_alive(runtime_task, None)

def _fetch_asset(self, url):
cachedirs = self.config.get("datadir.paths.cache_dirs")
Expand Down

0 comments on commit 021660d

Please sign in to comment.