mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix minion process detection to work with old pyinstaller salt packages
This commit is contained in:
parent
454a74c8d7
commit
3604f6a025
1 changed files with 42 additions and 32 deletions
|
@ -1,8 +1,26 @@
|
|||
import logging
|
||||
|
||||
import packaging.version
|
||||
import psutil
|
||||
import pytest
|
||||
from pytestskipmarkers.utils import platform
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_running_salt_minion_pid(process_name):
|
||||
# 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
|
||||
pids = []
|
||||
for proc in psutil.process_iter():
|
||||
if "salt" in proc.name():
|
||||
cmdl_strg = " ".join(str(element) for element in proc.cmdline())
|
||||
if process_name in cmdl_strg:
|
||||
pids.append(proc.pid)
|
||||
return pids
|
||||
|
||||
|
||||
def test_salt_upgrade(salt_call_cli, install_salt):
|
||||
"""
|
||||
|
@ -17,9 +35,8 @@ def test_salt_upgrade(salt_call_cli, install_salt):
|
|||
# Verify previous install version is setup correctly and works
|
||||
ret = salt_call_cli.run("test.version")
|
||||
assert ret.returncode == 0
|
||||
assert packaging.version.parse(ret.data) < packaging.version.parse(
|
||||
install_salt.artifact_version
|
||||
)
|
||||
installed_version = packaging.version.parse(ret.data)
|
||||
assert installed_version < packaging.version.parse(install_salt.artifact_version)
|
||||
|
||||
# Test pip install before an upgrade
|
||||
dep = "PyGithub==1.56.0"
|
||||
|
@ -32,45 +49,38 @@ 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"
|
||||
if installed_version < packaging.version.parse("3006.0"):
|
||||
# This is using PyInstaller
|
||||
process_name = "run minion"
|
||||
else:
|
||||
process_name = "salt-minion"
|
||||
|
||||
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 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
|
||||
if platform.is_windows():
|
||||
process_name = "salt-minion.exe"
|
||||
else:
|
||||
process_name = "salt-minion"
|
||||
old_pids = _get_running_salt_minion_pid(process_name)
|
||||
assert old_pids
|
||||
|
||||
# Upgrade Salt from previous version and test
|
||||
install_salt.install(upgrade=True)
|
||||
ret = salt_call_cli.run("test.version")
|
||||
assert ret.returncode == 0
|
||||
assert packaging.version.parse(ret.data) == packaging.version.parse(
|
||||
install_salt.artifact_version
|
||||
)
|
||||
installed_version = packaging.version.parse(ret.data)
|
||||
assert installed_version == packaging.version.parse(install_salt.artifact_version)
|
||||
|
||||
# Verify there is a new running minion 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)
|
||||
if installed_version < packaging.version.parse("3006.0"):
|
||||
# This is using PyInstaller
|
||||
process_name = "run minion"
|
||||
else:
|
||||
if platform.is_windows():
|
||||
process_name = "salt-minion.exe"
|
||||
else:
|
||||
process_name = "salt-minion"
|
||||
new_pids = _get_running_salt_minion_pid(process_name)
|
||||
|
||||
assert new_pid
|
||||
assert new_pid != old_pid
|
||||
assert new_pids
|
||||
assert new_pids != old_pids
|
||||
|
||||
if install_salt.relenv:
|
||||
new_py_version = install_salt.package_python_version()
|
||||
|
|
Loading…
Add table
Reference in a new issue