fix: enhance plugin manager service bootstrap to support sudo execution

This commit is contained in:
Rightup committed 2026-09-07 12:06:38 +01:00
1 parent 3afec59c1a
commit b1c9b6f6a5
44 files changed
+114 -69

No files matched your search

+25 -8
View File
@@ -228,21 +228,38 @@ def test_restart_service_systemctl_and_sudo_paths(monkeypatch):
assert "Restart command failed" in msg
def test_ensure_plugin_manager_service_runs_root_bootstrap(monkeypatch):
def test_ensure_plugin_manager_service_runs_sudo_bootstrap(monkeypatch):
monkeypatch.setattr(su, "is_container", lambda: False)
monkeypatch.setattr(su, "is_buildroot", lambda: False)
monkeypatch.setattr(su.os, "geteuid", lambda: 1000)
monkeypatch.setattr(
su.shutil, "which", lambda name: "/usr/bin/sudo" if name == "sudo" else None
su.os.path, "isfile", lambda p: p == "/opt/openhop_repeater/venv/bin/python"
)
monkeypatch.setattr(
su.subprocess,
"run",
lambda *args, **kwargs: subprocess.CompletedProcess(
args=args[0], returncode=0, stdout="ok", stderr=""
),
su.shutil, "which", lambda name: "/usr/bin/sudo" if name == "sudo" else None
)
calls = []
def _run(cmd, **kwargs):
calls.append(cmd)
if cmd[:3] == ["/usr/bin/sudo", "--non-interactive", "/bin/systemctl"] and cmd[3:5] == [
"is-active",
"--quiet",
]:
return subprocess.CompletedProcess(args=cmd, returncode=1, stdout="", stderr="")
return subprocess.CompletedProcess(args=cmd, returncode=0, stdout="ok", stderr="")
monkeypatch.setattr(su.subprocess, "run", _run)
ok, msg = su.ensure_plugin_manager_service()
assert ok is True
assert "root privileges" in msg.lower()
assert msg == "Plugin-manager service is installed and active"
install_call = next(
call
for call in calls
if call[:3] == ["/usr/bin/sudo", "--non-interactive", "/usr/bin/install"]
)
assert install_call[:3] == ["/usr/bin/sudo", "--non-interactive", "/usr/bin/install"]
assert install_call[-1] == "/etc/systemd/system/openhop-plugin-manager.service"
assert calls[-1][:3] == ["/usr/bin/sudo", "--non-interactive", "/bin/systemctl"]