From 1168334a4016c7edf8512a165fd4b8d0471650f9 Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 29 Oct 2024 08:45:57 -0600 Subject: [PATCH] Handle zombie processes when getting pids --- .../pkg/downgrade/test_salt_downgrade.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/pytests/pkg/downgrade/test_salt_downgrade.py b/tests/pytests/pkg/downgrade/test_salt_downgrade.py index a195bb880c72..45d73d381940 100644 --- a/tests/pytests/pkg/downgrade/test_salt_downgrade.py +++ b/tests/pytests/pkg/downgrade/test_salt_downgrade.py @@ -18,16 +18,26 @@ def _get_running_named_salt_pid(process_name): pids = [] for proc in psutil.process_iter(): - cmdl_strg = " ".join(str(element) for element in proc.cmdline()) - if process_name in cmdl_strg: - pids.append(proc.pid) + cmd_line = "" + try: + cmd_line = " ".join(str(element) for element in proc.cmdline()) + except psutil.ZombieProcess: + # Even though it's a zombie process, it still has a cmdl_string and + # a pid, so we'll use it + pass + if process_name in cmd_line: + try: + pids.append(proc.pid) + except psutil.NoSuchProcess: + # Process is now closed + continue return pids def test_salt_downgrade_minion(salt_call_cli, install_salt): """ - Test an downgrade of Salt Minion. + Test a downgrade of Salt Minion. """ is_restart_fixed = packaging.version.parse( install_salt.prev_version