Skip to content

Commit

Permalink
Podman spawner: add lazy property with Podman instance
Browse files Browse the repository at this point in the history
Signed-off-by: Cleber Rosa <[email protected]>
  • Loading branch information
clebergnu committed Oct 20, 2023
1 parent ee45648 commit 061873c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions avocado/plugins/spawners/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ class PodmanSpawner(DeploymentSpawner, SpawnerMixin):
def __init__(self, config=None, job=None): # pylint: disable=W0231
SpawnerMixin.__init__(self, config, job)
self.environment = f"podman:{self.config.get('spawner.podman.image')}"
self._podman = None

@property
def podman(self):
if self._podman is None:
podman_bin = self.config.get("spawner.podman.bin")
try:
self._podman = Podman(podman_bin)
except PodmanException as ex:
LOG.error(ex)
return self._podman

def is_task_alive(self, runtime_task): # pylint: disable=W0221
if runtime_task.spawner_handle is None:
Expand Down Expand Up @@ -268,13 +279,6 @@ async def _create_container_for_task(

async def spawn_task(self, runtime_task):
self.create_task_output_dir(runtime_task)
podman_bin = self.config.get("spawner.podman.bin")
try:
# pylint: disable=W0201
self.podman = Podman(podman_bin)
except PodmanException as ex:
LOG.error(ex)
return False

major, minor, _ = await self.python_version
# Return only the "to" location
Expand Down

0 comments on commit 061873c

Please sign in to comment.