create_dhcp_reservation: a failed searchReservation is ignored and the reservation is added anyway #40

Closed
opened 2026-11-01 21:44:46 +00:00 by christianmanivong · 0 comments
Owner

What happens

create_dhcp_reservation (napalm_opnsense/opnsense.py 1433-1517) looks for an existing reservation for the IP so a retry updates it instead of adding a second one. If that search fails, it logs at debug level and goes on (line 1490):

logger.debug("Kea reservation search failed, proceeding to add: %s", exc)

With existing_row still None, it posts to /api/kea/dhcpv4/addReservation (line 1511). If a reservation for the IP exists — the case the search is there for (a retried VM provisioning, netOrk's _push_and_record_reservation) — the add is rejected and the caller gets "Kea rejected DHCP reservation for …" instead of the search error; if OPNsense's model accepts it, a second reservation for the same IP is written, which the code's own comment says Kea refuses to load. Either way the failed read is invisible (debug level) and a write follows a read that did not happen.

Related: #26 (the search matches on IP only). Separate cause.

Expected

A failed searchReservation raises (RuntimeError naming the search), before anything is written. Test-first: searchReservation raising → create_dhcp_reservation raises and never posts addReservation.

Priority: P3 — a write on the DHCP server based on a read that failed.

Found during the bug sweep of 2026-11-01.

## What happens `create_dhcp_reservation` (`napalm_opnsense/opnsense.py` 1433-1517) looks for an existing reservation for the IP so a retry updates it instead of adding a second one. If that search fails, it logs at debug level and goes on (line 1490): ```python logger.debug("Kea reservation search failed, proceeding to add: %s", exc) ``` With `existing_row` still `None`, it posts to `/api/kea/dhcpv4/addReservation` (line 1511). If a reservation for the IP exists — the case the search is there for (a retried VM provisioning, netOrk's `_push_and_record_reservation`) — the add is rejected and the caller gets "Kea rejected DHCP reservation for …" instead of the search error; if OPNsense's model accepts it, a second reservation for the same IP is written, which the code's own comment says Kea refuses to load. Either way the failed read is invisible (debug level) and a write follows a read that did not happen. Related: #26 (the search matches on IP only). Separate cause. ## Expected A failed `searchReservation` raises (`RuntimeError` naming the search), before anything is written. Test-first: `searchReservation` raising → `create_dhcp_reservation` raises and never posts `addReservation`. Priority: P3 — a write on the DHCP server based on a read that failed. Found during the bug sweep of 2026-11-01.
christianmanivong added the
prio
P3
bug
labels 2026-11-01 21:44:46 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-opnsense#40