driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m16s
driver / test (3.13) (pull_request) Successful in 1m11s
driver / test (3.12) (pull_request) Successful in 1m16s
driver / lowest (pull_request) Successful in 30s
driver / build (pull_request) Successful in 34s
driver / security (pull_request) Successful in 1m5s
CI / driver (pull_request) Successful in 2m38s
driver / publish (pull_request) Skipped
The router's host status, read by napalm-device-types' command over an SSH exec channel: whether it needs a reboot, how full its filesystems are, and, with napalm-device-types 4.32, whether apk or opkg was left halfway. Refs NetOrk/netork#851
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
"""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()
|