Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Commit

Permalink
Lazily load podman executable (#82)
Browse files Browse the repository at this point in the history
When we introduced the ability to specify podman executable, we
inadvertently changed the behavior of the loading mechanism (commit
e120aa1).

Before that change, it was possible to initialize the podman driver even
if the podman executable was not present. In other words, it was OK to
install the podman driver without having podman installed on the system.

With the new mechanism in place, Molecule will fail to start when the
podman driver is installed and there is no podman executable available
on the system.

This commit restores the od lazy-loading behavior.
  • Loading branch information
tadeboro authored Sep 5, 2021
1 parent 57c123c commit e2d78b4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ jobs:
- tox_env: lint
# - tox_env: docs
- tox_env: py36-ansible29
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py36-ansible210
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py36-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py37-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py38-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py39-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py39-devel-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: packaging

steps:
Expand Down
15 changes: 11 additions & 4 deletions src/molecule_podman/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,17 @@ def __init__(self, config=None):
# MOLECULE_PODMAN_EXECUTABLE
# An example could be MOLECULE_PODMAN_EXECUTABLE=podman-remote
self.podman_exec = os.environ.get("MOLECULE_PODMAN_EXECUTABLE", "podman")
self.podman_cmd = distutils.spawn.find_executable(self.podman_exec)
if not self.podman_cmd:
msg = f"command not found in PATH {self.podman_exec}"
util.sysexit_with_message(msg)
self._podman_cmd = None

@property
def podman_cmd(self):
"""Lazily calculate the podman command."""
if not self._podman_cmd:
self._podman_cmd = distutils.spawn.find_executable(self.podman_exec)
if not self._podman_cmd:
msg = f"command not found in PATH {self.podman_exec}"
util.sysexit_with_message(msg)
return self._podman_cmd

@property
def name(self):
Expand Down
8 changes: 8 additions & 0 deletions src/molecule_podman/test/test_driver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
"""Unit tests."""
from molecule import api

from molecule_podman.driver import Podman


def test_driver_is_detected():
"""Asserts that molecule recognizes the driver."""
assert any(str(d) == "podman" for d in api.drivers())


def test_driver_initializes_without_podman_executable(monkeypatch):
"""Make sure we can initiaize driver without having an executable present."""
monkeypatch.setenv("MOLECULE_PODMAN_EXECUTABLE", "bad-executable")
Podman()

0 comments on commit e2d78b4

Please sign in to comment.