Skip to content

Commit

Permalink
test: detect broken podman (#2483)
Browse files Browse the repository at this point in the history
Improved podman detection so we fail fast if current installation does
not pass `podman info` minimal test. This should save time running
tests on systems what are not properly configured.

Skips will happen only on platforms that are known not to support
podman, but on those supporting it, tests will fail.

Enables lru_cache on podman/docker checks in order to improve
testing runtime performance.
  • Loading branch information
ssbarnea committed Jan 5, 2020
1 parent 03dea6f commit 17323ef
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion molecule/test/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def skip_test(request, driver_name):
msg_tmpl = "Skipped '{}' not supported"
support_checks_map = {
'docker': supports_docker,
'podman': lambda: min_ansible("2.8.6") and platform.system() != 'Darwin',
'podman': supports_podman,
'delegated': lambda: True,
}
try:
Expand Down Expand Up @@ -253,11 +253,16 @@ def get_docker_executable():
return distutils.spawn.find_executable('docker')


def get_podman_executable():
return distutils.spawn.find_executable('podman')


def get_virtualbox_executable():
return distutils.spawn.find_executable('VBoxManage')


@pytest.helpers.register
@util.lru_cache()
def supports_docker():
docker = get_docker_executable()
if docker:
Expand All @@ -277,6 +282,29 @@ def supports_docker():
return True


@pytest.helpers.register
@util.lru_cache()
def supports_podman():
# Returns true if podman is supported and working
# Returns false if podman in not supported
# Calls pytest.fail if podman appears to be broken
podman = get_podman_executable()
if not min_ansible("2.8.6") or platform.system() == 'Darwin' or not podman:
return False

result = util.run([podman, "info"], stdout=PIPE, universal_newlines=True)
if result.returncode != 0:
LOG.error(
"Error %s returned from `podman info`: %s",
result.returncode,
result.stdout,
)
pytest.fail("Cannot run podman tests with a broken podman installation.")
return False

return True


def min_ansible(version):
"""Ensure current Ansible is newer than a given a minimal one."""
try:
Expand Down

0 comments on commit 17323ef

Please sign in to comment.