Changes for running pkg tests on Mac.

This commit is contained in:
Gareth J. Greenaway 2023-01-25 17:21:05 -08:00 committed by Pedro Algarvio
parent cc21e0fdec
commit 6ee6784d24
5 changed files with 41 additions and 70 deletions

View file

@ -33,7 +33,12 @@ def version():
artifact.name,
)
if _version:
_version = _version.groups()[0].replace("_", "-").replace("~", "")
_version = (
_version.groups()[0]
.replace("_", "-")
.replace("~", "")
.replace("-py3-x86-64", "")
)
break
return _version
@ -83,7 +88,11 @@ def salt_factories_root_dir(request, tmp_path_factory):
if root_dir is not None:
yield root_dir
else:
root_dir = tmp_path_factory.mktemp("salt-tests")
if platform.is_darwin():
root_dir = pathlib.Path("/tmp/salt-tests-tmpdir")
root_dir.mkdir(mode=0o777, parents=True, exist_ok=True)
else:
root_dir = tmp_path_factory.mktemp("salt-tests")
try:
yield root_dir
finally:
@ -249,6 +258,8 @@ def salt_master(salt_factories, install_salt, state_tree, pillar_tree):
str(salt_factories.get_salt_log_handlers_path()),
],
}
if platform.is_darwin():
config_defaults["enable_fqdns_grains"] = False
config_overrides = {
"timeout": 30,
"file_roots": state_tree.as_dict(),
@ -291,6 +302,8 @@ def salt_minion(salt_master, install_salt):
"engines_dirs": salt_master.config["engines_dirs"].copy(),
"log_handlers_dirs": salt_master.config["log_handlers_dirs"].copy(),
}
if platform.is_darwin():
config_defaults["enable_fqdns_grains"] = False
config_overrides = {
"id": minion_id,
"file_roots": salt_master.config["file_roots"].copy(),

View file

@ -1,42 +0,0 @@
import hashlib
import logging
import sys
import pytest
log = logging.getLogger(__name__)
@pytest.mark.usefixtures("version")
def test_hashes(install_salt, salt_cli, salt_minion):
"""
Test the hashes generated for both single binary
and the onedir packages.
"""
if not install_salt.compressed:
pytest.skip("This test requires the single binary or onedir package")
hashes = install_salt.salt_hashes
pkg = install_salt.pkgs[0]
with open(pkg, "rb") as fh:
file_bytes = fh.read()
delimiter = "/"
if sys.platform.startswith("win"):
delimiter = "\\"
for _hash in hashes.keys():
hash_file = hashes[_hash]["file"]
found_hash = False
with open(hash_file) as fp:
for line in fp:
if pkg.rsplit(delimiter, 1)[-1] in line:
found_hash = True
assert (
getattr(hashlib, _hash.lower())(file_bytes).hexdigest()
== line.split()[0]
)
if not found_hash:
assert False, f"A {_hash} hash was not found in {hash_file} for pkg {pkg}"

View file

@ -11,7 +11,10 @@ from pytestskipmarkers.utils import platform
def pypath():
if platform.is_windows():
return pathlib.Path(os.getenv("LocalAppData"), "salt", "bin")
return pathlib.Path(f"{os.sep}opt", "saltstack", "salt", "bin")
elif platform.is_darwin():
return pathlib.Path(f"{os.sep}opt", "salt", "bin")
else:
return pathlib.Path(f"{os.sep}opt", "saltstack", "salt", "bin")
@pytest.fixture(autouse=True)

View file

@ -26,6 +26,8 @@ def test_salt_versions_report_master(install_salt):
python_executable = pathlib.Path(
r"C:\Program Files\Salt Project\Salt\Scripts\python.exe"
)
elif sys.platform == "darwin":
python_executable = pathlib.Path("/opt/salt/bin/python3")
else:
python_executable = pathlib.Path("/opt/saltstack/salt/bin/python3")
py_version = subprocess.run(
@ -70,7 +72,7 @@ def test_compare_versions(version, binary, install_salt):
"symlink",
[
# We can't create a salt symlink because there is a salt directory
# "salt",
"salt",
"salt-api",
"salt-call",
"salt-cloud",
@ -80,7 +82,7 @@ def test_compare_versions(version, binary, install_salt):
"salt-minion",
"salt-proxy",
"salt-run",
"salt-spm",
"spm",
"salt-ssh",
"salt-syndic",
],
@ -94,7 +96,7 @@ def test_symlinks_created(version, symlink, install_salt):
"This test is for the installer package only (pkg). It does not "
"apply to the tarball"
)
ret = install_salt.proc.run(install_salt.bin_dir / symlink, "--version")
ret = install_salt.proc.run(pathlib.Path("/usr/local/sbin") / symlink, "--version")
ret.stdout.matcher.fnmatch_lines([f"*{version}*"])

View file

@ -135,7 +135,7 @@ class SaltPkgInstall:
).resolve()
elif platform.is_darwin():
# TODO: Add mac install dir path
install_dir = ""
install_dir = pathlib.Path("/opt", "salt")
else:
install_dir = pathlib.Path("/opt", "saltstack", "salt")
return install_dir
@ -194,7 +194,6 @@ class SaltPkgInstall:
self.onedir = True
self.installer_pkg = True
self.bin_dir = self.root / "salt" / "bin"
self.run_root = self.bin_dir / "run"
elif file_ext == "tar.gz":
with tarfile.open(f_path) as tar:
# The first item will be called salt
@ -243,20 +242,21 @@ class SaltPkgInstall:
}
else:
self.binary_paths = {
"salt": [str(self.run_root)],
"api": [str(self.run_root), "api"],
"call": [str(self.run_root), "call"],
"cloud": [str(self.run_root), "cloud"],
"cp": [str(self.run_root), "cp"],
"key": [str(self.run_root), "key"],
"master": [str(self.run_root), "master"],
"minion": [str(self.run_root), "minion"],
"proxy": [str(self.run_root), "proxy"],
"run": [str(self.run_root), "run"],
"ssh": [str(self.run_root), "ssh"],
"syndic": [str(self.run_root), "syndic"],
"spm": [str(self.run_root), "spm"],
"pip": [str(self.run_root), "pip"],
"salt": [self.install_dir / "salt"],
"api": [self.install_dir / "salt-api"],
"call": [self.install_dir / "salt-call"],
"cloud": [self.install_dir / "salt-cloud"],
"cp": [self.install_dir / "salt-cp"],
"key": [self.install_dir / "salt-key"],
"master": [self.install_dir / "salt-master"],
"minion": [self.install_dir / "salt-minion"],
"proxy": [self.install_dir / "salt-proxy"],
"run": [self.install_dir / "salt-run"],
"ssh": [self.install_dir / "salt-ssh"],
"syndic": [self.install_dir / "salt-syndic"],
"spm": [self.install_dir / "spm"],
"pip": [self.install_dir / "salt-pip"],
"python": [self.install_dir / "bin" / "python3"],
}
@staticmethod
@ -1097,16 +1097,11 @@ class PkgMixin:
def get_script_path(self):
if self.salt_pkg_install.compressed:
return str(self.salt_pkg_install.run_root)
return str(self.salt_pkg_install.install_dir / self.script_name)
return super().get_script_path()
def get_base_script_args(self):
base_script_args = []
if self.salt_pkg_install.compressed:
if self.script_name == "spm":
base_script_args.append(self.script_name)
elif self.script_name != "salt":
base_script_args.append(self.script_name.split("salt-")[-1])
base_script_args.extend(super().get_base_script_args())
return base_script_args