fix: get_dhcp_leases raises when no lease source answered (#27) #29

Merged
christianmanivong merged 1 commits from fix/dhcp-leases-raise-when-unread into master 2026-10-20 23:36:59 +00:00
Owner

Summary

When Kea, ISC DHCP and the ARP fallback all failed, get_dhcp_leases() returned [], which a caller cannot tell from a server with no leases. netOrk is changing its poll so that an empty answer clears the stored leases (NetOrk/netork#1189); with the old behaviour an API outage would wipe them. The driver now raises when nothing could be read.

Changes

  • get_dhcp_leases() records which sources answered and why the others failed; raises RuntimeError("No DHCP lease source answered -- Kea: …; ISC DHCP: …; ARP table: …") instead of return [].
  • Rule (in the docstring): Kea/ISC leases first; else the ARP rows (state: "arp"); [] only when a lease source answered empty; both lease sources failed and ARP failed or empty → raise (ARP rows are no lease data).
  • New tests/unit/test_dhcp_leases.py (9 cases).

Related Issue

Closes #27

Testing

  • Driver suite: 441 passed (the two "nothing answered" cases red before).
  • netOrk: a real OPNsenseDriver with every request failing gives dhcp_leases: None in the poll, so stored leases are kept; 321 related netOrk tests passed.
## Summary When Kea, ISC DHCP and the ARP fallback all failed, `get_dhcp_leases()` returned `[]`, which a caller cannot tell from a server with no leases. netOrk is changing its poll so that an empty answer clears the stored leases (NetOrk/netork#1189); with the old behaviour an API outage would wipe them. The driver now raises when nothing could be read. ## Changes - `get_dhcp_leases()` records which sources answered and why the others failed; raises `RuntimeError("No DHCP lease source answered -- Kea: …; ISC DHCP: …; ARP table: …")` instead of `return []`. - Rule (in the docstring): Kea/ISC leases first; else the ARP rows (`state: "arp"`); `[]` only when a lease source answered empty; both lease sources failed and ARP failed or empty → raise (ARP rows are no lease data). - New `tests/unit/test_dhcp_leases.py` (9 cases). ## Related Issue Closes #27 ## Testing - Driver suite: 441 passed (the two "nothing answered" cases red before). - netOrk: a real `OPNsenseDriver` with every request failing gives `dhcp_leases: None` in the poll, so stored leases are kept; 321 related netOrk tests passed.
christianmanivong added 1 commit 2026-10-20 23:02:27 +00:00
fix: get_dhcp_leases raises when no lease source answered (#27)
CI / test (3.10) (push) Successful in 32s
CI / test (3.11) (push) Successful in 34s
CI / test (3.12) (push) Successful in 33s
CI / test (3.10) (pull_request) Successful in 32s
CI / test (3.11) (pull_request) Successful in 29s
CI / test (3.12) (pull_request) Successful in 34s
5a6e573300
When Kea, ISC DHCP and the ARP fallback all failed, get_dhcp_leases()
returned [], which a caller cannot tell from a server with no leases. It now
raises a RuntimeError naming each failure, and returns [] only when a source
answered with nothing. An empty ARP table after both lease sources failed
counts as unread too, since ARP rows are no lease data.

Closes #27
christianmanivong merged commit 692a584fd2 into master 2026-10-20 23:36:59 +00:00
christianmanivong deleted branch fix/dhcp-leases-raise-when-unread 2026-10-20 23:36:59 +00:00
Sign in to join this conversation.