feat(power): shutdown_host through HostShutdownMixin, 0.25.0 (NetOrk/netork#2841) #92

Merged
christianmanivong merged 2 commits from feature/host-shutdown-2841 into main 2026-11-29 22:01:05 +00:00
Owner

shutdown_host() next to reboot_host(): /sbin/poweroff, detached (sh -c '(trap "" HUP; sleep 2; /sbin/poweroff) …&') through the privileged path, so the call returns before the session drops. Same error contract as the reboot: a non-zero or missing status raises RuntimeError with the host's output (plus the sudo hint when sudo wants a password). poweroff rather than shutdown -h now: systemd, sysvinit and BusyBox all ship it, and sysvinit's -h may only halt.

Version 0.25.0 with its CHANGELOG entry. Tests: TestShutdownHost (5) in tests/test_linux.py, and shutdown_host in the sudo-line check; full suite 480 passed.

Part of NetOrk/netork#2841: the device header gets Restart and Shut down for hardware devices. netOrk offers each button where the driver has the method (callable(getattr(driver, "reboot_host" / "shutdown_host", None))), so defining it is what switches the button on. The contracts are HostRebootMixin / HostShutdownMixin in napalm-device-types, already mixed in through DeviceTypeDriver; the minimum napalm-device-types version needs no change.

netOrk's feature/host-shutdown-2841 pins this branch's commit for now; once this is merged, the pin moves to the merge commit.

`shutdown_host()` next to `reboot_host()`: `/sbin/poweroff`, detached (`sh -c '(trap "" HUP; sleep 2; /sbin/poweroff) …&'`) through the privileged path, so the call returns before the session drops. Same error contract as the reboot: a non-zero or missing status raises `RuntimeError` with the host's output (plus the sudo hint when sudo wants a password). `poweroff` rather than `shutdown -h now`: systemd, sysvinit and BusyBox all ship it, and sysvinit's `-h` may only halt. Version 0.25.0 with its CHANGELOG entry. Tests: `TestShutdownHost` (5) in `tests/test_linux.py`, and `shutdown_host` in the sudo-line check; full suite 480 passed. Part of NetOrk/netork#2841: the device header gets Restart and Shut down for hardware devices. netOrk offers each button where the driver has the method (`callable(getattr(driver, "reboot_host" / "shutdown_host", None))`), so defining it is what switches the button on. The contracts are `HostRebootMixin` / `HostShutdownMixin` in napalm-device-types, already mixed in through `DeviceTypeDriver`; the minimum napalm-device-types version needs no change. netOrk's `feature/host-shutdown-2841` pins this branch's commit for now; once this is merged, the pin moves to the merge commit.
christianmanivong added 1 commit 2026-11-29 21:53:23 +00:00
feat(power): shutdown_host through HostShutdownMixin, 0.25.0 (NetOrk/netork#2841)
driver / lint (pull_request) Successful in 11s
driver / standard (pull_request) Failing after 14s
driver / lowest (pull_request) Successful in 27s
driver / types (pull_request) Successful in 59s
driver / test (3.13) (pull_request) Successful in 51s
driver / test (3.12) (pull_request) Successful in 1m2s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Failing after 1m41s
driver / publish (pull_request) Skipped
f876ac4598
The host's clean shutdown next to reboot_host: /sbin/poweroff as root,
detached and two seconds late like the restart, so the exit status comes
back before the session drops. A refusal raises RuntimeError with what
the host said, plus the sudo password hint where sudo wanted one.

poweroff rather than shutdown -h now: systemd links it to systemctl
poweroff, sysvinit and BusyBox ship it themselves, while BusyBox has no
shutdown and sysvinit's -h may only halt.
christianmanivong added 1 commit 2026-11-29 21:56:01 +00:00
refactor(power): reboot_host and shutdown_host in a mixin of their own (NetOrk/netork#2841)
driver / standard (pull_request) Successful in 13s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 52s
driver / lowest (pull_request) Successful in 28s
driver / test (3.13) (pull_request) Successful in 57s
driver / build (pull_request) Successful in 25s
driver / test (3.12) (pull_request) Successful in 1m9s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Successful in 2m5s
driver / publish (pull_request) Skipped
d0a86c1046
linux.py must not grow (python_file_lines, 1990): the power methods,
their detached commands and _launch_detached move to _host_power.py
(LinuxHostPowerMixin), and linux.py shrinks to 1972 lines, recorded in
the baseline. Behaviour unchanged; the 480 tests pass as they were.
christianmanivong merged commit 5fc6d96ea7 into main 2026-11-29 22:01:05 +00:00
christianmanivong deleted branch feature/host-shutdown-2841 2026-11-29 22:01:05 +00:00
Sign in to join this conversation.