Skip to content

Commit

Permalink
Fix RedHat family systemd restart on upgrade, and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
David Murphy committed Mar 25, 2024
1 parent 1f08a3c commit b4ba8b1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
1 change: 1 addition & 0 deletions changelog/66143.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix systemctl with "try-restart" instead of "retry-restart" within the RPM spec, properly restarting upgraded services
8 changes: 4 additions & 4 deletions pkg/rpm/salt.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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 || :
Expand Down Expand Up @@ -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 || :
Expand All @@ -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 || :
Expand Down Expand Up @@ -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 || :
Expand Down
33 changes: 21 additions & 12 deletions tests/pytests/pkg/downgrade/test_salt_downgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
33 changes: 21 additions & 12 deletions tests/pytests/pkg/upgrade/test_salt_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit b4ba8b1

Please sign in to comment.