File fix-problematic-tests-and-allow-smooth-tests-executi.patch of Package salt
From 881ced07e9984718484ef898303123d193eaeebf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
<psuarezhernandez@suse.com>
Date: Mon, 26 Feb 2024 11:25:22 +0000
Subject: [PATCH] Fix problematic tests and allow smooth tests
executions on containers
* Align boto imports in tests with Salt modules
Some modules `import boto` to set log levels. The related tests don't
import `boto`. This can cause a problem when `boto` is not available.
Tests are skipped when HAS_BOTO in the test_boto_*.py is False. Not
trying to `import boto` can leave HAS_BOTO=True in the test file even
though HAS_BOTO is False on the application side. In this case, tests
are not skipped and fail.
* Fix mock order in test_dig (test_network.py)
`salt.utils.path.which` should not be mocked before `network.__utils__`. The
Salt loader calls `salt.utils.network.linux_interfaces`, which needs the real
`salt.utils.path.which`.
* Fix mock calls
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
(cherry picked from commit 3506e7fd0e84320b2873370f1fe527025c244dca)
* Skip venafiapi test if vcert module not available
The same HAS_VCERT check is done in the runner module.
* Moving tests/integration/modules/test_cmdmod.py to pytest, Gareth J Greenaway original author
(cherry picked from commit 2c1040b4c2885efaa86576fd88eb36bb550b5996)
* The repo.saltproject.io `index.html` file changed it's contents. Fix tests.
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
(cherry picked from commit 672f6586d7c3cdb0e8c5ee42524895035aafcc23)
* Skip hwclock test when executed inside a container
* Skip git pillar tests when executed inside a container
These tests require a Git repository container, which is hard to correctly set
up when executing the tests in the container in GH Actions.
Using --network host can help, but there was still an error (the git repos were
empty) when I tried to set this up.
* Skip test requiring systemd inside container
* Exclude tests for hgfs if missing hglib
* Skip and fix tests when running on containers
* Fix some failing test causing problem in SUSE environments
* Skip more tests when running on containers
* Use skipif instead of skip_if as it seems not behaving equally
* Skip more tests that cannot run in a container
* Remove SSH test which doesn't make sense after lock mechanism
* Fix failing boto tests
* Skip unmaintained tests upstream around zcbuildout
* Skip some tests that does not run well in GH Actions
---------
Co-authored-by: Pedro Algarvio <palgarvio@vmware.com>
Co-authored-by: Gareth J. Greenaway <gareth@saltstack.com>
Co-authored-by: Alexander Graul <agraul@suse.com>
---
tests/integration/modules/test_timezone.py | 3 ++
tests/integration/pillar/test_git_pillar.py | 3 ++
tests/pytests/functional/cache/test_consul.py | 4 ++
tests/pytests/functional/cache/test_mysql.py | 4 ++
.../pytests/functional/modules/test_cmdmod.py | 44 +++++++++++++++----
.../pytests/functional/modules/test_system.py | 3 ++
.../states/rabbitmq/test_cluster.py | 4 ++
.../functional/states/rabbitmq/test_plugin.py | 4 ++
.../functional/states/rabbitmq/test_policy.py | 4 ++
.../states/rabbitmq/test_upstream.py | 4 ++
.../functional/states/rabbitmq/test_user.py | 4 ++
.../functional/states/rabbitmq/test_vhost.py | 4 ++
tests/pytests/functional/states/test_pkg.py | 21 ++-------
.../integration/cli/test_syndic_eauth.py | 6 +++
.../integration/daemons/test_memory_leak.py | 6 +++
tests/pytests/integration/ssh/test_log.py | 3 ++
tests/pytests/integration/ssh/test_master.py | 5 +++
.../integration/ssh/test_py_versions.py | 3 ++
.../pytests/integration/ssh/test_ssh_setup.py | 2 +
.../scenarios/compat/test_with_versions.py | 4 ++
.../multimaster/test_failover_master.py | 3 ++
tests/pytests/scenarios/setup/test_install.py | 5 +++
tests/pytests/unit/utils/event/test_event.py | 30 +++++++++++++
tests/unit/modules/test_network.py | 6 ++-
24 files changed, 151 insertions(+), 28 deletions(-)
diff --git a/tests/integration/modules/test_timezone.py b/tests/integration/modules/test_timezone.py
index 3af9bf628e..5a2ed6dde4 100644
--- a/tests/integration/modules/test_timezone.py
+++ b/tests/integration/modules/test_timezone.py
@@ -5,6 +5,7 @@ Linux and Solaris are supported
"""
import pytest
+import os
from tests.support.case import ModuleCase
@@ -16,6 +17,8 @@ except ImportError:
HAS_TZLOCAL = False
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+@pytest.mark.skipif(INSIDE_CONTAINER, reason="No hwclock in a container")
class TimezoneLinuxModuleTest(ModuleCase):
def setUp(self):
"""
diff --git a/tests/integration/pillar/test_git_pillar.py b/tests/integration/pillar/test_git_pillar.py
index e390da7aec..2a21296712 100644
--- a/tests/integration/pillar/test_git_pillar.py
+++ b/tests/integration/pillar/test_git_pillar.py
@@ -63,6 +63,7 @@ https://github.com/git/git/commit/6bc0cb5
https://github.com/unbit/uwsgi/commit/ac1e354
"""
+import os
import random
import string
import sys
@@ -100,9 +101,11 @@ try:
except Exception: # pylint: disable=broad-except
HAS_PYGIT2 = False
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
pytestmark = [
SKIP_INITIAL_PHOTONOS_FAILURES,
pytest.mark.skip_on_platforms(windows=True, darwin=True),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Communication problems between containers."),
]
diff --git a/tests/pytests/functional/cache/test_consul.py b/tests/pytests/functional/cache/test_consul.py
index 0a42913b6c..14f9fa340d 100644
--- a/tests/pytests/functional/cache/test_consul.py
+++ b/tests/pytests/functional/cache/test_consul.py
@@ -1,4 +1,5 @@
import logging
+import os
import socket
import time
@@ -13,10 +14,13 @@ docker = pytest.importorskip("docker")
log = logging.getLogger(__name__)
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.skip_on_fips_enabled_platform,
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing("dockerd"),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/functional/cache/test_mysql.py b/tests/pytests/functional/cache/test_mysql.py
index c283872c08..e15fc732a4 100644
--- a/tests/pytests/functional/cache/test_mysql.py
+++ b/tests/pytests/functional/cache/test_mysql.py
@@ -1,4 +1,5 @@
import logging
+import os
import pytest
@@ -11,9 +12,12 @@ docker = pytest.importorskip("docker")
log = logging.getLogger(__name__)
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing("dockerd"),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/functional/modules/test_cmdmod.py b/tests/pytests/functional/modules/test_cmdmod.py
index f8dbb7e113..42427c2b1f 100644
--- a/tests/pytests/functional/modules/test_cmdmod.py
+++ b/tests/pytests/functional/modules/test_cmdmod.py
@@ -1,6 +1,7 @@
import os
import random
import sys
+from contextlib import contextmanager
import pytest
@@ -109,6 +110,20 @@ def test_run(cmdmod, grains):
assert cmdmod.run('echo "a=b" | sed -e s/=/:/g', python_shell=True) == "a:b"
+@contextmanager
+def _ensure_user_exists(name, usermod):
+ if name in usermod.info(name).values():
+ # User already exists; don't touch
+ yield
+ else:
+ # Need to create user for test
+ usermod.add(name)
+ try:
+ yield
+ finally:
+ usermod.delete(name, remove=True)
+
+
@pytest.mark.slow_test
def test_stdout(cmdmod):
"""
@@ -295,6 +310,8 @@ def test_tty(cmdmod):
assert "Success" in ret
+@pytest.mark.skip_on_windows
+@pytest.mark.skip_if_binaries_missing("which")
def test_which(cmdmod):
"""
cmd.which
@@ -314,6 +331,9 @@ def test_which(cmdmod):
assert cmd_which.rstrip().lower() == cmd_run.rstrip().lower()
+
+@pytest.mark.skip_on_windows
+@pytest.mark.skip_if_binaries_missing("which")
def test_which_bin(cmdmod):
"""
cmd.which_bin
@@ -426,7 +446,8 @@ def test_cwd_runas(cmdmod, usermod, runas_usr, tmp_path):
cwd_normal = cmdmod.run_stdout(cmd, cwd=tmp_cwd).rstrip("\n")
assert tmp_cwd == cwd_normal
- cwd_runas = cmdmod.run_stdout(cmd, cwd=tmp_cwd, runas=runas_usr).rstrip("\n")
+ with _ensure_user_exists(runas_usr, usermod):
+ cwd_runas = cmdmod.run_stdout(cmd, cwd=tmp_cwd, runas=runas_usr).rstrip("\n")
assert tmp_cwd == cwd_runas
@@ -439,7 +460,8 @@ def test_runas_env(cmdmod, usermod, runas_usr):
cmd.run should be able to change working directory correctly, whether
or not runas is in use.
"""
- user_path = cmdmod.run_stdout('printf %s "$PATH"', runas=runas_usr)
+ with _ensure_user_exists(runas_usr, usermod):
+ user_path = cmdmod.run_stdout('printf %s "$PATH"', runas=runas_usr)
# XXX: Not sure of a better way. Environment starts out with
# /bin:/usr/bin and should be populated by path helper and the bash
# profile.
@@ -462,11 +484,14 @@ def test_runas_complex_command_bad_cwd(cmdmod, usermod, runas_usr, tmp_path):
"""
tmp_cwd = str(tmp_path)
os.chmod(tmp_cwd, 0o700)
- cmd_result = cmdmod.run_all(
- 'pwd; pwd; : $(echo "You have failed the test" >&2)',
- cwd=tmp_cwd,
- runas=runas_usr,
- )
+
+ with _ensure_user_exists(runas_usr, usermod):
+ cmd_result = cmdmod.run_all(
+ 'pwd; pwd; : $(echo "You have failed the test" >&2)',
+ cwd=tmp_cwd,
+ runas=runas_usr,
+ )
+
assert "" == cmd_result["stdout"]
assert "You have failed the test" not in cmd_result["stderr"]
assert 0 != cmd_result["retcode"]
@@ -481,10 +506,12 @@ def test_runas(cmdmod, usermod, runas_usr):
"""
Ensure that the env is the runas user's
"""
- out = cmdmod.run("env", runas=runas_usr).splitlines()
+ with _ensure_user_exists(runas_usr, usermod):
+ out = cmdmod.run("env", runas=runas_usr).splitlines()
assert f"USER={runas_usr}" in out
+@pytest.mark.skip_if_binaries_missing("sleep", reason="sleep cmd not installed")
def test_timeout(cmdmod):
"""
cmd.run trigger timeout
@@ -501,6 +528,7 @@ def test_timeout(cmdmod):
assert "Timed out" in out
+@pytest.mark.skip_if_binaries_missing("sleep", reason="sleep cmd not installed")
def test_timeout_success(cmdmod):
"""
cmd.run sufficient timeout to succeed
diff --git a/tests/pytests/functional/modules/test_system.py b/tests/pytests/functional/modules/test_system.py
index 07f34e8a51..57e68a5bbe 100644
--- a/tests/pytests/functional/modules/test_system.py
+++ b/tests/pytests/functional/modules/test_system.py
@@ -10,9 +10,12 @@ import pytest
import salt.utils.files
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.skip_unless_on_linux,
pytest.mark.slow_test,
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="No systemd in container."),
]
log = logging.getLogger(__name__)
diff --git a/tests/pytests/functional/states/rabbitmq/test_cluster.py b/tests/pytests/functional/states/rabbitmq/test_cluster.py
index f8b4bdc225..210b22a236 100644
--- a/tests/pytests/functional/states/rabbitmq/test_cluster.py
+++ b/tests/pytests/functional/states/rabbitmq/test_cluster.py
@@ -3,6 +3,7 @@ Integration tests for the rabbitmq_cluster states
"""
import logging
+import os
import pytest
@@ -13,11 +14,14 @@ pytest.importorskip("docker")
log = logging.getLogger(__name__)
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing(
"docker", "dockerd", reason="Docker not installed"
),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/functional/states/rabbitmq/test_plugin.py b/tests/pytests/functional/states/rabbitmq/test_plugin.py
index e1b686e336..f119149053 100644
--- a/tests/pytests/functional/states/rabbitmq/test_plugin.py
+++ b/tests/pytests/functional/states/rabbitmq/test_plugin.py
@@ -3,6 +3,7 @@ Integration tests for the rabbitmq_plugin states
"""
import logging
+import os
import pytest
@@ -14,11 +15,14 @@ log = logging.getLogger(__name__)
pytest.importorskip("docker")
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing(
"docker", "dockerd", reason="Docker not installed"
),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/functional/states/rabbitmq/test_policy.py b/tests/pytests/functional/states/rabbitmq/test_policy.py
index e5cee97cbc..7ccf6a522e 100644
--- a/tests/pytests/functional/states/rabbitmq/test_policy.py
+++ b/tests/pytests/functional/states/rabbitmq/test_policy.py
@@ -3,6 +3,7 @@ Integration tests for the rabbitmq_policy states
"""
import logging
+import os
import pytest
@@ -14,11 +15,14 @@ log = logging.getLogger(__name__)
pytest.importorskip("docker")
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing(
"docker", "dockerd", reason="Docker not installed"
),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/functional/states/rabbitmq/test_upstream.py b/tests/pytests/functional/states/rabbitmq/test_upstream.py
index cfdad35aba..c7bcf3b0d4 100644
--- a/tests/pytests/functional/states/rabbitmq/test_upstream.py
+++ b/tests/pytests/functional/states/rabbitmq/test_upstream.py
@@ -3,6 +3,7 @@ Integration tests for the rabbitmq_user states
"""
import logging
+import os
import pytest
@@ -13,11 +14,14 @@ log = logging.getLogger(__name__)
pytest.importorskip("docker")
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing(
"docker", "dockerd", reason="Docker not installed"
),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/functional/states/rabbitmq/test_user.py b/tests/pytests/functional/states/rabbitmq/test_user.py
index 2f9b22d28d..31723df7be 100644
--- a/tests/pytests/functional/states/rabbitmq/test_user.py
+++ b/tests/pytests/functional/states/rabbitmq/test_user.py
@@ -3,6 +3,7 @@ Integration tests for the rabbitmq_user states
"""
import logging
+import os
import pytest
@@ -13,11 +14,14 @@ log = logging.getLogger(__name__)
pytest.importorskip("docker")
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing(
"docker", "dockerd", reason="Docker not installed"
),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/functional/states/rabbitmq/test_vhost.py b/tests/pytests/functional/states/rabbitmq/test_vhost.py
index a648d41854..d6ac6901a2 100644
--- a/tests/pytests/functional/states/rabbitmq/test_vhost.py
+++ b/tests/pytests/functional/states/rabbitmq/test_vhost.py
@@ -3,6 +3,7 @@ Integration tests for the rabbitmq_user states
"""
import logging
+import os
import pytest
@@ -13,11 +14,14 @@ log = logging.getLogger(__name__)
pytest.importorskip("docker")
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing(
"docker", "dockerd", reason="Docker not installed"
),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/functional/states/test_pkg.py b/tests/pytests/functional/states/test_pkg.py
index 9337eab233..29fe757db2 100644
--- a/tests/pytests/functional/states/test_pkg.py
+++ b/tests/pytests/functional/states/test_pkg.py
@@ -82,22 +82,7 @@ def PKG_CAP_TARGETS(grains):
_PKG_CAP_TARGETS = []
if grains["os_family"] == "Suse":
if grains["os"] == "SUSE":
- _PKG_CAP_TARGETS = [("perl(YAML)", "perl-YAML")]
- # sudo zypper install 'perl(YAML)'
- # Loading repository data...
- # Reading installed packages...
- # 'perl(YAML)' not found in package names. Trying capabilities.
- # Resolving package dependencies...
- #
- # The following NEW package is going to be installed:
- # perl-YAML
- #
- # 1 new package to install.
- # Overall download size: 85.3 KiB. Already cached: 0 B. After the operation, additional 183.3 KiB will be used.
- # Continue? [y/n/v/...? shows all options] (y):
-
- # So, it just doesn't work here? skip it for now
- _PKG_CAP_TARGETS.clear()
+ _PKG_CAP_TARGETS = [("perl(Error)", "perl-Error")]
if not _PKG_CAP_TARGETS:
pytest.skip("Capability not provided")
return _PKG_CAP_TARGETS
@@ -892,8 +877,8 @@ def test_pkg_cap_003_installed_multipkg_with_version(
This is a destructive test as it installs and then removes two packages
"""
target, realpkg = PKG_CAP_TARGETS[0]
- version = latest_version(target)
- realver = latest_version(realpkg)
+ version = modules.pkg.version(target)
+ realver = modules.pkg.version(realpkg)
# If this condition is False, we need to find new targets.
# This needs to be able to test successful installation of packages.
diff --git a/tests/pytests/integration/cli/test_syndic_eauth.py b/tests/pytests/integration/cli/test_syndic_eauth.py
index e1d159cdf9..868f596b11 100644
--- a/tests/pytests/integration/cli/test_syndic_eauth.py
+++ b/tests/pytests/integration/cli/test_syndic_eauth.py
@@ -1,5 +1,8 @@
import json
import logging
+import os
+import pathlib
+import tempfile
import time
import pytest
@@ -10,9 +13,12 @@ docker = pytest.importorskip("docker")
log = logging.getLogger(__name__)
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.core_test,
pytest.mark.timeout_unless_on_windows(600),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/integration/daemons/test_memory_leak.py b/tests/pytests/integration/daemons/test_memory_leak.py
index 8461edeb55..92984acbe8 100644
--- a/tests/pytests/integration/daemons/test_memory_leak.py
+++ b/tests/pytests/integration/daemons/test_memory_leak.py
@@ -1,4 +1,5 @@
import multiprocessing
+import os
import time
import psutil
@@ -20,6 +21,8 @@ pytestmark = [
),
]
+GITHUB_ACTIONS = bool(os.getenv("GITHUB_ACTIONS", False))
+
@pytest.fixture
def file_add_delete_sls(tmp_path, salt_master):
@@ -51,6 +54,9 @@ def file_add_delete_sls(tmp_path, salt_master):
# This test is fundimentally flawed. Needs to be re-factored to test the memory
# consuption of the minoin process not system wide memory.
@pytest.mark.skip(reason="Flawed test")
+@pytest.mark.skip_on_darwin(reason="MacOS is a spawning platform, won't work")
+@pytest.mark.skipif(GITHUB_ACTIONS, reason="Test is failing in GitHub Actions")
+@pytest.mark.flaky(max_runs=4)
def test_memory_leak(salt_cli, salt_minion, file_add_delete_sls):
max_usg = None
diff --git a/tests/pytests/integration/ssh/test_log.py b/tests/pytests/integration/ssh/test_log.py
index de498b8d64..686ff4a363 100644
--- a/tests/pytests/integration/ssh/test_log.py
+++ b/tests/pytests/integration/ssh/test_log.py
@@ -3,6 +3,7 @@ Integration tests for salt-ssh logging
"""
import logging
+import os
import time
import pytest
@@ -12,12 +13,14 @@ from tests.support.helpers import Keys
pytest.importorskip("docker")
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
log = logging.getLogger(__name__)
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing("dockerd"),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/integration/ssh/test_master.py b/tests/pytests/integration/ssh/test_master.py
index 5a81fcb8d0..94f4a2093f 100644
--- a/tests/pytests/integration/ssh/test_master.py
+++ b/tests/pytests/integration/ssh/test_master.py
@@ -2,6 +2,8 @@
Simple Smoke Tests for Connected SSH minions
"""
+import os
+
import pytest
from saltfactories.utils.functional import StateResult
@@ -10,7 +12,10 @@ pytestmark = [
pytest.mark.skip_on_windows(reason="salt-ssh not available on Windows"),
]
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
+@pytest.mark.skipif(INSIDE_CONTAINER, reason="No systemd in container.")
@pytest.mark.skip_if_not_root
def test_service(salt_ssh_cli, grains):
service = "cron"
diff --git a/tests/pytests/integration/ssh/test_py_versions.py b/tests/pytests/integration/ssh/test_py_versions.py
index 749aab061c..b77aba0bb7 100644
--- a/tests/pytests/integration/ssh/test_py_versions.py
+++ b/tests/pytests/integration/ssh/test_py_versions.py
@@ -3,6 +3,7 @@ Integration tests for salt-ssh py_versions
"""
import logging
+import os
import socket
import time
@@ -13,12 +14,14 @@ from tests.support.helpers import Keys
pytest.importorskip("docker")
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
log = logging.getLogger(__name__)
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing("dockerd"),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/integration/ssh/test_ssh_setup.py b/tests/pytests/integration/ssh/test_ssh_setup.py
index 6d6ebbeb4d..94182d03ae 100644
--- a/tests/pytests/integration/ssh/test_ssh_setup.py
+++ b/tests/pytests/integration/ssh/test_ssh_setup.py
@@ -18,12 +18,14 @@ from tests.support.helpers import Keys
pytest.importorskip("docker")
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
log = logging.getLogger(__name__)
pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_binaries_missing("dockerd"),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/scenarios/compat/test_with_versions.py b/tests/pytests/scenarios/compat/test_with_versions.py
index 60c486864a..1187158f3d 100644
--- a/tests/pytests/scenarios/compat/test_with_versions.py
+++ b/tests/pytests/scenarios/compat/test_with_versions.py
@@ -6,6 +6,7 @@
"""
import logging
+import os
import pathlib
import pytest
@@ -20,6 +21,8 @@ docker = pytest.importorskip("docker")
log = logging.getLogger(__name__)
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.skip("GREAT MODULE MIGRATION"),
@@ -28,6 +31,7 @@ pytestmark = [
pytest.mark.skipif(
salt.utils.platform.is_photonos() is True, reason="Skip on PhotonOS"
),
+ pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
]
diff --git a/tests/pytests/scenarios/failover/multimaster/test_failover_master.py b/tests/pytests/scenarios/failover/multimaster/test_failover_master.py
index e996469789..4e0bb49f6f 100644
--- a/tests/pytests/scenarios/failover/multimaster/test_failover_master.py
+++ b/tests/pytests/scenarios/failover/multimaster/test_failover_master.py
@@ -14,7 +14,10 @@ pytestmark = [
log = logging.getLogger(__name__)
+GITHUB_ACTIONS = bool(os.getenv("GITHUB_ACTIONS", False))
+
+@pytest.mark.skipif(GITHUB_ACTIONS, reason="Test is failing in GitHub Actions")
def test_pki(salt_mm_failover_master_1, salt_mm_failover_master_2, caplog):
"""
Verify https://docs.saltproject.io/en/latest/topics/tutorials/multimaster_pki.html
diff --git a/tests/pytests/scenarios/setup/test_install.py b/tests/pytests/scenarios/setup/test_install.py
index 5953a9640c..a4494ce08f 100644
--- a/tests/pytests/scenarios/setup/test_install.py
+++ b/tests/pytests/scenarios/setup/test_install.py
@@ -19,11 +19,16 @@ from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
log = logging.getLogger(__name__)
+INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
pytestmark = [
pytest.mark.core_test,
pytest.mark.windows_whitelisted,
pytest.mark.skip_initial_onedir_failure,
pytest.mark.skip_if_binaries_missing(*KNOWN_BINARY_NAMES, check_all=False),
+ pytest.mark.skipif(
+ INSIDE_CONTAINER, reason="No gcc and python3-devel in container."
+ ),
]
diff --git a/tests/pytests/unit/utils/event/test_event.py b/tests/pytests/unit/utils/event/test_event.py
index a91ba88f21..a5c423fae1 100644
--- a/tests/pytests/unit/utils/event/test_event.py
+++ b/tests/pytests/unit/utils/event/test_event.py
@@ -46,6 +46,36 @@ def _assert_got_event(evt, data, msg=None, expected_failure=False):
assert data[key] != evt[key]
+def test_master_event(sock_dir):
+ with salt.utils.event.MasterEvent(str(sock_dir), listen=False) as me:
+ assert me.puburi == str(sock_dir / "master_event_pub.ipc")
+ assert me.pulluri == str(sock_dir / "master_event_pull.ipc")
+
+
+def test_minion_event(sock_dir):
+ opts = dict(id="foo", sock_dir=str(sock_dir))
+ id_hash = hashlib.sha256(salt.utils.stringutils.to_bytes(opts["id"])).hexdigest()[
+ :10
+ ]
+ with salt.utils.event.MinionEvent(opts, listen=False) as me:
+ assert me.puburi == str(sock_dir / f"minion_event_{id_hash}_pub.ipc")
+ assert me.pulluri == str(sock_dir / f"minion_event_{id_hash}_pull.ipc")
+
+
+def test_minion_event_tcp_ipc_mode():
+ opts = dict(id="foo", ipc_mode="tcp")
+ with salt.utils.event.MinionEvent(opts, listen=False) as me:
+ assert me.puburi == 4510
+ assert me.pulluri == 4511
+
+
+def test_minion_event_no_id(sock_dir):
+ with salt.utils.event.MinionEvent(dict(sock_dir=str(sock_dir)), listen=False) as me:
+ id_hash = hashlib.sha256(salt.utils.stringutils.to_bytes("")).hexdigest()[:10]
+ assert me.puburi == str(sock_dir / f"minion_event_{id_hash}_pub.ipc")
+ assert me.pulluri == str(sock_dir / f"minion_event_{id_hash}_pull.ipc")
+
+
@pytest.mark.slow_test
def test_event_single(sock_dir):
"""Test a single event is received"""
diff --git a/tests/unit/modules/test_network.py b/tests/unit/modules/test_network.py
index 34b06250fc..9eef9a02f5 100644
--- a/tests/unit/modules/test_network.py
+++ b/tests/unit/modules/test_network.py
@@ -153,9 +153,11 @@ class NetworkTestCase(TestCase, LoaderModuleMockMixin):
"""
Test for Performs a DNS lookup with dig
"""
- with patch("salt.utils.path.which", MagicMock(return_value="dig")), patch.dict(
+ with patch.dict(
network.__utils__, {"network.sanitize_host": MagicMock(return_value="A")}
- ), patch.dict(network.__salt__, {"cmd.run": MagicMock(return_value="A")}):
+ ), patch("salt.utils.path.which", MagicMock(return_value="dig")), patch.dict(
+ network.__salt__, {"cmd.run": MagicMock(return_value="A")}
+ ):
self.assertEqual(network.dig("host"), "A")
def test_arp(self):
--
2.47.0