From 6f7b448591ed8084a12bdb87426000853f61b15e Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Tue, 7 Jan 2025 20:34:01 -0700 Subject: [PATCH] Fix pkg tests on debian containers --- tests/integration/modules/test_timezone.py | 13 +++++++++++++ .../functional/states/pkgrepo/test_debian.py | 3 +++ tests/pytests/functional/test_version.py | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/tests/integration/modules/test_timezone.py b/tests/integration/modules/test_timezone.py index 3af9bf628ec..473b4d94398 100644 --- a/tests/integration/modules/test_timezone.py +++ b/tests/integration/modules/test_timezone.py @@ -4,6 +4,8 @@ Integration tests for timezone module Linux and Solaris are supported """ +import subprocess + import pytest from tests.support.case import ModuleCase @@ -16,6 +18,16 @@ except ImportError: HAS_TZLOCAL = False +def _check_systemctl(): + if not hasattr(_check_systemctl, "memo"): + proc = subprocess.run(["systemctl"], capture_output=True, check=False) + _check_systemctl.memo = ( + b"Failed to get D-Bus connection: No such file or directory" in proc.stderr + ) + return _check_systemctl.memo + + +@pytest.mark.skipif(_check_systemctl(), reason="systemctl degraded") class TimezoneLinuxModuleTest(ModuleCase): def setUp(self): """ @@ -32,6 +44,7 @@ class TimezoneLinuxModuleTest(ModuleCase): self.assertIn(ret, timescale) +@pytest.mark.skipif(_check_systemctl(), reason="systemctl degraded") class TimezoneSolarisModuleTest(ModuleCase): def setUp(self): """ diff --git a/tests/pytests/functional/states/pkgrepo/test_debian.py b/tests/pytests/functional/states/pkgrepo/test_debian.py index 8205cb06ca7..9cacf657f5b 100644 --- a/tests/pytests/functional/states/pkgrepo/test_debian.py +++ b/tests/pytests/functional/states/pkgrepo/test_debian.py @@ -27,6 +27,9 @@ pytestmark = [ @pytest.fixture def pkgrepo(states, grains): + sources = pathlib.Path("/etc/apt/sources.list") + if not sources.exists(): + sources.touch() if grains["os_family"] != "Debian": raise pytest.skip.Exception( "Test only for debian based platforms", _use_item_location=True diff --git a/tests/pytests/functional/test_version.py b/tests/pytests/functional/test_version.py index b0e40dc3666..bf1a5c4b7e8 100644 --- a/tests/pytests/functional/test_version.py +++ b/tests/pytests/functional/test_version.py @@ -25,6 +25,11 @@ def salt_extension(tmp_path_factory): def test_salt_extensions_in_versions_report(tmp_path, salt_extension): with SaltVirtualEnv(venv_dir=tmp_path / ".venv") as venv: + # These are required for the test to pass, why are they not already + # installed? + venv.install("pyyaml") + venv.install("looseversion") + venv.install("packaging") # Install our extension into the virtualenv venv.install(str(salt_extension.srcdir)) installed_packages = venv.get_installed_packages() @@ -47,6 +52,12 @@ def test_salt_extensions_absent_in_versions_report(tmp_path, salt_extension): Ensure that the 'Salt Extensions' header does not show up when no extension is installed """ with SaltVirtualEnv(venv_dir=tmp_path / ".venv") as venv: + # These are required for the test to pass, why are they not already + # installed? + venv.install("pyyaml") + venv.install("looseversion") + venv.install("packaging") + venv.install("distro") installed_packages = venv.get_installed_packages() assert salt_extension.name not in installed_packages ret = venv.run_code(