2023-08-16 17:04:48 -04:00
|
|
|
import packaging.version
|
2024-02-09 11:06:09 -07:00
|
|
|
import psutil
|
2023-01-17 11:21:32 -07:00
|
|
|
import pytest
|
2024-02-09 11:06:09 -07:00
|
|
|
from pytestskipmarkers.utils import platform
|
2023-01-17 11:21:32 -07:00
|
|
|
|
|
|
|
|
2023-07-14 16:18:41 -04:00
|
|
|
def test_salt_upgrade(salt_call_cli, install_salt):
|
2023-01-17 11:21:32 -07:00
|
|
|
"""
|
2023-07-14 16:18:41 -04:00
|
|
|
Test an upgrade of Salt.
|
2023-01-17 11:21:32 -07:00
|
|
|
"""
|
|
|
|
if not install_salt.upgrade:
|
|
|
|
pytest.skip("Not testing an upgrade, do not run")
|
2023-07-14 16:18:41 -04:00
|
|
|
|
2023-08-03 17:02:44 -04:00
|
|
|
if install_salt.relenv:
|
|
|
|
original_py_version = install_salt.package_python_version()
|
2023-07-14 16:18:41 -04:00
|
|
|
|
|
|
|
# Verify previous install version is setup correctly and works
|
2023-08-02 17:33:37 -04:00
|
|
|
ret = salt_call_cli.run("test.version")
|
2023-01-17 11:21:32 -07:00
|
|
|
assert ret.returncode == 0
|
2023-08-16 17:04:48 -04:00
|
|
|
assert packaging.version.parse(ret.data) < packaging.version.parse(
|
|
|
|
install_salt.artifact_version
|
|
|
|
)
|
2023-01-17 11:21:32 -07:00
|
|
|
|
2023-07-14 16:18:41 -04:00
|
|
|
# Test pip install before an upgrade
|
2023-03-18 22:55:09 +00:00
|
|
|
dep = "PyGithub==1.56.0"
|
2023-01-17 11:21:32 -07:00
|
|
|
install = salt_call_cli.run("--local", "pip.install", dep)
|
|
|
|
assert install.returncode == 0
|
2023-07-14 16:18:41 -04:00
|
|
|
|
|
|
|
# Verify we can use the module dependent on the installed package
|
|
|
|
repo = "https://github.com/saltstack/salt.git"
|
2023-01-17 11:21:32 -07:00
|
|
|
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
|
|
|
|
assert "Authentication information could" in use_lib.stderr
|
2023-06-16 10:48:56 +01:00
|
|
|
|
2024-02-09 11:06:09 -07:00
|
|
|
# Verify there is a running minion by getting its PID
|
2024-03-25 15:49:38 -06:00
|
|
|
salt_name = "salt"
|
2024-02-09 11:06:09 -07:00
|
|
|
if platform.is_windows():
|
|
|
|
process_name = "salt-minion.exe"
|
|
|
|
else:
|
|
|
|
process_name = "salt-minion"
|
2024-03-25 15:49:38 -06:00
|
|
|
|
|
|
|
old_pid = []
|
|
|
|
|
|
|
|
# psutil process name only returning first part of the command '/opt/saltstack/'
|
|
|
|
# need to check all of command line for salt-minion
|
|
|
|
# ['/opt/saltstack/salt/bin/python3.10 /usr/bin/salt-minion MultiMinionProcessManager MinionProcessManager']
|
|
|
|
# and psutil is only returning the salt-minion once
|
2024-02-09 11:06:09 -07:00
|
|
|
for proc in psutil.process_iter():
|
2024-03-25 15:49:38 -06:00
|
|
|
if salt_name in proc.name():
|
|
|
|
cmdl_strg = " ".join(str(element) for element in proc.cmdline())
|
|
|
|
if process_name in cmdl_strg:
|
|
|
|
old_pid.append(proc.pid)
|
|
|
|
|
|
|
|
assert old_pid
|
2024-02-09 11:06:09 -07:00
|
|
|
|
2023-07-14 16:18:41 -04:00
|
|
|
# Upgrade Salt from previous version and test
|
2023-01-17 11:21:32 -07:00
|
|
|
install_salt.install(upgrade=True)
|
2023-08-02 17:33:37 -04:00
|
|
|
ret = salt_call_cli.run("test.version")
|
2023-01-17 11:21:32 -07:00
|
|
|
assert ret.returncode == 0
|
2023-08-16 17:04:48 -04:00
|
|
|
assert packaging.version.parse(ret.data) == packaging.version.parse(
|
|
|
|
install_salt.artifact_version
|
|
|
|
)
|
2023-01-17 11:21:32 -07:00
|
|
|
|
2024-02-09 11:06:09 -07:00
|
|
|
# Verify there is a new running minion by getting its PID and comparing it
|
|
|
|
# with the PID from before the upgrade
|
2024-03-25 15:49:38 -06:00
|
|
|
new_pid = []
|
2024-02-09 11:06:09 -07:00
|
|
|
for proc in psutil.process_iter():
|
2024-03-25 15:49:38 -06:00
|
|
|
if salt_name in proc.name():
|
|
|
|
cmdl_strg = " ".join(str(element) for element in proc.cmdline())
|
|
|
|
if process_name in cmdl_strg:
|
|
|
|
new_pid.append(proc.pid)
|
|
|
|
|
|
|
|
assert new_pid
|
2024-02-09 11:06:09 -07:00
|
|
|
assert new_pid != old_pid
|
|
|
|
|
2023-08-08 17:04:47 -04:00
|
|
|
if install_salt.relenv:
|
|
|
|
new_py_version = install_salt.package_python_version()
|
|
|
|
if new_py_version == original_py_version:
|
|
|
|
# test pip install after an upgrade
|
|
|
|
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
|
2024-02-09 11:06:09 -07:00
|
|
|
assert "Authentication information could" in use_lib.stderr
|