"""The host status of an OpenWrt device (napalm-device-types ``HostStatusMixin``). The command and its parse are napalm-device-types': whether the router needs a reboot, how full its filesystems are, and whether apk (OpenWrt 25.12) or opkg (before) was left halfway (NetOrk/netork#851). The driver only carries the command across, over an SSH exec channel, because busybox ash cuts an interactive line at 512 characters and the command is longer. The report is shaped after what the command prints on OpenWrt 25.12 (no systemd, no apt, one kernel under ``/lib/modules``, ``/`` an overlay); it still has to be checked against a real router. """ from __future__ import annotations from unittest.mock import MagicMock, patch from napalm_device_types import CommandResult from napalm_device_types.host_status import HOST_STATUS_COMMAND, parse_host_status from napalm_openwrt.openwrt import OpenWrtDriver REPORT = """HSTAT_BEGIN [kernel] 6.12.57 [modules] 6.12.57 [pm-running] [apk-audit] s luci-app-sqm [filesystems] Filesystem 1024-blocks Used Available Capacity Mounted on overlayfs:/overlay 93184 5132 83392 6% / tmpfs 245696 304 245392 0% /tmp [timers] apt-daily-upgrade.timer dnf-automatic.timer dnf-automatic-install.timer [dnf-automatic] HSTAT_END """ def _driver() -> OpenWrtDriver: with patch("napalm_openwrt.openwrt.ConnectHandler"): drv = OpenWrtDriver(hostname="192.0.2.15", username="root", password="") drv.device = MagicMock() return drv def test_the_host_status_is_napalm_device_types_reading(): drv = _driver() with patch( "napalm_openwrt.openwrt.run_on_transport", return_value=CommandResult(REPORT, "", 0) ): status = drv.get_host_status() assert status == parse_host_status(REPORT) assert status["reboot_required"] is False def test_the_command_goes_over_an_exec_channel_not_the_shell(): drv = _driver() transport = drv.device.remote_conn_pre.get_transport.return_value done = CommandResult(REPORT, "", 0) with patch("napalm_openwrt.openwrt.run_on_transport", return_value=done) as run: drv.get_host_status() assert run.call_args.args[:2] == (transport, HOST_STATUS_COMMAND) drv.device.send_command.assert_not_called()