feat(access-point): SSID settings, radio channels, VLAN names, the AP configuration and DHCP leases through declared methods (NetOrk/netork#695)

push_ssid_config, set_radio_channels and set_vlan_name run as checked
uci steps (#35): a refused step raises naming itself and reverts what
was staged. set_radio_channels replaces the undeclared push_radio_channel.

apply_ap_config takes napalm-device-types' ApConfigDict and the parts
the caller found different and writes them as one detached script: the
builder netOrk had in _uci_builders.py, moved here. It answers which
parts it wrote and which it could not, whether the AP restarts, and the
script with every passphrase masked. A passphrase part now writes the
key.

get_dhcp_leases reads dnsmasq's lease file.

Needs napalm-device-types 4.54.0; CI pre-installs it from its branch
until it is on PyPI.
This commit is contained in:
Christian Manivong committed 2026-11-29 20:51:27 +01:00
1 parent dd3e3f1543
commit 634bc9c793
18 files changed
+2108 -40

No files matched your search

+56 -8
View File
@@ -1,4 +1,4 @@
"""Wireless writes: ``push_mac_acl`` and ``push_radio_channel`` (NAPALM/napalm-openwrt#35).
"""Wireless writes: ``push_mac_acl`` and ``set_radio_channels`` (NAPALM/napalm-openwrt#35).
Each ``uci`` step runs on an exec channel of its own, with its exit status checked: a
refused step raises and names itself, nothing staged after a refusal is committed, and
@@ -248,13 +248,13 @@ def test_a_login_other_than_root_is_refused_before_anything_runs():
drv.device.remote_conn_pre.get_transport.assert_not_called()
# -- push_radio_channel ------------------------------------------------------------------------
# -- set_radio_channels (NetOrk/netork#695) ---------------------------------------------------
def test_a_channel_is_set_committed_and_wifi_restarted():
"""``wifi`` (a full restart), not ``wifi reload``: many radios keep the old channel."""
ap = _Ap()
_driver(ap).push_radio_channel("radio1", 44)
_driver(ap).set_radio_channels({"radio1": 44})
assert ap.commands == [
_uci("set", "wireless.radio1.channel=44"),
@@ -263,28 +263,71 @@ def test_a_channel_is_set_committed_and_wifi_restarted():
]
def test_every_radio_changes_in_one_commit_and_one_restart():
ap = _Ap()
_driver(ap).set_radio_channels({"radio0": 6, "radio1": 36})
assert ap.commands == [
_uci("set", "wireless.radio0.channel=6"),
_uci("set", "wireless.radio1.channel=36"),
_uci("commit", "wireless"),
"wifi",
]
def test_channel_zero_is_auto():
ap = _Ap()
_driver(ap).push_radio_channel("radio0", 0)
_driver(ap).set_radio_channels({"radio0": 0})
assert ap.commands[0] == _uci("set", "wireless.radio0.channel=auto")
def test_no_channels_send_nothing():
ap = _Ap()
_driver(ap).set_radio_channels({})
assert ap.commands == []
@pytest.mark.parametrize(
"channels",
[
{"radio0; reboot": 6},
{"wireless.radio0": 6},
{"": 6},
{"radio0": -1},
{"radio0": "6"},
{"radio0": True},
],
)
def test_a_radio_or_channel_the_ap_cannot_take_raises_before_anything_is_sent(channels):
ap = _Ap()
with pytest.raises(ValueError):
_driver(ap).set_radio_channels(channels)
assert ap.commands == []
def test_a_refused_channel_raises_and_does_not_restart_wifi():
"""The other radio's change is reverted with it: no radio changes."""
refused = _uci("set", "wireless.radio9.channel=6")
ap = _Ap({refused: INVALID_ARGUMENT})
with pytest.raises(CommandErrorException) as caught:
_driver(ap).push_radio_channel("radio9", 6)
_driver(ap).set_radio_channels({"radio0": 1, "radio9": 6})
assert refused in str(caught.value)
assert "Invalid argument" in str(caught.value)
assert ap.commands == [refused, _uci("revert", "wireless")]
assert ap.commands == [
_uci("set", "wireless.radio0.channel=1"),
refused,
_uci("revert", "wireless"),
]
def test_a_refused_channel_commit_does_not_restart_wifi():
ap = _Ap({_uci("commit", "wireless"): IO_ERROR})
with pytest.raises(CommandErrorException, match="I/O error"):
_driver(ap).push_radio_channel("radio0", 6)
_driver(ap).set_radio_channels({"radio0": 6})
assert "wifi" not in ap.commands
@@ -292,7 +335,12 @@ def test_a_refused_channel_commit_does_not_restart_wifi():
def test_a_failed_wifi_restart_raises_naming_it():
ap = _Ap({"wifi": CommandResult("", "", 1)})
with pytest.raises(CommandErrorException, match="`wifi`.*exit status 1"):
_driver(ap).push_radio_channel("radio0", 6)
_driver(ap).set_radio_channels({"radio0": 6})
def test_the_undeclared_channel_write_is_gone():
"""``set_radio_channels`` replaces it; nothing calls a name the contract lacks."""
assert not hasattr(OpenWrtDriver, "push_radio_channel")
@pytest.mark.parametrize("mode", ["deny", "Blacklist", "disable", ""])