2023-01-27 09:24:36 -07:00
|
|
|
import os.path
|
2023-01-18 20:14:05 -05:00
|
|
|
import pathlib
|
2023-10-18 12:49:59 -06:00
|
|
|
import re
|
2023-01-18 20:14:05 -05:00
|
|
|
import subprocess
|
2023-01-17 11:21:32 -07:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
from pytestskipmarkers.utils import platform
|
|
|
|
|
|
|
|
|
2023-01-27 09:24:36 -07:00
|
|
|
@pytest.mark.skip_on_windows
|
2023-01-17 11:21:32 -07:00
|
|
|
def test_salt_version(version, install_salt):
|
|
|
|
"""
|
2023-01-27 09:24:36 -07:00
|
|
|
Test version output from salt --version
|
2023-01-17 11:21:32 -07:00
|
|
|
"""
|
2023-01-27 09:24:36 -07:00
|
|
|
test_bin = os.path.join(*install_salt.binary_paths["salt"])
|
|
|
|
ret = install_salt.proc.run(test_bin, "--version")
|
2023-02-28 15:55:31 -05:00
|
|
|
actual = ret.stdout.strip().split(" ")[:2]
|
|
|
|
expected = ["salt", version]
|
|
|
|
assert actual == expected
|
2023-01-17 11:21:32 -07:00
|
|
|
|
|
|
|
|
2023-01-27 09:24:36 -07:00
|
|
|
@pytest.mark.skip_on_windows
|
2023-01-17 11:21:32 -07:00
|
|
|
def test_salt_versions_report_master(install_salt):
|
|
|
|
"""
|
|
|
|
Test running --versions-report on master
|
|
|
|
"""
|
2023-08-08 17:04:47 -04:00
|
|
|
if not install_salt.relenv and not install_salt.classic:
|
|
|
|
pytest.skip("Unable to get the python version dynamically from tiamat builds")
|
2023-01-27 09:24:36 -07:00
|
|
|
test_bin = os.path.join(*install_salt.binary_paths["master"])
|
|
|
|
python_bin = os.path.join(*install_salt.binary_paths["python"])
|
|
|
|
ret = install_salt.proc.run(test_bin, "--versions-report")
|
2023-01-17 11:21:32 -07:00
|
|
|
ret.stdout.matcher.fnmatch_lines(["*Salt Version:*"])
|
2023-01-18 20:14:05 -05:00
|
|
|
py_version = subprocess.run(
|
2023-01-27 09:24:36 -07:00
|
|
|
[str(python_bin), "--version"],
|
2023-09-13 17:30:09 +01:00
|
|
|
capture_output=True,
|
2023-01-18 20:14:05 -05:00
|
|
|
).stdout
|
|
|
|
py_version = py_version.decode().strip().replace(" ", ": ")
|
|
|
|
ret.stdout.matcher.fnmatch_lines([f"*{py_version}*"])
|
2023-01-17 11:21:32 -07:00
|
|
|
|
|
|
|
|
2023-02-01 12:34:04 -07:00
|
|
|
@pytest.mark.skip_on_windows
|
2023-01-17 11:21:32 -07:00
|
|
|
def test_salt_versions_report_minion(salt_cli, salt_minion):
|
|
|
|
"""
|
|
|
|
Test running test.versions_report on minion
|
|
|
|
"""
|
2023-11-20 13:15:04 +00:00
|
|
|
# Make sure the minion is running
|
|
|
|
assert salt_minion.is_running()
|
|
|
|
# Make sure we can ping the minion ...
|
|
|
|
ret = salt_cli.run(
|
|
|
|
"--timeout=240", "test.ping", minion_tgt=salt_minion.id, _timeout=240
|
|
|
|
)
|
|
|
|
assert ret.returncode == 0
|
|
|
|
assert ret.data is True
|
|
|
|
ret = salt_cli.run(
|
|
|
|
"--hard-crash",
|
|
|
|
"--failhard",
|
|
|
|
"--timeout=240",
|
|
|
|
"test.versions_report",
|
|
|
|
minion_tgt=salt_minion.id,
|
|
|
|
_timeout=240,
|
|
|
|
)
|
2023-01-17 11:21:32 -07:00
|
|
|
ret.stdout.matcher.fnmatch_lines(["*Salt Version:*"])
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"binary", ["master", "cloud", "syndic", "minion", "call", "api"]
|
|
|
|
)
|
|
|
|
def test_compare_versions(version, binary, install_salt):
|
|
|
|
"""
|
|
|
|
Test compare versions
|
|
|
|
"""
|
2023-01-27 09:24:36 -07:00
|
|
|
if binary in install_salt.binary_paths:
|
2023-08-10 18:43:02 -04:00
|
|
|
ret = install_salt.proc.run(
|
|
|
|
*install_salt.binary_paths[binary],
|
|
|
|
"--version",
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
)
|
2023-02-21 15:41:48 -07:00
|
|
|
ret.stdout.matcher.fnmatch_lines([f"*{version}*"])
|
2023-01-27 09:24:36 -07:00
|
|
|
else:
|
2023-04-15 16:27:43 +01:00
|
|
|
if platform.is_windows():
|
|
|
|
pytest.skip(f"Binary not available on windows: {binary}")
|
|
|
|
pytest.fail(
|
|
|
|
f"Platform is not Windows and yet the binary {binary!r} is not available"
|
|
|
|
)
|
2023-01-17 11:21:32 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_unless_on_darwin()
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"symlink",
|
|
|
|
[
|
|
|
|
# We can't create a salt symlink because there is a salt directory
|
2023-01-25 17:21:05 -08:00
|
|
|
"salt",
|
2023-01-17 11:21:32 -07:00
|
|
|
"salt-api",
|
|
|
|
"salt-call",
|
|
|
|
"salt-cloud",
|
|
|
|
"salt-cp",
|
|
|
|
"salt-key",
|
|
|
|
"salt-master",
|
|
|
|
"salt-minion",
|
|
|
|
"salt-proxy",
|
|
|
|
"salt-run",
|
2023-01-25 17:21:05 -08:00
|
|
|
"spm",
|
2023-01-17 11:21:32 -07:00
|
|
|
"salt-ssh",
|
|
|
|
"salt-syndic",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_symlinks_created(version, symlink, install_salt):
|
|
|
|
"""
|
|
|
|
Test symlinks created
|
|
|
|
"""
|
2023-08-30 14:38:39 -04:00
|
|
|
if install_salt.classic:
|
|
|
|
pytest.skip("Symlinks not created for classic macos builds, we adjust the path")
|
|
|
|
if not install_salt.relenv and symlink == "spm":
|
2023-08-29 13:41:39 -04:00
|
|
|
symlink = "salt-spm"
|
2023-01-25 17:21:05 -08:00
|
|
|
ret = install_salt.proc.run(pathlib.Path("/usr/local/sbin") / symlink, "--version")
|
2023-01-17 11:21:32 -07:00
|
|
|
ret.stdout.matcher.fnmatch_lines([f"*{version}*"])
|
|
|
|
|
|
|
|
|
2023-01-27 09:24:36 -07:00
|
|
|
@pytest.mark.skip_on_windows()
|
2023-01-17 11:21:32 -07:00
|
|
|
def test_compare_pkg_versions_redhat_rc(version, install_salt):
|
|
|
|
"""
|
2023-01-27 09:24:36 -07:00
|
|
|
Test compare pkg versions for redhat RC packages. A tilde should be included
|
|
|
|
in RC Packages and it should test to be a lower version than a non RC
|
|
|
|
package of the same version. For example, v3004~rc1 should be less than
|
|
|
|
v3004.
|
2023-01-17 11:21:32 -07:00
|
|
|
"""
|
2023-11-09 12:36:29 -05:00
|
|
|
if install_salt.distro_id not in ("centos", "redhat", "amzn", "fedora", "photon"):
|
2023-01-17 11:21:32 -07:00
|
|
|
pytest.skip("Only tests rpm packages")
|
|
|
|
|
|
|
|
pkg = [x for x in install_salt.pkgs if "rpm" in x]
|
|
|
|
if not pkg:
|
|
|
|
pytest.skip("Not testing rpm packages")
|
|
|
|
pkg = pkg[0].split("/")[-1]
|
2023-11-09 12:36:29 -05:00
|
|
|
if "rc" not in ".".join(pkg.split(".")[:2]):
|
2023-01-17 11:21:32 -07:00
|
|
|
pytest.skip("Not testing an RC package")
|
|
|
|
assert "~" in pkg
|
|
|
|
comp_pkg = pkg.split("~")[0]
|
|
|
|
ret = install_salt.proc.run("rpmdev-vercmp", pkg, comp_pkg)
|
|
|
|
ret.stdout.matcher.fnmatch_lines([f"{pkg} < {comp_pkg}"])
|