push_mac_acl and push_radio_channel (napalm_openwrt/wireless_mixin.py) sent each step through _send_command (the interactive netmiko shell) and never looked at the result:
a refused uci set …macfilter, uci add_list …maclist, uci commit wireless or wifi reload passed silently;
push_mac_acl with an SSID that no wifi-iface carries did nothing and returned normally;
push_radio_channel restarted wifi even when the uci set was refused.
STANDARDS §3/§4: a refused step of an action must raise. The caller could not tell an applied ACL from one that never landed.
Cause
The shell channel gives no exit status, and several steps hid theirs on purpose (uci -q delete … || true, uci delete … 2>/dev/null || true), since deleting an option that does not exist exits 1.
Fix
A checked step runner, napalm_openwrt/uci_steps.py (UciStepsMixin, strict mypy), meant to be reused by the UCI writes that move into the driver later:
_uci_step(command) runs one command through the driver's run_command (SSH exec channel, real exit code, stderr apart), as root, and raises CommandErrorException naming the command and what the router said when it exits non-zero.
_uci_apply(config, changes, restart) stages the changes, commits, then restarts. A refusal before or at the commit runs uci revert <config> and re-raises, so nothing is committed and nothing restarted. Without the revert, the staged half of a refused ACL (say macfilter='allow' with half the list) would be committed by the next push of any SSID. A failed revert is logged; the refusal stays the error. A refused restart comes after the commit, and its message says the change is committed.
parse_uci_show reads uci -q show (sections, types, options; values unquoted as uci prints them, '\'' included).
push_mac_acl reads uci -q show wireless once (checked), takes the wifi-iface sections whose ssid is the SSID, raises when there are none, and builds the changes per section: macfilter set (or, for "off", deleted), the maclist deleted only where the section has one, each MAC added. No step hides its status any more. push_radio_channel is one change, then uci commit wireless, then wifi. Words are quoted with shlex.join, so a MAC, SSID section or radio name cannot run as shell.
Behaviour kept: "off" deletes the options (never macfilter='disable'), a whitelist without MACs is "off", the channel push uses wifi (full restart), the MAC push wifi reload.
Running as root: run_command(privileged=True), so a login other than root is refused with PermissionError before anything runs (OpenWrt has no sudo; uci could not commit as another user anyway).
Tests
Fixtures only (no device). tests/unit/test_wireless_writes.py: a fake AP behind run_command answers uci -q show wireless in the shape OpenWrt 23.05 prints it (stock default_radioN sections, a list on one line, a quote inside an SSID) and refuses chosen commands with uci's own messages (uci: Invalid argument, uci: I/O error).
the exact command sequence for a blacklist (two sections with the SSID, one with an existing list), a whitelist, "off" (deletes only what exists), an empty whitelist, and an SSID with a quote and a space;
no section with the SSID raises and writes nothing; a failed read raises and writes nothing;
a refused set, delete or add_list raises naming the step and the router's message, nothing after it is sent, uci revert wireless runs, no commit, no reload;
a refused commit raises and reverts, no reload; a failed wifi reload raises naming it;
a failed revert keeps the refusal as the error; every step runs privileged; a non-root login is refused before the transport is touched;
the channel push: sequence, 0 → auto, refused set (revert, no commit, no restart), refused commit (no restart), failed wifi.
19 of these failed before the change (red), all pass now. The superseded TestPushRadioChannel/TestPushMacAcl in test_driver.py (which mocked _send_command) are removed; their cases are covered in the new file.
pytest 345 passed (coverage 74.6 %), ruff format/check clean, mypy clean on the package (with napalm-device-types resolvable), napalm-standard check and ratchet green. README (new "Wireless writes" section) and CHANGELOG ([Unreleased] → Fixed) updated.
## What was wrong
`push_mac_acl` and `push_radio_channel` (`napalm_openwrt/wireless_mixin.py`) sent each step through `_send_command` (the interactive netmiko shell) and never looked at the result:
- a refused `uci set …macfilter`, `uci add_list …maclist`, `uci commit wireless` or `wifi reload` passed silently;
- `push_mac_acl` with an SSID that no `wifi-iface` carries did nothing and returned normally;
- `push_radio_channel` restarted wifi even when the `uci set` was refused.
STANDARDS §3/§4: a refused step of an action must raise. The caller could not tell an applied ACL from one that never landed.
## Cause
The shell channel gives no exit status, and several steps hid theirs on purpose (`uci -q delete … || true`, `uci delete … 2>/dev/null || true`), since deleting an option that does not exist exits 1.
## Fix
A checked step runner, `napalm_openwrt/uci_steps.py` (`UciStepsMixin`, strict mypy), meant to be reused by the UCI writes that move into the driver later:
- `_uci_step(command)` runs one command through the driver's `run_command` (SSH exec channel, real exit code, stderr apart), as root, and raises `CommandErrorException` naming the command and what the router said when it exits non-zero.
- `_uci_apply(config, changes, restart)` stages the changes, commits, then restarts. A refusal before or at the commit runs `uci revert <config>` and re-raises, so nothing is committed and nothing restarted. Without the revert, the staged half of a refused ACL (say `macfilter='allow'` with half the list) would be committed by the next push of any SSID. A failed revert is logged; the refusal stays the error. A refused restart comes after the commit, and its message says the change is committed.
- `parse_uci_show` reads `uci -q show` (sections, types, options; values unquoted as uci prints them, `'\''` included).
`push_mac_acl` reads `uci -q show wireless` once (checked), takes the `wifi-iface` sections whose `ssid` is the SSID, raises when there are none, and builds the changes per section: `macfilter` set (or, for "off", deleted), the `maclist` deleted only where the section has one, each MAC added. No step hides its status any more. `push_radio_channel` is one change, then `uci commit wireless`, then `wifi`. Words are quoted with `shlex.join`, so a MAC, SSID section or radio name cannot run as shell.
Behaviour kept: "off" deletes the options (never `macfilter='disable'`), a whitelist without MACs is "off", the channel push uses `wifi` (full restart), the MAC push `wifi reload`.
Running as root: `run_command(privileged=True)`, so a login other than root is refused with `PermissionError` before anything runs (OpenWrt has no sudo; uci could not commit as another user anyway).
## Tests
Fixtures only (no device). `tests/unit/test_wireless_writes.py`: a fake AP behind `run_command` answers `uci -q show wireless` in the shape OpenWrt 23.05 prints it (stock `default_radioN` sections, a list on one line, a quote inside an SSID) and refuses chosen commands with uci's own messages (`uci: Invalid argument`, `uci: I/O error`).
- the exact command sequence for a blacklist (two sections with the SSID, one with an existing list), a whitelist, "off" (deletes only what exists), an empty whitelist, and an SSID with a quote and a space;
- no section with the SSID raises and writes nothing; a failed read raises and writes nothing;
- a refused `set`, `delete` or `add_list` raises naming the step and the router's message, nothing after it is sent, `uci revert wireless` runs, no commit, no reload;
- a refused commit raises and reverts, no reload; a failed `wifi reload` raises naming it;
- a failed revert keeps the refusal as the error; every step runs privileged; a non-root login is refused before the transport is touched;
- the channel push: sequence, `0` → `auto`, refused set (revert, no commit, no restart), refused commit (no restart), failed `wifi`.
19 of these failed before the change (red), all pass now. The superseded `TestPushRadioChannel`/`TestPushMacAcl` in `test_driver.py` (which mocked `_send_command`) are removed; their cases are covered in the new file.
pytest 345 passed (coverage 74.6 %), ruff format/check clean, mypy clean on the package (with napalm-device-types resolvable), `napalm-standard check` and `ratchet` green. README (new "Wireless writes" section) and CHANGELOG (`[Unreleased]` → Fixed) updated.
Closes #35
push_mac_acl and push_radio_channel sent each step through the
interactive shell and never looked at the result: a refused uci set,
add_list, commit or wifi reload passed silently, an SSID no wifi-iface
carried did nothing, and wifi was restarted after a refused channel.
Each step now runs on an SSH exec channel of its own, as root, with its
exit status checked (uci_steps.UciStepsMixin). A refused step raises
CommandErrorException naming the command and what the router said; a
refusal before the commit reverts what was staged, so a later commit
does not apply half of it, and wifi is not restarted. push_mac_acl
reads the sections once, raises when none carries the SSID, and deletes
macfilter/maclist only where a section has them instead of hiding each
delete's status behind `|| true`.
Closes#35
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What was wrong
push_mac_aclandpush_radio_channel(napalm_openwrt/wireless_mixin.py) sent each step through_send_command(the interactive netmiko shell) and never looked at the result:uci set …macfilter,uci add_list …maclist,uci commit wirelessorwifi reloadpassed silently;push_mac_aclwith an SSID that nowifi-ifacecarries did nothing and returned normally;push_radio_channelrestarted wifi even when theuci setwas refused.STANDARDS §3/§4: a refused step of an action must raise. The caller could not tell an applied ACL from one that never landed.
Cause
The shell channel gives no exit status, and several steps hid theirs on purpose (
uci -q delete … || true,uci delete … 2>/dev/null || true), since deleting an option that does not exist exits 1.Fix
A checked step runner,
napalm_openwrt/uci_steps.py(UciStepsMixin, strict mypy), meant to be reused by the UCI writes that move into the driver later:_uci_step(command)runs one command through the driver'srun_command(SSH exec channel, real exit code, stderr apart), as root, and raisesCommandErrorExceptionnaming the command and what the router said when it exits non-zero._uci_apply(config, changes, restart)stages the changes, commits, then restarts. A refusal before or at the commit runsuci revert <config>and re-raises, so nothing is committed and nothing restarted. Without the revert, the staged half of a refused ACL (saymacfilter='allow'with half the list) would be committed by the next push of any SSID. A failed revert is logged; the refusal stays the error. A refused restart comes after the commit, and its message says the change is committed.parse_uci_showreadsuci -q show(sections, types, options; values unquoted as uci prints them,'\''included).push_mac_aclreadsuci -q show wirelessonce (checked), takes thewifi-ifacesections whosessidis the SSID, raises when there are none, and builds the changes per section:macfilterset (or, for "off", deleted), themaclistdeleted only where the section has one, each MAC added. No step hides its status any more.push_radio_channelis one change, thenuci commit wireless, thenwifi. Words are quoted withshlex.join, so a MAC, SSID section or radio name cannot run as shell.Behaviour kept: "off" deletes the options (never
macfilter='disable'), a whitelist without MACs is "off", the channel push useswifi(full restart), the MAC pushwifi reload.Running as root:
run_command(privileged=True), so a login other than root is refused withPermissionErrorbefore anything runs (OpenWrt has no sudo; uci could not commit as another user anyway).Tests
Fixtures only (no device).
tests/unit/test_wireless_writes.py: a fake AP behindrun_commandanswersuci -q show wirelessin the shape OpenWrt 23.05 prints it (stockdefault_radioNsections, a list on one line, a quote inside an SSID) and refuses chosen commands with uci's own messages (uci: Invalid argument,uci: I/O error).set,deleteoradd_listraises naming the step and the router's message, nothing after it is sent,uci revert wirelessruns, no commit, no reload;wifi reloadraises naming it;0→auto, refused set (revert, no commit, no restart), refused commit (no restart), failedwifi.19 of these failed before the change (red), all pass now. The superseded
TestPushRadioChannel/TestPushMacAclintest_driver.py(which mocked_send_command) are removed; their cases are covered in the new file.pytest 345 passed (coverage 74.6 %), ruff format/check clean, mypy clean on the package (with napalm-device-types resolvable),
napalm-standard checkandratchetgreen. README (new "Wireless writes" section) and CHANGELOG ([Unreleased]→ Fixed) updated.Closes #35