From e1137ba9fd3f01e167f646d2dae7981148d9c66d Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Sun, 5 Jan 2020 10:09:28 +0000 Subject: [PATCH] test: detect broken podman 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. --- molecule/test/functional/conftest.py | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/molecule/test/functional/conftest.py b/molecule/test/functional/conftest.py index 34bba516f6..059c1d7c8c 100644 --- a/molecule/test/functional/conftest.py +++ b/molecule/test/functional/conftest.py @@ -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: @@ -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: @@ -277,6 +282,30 @@ 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 + if min_ansible("2.8.6") and platform.system() != 'Darwin': + podman = get_podman_executable() + if podman: + 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 + return False + + def min_ansible(version): """Ensure current Ansible is newer than a given a minimal one.""" try: