Updated preinst and initial downgrade and upgrade salt-master tests

This commit is contained in:
David Murphy 2024-05-02 15:39:03 -06:00 committed by Daniel Wozniak
parent 5ec86050ca
commit f9bd4ad1b6
5 changed files with 127 additions and 7 deletions

View file

@ -17,7 +17,7 @@ case "$1" in
db_set salt-api/user $CUR_USER
chown -R $CUR_USER:$CUR_GROUP /var/log/salt/api
if command -v systemctl; then
SM_ENABLED=$(systemctl show salt-api | grep -w UnitFileState | cut -d '=' -f 2)
SM_ENABLED=$(systemctl show -p UnitFileState salt-api | cut -d '=' -f 2)
db_get salt-api/enabled $SM_ENABLED
SM_ACTIVE=$(systemctl is-active salt-api)
db_get salt-api/active $SM_ACTIVE

View file

@ -34,7 +34,7 @@ case "$1" in
chown -R $CUR_USER:$CUR_GROUP /etc/salt/pki/master /etc/salt/master.d /var/log/salt/master \
/var/log/salt/key /var/cache/salt/master /var/run/salt/master
if command -v systemctl; then
SM_ENABLED=$(systemctl show salt-master | grep -w UnitFileState | cut -d '=' -f 2)
SM_ENABLED=$(systemctl show -p UnitFileState salt-master | cut -d '=' -f 2)
db_get salt-master/enabled $SM_ENABLED
SM_ACTIVE=$(systemctl is-active salt-master)
db_get salt-master/active $SM_ACTIVE

View file

@ -19,7 +19,7 @@ case "$1" in
chown -R $CUR_USER:$CUR_GROUP /etc/salt/pki/minion /etc/salt/minion.d /var/log/salt/minion \
/var/cache/salt/minion /var/run/salt/minion
if command -v systemctl; then
SM_ENABLED=$(systemctl show salt-minion | grep -w UnitFileState | cut -d '=' -f 2)
SM_ENABLED=$(systemctl show -p UnitFileState salt-minion | cut -d '=' -f 2)
db_get salt-minion/enabled $SM_ENABLED
SM_ACTIVE=$(systemctl is-active salt-minion)
db_get salt-minion/active $SM_ACTIVE

View file

@ -3,9 +3,9 @@ import psutil
from pytestskipmarkers.utils import platform
def test_salt_downgrade(salt_call_cli, install_salt):
def test_salt_downgrade_minion(salt_call_cli, install_salt):
"""
Test an upgrade of Salt.
Test an downgrade of Salt Minion.
"""
is_downgrade_to_relenv = packaging.version.parse(
install_salt.prev_version
@ -87,3 +87,66 @@ def test_salt_downgrade(salt_call_cli, install_salt):
# test pip install after a downgrade
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
assert "Authentication information could" in use_lib.stderr
@pytest.mark.skip_unless_on_linux(reason="Only supported on Linux family")
def test_salt_downgrade_master(salt_cli, install_salt):
"""
Test an downgrade of Salt Master.
"""
if not install_salt.downgrade:
pytest.skip("Not testing a downgrade, do not run")
is_downgrade_to_relenv = packaging.version.parse(
install_salt.prev_version
) >= packaging.version.parse("3006.0")
if is_downgrade_to_relenv:
original_py_version = install_salt.package_python_version()
# Verify current install version is setup correctly and works
ret = salt_cli.run("--version")
assert ret.returncode == 0
assert packaging.version.parse(ret.data) == packaging.version.parse(
install_salt.artifact_version
)
# Verify there is a running master by getting its PID
salt_name = "salt"
process_name = "salt-master"
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-master EventPublisher']
# and psutil is only returning the salt-minion once
for proc in psutil.process_iter():
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
# Downgrade Salt to the previous version and test
install_salt.install(downgrade=True)
bin_file = "salt"
# Verify there is a new running master by getting its PID and comparing it
# with the PID from before the upgrade
new_pid = []
for proc in psutil.process_iter():
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
assert new_pid != old_pid
ret = install_salt.proc.run(bin_file, "--version")
assert ret.returncode == 0
assert packaging.version.parse(
ret.stdout.strip().split()[1]
) < packaging.version.parse(install_salt.artifact_version)

View file

@ -21,9 +21,9 @@ def _get_running_salt_minion_pid(process_name):
return pids
def test_salt_upgrade(salt_call_cli, install_salt):
def test_salt_upgrade_minion(salt_call_cli, install_salt):
"""
Test an upgrade of Salt.
Test an upgrade of Salt Minion.
"""
if install_salt.relenv:
original_py_version = install_salt.package_python_version()
@ -84,3 +84,60 @@ def test_salt_upgrade(salt_call_cli, install_salt):
# test pip install after an upgrade
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
assert "Authentication information could" in use_lib.stderr
@pytest.mark.skip_unless_on_linux(reason="Only supported on Linux family")
def test_salt_upgrade_master(salt_cli, install_salt):
"""
Test an upgrade of Salt Master.
"""
if not install_salt.upgrade:
pytest.skip("Not testing an upgrade, do not run")
if install_salt.relenv:
original_py_version = install_salt.package_python_version()
# Verify previous install version is setup correctly and works
ret = salt_cli.run("--version")
assert ret.returncode == 0
assert packaging.version.parse(ret.data) < packaging.version.parse(
install_salt.artifact_version
)
# Verify there is a running minion by getting its PID
salt_name = "salt"
process_name = "salt-master"
old_pid = []
# psutil process name only returning first part of the command '/opt/saltstack/'
# need to check all of command line for salt-master
# ['/opt/saltstack/salt/bin/python3.10 /usr/bin/salt-master EventPublisher']
# and psutil is only returning the salt-minion once
for proc in psutil.process_iter():
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
# Upgrade Salt from previous version and test
install_salt.install(upgrade=True)
ret = salt_cli.run("--version")
assert ret.returncode == 0
assert packaging.version.parse(ret.data) == packaging.version.parse(
install_salt.artifact_version
)
# Verify there is a new running master by getting its PID and comparing it
# with the PID from before the upgrade
new_pid = []
for proc in psutil.process_iter():
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
assert new_pid != old_pid