9 Commits
Author SHA1 Message Date
christianmanivong dd3e3f1543 Merge pull request 'feat(wireless): get_radio_status says whether each radio runs, 0.10.0 (NetOrk/netork#31)' (#53) from feature/radio-runtime-state into main
driver / standard (push) Successful in 16s
driver / lint (push) Successful in 19s
driver / types (push) Successful in 56s
driver / test (3.12) (push) Successful in 57s
driver / lowest (push) Successful in 30s
driver / test (3.13) (push) Successful in 1m0s
driver / build (push) Successful in 27s
driver / security (push) Successful in 59s
driver / publish (push) Successful in 29s
CI / driver (push) Successful in 3m0s
2026-11-28 02:07:50 +00:00
Christian Manivong 8539c4c8c7 chore(release): 0.10.0
driver / lint (pull_request) Successful in 17s
driver / types (pull_request) Successful in 1m0s
driver / test (3.12) (pull_request) Successful in 1m3s
driver / lowest (pull_request) Successful in 33s
driver / test (3.13) (pull_request) Successful in 1m4s
driver / build (pull_request) Successful in 32s
driver / standard (pull_request) Successful in 17s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m40s
driver / publish (pull_request) Skipped
2026-11-28 03:02:21 +01:00
Christian Manivong dcb4932535 feat(wireless): get_radio_status says whether each radio runs (NetOrk/netork#31)
up, pending and setup_failed come from netifd (ubus call network.wireless
status, its retry_setup_failed for the last), beside the configuration read
before. A key netifd does not answer with a boolean is left out, and all
three are left out where the call fails or breaks off; the configuration
stays either way. On 2026-07-16 every radio of the fleet sat in a restart
loop with its configuration saying enabled; this is the state that showed it.

The htmode table moves to module level, which keeps get_radio_status within
the quality ratchet.
2026-11-28 03:02:21 +01:00
christianmanivong ecf8c427fc Merge pull request 'docs: no services restart reading on OpenWrt, and a test that keeps it so (NetOrk/netork#2750)' (#52) from docs/no-services-restart into main
driver / standard (push) Successful in 19s
driver / lint (push) Successful in 18s
driver / types (push) Successful in 1m4s
driver / test (3.13) (push) Successful in 57s
driver / test (3.12) (push) Successful in 1m14s
driver / lowest (push) Successful in 33s
driver / build (push) Successful in 36s
driver / security (push) Successful in 1m7s
CI / driver (push) Successful in 2m54s
driver / publish (push) Skipped
2026-11-26 18:56:46 +00:00
Christian Manivong a9abfd535c docs: no services restart reading on OpenWrt, and a test that keeps it so (NetOrk/netork#2750)
driver / standard (pull_request) Successful in 20s
driver / lint (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m5s
driver / test (3.13) (pull_request) Successful in 59s
driver / test (3.12) (pull_request) Successful in 1m16s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m7s
CI / driver (pull_request) Successful in 2m50s
driver / publish (pull_request) Skipped
An upgrade leaves the old files in the read-only image, and the kernel can
name them by their /rom or /overlay/upper path rather than as deleted, so
napalm-device-types' /proc scan could read clean right after an upgrade.
Without the method the caller shows the reading as not made. A reading of
OpenWrt's own is #51.
2026-11-26 18:56:33 +01:00
christianmanivong f186bcd10e Merge pull request 'chore(release): 0.9.0' (#50) from chore/release-0.9.0 into main
driver / types (push) Successful in 58s
driver / standard (push) Successful in 17s
driver / lint (push) Successful in 14s
driver / test (3.12) (push) Successful in 59s
driver / test (3.13) (push) Successful in 52s
driver / lowest (push) Successful in 28s
driver / build (push) Successful in 27s
driver / security (push) Successful in 1m1s
driver / publish (push) Successful in 29s
CI / driver (push) Successful in 6m2s
2026-11-26 12:26:05 +00:00
Christian Manivong fa5ed09b4c refactor(zabbix): closing the agent's rule in steps, within the quality ratchet
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 17s
driver / types (pull_request) Successful in 48s
driver / test (3.13) (pull_request) Successful in 45s
driver / test (3.12) (pull_request) Successful in 52s
driver / lowest (pull_request) Successful in 24s
driver / build (pull_request) Successful in 25s
driver / security (pull_request) Successful in 58s
CI / driver (pull_request) Successful in 2m0s
driver / publish (pull_request) Skipped
2026-11-26 12:24:34 +01:00
Christian Manivong dfd9b70278 chore(release): 0.9.0
driver / standard (pull_request) Failing after 15s
driver / lint (pull_request) Successful in 11s
driver / test (3.12) (pull_request) Failing after 20s
driver / types (pull_request) Failing after 28s
driver / test (3.13) (pull_request) Failing after 13s
driver / lowest (pull_request) Failing after 14s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Failing after 40s
CI / driver (pull_request) Failing after 1m32s
driver / publish (pull_request) Skipped
2026-11-26 08:26:35 +01:00
Christian Manivong 36d4802624 feat(zabbix): an active-only agent closes the port netOrk opened for it (NetOrk/netork#2693)
_revoke_zabbix_agent_sources deletes the named rule section netOrk wrote for
the agent (allow_zabbix_agent, allow_zabbix_agent_from_<zone>) and reloads
the firewall where one runs. Rules with other keys stay and are reported.
2026-11-26 08:23:32 +01:00
9 changed files with 449 additions and 27 deletions

No files matched your search

+20
View File
@@ -7,6 +7,26 @@ recorded here; their history is the git log.
## [Unreleased]
## [0.10.0] - 2026-11-28
### Added
- `get_radio_status()` says whether each radio runs (NetOrk/netork#31): `up`, `pending`
and `setup_failed` from netifd (`ubus call network.wireless status`, its
`retry_setup_failed` for the last), beside the configuration it read before. A key
netifd does not answer with a boolean is left out, and all three are left out where the
call fails. On 2026-07-16 every radio of the fleet sat in a restart loop with its
configuration saying `enabled`; this is the state that showed it.
## [0.9.0] - 2026-11-26
### Added
- An active-only Zabbix agent closes the port netOrk opened for it on an earlier passive run
(`_revoke_zabbix_agent_sources`, napalm-device-types `ZabbixAgentMixin`,
NetOrk/netork#2693): the firewall step deletes the rule netOrk wrote -- the named section
`allow_zabbix_agent` or `allow_zabbix_agent_from_<zone>` -- from the configuration and
reloads the firewall where one runs. A rule written in LuCI has an anonymous `cfgXXXX` key
and stays; the rules for the port left in place are named.
## [0.8.0] - 2026-11-17
### Changed
+1
View File
@@ -72,6 +72,7 @@ device.close()
| `get_ntp_servers` / `get_ntp_peers` | ✅ | `system.ntp.server` in UCI, every server of the list; none while `system.ntp.enabled` is off -- the same list as `get_time_sync()` |
| `get_time_sync()` | ✅ | napalm-device-types `TimeSyncMixin`: the servers as above, the zone from `zonename` where the rule in `timezone` is that zone's (else the one zone with that rule, or none); `synchronized` is not readable (None) |
| `get_firmware_offer()` | ✅ | napalm-device-types `FirmwareOfferMixin`: the newest release of the device's own line on the attended sysupgrade server (see *Firmware upgrade*) |
| `get_services_need_restart()` | ❌ | deliberately not offered (NetOrk/netork#2750): an upgrade writes the new files to the overlay while the old ones stay in the read-only image, and `/proc/<pid>/maps` can name those by their `/rom` or `/overlay/upper` path rather than as deleted (Linux before 6.8 shows an overlay file's real path). napalm-device-types' `/proc` scan could then read clean exactly after an upgrade; without the method the caller shows the reading as not made. A reading of OpenWrt's own is #51 |
## Configuration management
+73 -21
View File
@@ -12,6 +12,7 @@
from __future__ import annotations
import json
import logging
import re
from typing import Any
@@ -33,6 +34,55 @@ _ACL_OPTIONS = ("macfilter", "maclist")
_MACFILTER_BY_MODE = {"whitelist": "allow", "blacklist": "deny", "off": None}
#: netifd's state of each radio: whether it runs, not what it is configured to do.
_WIRELESS_STATUS = "ubus call network.wireless status"
#: The runtime keys of ``RadioStatusDict`` and netifd's name for each.
_RUNTIME_KEYS = {"up": "up", "pending": "pending", "setup_failed": "retry_setup_failed"}
#: Channel bandwidth in MHz by ``htmode`` (``VHT80`` is 80 MHz).
_HTMODE_WIDTH = {
"HT20": 20,
"HT40": 40,
"VHT20": 20,
"VHT40": 40,
"VHT80": 80,
"VHT80+80": 80,
"VHT160": 160,
"HE20": 20,
"HE40": 40,
"HE80": 80,
"HE160": 160,
"EHT20": 20,
"EHT40": 40,
"EHT80": 80,
"EHT160": 160,
"EHT320": 320,
}
def parse_wireless_status(text: str) -> dict[str, dict[str, bool]]:
"""``up``, ``pending`` and ``setup_failed`` per radio from netifd's JSON answer.
A key netifd does not give as a boolean is left out, never guessed: before
OpenWrt 19.07 it had no ``retry_setup_failed``. Text that is no JSON object
(a refused call) gives {}.
"""
try:
status = json.loads(text)
except ValueError:
return {}
if not isinstance(status, dict):
return {}
radios: dict[str, dict[str, bool]] = {}
for radio, state in status.items():
if isinstance(state, dict):
radios[radio] = {
key: state[name]
for key, name in _RUNTIME_KEYS.items()
if isinstance(state.get(name), bool)
}
return radios
def _mac_acl_changes(sec: UciSection, mode: str, macs: list[str]) -> list[str]:
"""The ``uci`` changes that give *sec* the ACL *mode* with *macs*.
@@ -659,10 +709,11 @@ class OpenWrtWirelessMixin(UciStepsMixin):
self._uci_apply(_WIRELESS, changes, _WIFI_RELOAD)
def get_radio_status(self) -> dict[str, Any]:
"""Return radio status from UCI and iwinfo.
"""Return radio status from UCI, iwinfo and netifd.
Combines ``uci show wireless`` for static config with ``iwinfo``
output for runtime channel/frequency and tx-power data.
output for runtime channel/frequency and tx-power data, and
``ubus call network.wireless status`` for whether each radio runs.
Returns a dict keyed by radio name (e.g. ``"radio0"``) with:
@@ -674,6 +725,8 @@ class OpenWrtWirelessMixin(UciStepsMixin):
* frequency (float) — centre frequency in MHz (0 if unknown)
* htmode (str) — e.g. ``"HT20"``, ``"VHT80"``, ``"HE80"``
* country (str) — regulatory country code, e.g. ``"DE"``
* up, pending, setup_failed (bool) — netifd's state; left out without
an answer from ubus (see :func:`parse_wireless_status`)
"""
from napalm_device_types.models import RadioStatusDict
@@ -714,25 +767,6 @@ class OpenWrtWirelessMixin(UciStepsMixin):
htmode = cfg.get("htmode", "")
country = cfg.get("country", "")
# Derive channel_width from htmode string (e.g. VHT80 → 80 MHz)
_HTMODE_WIDTH = {
"HT20": 20,
"HT40": 40,
"VHT20": 20,
"VHT40": 40,
"VHT80": 80,
"VHT80+80": 80,
"VHT160": 160,
"HE20": 20,
"HE40": 40,
"HE80": 80,
"HE160": 160,
"EHT20": 20,
"EHT40": 40,
"EHT80": 80,
"EHT160": 160,
"EHT320": 320,
}
channel_width = _HTMODE_WIDTH.get(htmode.upper(), 0)
result[radio] = {
@@ -790,4 +824,22 @@ class OpenWrtWirelessMixin(UciStepsMixin):
if pwr_m:
result[current_radio]["tx_power"] = int(pwr_m.group(1))
self._add_radio_runtime(result)
return result
def _add_radio_runtime(self, radios: dict[str, Any]) -> None:
"""Add to *radios* whether each runs, as netifd says it (NetOrk/netork#31).
Nothing is added without an answer, and no radio the configuration lacks.
"""
try:
answer = self.run_command(_WIRELESS_STATUS, timeout=30)
except Exception as exc: # noqa: BLE001 - like iwinfo: the configuration stays
logger.debug("%s failed: %s", _WIRELESS_STATUS, exc)
return
if answer.exit_code:
logger.debug("%s exited %s: %s", _WIRELESS_STATUS, answer.exit_code, answer.stderr)
return
for radio, state in parse_wireless_status(answer.stdout).items():
if radio in radios:
radios[radio].update(state)
+80 -2
View File
@@ -20,7 +20,8 @@ Zabbix publishes no repository for OpenWrt, so the feed is the only source.
The package index lives in RAM and is gone after every restart; the template loads
it first (``refresh_available_updates``). The firewall step opens tcp/``listen_port``
in the zone that owns the management address, the way the SNMP agent's step opens
udp/161 -- and only where a firewall runs: an access point often runs none.
udp/161 -- and only where a firewall runs: an access point often runs none. For an
active-only agent it deletes that rule again, by its key (NetOrk/netork#2693).
"""
from __future__ import annotations
@@ -50,6 +51,15 @@ _FIREWALL_RUNS = (
)
#: The key of the rule ``_allow_zabbix_agent_sources`` writes, unscoped or per zone.
_RULE_KEY = "allow_zabbix_agent"
def _netork_rule(key: str) -> bool:
"""Whether the firewall section *key* is the rule netOrk writes for the agent."""
return key == _RULE_KEY or key.startswith(f"{_RULE_KEY}_from_")
def _failed(result: CommandResult, what: str) -> FixStepOutcomeDict:
detail = (result.stderr or result.stdout or "").strip()[-300:]
return {"ok": False, "output": f"{what}: {detail or result.exit_code}"}
@@ -92,7 +102,7 @@ class OpenWrtZabbixAgentMixin(ZabbixAgentMixin):
if self._send_command(_FIREWALL_RUNS).strip() != "on":
return {"ok": True, "output": "no firewall runs; nothing to open"}
outcome = self._allow_in_management_zone(
key="allow_zabbix_agent",
key=_RULE_KEY,
name="Allow-Zabbix-Agent",
proto="tcp",
port=int(settings["listen_port"]),
@@ -101,6 +111,66 @@ class OpenWrtZabbixAgentMixin(ZabbixAgentMixin):
)
return {"ok": bool(outcome["ok"]), "output": str(outcome["output"])}
def _revoke_zabbix_agent_sources(self, settings: ZabbixAgentSettingsDict) -> FixStepOutcomeDict:
"""For an active-only agent: delete the rules netOrk wrote for the agent on an
earlier passive run, and nothing else (NetOrk/netork#2693).
netOrk's are the named sections ``allow_zabbix_agent`` and
``allow_zabbix_agent_from_<zone>`` (``_allow_zabbix_agent_sources``); a rule
written in LuCI gets an anonymous ``cfgXXXX`` key. Other rules for the port stay
and are named. The firewall reloads where one runs.
"""
port = int(settings["listen_port"])
mine, others = self._agent_rules(port)
lines: list[str] = []
ok = True
if mine:
removed = self._delete_rules(mine)
if not removed["ok"]:
return removed
lines.append(str(removed["output"]))
ok = self._reload_if_running(lines)
else:
lines.append("netOrk wrote no rule for the agent; nothing removed")
if others:
lines.append(
f"{len(others)} rule(s) for tcp/{port} that netOrk did not write are left in"
f" place: {', '.join(others)}"
)
return {"ok": ok, "output": "; ".join(lines)}
def _agent_rules(self, port: int) -> tuple[list[str], list[str]]:
"""The rule sections netOrk wrote for the agent, and the others for *port*."""
sections = self._parse_uci_sections(self._send_command("uci show firewall 2>/dev/null"))
rules = {key: opts for key, opts in sections.items() if opts.get("_type") == "rule"}
mine = sorted(key for key in rules if _netork_rule(key))
others = sorted(
key
for key, opts in rules.items()
if key not in mine and self._uci_scalar(opts.get("dest_port", "")) == str(port)
)
return mine, others
def _delete_rules(self, keys: list[str]) -> FixStepOutcomeDict:
deletes = "; ".join(f"uci -q delete firewall.{key}" for key in keys)
done = self._rc_step(f"{deletes}; uci commit firewall", "")
if not done["ok"]:
return {"ok": False, "output": str(done["output"])}
return {
"ok": True,
"output": f"removed the rule(s) netOrk wrote for the agent: {', '.join(keys)}",
}
def _reload_if_running(self, lines: list[str]) -> bool:
"""Reload the firewall where one runs; False where it refused the ruleset."""
if self._send_command(_FIREWALL_RUNS).strip() != "on":
return True
reload_out = self._send_command(
"fw4 reload 2>&1 || /etc/init.d/firewall reload 2>&1"
).strip()
lines.append(f"reload: {reload_out or 'ok'}")
return not self._fw_reload_failed(reload_out)
if TYPE_CHECKING: # pragma: no cover - the driver's
def run_command(
@@ -117,3 +187,11 @@ class OpenWrtZabbixAgentMixin(ZabbixAgentMixin):
def _allow_in_management_zone(
self, *, key: str, name: str, proto: str, port: int, sources: list[str], word: str
) -> dict[str, Any]: ...
def _parse_uci_sections(self, raw: str) -> dict[str, dict[str, str]]: ...
def _uci_scalar(self, value: str) -> str: ...
def _rc_step(self, command: str, done: str) -> dict[str, Any]: ...
def _fw_reload_failed(self, output: str) -> bool: ...
+2 -2
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "napalm-openwrt"
version = "0.8.0"
version = "0.10.0"
description = "NAPALM driver for OpenWrt routers/access-points"
readme = "README.md"
license = "Apache-2.0"
@@ -21,7 +21,7 @@ classifiers = [
]
dependencies = [
"napalm>=5.1", # older releases import pkg_resources, which a 3.12 venv lacks
"napalm_device_types>=4.41.0", # FirmwareUpgradeMixin
"napalm_device_types>=4.43.0", # ZabbixAgentMixin._revoke_zabbix_agent_sources
"netmiko>=4.0.0",
"paramiko>=5.0.0", # CVE-2026-44405
"netaddr>=0.7.19", # IPAddress; below it the package has none (CI lowest job)
+1 -1
View File
@@ -31,7 +31,7 @@
"napalm_openwrt/vlan_mixin.py::OpenWrtVLANMixin.get_network_instances": 61,
"napalm_openwrt/vlan_mixin.py::OpenWrtVLANMixin.get_vlans": 106,
"napalm_openwrt/wireless_mixin.py::OpenWrtWirelessMixin._parse_iw_scan": 93,
"napalm_openwrt/wireless_mixin.py::OpenWrtWirelessMixin.get_radio_status": 133,
"napalm_openwrt/wireless_mixin.py::OpenWrtWirelessMixin.get_radio_status": 118,
"napalm_openwrt/wireless_mixin.py::OpenWrtWirelessMixin.get_ssids": 240,
"napalm_openwrt/wireless_mixin.py::OpenWrtWirelessMixin.get_wireless_clients": 152
},
+166
View File
@@ -0,0 +1,166 @@
"""``get_radio_status``: each radio's configuration and whether it runs (NetOrk/netork#31).
On 2026-07-16 a rejected UCI value kept every radio of the fleet in a netifd restart
loop. The configuration said ``enabled``; only netifd's own state said otherwise:
``ubus call network.wireless status`` answers per radio with ``up``, ``pending``
and ``retry_setup_failed``. The driver reports those three as they are and leaves
them out where ubus gives no answer; what they mean is netOrk's to say.
``WIRELESS_STATUS`` is the shape OpenWrt 23.05 prints, trimmed to the keys read:
radio0 in the incident's state (setup given up), radio1 running.
"""
from __future__ import annotations
import json
from unittest.mock import MagicMock, patch
from napalm_device_types import CommandResult
from napalm_openwrt.openwrt import OpenWrtDriver
UBUS = "ubus call network.wireless status"
UCI = """\
wireless.radio0=wifi-device
wireless.radio0.channel='1'
wireless.radio0.band='2g'
wireless.radio0.htmode='HT20'
wireless.radio1=wifi-device
wireless.radio1.channel='36'
wireless.radio1.band='5g'
wireless.radio1.htmode='VHT80'
wireless.radio2=wifi-device
wireless.radio2.band='6g'
wireless.radio2.disabled='1'
"""
WIRELESS_STATUS = {
"radio0": {
"up": False,
"pending": False,
"autostart": True,
"disabled": False,
"retry_setup_failed": True,
"config": {"channel": "1", "band": "2g"},
"interfaces": [],
},
"radio1": {
"up": True,
"pending": False,
"autostart": True,
"disabled": False,
"retry_setup_failed": False,
"config": {"channel": "36", "band": "5g"},
"interfaces": [{"section": "default_radio1", "ifname": "phy1-ap0"}],
},
"radio2": {
"up": False,
"pending": False,
"autostart": True,
"disabled": True,
"retry_setup_failed": False,
"interfaces": [],
},
}
def _driver(ubus: CommandResult) -> tuple[OpenWrtDriver, list[str]]:
with patch("napalm_openwrt.openwrt.ConnectHandler"):
drv = OpenWrtDriver(hostname="192.0.2.15", username="root", password="")
drv.device = MagicMock()
sent: list[str] = []
def send_command(command: str) -> str:
return UCI if command == "uci show wireless" else ""
def run_command(command: str, **_kw: object) -> CommandResult:
sent.append(command)
return ubus
drv._send_command = send_command # type: ignore[method-assign]
drv.run_command = run_command # type: ignore[method-assign]
return drv, sent
def _answer(status: dict) -> CommandResult:
return CommandResult(json.dumps(status, indent="\t"), "", 0)
def test_a_radio_that_gave_up_its_setup_says_so():
radios = _driver(_answer(WIRELESS_STATUS))[0].get_radio_status()
assert radios["radio0"]["enabled"] is True
assert (radios["radio0"]["up"], radios["radio0"]["pending"]) == (False, False)
assert radios["radio0"]["setup_failed"] is True
def test_a_running_radio_says_it_is_up():
radio = _driver(_answer(WIRELESS_STATUS))[0].get_radio_status()["radio1"]
assert (radio["up"], radio["pending"], radio["setup_failed"]) == (True, False, False)
def test_a_disabled_radio_keeps_its_configuration_and_its_state():
radio = _driver(_answer(WIRELESS_STATUS))[0].get_radio_status()["radio2"]
assert radio["enabled"] is False
assert radio["up"] is False
def test_the_state_is_read_with_one_ubus_call():
drv, sent = _driver(_answer(WIRELESS_STATUS))
drv.get_radio_status()
assert sent == [UBUS]
def test_no_answer_from_ubus_leaves_the_state_out():
radios = _driver(CommandResult("", "Command failed: Not found\n", 4))[0].get_radio_status()
assert set(radios) == {"radio0", "radio1", "radio2"}
assert not any({"up", "pending", "setup_failed"} & set(r) for r in radios.values())
def test_output_that_is_no_json_leaves_the_state_out():
radios = _driver(CommandResult("Permission denied\n", "", 0))[0].get_radio_status()
assert "up" not in radios["radio0"]
def test_a_key_ubus_does_not_give_is_left_out_not_guessed():
# Before OpenWrt 19.07 netifd had no retry_setup_failed.
old = {"radio0": {"up": False, "pending": True}}
radio = _driver(_answer(old))[0].get_radio_status()["radio0"]
assert (radio["up"], radio["pending"]) == (False, True)
assert "setup_failed" not in radio
assert "up" not in _driver(_answer(old))[0].get_radio_status()["radio1"]
def test_a_value_that_is_no_boolean_is_left_out():
odd = {"radio0": {"up": "yes", "pending": None, "retry_setup_failed": 1}}
radio = _driver(_answer(odd))[0].get_radio_status()["radio0"]
assert not {"up", "pending", "setup_failed"} & set(radio)
def test_a_radio_only_ubus_knows_is_not_added():
extra = {**WIRELESS_STATUS, "radio9": {"up": True}}
radios = _driver(_answer(extra))[0].get_radio_status()
assert "radio9" not in radios
def test_a_call_that_breaks_off_keeps_the_configuration():
"""Like the iwinfo read: the configuration was read, a lost runtime state loses nothing else."""
drv, _ = _driver(_answer(WIRELESS_STATUS))
def broken(command: str, **_kw: object) -> CommandResult:
raise TimeoutError("channel closed")
drv.run_command = broken # type: ignore[method-assign]
radios = drv.get_radio_status()
assert radios["radio0"]["enabled"] is True
assert "up" not in radios["radio0"]
+16
View File
@@ -0,0 +1,16 @@
"""No ``get_services_need_restart`` on OpenWrt (NetOrk/netork#2750).
napalm-device-types' ``ServicesRestartMixin`` finds replaced code as deleted files in
``/proc/<pid>/maps``. On OpenWrt an upgrade leaves the old files in the read-only image,
and the kernel can name them by their ``/rom`` or ``/overlay/upper`` path (Linux
before 6.8 shows an overlay file's real path), so that scan could read clean right
after an upgrade. The driver does not offer it,
and the caller shows the reading as not made.
"""
from napalm_openwrt.openwrt import OpenWrtDriver
def test_it_is_not_offered():
assert not hasattr(OpenWrtDriver, "get_services_need_restart")
assert not hasattr(OpenWrtDriver, "_run_services_restart_command")
+90 -1
View File
@@ -34,6 +34,8 @@ class _Shell:
self.installed = installed
self.nft_hits = nft_hits
self.issued: list[str] = []
self.firewall = UCI_FIREWALL_HEALTHY
self.reload = ""
def __call__(self, cmd, **kw):
self.issued.append(cmd)
@@ -54,7 +56,9 @@ class _Shell:
self.installed = True
return "ok\n__OWRT_RC=0"
if cmd.startswith("uci show firewall"):
return UCI_FIREWALL_HEALTHY
return self.firewall
if cmd.startswith("fw4 reload"):
return self.reload
if cmd.startswith("uci show network"):
return UCI_NETWORK_STATIC
if "$SSH_CONNECTION" in cmd:
@@ -234,3 +238,88 @@ class _SnmpShell:
self.shell.issued.append(cmd)
return "1"
return self.shell(cmd, **kw)
# --- Active only: closing the rule netOrk wrote (NetOrk/netork#2693) ----------------
ACTIVE_ONLY = {**SETTINGS, "active_only": True, "allowed_sources": []}
NETORK_RULES = """\
firewall.allow_zabbix_agent_from_lan=rule
firewall.allow_zabbix_agent_from_lan.name='Allow-Zabbix-Agent'
firewall.allow_zabbix_agent_from_lan.proto='tcp'
firewall.allow_zabbix_agent_from_lan.dest_port='10050'
firewall.allow_zabbix_agent_from_lan.src='lan'
firewall.allow_zabbix_agent=rule
firewall.allow_zabbix_agent.name='Allow-Zabbix-Agent'
firewall.allow_zabbix_agent.dest_port='10051'
"""
OPERATOR_RULE = """\
firewall.cfg0e92bd=rule
firewall.cfg0e92bd.name='zabbix from the monitoring VLAN'
firewall.cfg0e92bd.proto='tcp'
firewall.cfg0e92bd.dest_port='10050'
firewall.allow_zabbix_agent_backup=rule
firewall.allow_zabbix_agent_backup.dest_port='10050'
"""
def _deletes(shell) -> list[str]:
return [c for c in shell.issued if "uci -q delete firewall." in c]
def test_active_only_removes_the_rules_netork_wrote_and_reloads(owrt, shell):
shell.firewall = UCI_FIREWALL_HEALTHY + NETORK_RULES
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
assert result["success"] is True, result["output"]
deletes = " ".join(_deletes(shell))
assert "uci -q delete firewall.allow_zabbix_agent_from_lan" in deletes
assert "uci -q delete firewall.allow_zabbix_agent;" in deletes + ";"
assert "uci commit firewall" in deletes
assert any(c.startswith("fw4 reload") for c in shell.issued)
assert "allow_zabbix_agent_from_lan" in result["steps"][2]["output"]
assert not any("uci set firewall.allow_zabbix_agent" in c for c in shell.issued)
def test_rules_the_operator_wrote_stay_and_are_reported(owrt, shell):
shell.firewall = UCI_FIREWALL_HEALTHY + NETORK_RULES + OPERATOR_RULE
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
deletes = " ".join(_deletes(shell))
assert "cfg0e92bd" not in deletes
assert "allow_zabbix_agent_backup" not in deletes
firewall = result["steps"][2]["output"]
assert "2 rule(s) for tcp/10050" in firewall
assert "cfg0e92bd" in firewall
def test_without_a_rule_netork_wrote_nothing_changes(owrt, shell):
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
assert result["success"] is True
assert _deletes(shell) == []
assert not any(c.startswith("fw4 reload") for c in shell.issued)
assert "netOrk wrote no rule" in result["steps"][2]["output"]
def test_without_a_running_firewall_the_rule_still_goes_from_the_configuration(owrt, shell):
shell.firewall = UCI_FIREWALL_HEALTHY + NETORK_RULES
shell.firewall_runs = False
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
assert result["success"] is True
assert _deletes(shell)
assert not any(c.startswith("fw4 reload") for c in shell.issued)
def test_a_reload_the_firewall_refuses_fails(owrt, shell):
shell.firewall = UCI_FIREWALL_HEALTHY + NETORK_RULES
shell.reload = "Section @rule[3] is not a valid rule"
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
assert result["success"] is False
assert result["steps"][-1]["step"] == "firewall"