feat: reboot_host (0.5.0)
CI / test (3.10) (push) Successful in 26s
CI / test (3.11) (push) Successful in 23s
CI / test (3.12) (push) Successful in 26s
CI / test (3.10) (pull_request) Successful in 25s
CI / test (3.11) (pull_request) Successful in 24s
CI / test (3.12) (pull_request) Successful in 25s

HostRebootMixin's reboot_host over the command channel: reboot detached
and two seconds late, so the answer comes back before the session goes
down, and a refusal is raised instead of being mistaken for the dropped
session. netOrk sent /sbin/reboot through the private _send_command and
could not tell the two apart (netOrk #1113). A login other than root is
refused before anything runs.
This commit is contained in:
Christian Manivong committed 2026-10-18 14:45:44 +02:00
1 parent 5169d2438f
commit d89bb38688
3 files changed
+52 -1

No files matched your search

+21
View File
@@ -65,6 +65,11 @@ def _sources(settings: dict) -> list[str]:
]
#: ``reboot`` detached from the session and two seconds late: the answer comes
#: back first, and a hang-up from the closing session does not stop it.
_REBOOT_DETACHED = "sh -c '(trap \"\" HUP; sleep 2; reboot) </dev/null >/dev/null 2>&1 &'"
class OpenWrtDriver(
OpenWrtInterfaceMixin,
OpenWrtVLANMixin,
@@ -223,6 +228,22 @@ class OpenWrtDriver(
self._check_privilege(privileged)
return open_stream_on_transport(self._transport(), command)
def reboot_host(self) -> None:
"""Restart the AP (``HostRebootMixin``); returns once the restart is under way.
Detached and two seconds late, so the answer comes back before the
session goes down; a refusal is raised, not mistaken for that.
:raises RuntimeError: for a login other than root, or a refused reboot.
"""
try:
result = self.run_command(_REBOOT_DETACHED, privileged=True, timeout=30)
except PermissionError as exc:
raise RuntimeError(str(exc)) from exc
if result.exit_code:
reason = result.stderr.strip() or result.stdout.strip()
raise RuntimeError(reason or f"reboot exited with status {result.exit_code}")
def _run_listening_sockets_command(self, command: str, *, privileged: bool) -> str:
"""Run the listening-socket command for ``ListeningSocketsMixin``.