File make-tests-compatible-with-venv-bundle.patch of Package salt
From 04f936f320654a3488321ec91f0417be0c2f7173 Mon Sep 17 00:00:00 2001
From: Marek Czernek <marek.czernek@suse.com>
Date: Wed, 7 Aug 2024 10:28:07 +0200
Subject: [PATCH] Make tests compatible with venv bundle
Co-authored-by: cmcmarrow <charles.mcmarrow.4@gmail.com>
---
.../utils/yamllint/test_yamllint.py | 2 +-
tests/pytests/unit/modules/test_pip.py | 63 +++++++++++++------
tests/pytests/unit/states/test_pkgrepo.py | 3 +-
tests/pytests/unit/test_fileserver.py | 8 +--
tests/pytests/unit/utils/test_msgpack.py | 2 +-
tests/pytests/unit/utils/test_pycrypto.py | 25 ++++----
tests/unit/test_config.py | 22 ++++++-
7 files changed, 80 insertions(+), 45 deletions(-)
diff --git a/tests/pytests/functional/utils/yamllint/test_yamllint.py b/tests/pytests/functional/utils/yamllint/test_yamllint.py
index 403c6fc610..3c730523c4 100644
--- a/tests/pytests/functional/utils/yamllint/test_yamllint.py
+++ b/tests/pytests/functional/utils/yamllint/test_yamllint.py
@@ -7,7 +7,7 @@ import salt.utils.versions as versions
try:
import salt.utils.yamllint as yamllint
- YAMLLINT_AVAILABLE = True
+ YAMLLINT_AVAILABLE = yamllint.has_yamllint()
except ImportError:
YAMLLINT_AVAILABLE = False
diff --git a/tests/pytests/unit/modules/test_pip.py b/tests/pytests/unit/modules/test_pip.py
index 1991b551a3..6430c0d53d 100644
--- a/tests/pytests/unit/modules/test_pip.py
+++ b/tests/pytests/unit/modules/test_pip.py
@@ -15,6 +15,10 @@ MISSING_SETUP_PY_FILE = not os.path.exists(
os.path.join(RUNTIME_VARS.CODE_DIR, "setup.py")
)
+TARGET = []
+if os.environ.get('VENV_PIP_TARGET'):
+ TARGET = ["--target", os.environ.get('VENV_PIP_TARGET')]
+
class FakeFopen:
def __init__(self, filename):
@@ -102,6 +106,7 @@ def test_install_frozen_app(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
pkg,
]
mock.assert_called_with(
@@ -123,6 +128,7 @@ def test_install_source_app(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
pkg,
]
mock.assert_called_with(
@@ -143,6 +149,7 @@ def test_fix4361(python_binary):
"install",
"--requirement",
"requirements.txt",
+ *TARGET,
]
mock.assert_called_with(
expected_cmd,
@@ -169,7 +176,7 @@ def test_install_multiple_editable(python_binary):
"git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting",
]
- expected = [*python_binary, "install"]
+ expected = [*python_binary, "install", *TARGET]
for item in editables:
expected.extend(["--editable", item])
@@ -205,7 +212,7 @@ def test_install_multiple_pkgs_and_editables(python_binary):
"git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting",
]
- expected = [*python_binary, "install"]
+ expected = [*python_binary, "install", *TARGET]
expected.extend(pkgs)
for item in editables:
expected.extend(["--editable", item])
@@ -241,6 +248,7 @@ def test_install_multiple_pkgs_and_editables(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
pkgs[0],
"--editable",
editables[0],
@@ -268,7 +276,7 @@ def test_issue5940_install_multiple_pip_mirrors(python_binary):
expected = [*python_binary, "install", "--use-mirrors"]
for item in mirrors:
expected.extend(["--mirrors", item])
- expected.append("pep8")
+ expected = [*expected, *TARGET, "pep8"]
# Passing mirrors as a list
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
@@ -300,6 +308,7 @@ def test_issue5940_install_multiple_pip_mirrors(python_binary):
"--use-mirrors",
"--mirrors",
mirrors[0],
+ *TARGET,
"pep8",
]
@@ -327,7 +336,7 @@ def test_install_with_multiple_find_links(python_binary):
expected = [*python_binary, "install"]
for item in find_links:
expected.extend(["--find-links", item])
- expected.append(pkg)
+ expected = [*expected, *TARGET, pkg]
# Passing mirrors as a list
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
@@ -370,6 +379,7 @@ def test_install_with_multiple_find_links(python_binary):
"install",
"--find-links",
find_links[0],
+ *TARGET,
pkg,
]
@@ -435,6 +445,7 @@ def test_install_cached_requirements_used(python_binary):
"install",
"--requirement",
"my_cached_reqs",
+ *TARGET,
]
mock.assert_called_with(
expected,
@@ -491,6 +502,7 @@ def test_install_log_argument_in_resulting_command(python_binary, tmp_path):
"install",
"--log",
log_path,
+ *TARGET,
pkg,
]
mock.assert_called_with(
@@ -521,7 +533,7 @@ def test_install_timeout_argument_in_resulting_command(python_binary):
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, timeout=10)
mock.assert_called_with(
- expected + [10, pkg],
+ expected + [10, *TARGET, pkg],
saltenv="base",
runas=None,
use_vt=False,
@@ -533,7 +545,7 @@ def test_install_timeout_argument_in_resulting_command(python_binary):
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, timeout="10")
mock.assert_called_with(
- expected + ["10", pkg],
+ expected + ["10", *TARGET, pkg],
saltenv="base",
runas=None,
use_vt=False,
@@ -557,6 +569,7 @@ def test_install_index_url_argument_in_resulting_command(python_binary):
"install",
"--index-url",
index_url,
+ *TARGET,
pkg,
]
mock.assert_called_with(
@@ -579,6 +592,7 @@ def test_install_extra_index_url_argument_in_resulting_command(python_binary):
"install",
"--extra-index-url",
extra_index_url,
+ *TARGET,
pkg,
]
mock.assert_called_with(
@@ -595,7 +609,7 @@ def test_install_no_index_argument_in_resulting_command(python_binary):
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, no_index=True)
- expected = [*python_binary, "install", "--no-index", pkg]
+ expected = [*python_binary, "install", "--no-index", *TARGET, pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -611,7 +625,7 @@ def test_install_build_argument_in_resulting_command(python_binary):
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, build=build)
- expected = [*python_binary, "install", "--build", build, pkg]
+ expected = [*python_binary, "install", "--build", build, *TARGET, pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -646,6 +660,7 @@ def test_install_download_argument_in_resulting_command(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
"--download",
download,
pkg,
@@ -664,7 +679,7 @@ def test_install_no_download_argument_in_resulting_command(python_binary):
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, no_download=True)
- expected = [*python_binary, "install", "--no-download", pkg]
+ expected = [*python_binary, "install", *TARGET, "--no-download", pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -691,6 +706,7 @@ def test_install_download_cache_dir_arguments_in_resulting_command(python_binary
expected = [
*python_binary,
"install",
+ *TARGET,
cmd_arg,
download_cache,
pkg,
@@ -720,7 +736,7 @@ def test_install_source_argument_in_resulting_command(python_binary):
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, source=source)
- expected = [*python_binary, "install", "--source", source, pkg]
+ expected = [*python_binary, "install", *TARGET, "--source", source, pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -739,6 +755,7 @@ def test_install_exists_action_argument_in_resulting_command(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
"--exists-action",
action,
pkg,
@@ -761,7 +778,7 @@ def test_install_install_options_argument_in_resulting_command(python_binary):
install_options = ["--exec-prefix=/foo/bar", "--install-scripts=/foo/bar/bin"]
pkg = "pep8"
- expected = [*python_binary, "install"]
+ expected = [*python_binary, "install", *TARGET]
for item in install_options:
expected.extend(["--install-option", item])
expected.append(pkg)
@@ -797,6 +814,7 @@ def test_install_install_options_argument_in_resulting_command(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
"--install-option",
install_options[0],
pkg,
@@ -814,7 +832,7 @@ def test_install_global_options_argument_in_resulting_command(python_binary):
global_options = ["--quiet", "--no-user-cfg"]
pkg = "pep8"
- expected = [*python_binary, "install"]
+ expected = [*python_binary, "install", *TARGET]
for item in global_options:
expected.extend(["--global-option", item])
expected.append(pkg)
@@ -850,6 +868,7 @@ def test_install_global_options_argument_in_resulting_command(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
"--global-option",
global_options[0],
pkg,
@@ -868,7 +887,7 @@ def test_install_upgrade_argument_in_resulting_command(python_binary):
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, upgrade=True)
- expected = [*python_binary, "install", "--upgrade", pkg]
+ expected = [*python_binary, "install", *TARGET, "--upgrade", pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -886,6 +905,7 @@ def test_install_force_reinstall_argument_in_resulting_command(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
"--force-reinstall",
pkg,
]
@@ -906,6 +926,7 @@ def test_install_ignore_installed_argument_in_resulting_command(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
"--ignore-installed",
pkg,
]
@@ -923,7 +944,7 @@ def test_install_no_deps_argument_in_resulting_command(python_binary):
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, no_deps=True)
- expected = [*python_binary, "install", "--no-deps", pkg]
+ expected = [*python_binary, "install", *TARGET, "--no-deps", pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -938,7 +959,7 @@ def test_install_no_install_argument_in_resulting_command(python_binary):
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, no_install=True)
- expected = [*python_binary, "install", "--no-install", pkg]
+ expected = [*python_binary, "install", *TARGET, "--no-install", pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -954,7 +975,7 @@ def test_install_proxy_argument_in_resulting_command(python_binary):
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg, proxy=proxy)
- expected = [*python_binary, "install", "--proxy", proxy, pkg]
+ expected = [*python_binary, "install", "--proxy", proxy, *TARGET, pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -981,7 +1002,7 @@ def test_install_proxy_false_argument_in_resulting_command(python_binary):
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
with patch.dict(pip.__opts__, config_mock):
pip.install(pkg, proxy=proxy)
- expected = [*python_binary, "install", pkg]
+ expected = [*python_binary, "install", *TARGET, pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -1012,6 +1033,7 @@ def test_install_global_proxy_in_resulting_command(python_binary):
"install",
"--proxy",
proxy,
+ *TARGET,
pkg,
]
mock.assert_called_with(
@@ -1032,6 +1054,7 @@ def test_install_multiple_requirements_arguments_in_resulting_command(python_bin
expected = [*python_binary, "install"]
for item in cached_reqs:
expected.extend(["--requirement", item])
+ expected.extend(TARGET)
# Passing option as a list
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
@@ -1068,6 +1091,7 @@ def test_install_multiple_requirements_arguments_in_resulting_command(python_bin
"install",
"--requirement",
cached_reqs[0],
+ *TARGET,
]
mock.assert_called_with(
expected,
@@ -1088,6 +1112,7 @@ def test_install_extra_args_arguments_in_resulting_command(python_binary):
expected = [
*python_binary,
"install",
+ *TARGET,
pkg,
"--latest-pip-kwarg",
"param",
@@ -1603,7 +1628,7 @@ def test_install_pre_argument_in_resulting_command(python_binary):
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
with patch("salt.modules.pip.version", MagicMock(return_value="1.3")):
pip.install(pkg, pre_releases=True)
- expected = [*python_binary, "install", pkg]
+ expected = [*python_binary, "install", *TARGET, pkg]
mock.assert_called_with(
expected,
saltenv="base",
@@ -1619,7 +1644,7 @@ def test_install_pre_argument_in_resulting_command(python_binary):
):
with patch("salt.modules.pip._get_pip_bin", MagicMock(return_value=["pip"])):
pip.install(pkg, pre_releases=True)
- expected = ["pip", "install", "--pre", pkg]
+ expected = ["pip", "install", *TARGET, "--pre", pkg]
mock_run_all.assert_called_with(
expected,
saltenv="base",
diff --git a/tests/pytests/unit/states/test_pkgrepo.py b/tests/pytests/unit/states/test_pkgrepo.py
index 5f540bd245..14d17ad3f9 100644
--- a/tests/pytests/unit/states/test_pkgrepo.py
+++ b/tests/pytests/unit/states/test_pkgrepo.py
@@ -1,7 +1,6 @@
"""
:codeauthor: Tyler Johnson <tjohnson@saltstack.com>
"""
-
import pytest
import salt.states.pkgrepo as pkgrepo
@@ -390,7 +389,7 @@ def test_migrated_wrong_method():
with patch.dict(pkgrepo.__grains__, grains), patch.dict(
pkgrepo.__salt__, salt_mock
):
- assert pkgrepo.migrated("/mnt", method_="magic") == {
+ assert pkgrepo.migrated("/mnt", method="magic") == {
"name": "/mnt",
"result": False,
"changes": {},
diff --git a/tests/pytests/unit/test_fileserver.py b/tests/pytests/unit/test_fileserver.py
index 8dd3ea0a27..49be3967dc 100644
--- a/tests/pytests/unit/test_fileserver.py
+++ b/tests/pytests/unit/test_fileserver.py
@@ -75,9 +75,7 @@ def test_file_server_url_escape(tmp_path):
opts = {
"fileserver_backend": ["roots"],
"extension_modules": "",
- "optimization_order": [
- 0,
- ],
+ "optimization_order": [0, 1],
"file_roots": {
"base": [fileroot],
},
@@ -102,9 +100,7 @@ def test_file_server_serve_url_escape(tmp_path):
opts = {
"fileserver_backend": ["roots"],
"extension_modules": "",
- "optimization_order": [
- 0,
- ],
+ "optimization_order": [0, 1],
"file_roots": {
"base": [fileroot],
},
diff --git a/tests/pytests/unit/utils/test_msgpack.py b/tests/pytests/unit/utils/test_msgpack.py
index e15da262b0..a87c5ed5a6 100644
--- a/tests/pytests/unit/utils/test_msgpack.py
+++ b/tests/pytests/unit/utils/test_msgpack.py
@@ -3,7 +3,7 @@ import pytest
import salt.utils.msgpack
from tests.support.mock import MagicMock, patch
-
+@pytest.mark.skipif(salt.utils.msgpack.version < (1, 0, 0), reason="Test requires msgpack version >= 1.0.0")
def test_load_encoding(tmp_path):
"""
test when using msgpack version >= 1.0.0 we
diff --git a/tests/pytests/unit/utils/test_pycrypto.py b/tests/pytests/unit/utils/test_pycrypto.py
index 1dfcf9621c..9dff08f883 100644
--- a/tests/pytests/unit/utils/test_pycrypto.py
+++ b/tests/pytests/unit/utils/test_pycrypto.py
@@ -57,21 +57,20 @@ def test_gen_hash_crypt(algorithm, expected):
"""
Test gen_hash with crypt library
"""
- with patch("salt.utils.pycrypto.methods", {}):
- ret = salt.utils.pycrypto.gen_hash(
- crypt_salt=expected["salt"], password=passwd, algorithm=algorithm
- )
- assert ret == expected["hashed"]
+ ret = salt.utils.pycrypto.gen_hash(
+ crypt_salt=expected["salt"], password=passwd, algorithm=algorithm
+ )
+ assert ret == expected["hashed"]
- ret = salt.utils.pycrypto.gen_hash(
- crypt_salt=expected["badsalt"], password=passwd, algorithm=algorithm
- )
- assert ret != expected["hashed"]
+ ret = salt.utils.pycrypto.gen_hash(
+ crypt_salt=expected["badsalt"], password=passwd, algorithm=algorithm
+ )
+ assert ret != expected["hashed"]
- ret = salt.utils.pycrypto.gen_hash(
- crypt_salt=None, password=passwd, algorithm=algorithm
- )
- assert ret != expected["hashed"]
+ ret = salt.utils.pycrypto.gen_hash(
+ crypt_salt=None, password=passwd, algorithm=algorithm
+ )
+ assert ret != expected["hashed"]
@pytest.mark.skipif(not salt.utils.pycrypto.HAS_CRYPT, reason="crypt not available")
diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py
index a67ae52bbb..84eb4253cf 100644
--- a/tests/unit/test_config.py
+++ b/tests/unit/test_config.py
@@ -85,10 +85,13 @@ class SampleConfTest(DefaultConfigsBase, TestCase):
"""
master_config = SAMPLE_CONF_DIR + "master"
ret = salt.config._read_conf_file(master_config)
+ # openSUSE modified the default config in
+ # https://github.com/opensuse/salt/commit/6ffbf7fcc178f32c670b177b25ed64658c59f1bf
+ expected_config = {"user": "salt", "syndic_user": "salt"}
self.assertEqual(
ret,
- {},
- f"Sample config file '{master_config}' must be commented out.",
+ expected_config,
+ "Sample config file '{}' must be commented out.".format(master_config),
)
def test_conf_minion_sample_is_commented(self):
@@ -343,7 +346,10 @@ class ConfigTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
with patched_environ(SALT_MINION_CONFIG=env_fpath):
# Should load from env variable, not the default configuration file
- config = salt.config.minion_config(f"{CONFIG_DIR}/minion")
+ # Override defaults from venv-minion conf
+ defaults = salt.config.DEFAULT_MINION_OPTS.copy()
+ defaults["default_include"] = ""
+ config = salt.config.minion_config("{}/minion".format(CONFIG_DIR), defaults=defaults)
self.assertEqual(config["log_file"], env_fpath)
root_dir = os.path.join(tempdir, "foo", "bar")
@@ -1945,6 +1951,11 @@ class APIConfigTestCase(DefaultConfigsBase, TestCase):
if salt.utils.platform.is_windows():
expected = f"{RUNTIME_VARS.TMP_ROOT_DIR}\\var\\log\\salt\\api"
+ if os.environ.get("VIRTUAL_ENV"):
+ # venv bundle configures --salt-logs-dir=%{_localstatedir}/log
+ # in the RPM spec file
+ expected = expected.replace("/salt/api", "/api")
+
ret = salt.config.api_config("/some/fake/path")
self.assertEqual(ret["log_file"], expected)
@@ -2016,6 +2027,11 @@ class APIConfigTestCase(DefaultConfigsBase, TestCase):
mock_pid = "c:\\mock\\root\\var\\run\\salt-api.pid"
mock_master_config["root_dir"] = "c:\\mock\\root"
+ if os.environ.get("VIRTUAL_ENV"):
+ # venv bundle configures --salt-logs-dir=%{_localstatedir}/log
+ # in the RPM spec file
+ mock_log = mock_log.replace("/salt", "")
+
with patch(
"salt.config.client_config", MagicMock(return_value=mock_master_config)
):
--
2.47.0