diff --git a/CHANGELOG.md b/CHANGELOG.md index db29251..2d8a08f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ recorded here; their history is the git log. ## [Unreleased] +### Added +- `RadioStatusDict` carries a radio's runtime state beside its configuration + (NetOrk/netork#31): `up` (the radio runs), `pending` (the device is still bringing it + up or down) and `setup_failed` (the device gave up bringing it up after its retries). + All three are optional: a driver that cannot read the state leaves them out. A radio + can be `enabled` and not run, as on 2026-07-16, when a rejected value kept every radio + of a fleet in a restart loop the configuration never showed. + ## [4.48.0] - 2026-11-27 ### Added diff --git a/napalm_device_types/access_point_models.py b/napalm_device_types/access_point_models.py new file mode 100644 index 0000000..324c8d5 --- /dev/null +++ b/napalm_device_types/access_point_models.py @@ -0,0 +1,115 @@ +"""The shapes an access point's getters return (models.py's Access Point part). + +Apart from ``models.py`` for its size; ``models`` re-exports each, so +``napalm_device_types.models.RadioStatusDict`` stays where callers import it. +""" + +from typing import NotRequired + +from typing_extensions import TypedDict + + +class WirelessClientDict(TypedDict): + mac: str + ssid: str + radio: str + signal: int + noise: int + tx_rate: float + rx_rate: float + uptime: int + # Optional fields populated by DHCP cross-reference (e.g. from firewall) + ip: NotRequired[str] + hostname: NotRequired[str] + lease_end: NotRequired[int] # Unix timestamp when DHCP lease expires + + +class SSIDDict(TypedDict): + enabled: bool + radio: str + bssid: str + encryption: str + hidden: bool + clients: int + + +class RadioStatusDict(TypedDict): + """One radio: ``enabled`` is the configuration, the rest what the radio does. + + The runtime state is left out where the driver cannot read it, never guessed + (NetOrk/netork#31): ``up`` whether the radio runs, ``pending`` whether the + device is still bringing it up or down, ``setup_failed`` whether the device + gave up bringing it up after its retries. + """ + + enabled: bool + band: str + channel: int + channel_width: int + tx_power: int + frequency: float + up: NotRequired[bool] + pending: NotRequired[bool] + setup_failed: NotRequired[bool] + + +class ChannelScanEntryDict(TypedDict): + """One neighboring AP entry as returned by get_channel_scan().""" + + bssid: str + ssid: str + frequency: int # centre frequency in MHz, e.g. 2437 + channel: int # channel number, e.g. 6 + signal_dbm: int # RSSI in dBm, e.g. -72 + channel_width: int # MHz: 20 / 40 / 80 / 160; 0 if unknown + band: str # "2.4GHz" | "5GHz" | "6GHz" + + +class WirelessConfigDict(TypedDict): + country_code: str + regulatory_domain: str + beacon_interval: int + dtim_period: int + rts_threshold: int + fragmentation_threshold: int + short_preamble: bool + wmm_enabled: bool + + +class FastTransitionConfigDict(TypedDict): + enabled: bool + ssid: str + mobility_domain: str + reassociation_deadline: int + r0_key_lifetime: int + r1_key_holder: str + pmk_r1_push: bool + over_ds: bool + + +class MeshPeerDict(TypedDict): + mac: str + radio: str + signal: int + tx_rate: float + rx_rate: float + uptime: int + hop_count: int + + +class MeshConfigDict(TypedDict): + enabled: bool + radio: str + mesh_id: str + path_metric: str + gate_announcements: bool + is_gate: bool + encryption: str + + +class SSIDBridgeDict(TypedDict): + ssid: str + bridge: str + vlan_id: int + tagged: bool + client_isolation: bool diff --git a/napalm_device_types/models.py b/napalm_device_types/models.py index f6b21cc..18b3bb5 100644 --- a/napalm_device_types/models.py +++ b/napalm_device_types/models.py @@ -8,7 +8,19 @@ from typing import Literal, NotRequired, get_args from typing_extensions import TypedDict -# The SNMP health profile shapes live in snmp_health_profile.py; re-exported here, where they were. +# The SNMP health profile shapes live in snmp_health_profile.py, those of the access +# point getters in access_point_models.py; re-exported here, where they were. +from napalm_device_types.access_point_models import ChannelScanEntryDict as ChannelScanEntryDict +from napalm_device_types.access_point_models import ( + FastTransitionConfigDict as FastTransitionConfigDict, +) +from napalm_device_types.access_point_models import MeshConfigDict as MeshConfigDict +from napalm_device_types.access_point_models import MeshPeerDict as MeshPeerDict +from napalm_device_types.access_point_models import RadioStatusDict as RadioStatusDict +from napalm_device_types.access_point_models import SSIDBridgeDict as SSIDBridgeDict +from napalm_device_types.access_point_models import SSIDDict as SSIDDict +from napalm_device_types.access_point_models import WirelessClientDict as WirelessClientDict +from napalm_device_types.access_point_models import WirelessConfigDict as WirelessConfigDict from napalm_device_types.snmp_health_profile import SnmpHealthProfile as SnmpHealthProfile from napalm_device_types.snmp_health_profile import SnmpInterfacesSpec as SnmpInterfacesSpec from napalm_device_types.snmp_health_profile import SnmpMemorySpec as SnmpMemorySpec @@ -130,101 +142,6 @@ class HostStatusDict(TypedDict): # --------------------------------------------------------------------------- -class WirelessClientDict(TypedDict): - mac: str - ssid: str - radio: str - signal: int - noise: int - tx_rate: float - rx_rate: float - uptime: int - # Optional fields populated by DHCP cross-reference (e.g. from firewall) - ip: NotRequired[str] - hostname: NotRequired[str] - lease_end: NotRequired[int] # Unix timestamp when DHCP lease expires - - -class SSIDDict(TypedDict): - enabled: bool - radio: str - bssid: str - encryption: str - hidden: bool - clients: int - - -class RadioStatusDict(TypedDict): - enabled: bool - band: str - channel: int - channel_width: int - tx_power: int - frequency: float - - -class ChannelScanEntryDict(TypedDict): - """One neighboring AP entry as returned by get_channel_scan().""" - - bssid: str - ssid: str - frequency: int # centre frequency in MHz, e.g. 2437 - channel: int # channel number, e.g. 6 - signal_dbm: int # RSSI in dBm, e.g. -72 - channel_width: int # MHz: 20 / 40 / 80 / 160; 0 if unknown - band: str # "2.4GHz" | "5GHz" | "6GHz" - - -class WirelessConfigDict(TypedDict): - country_code: str - regulatory_domain: str - beacon_interval: int - dtim_period: int - rts_threshold: int - fragmentation_threshold: int - short_preamble: bool - wmm_enabled: bool - - -class FastTransitionConfigDict(TypedDict): - enabled: bool - ssid: str - mobility_domain: str - reassociation_deadline: int - r0_key_lifetime: int - r1_key_holder: str - pmk_r1_push: bool - over_ds: bool - - -class MeshPeerDict(TypedDict): - mac: str - radio: str - signal: int - tx_rate: float - rx_rate: float - uptime: int - hop_count: int - - -class MeshConfigDict(TypedDict): - enabled: bool - radio: str - mesh_id: str - path_metric: str - gate_announcements: bool - is_gate: bool - encryption: str - - -class SSIDBridgeDict(TypedDict): - ssid: str - bridge: str - vlan_id: int - tagged: bool - client_isolation: bool - - class Dot1XConfigDict(TypedDict): """802.1X / WPA-Enterprise config for an access-point SSID.""" diff --git a/tests/quality_baseline.json b/tests/quality_baseline.json index 73db258..2591259 100644 --- a/tests/quality_baseline.json +++ b/tests/quality_baseline.json @@ -31,7 +31,7 @@ }, "mypy_relaxed": [], "python_file_lines": { - "napalm_device_types/models.py": 1436 + "napalm_device_types/models.py": 1353 }, "untyped_public": [] } diff --git a/tests/test_radio_runtime_state.py b/tests/test_radio_runtime_state.py new file mode 100644 index 0000000..0c43d2f --- /dev/null +++ b/tests/test_radio_runtime_state.py @@ -0,0 +1,29 @@ +"""A radio's runtime state beside its configuration (NetOrk/netork#31). + +A radio can be enabled in the configuration and still not run: the 2026-07-16 +incident put every radio of a fleet into a restart loop that the configuration +never showed. The state the device reports is three facts, each optional, +because a driver that cannot read it leaves it out rather than guessing. +""" + +from __future__ import annotations + +from typing import get_type_hints + +from napalm_device_types.models import RadioStatusDict + +RUNTIME = {"up", "pending", "setup_failed"} + + +def test_a_radio_may_say_whether_it_runs(): + hints = get_type_hints(RadioStatusDict) + assert RUNTIME <= set(hints) + assert all(hints[key] is bool for key in RUNTIME) + + +def test_the_runtime_state_is_optional(): + assert RUNTIME <= RadioStatusDict.__optional_keys__ + + +def test_the_configured_fields_stay_required(): + assert {"enabled", "band", "channel"} <= RadioStatusDict.__required_keys__