Fix RedHat family systemd restart on upgrade, and updated tests

This commit is contained in:
David Murphy 2024-03-25 15:49:38 -06:00 committed by Pedro Algarvio
parent 87d3344a7a
commit 53fce6957d
4 changed files with 47 additions and 28 deletions

1
changelog/66143.fixed.md Normal file
View file

@ -0,0 +1 @@
Fix systemctl with "try-restart" instead of "retry-restart" within the RPM spec, properly restarting upgraded services

View file

@ -475,7 +475,7 @@ ln -s -f /opt/saltstack/salt/salt-cloud %{_bindir}/salt-cloud
# %%systemd_post salt-master.service
if [ $1 -gt 1 ] ; then
# Upgrade
systemctl retry-restart salt-master.service >/dev/null 2>&1 || :
systemctl try-restart salt-master.service >/dev/null 2>&1 || :
else
# Initial installation
systemctl preset salt-master.service >/dev/null 2>&1 || :
@ -503,7 +503,7 @@ fi
# %%systemd_post salt-syndic.service
if [ $1 -gt 1 ] ; then
# Upgrade
systemctl retry-restart salt-syndic.service >/dev/null 2>&1 || :
systemctl try-restart salt-syndic.service >/dev/null 2>&1 || :
else
# Initial installation
systemctl preset salt-syndic.service >/dev/null 2>&1 || :
@ -514,7 +514,7 @@ ln -s -f /opt/saltstack/salt/salt-syndic %{_bindir}/salt-syndic
# %%systemd_post salt-minion.service
if [ $1 -gt 1 ] ; then
# Upgrade
systemctl retry-restart salt-minion.service >/dev/null 2>&1 || :
systemctl try-restart salt-minion.service >/dev/null 2>&1 || :
else
# Initial installation
systemctl preset salt-minion.service >/dev/null 2>&1 || :
@ -543,7 +543,7 @@ ln -s -f /opt/saltstack/salt/salt-ssh %{_bindir}/salt-ssh
# %%systemd_post salt-api.service
if [ $1 -gt 1 ] ; then
# Upgrade
systemctl retry-restart salt-api.service >/dev/null 2>&1 || :
systemctl try-restart salt-api.service >/dev/null 2>&1 || :
else
# Initial installation
systemctl preset salt-api.service >/dev/null 2>&1 || :

View file

@ -36,17 +36,25 @@ def test_salt_downgrade(salt_call_cli, install_salt):
assert "Authentication information could" in use_lib.stderr
# Verify there is a running minion by getting its PID
salt_name = "salt"
if platform.is_windows():
process_name = "salt-minion.exe"
else:
process_name = "salt-minion"
old_pid = None
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
for proc in psutil.process_iter():
if process_name in proc.name():
if psutil.Process(proc.ppid()).name() != process_name:
old_pid = proc.pid
break
assert old_pid is not None
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)
@ -61,13 +69,14 @@ def test_salt_downgrade(salt_call_cli, install_salt):
# Verify there is a new running minion by getting its PID and comparing it
# with the PID from before the upgrade
new_pid = None
new_pid = []
for proc in psutil.process_iter():
if process_name in proc.name():
if psutil.Process(proc.ppid()).name() != process_name:
new_pid = proc.pid
break
assert new_pid is not None
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")

View file

@ -32,17 +32,25 @@ def test_salt_upgrade(salt_call_cli, install_salt):
assert "Authentication information could" in use_lib.stderr
# Verify there is a running minion by getting its PID
salt_name = "salt"
if platform.is_windows():
process_name = "salt-minion.exe"
else:
process_name = "salt-minion"
old_pid = None
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
for proc in psutil.process_iter():
if process_name in proc.name():
if psutil.Process(proc.ppid()).name() != process_name:
old_pid = proc.pid
break
assert old_pid is not None
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)
@ -54,13 +62,14 @@ def test_salt_upgrade(salt_call_cli, install_salt):
# Verify there is a new running minion by getting its PID and comparing it
# with the PID from before the upgrade
new_pid = None
new_pid = []
for proc in psutil.process_iter():
if process_name in proc.name():
if psutil.Process(proc.ppid()).name() != process_name:
new_pid = proc.pid
break
assert new_pid is not None
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
if install_salt.relenv: