Be sure to run the installed script to confirm it works

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-05-02 22:07:00 +01:00 committed by Pedro Algarvio
parent 3584921fc6
commit a59929ad20
2 changed files with 29 additions and 37 deletions

View file

@ -474,12 +474,17 @@ def extras_pypath():
extras_dir = "extras-{}.{}".format(*sys.version_info)
if platform.is_windows():
return pathlib.Path(
os.getenv("ProgramFiles"), "Salt Project", "Salt", extras_dir, "bin"
os.getenv("ProgramFiles"), "Salt Project", "Salt", extras_dir
)
elif platform.is_darwin():
return pathlib.Path(f"/opt", "salt", extras_dir, "bin")
return pathlib.Path("/opt", "salt", extras_dir)
else:
return pathlib.Path(f"/opt", "saltstack", "salt", extras_dir, "bin")
return pathlib.Path("/opt", "saltstack", "salt", extras_dir)
@pytest.fixture(scope="module")
def extras_pypath_bin(extras_pypath):
return extras_pypath / "bin"
@pytest.fixture(scope="module")
@ -487,7 +492,7 @@ def salt_api(salt_master, install_salt, extras_pypath):
"""
start up and configure salt_api
"""
shutil.rmtree(str(extras_pypath.parent), ignore_errors=True)
shutil.rmtree(str(extras_pypath), ignore_errors=True)
start_timeout = None
if platform.is_windows() and install_salt.singlebin:
start_timeout = 240

View file

@ -13,25 +13,21 @@ def pypath():
if platform.is_windows():
return pathlib.Path(os.getenv("ProgramFiles"), "Salt Project", "Salt")
elif platform.is_darwin():
return pathlib.Path(f"{os.sep}opt", "salt", "bin")
return pathlib.Path("/opt", "salt", "bin")
else:
return pathlib.Path(f"{os.sep}opt", "saltstack", "salt", "bin")
return pathlib.Path("/opt", "saltstack", "salt", "bin")
@pytest.fixture(autouse=True)
def wipe_pydeps(install_salt, extras_pypath):
def wipe_pydeps(shell, install_salt, extras_pypath):
try:
yield
finally:
# Note, uninstalling anything with an associated script will leave the script.
# This is due to a bug in pip.
for dep in ["pep8", "PyGithub"]:
subprocess.run(
install_salt.binary_paths["pip"] + ["uninstall", "-y", dep],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False,
universal_newlines=True,
shell.run(
*(install_salt.binary_paths["pip"] + ["uninstall", "-y", dep]),
)
shutil.rmtree(extras_pypath, ignore_errors=True)
@ -56,32 +52,24 @@ def test_pip_install(salt_call_cli):
assert "The github execution module cannot be loaded" in use_lib.stderr
def test_pip_install_extras(install_salt, extras_pypath):
def test_pip_install_extras(shell, install_salt, extras_pypath_bin):
"""
Test salt-pip installs into the correct directory
"""
dep = "pep8"
extras_keyword = "extras"
extras_keyword = "extras-3"
if platform.is_windows():
check_path = extras_pypath / f"{dep}.exe"
check_path = extras_pypath_bin / f"{dep}.exe"
else:
check_path = extras_pypath / dep
check_path = extras_pypath_bin / dep
install_ret = subprocess.run(
install_salt.binary_paths["pip"] + ["install", dep],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
install_ret = shell.run(*(install_salt.binary_paths["pip"] + ["install", dep]))
assert install_ret.returncode == 0
ret = subprocess.run(
install_salt.binary_paths["pip"] + ["list", "--format=json"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
ret = shell.run(*(install_salt.binary_paths["pip"] + ["list", "--format=json"]))
assert ret.returncode == 0
pkgs_installed = json.loads(ret.stdout.strip().decode())
for pkg in pkgs_installed:
assert ret.data # We can parse the JSON output
for pkg in ret.data:
if pkg["name"] == dep:
break
else:
@ -89,15 +77,14 @@ def test_pip_install_extras(install_salt, extras_pypath):
f"The {dep!r} package was not found installed. Packages Installed: {pkgs_installed}"
)
show_ret = subprocess.run(
install_salt.binary_paths["pip"] + ["show", dep],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
show_ret = shell.run(*(install_salt.binary_paths["pip"] + ["show", dep]))
assert show_ret.returncode == 0
assert extras_keyword in show_ret.stdout.decode()
assert extras_keyword in show_ret.stdout
assert check_path.exists()
ret = shell.run(str(check_path), "--version")
assert ret.returncode == 0
def demote(user_uid, user_gid):
def result():
@ -108,8 +95,8 @@ def demote(user_uid, user_gid):
@pytest.mark.skip_on_windows(reason="We can't easily demote users on Windows")
def test_pip_non_root(install_salt, test_account, extras_pypath):
check_path = extras_pypath / "pep8"
def test_pip_non_root(shell, install_salt, test_account, extras_pypath_bin):
check_path = extras_pypath_bin / "pep8"
# We should be able to issue a --help without being root
ret = subprocess.run(
install_salt.binary_paths["salt"] + ["--help"],