Skip to content

Commit

Permalink
Explicitly set pythonpath for sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Nov 21, 2023
1 parent 6171742 commit ba05910
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/integration/pping_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
various pping integration tests
"""
import os
import sys
from pathlib import Path
import getpass
from shutil import which
Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand All @@ -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"]
Expand Down

0 comments on commit ba05910

Please sign in to comment.