fix(dhcp): declare DhcpLeasesMixin, answer in its shape (#53) #54

Merged
christianmanivong merged 1 commits from fix/declare-dhcp-leases-mixin into main 2026-12-05 06:07:50 +00:00
Owner

Closes #53

Declaring the mixin. OPNsenseDriver now declares napalm-device-types' DhcpLeasesMixin. It does so through OPNsenseDhcpLeasesMixin(DhcpLeasesMixin) in the new napalm_opnsense/dhcp_leases.py, the same pattern as OPNsenseTimeSyncMixin and OPNsenseScheduledJobsMixin. Contract tests and isinstance checks now find OPNsense.

  • get_dhcp_leases() moves there from opnsense.py and is typed -> list[DhcpLeaseDict]. The new module is under strict mypy, unlike opnsense.py, so mypy now checks the return shape against the declared contract.
  • It still reads the same sources in the same order: Kea, then ISC DHCP, then the ARP table fallback. The empty-answer and raise rules from #27 are unchanged. The method is split into small helpers, so opnsense.py shrinks from 3019 to 2914 lines and the baseline's get_dhcp_leases entries go away.
  • The floor is now napalm-device-types>=4.54.0.

Matching the declared shape.

  • A MAC is normalised to lower-case colon form with device-types' normalize_mac, so AA-BB-CC-DD-EE-01 reads as aa:bb:cc:dd:ee:01.
  • Kea's numeric state 0 is kept as "0". Before, it came out as "".
  • A Kea answer that is a plain list is read. Before, it raised AttributeError and counted as a failed source.
  • The ARP fallback rows stay as they are, with state: "arp". netOrk never stores them as leases.

Contract test: tests/unit/test_dhcp_leases_contract.py.

  • issubclass and isinstance against the mixin.
  • The method signature.
  • Every row from Kea, from ISC and from the ARP fallback has exactly the declared keys, each of its declared type, with a colon-form MAC.

CHANGELOG under [Unreleased]. Following this repo's practice, the version is bumped in a separate chore(release) commit, so it stays at 0.6.0 here.

Tests, run against napalm-device-types main plus #149:

  • Full suite: 654 passed, 86.05% coverage (floor 79). It took 30 minutes locally only because DNS lookups are slow on the test machine.
  • Also green: ruff check, ruff format --check, mypy napalm_opnsense, napalm-standard ratchet and napalm-standard check.

Priority: P4. The gap is only the declaration; netOrk calls the method either way.

Closes #53 **Declaring the mixin.** `OPNsenseDriver` now declares napalm-device-types' `DhcpLeasesMixin`. It does so through `OPNsenseDhcpLeasesMixin(DhcpLeasesMixin)` in the new `napalm_opnsense/dhcp_leases.py`, the same pattern as `OPNsenseTimeSyncMixin` and `OPNsenseScheduledJobsMixin`. Contract tests and `isinstance` checks now find OPNsense. - `get_dhcp_leases()` moves there from `opnsense.py` and is typed `-> list[DhcpLeaseDict]`. The new module is under strict mypy, unlike `opnsense.py`, so mypy now checks the return shape against the declared contract. - It still reads the same sources in the same order: Kea, then ISC DHCP, then the ARP table fallback. The empty-answer and raise rules from #27 are unchanged. The method is split into small helpers, so `opnsense.py` shrinks from 3019 to 2914 lines and the baseline's `get_dhcp_leases` entries go away. - The floor is now `napalm-device-types>=4.54.0`. **Matching the declared shape.** - A MAC is normalised to lower-case colon form with device-types' `normalize_mac`, so `AA-BB-CC-DD-EE-01` reads as `aa:bb:cc:dd:ee:01`. - Kea's numeric state `0` is kept as `"0"`. Before, it came out as `""`. - A Kea answer that is a plain list is read. Before, it raised `AttributeError` and counted as a failed source. - The ARP fallback rows stay as they are, with `state: "arp"`. netOrk never stores them as leases. **Contract test:** `tests/unit/test_dhcp_leases_contract.py`. - `issubclass` and `isinstance` against the mixin. - The method signature. - Every row from Kea, from ISC and from the ARP fallback has exactly the declared keys, each of its declared type, with a colon-form MAC. CHANGELOG under `[Unreleased]`. Following this repo's practice, the version is bumped in a separate `chore(release)` commit, so it stays at 0.6.0 here. Tests, run against napalm-device-types `main` plus #149: - Full suite: 654 passed, 86.05% coverage (floor 79). It took 30 minutes locally only because DNS lookups are slow on the test machine. - Also green: `ruff check`, `ruff format --check`, `mypy napalm_opnsense`, `napalm-standard ratchet` and `napalm-standard check`. Priority: P4. The gap is only the declaration; netOrk calls the method either way.
christianmanivong added 1 commit 2026-12-05 01:02:42 +00:00
fix(dhcp): declare DhcpLeasesMixin, answer in its shape (#53)
driver / lint (pull_request) Successful in 12s
driver / standard (pull_request) Successful in 15s
driver / lowest (pull_request) Successful in 33s
driver / types (pull_request) Successful in 54s
driver / test (3.12) (pull_request) Successful in 1m3s
driver / test (3.13) (pull_request) Successful in 55s
driver / build (pull_request) Successful in 25s
driver / security (pull_request) Successful in 56s
CI / driver (pull_request) Successful in 1m44s
driver / publish (pull_request) Skipped
1b9ed289d9
OPNsenseDriver implemented get_dhcp_leases without declaring
napalm-device-types' DhcpLeasesMixin, so contract tests and isinstance
checks missed it and nothing checked it against the declared signature.
It now lives in OPNsenseDhcpLeasesMixin(DhcpLeasesMixin), under strict
mypy and typed as DhcpLeaseDict; the floor is napalm-device-types
4.54.0.

Every row has the declared shape: the MAC normalised to lower-case
colon form, a numeric Kea state kept as its text, and a Kea answer that
is a plain list read instead of failing. The ARP fallback keeps its
state "arp" rows.
christianmanivong merged commit 3310074fa8 into main 2026-12-05 06:07:50 +00:00
christianmanivong deleted branch fix/declare-dhcp-leases-mixin 2026-12-05 06:07:50 +00:00
Sign in to join this conversation.