fix(dhcp): raise when the Kea reservation search fails
create_dhcp_reservation searched for an existing reservation so a retry updates it, but a failed search was logged at debug level and the add went ahead: a write based on a read that did not happen. Raise a RuntimeError naming searchReservation before anything is written. Closes #40
This commit is contained in:
1 parent
901df1b523
commit
0f730a4b9d
3 files changed
+39
-6
No files matched your search
@@ -1453,7 +1453,8 @@ class OPNsenseDriver(
|
||||
:param hostname: optional hostname to record on the reservation.
|
||||
:raises ValueError: if no Kea subnet contains ``ip``.
|
||||
:raises RuntimeError: if Kea rejects the reservation (validation
|
||||
errors), the Kea plugin isn't installed/enabled, or ``ip`` is
|
||||
errors), the Kea plugin isn't installed/enabled, the search for an
|
||||
existing reservation fails (nothing is written then), or ``ip`` is
|
||||
already reserved for another MAC (left untouched; the caller decides).
|
||||
"""
|
||||
try:
|
||||
@@ -1514,12 +1515,12 @@ class OPNsenseDriver(
|
||||
|
||||
def _kea_own_reservation(self, ip: str, mac: str) -> dict[str, Any] | None:
|
||||
"""*mac*'s reservation for *ip*, updated in place on a retry; raises if another
|
||||
MAC holds *ip* (#26)."""
|
||||
MAC holds *ip* (#26) or the search fails (#40)."""
|
||||
try:
|
||||
own, other = split_by_mac(self._kea_reservations_at(ip), mac)
|
||||
except Exception as exc:
|
||||
logger.debug("Kea reservation search failed, proceeding to add: %s", exc)
|
||||
return None
|
||||
rows = self._kea_reservations_at(ip)
|
||||
except RequestException as exc:
|
||||
raise RuntimeError(f"Kea searchReservation for {ip} failed: {exc}") from exc
|
||||
own, other = split_by_mac(rows, mac)
|
||||
if own is None and other:
|
||||
raise RuntimeError(f"Kea already reserves {ip} for {other}, not {normalize_mac(mac)}")
|
||||
return own
|
||||
|
||||
Reference in new issue
Block a user