From ba059106d0f841b287ba7c267ad1e84176658c71 Mon Sep 17 00:00:00 2001 From: Hanne Moa Date: Tue, 21 Nov 2023 13:12:30 +0100 Subject: [PATCH] Explicitly set pythonpath for sudo --- tests/integration/pping_test.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/integration/pping_test.py b/tests/integration/pping_test.py index 6152e34cfa..26ef0c57ef 100644 --- a/tests/integration/pping_test.py +++ b/tests/integration/pping_test.py @@ -2,6 +2,7 @@ various pping integration tests """ import os +import sys from pathlib import Path import getpass from shutil import which @@ -18,7 +19,7 @@ from nav.config import find_config_file -BINDIR = './python/nav/bin' +BINDIR = Path('./python/nav/bin').absolute() def can_be_root(): @@ -76,7 +77,11 @@ def get_root_method(): if os.geteuid() == 0: return [] elif os.system("sudo true") == 0: - return ["sudo", "-E"] + pythonpath = ":".join(sys.path) + if pythonpath[0] != ":": + pythonpath = ":" + pythonpath + pythonpath = str(BINDIR) + pythonpath + return ["sudo", "-E", "PYTHONDIR=%s" % pythonpath] elif os.system("gosu root true") == 0: return ["gosu", "root"] else: @@ -90,7 +95,7 @@ def get_pping_output(timeout=5): Also asserts that pping shouldn't unexpectedly exit with a zero exitcode. """ - pping = Path(BINDIR).absolute() / 'pping.py' + pping = BINDIR / 'pping.py' assert pping.exists(), "Cannot find pping.py on path" pping = str(pping) cmd = get_root_method() + ["/usr/bin/timeout", str(timeout), pping, "-f"]