refactor(dhcp): move the Kea subnet lookup into kea_reservations
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 17s
driver / types (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 1m17s
driver / test (3.13) (pull_request) Successful in 1m12s
driver / lowest (pull_request) Successful in 36s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m7s
CI / driver (pull_request) Successful in 2m56s
driver / publish (pull_request) Skipped

create_dhcp_reservation and _kea_subnet_uuid_for each walked the
searchSubnet rows for the one holding an address. Both now call the
pure subnet_containing(), which brings create_dhcp_reservation under
the complexity limit and back below its recorded length after #40;
the quality baseline records the shrunk entries.
This commit is contained in:
Christian Manivong committed 2026-11-02 08:51:21 +01:00
1 parent 96a4a139d0
commit 6ac7a6f6a2
4 files changed
+55 -26

No files matched your search

+2 -3
View File
@@ -10,7 +10,6 @@
"napalm_opnsense/opnsense.py::OPNsenseDriver._kea_read_list": 11,
"napalm_opnsense/opnsense.py::OPNsenseDriver.apply_dhcp_subnet": 21,
"napalm_opnsense/opnsense.py::OPNsenseDriver.apply_firewall_rule": 11,
"napalm_opnsense/opnsense.py::OPNsenseDriver.create_dhcp_reservation": 12,
"napalm_opnsense/opnsense.py::OPNsenseDriver.delete_dhcp_reservation_and_lease": 11,
"napalm_opnsense/opnsense.py::OPNsenseDriver.get_bgp_neighbors": 16,
"napalm_opnsense/opnsense.py::OPNsenseDriver.get_dhcp_leases": 15,
@@ -33,7 +32,7 @@
"function_lines": {
"napalm_opnsense/opnsense.py::OPNsenseDriver._regenerate_web_cert": 51,
"napalm_opnsense/opnsense.py::OPNsenseDriver.apply_dhcp_subnet": 60,
"napalm_opnsense/opnsense.py::OPNsenseDriver.create_dhcp_reservation": 72,
"napalm_opnsense/opnsense.py::OPNsenseDriver.create_dhcp_reservation": 64,
"napalm_opnsense/opnsense.py::OPNsenseDriver.delete_dhcp_reservation_and_lease": 79,
"napalm_opnsense/opnsense.py::OPNsenseDriver.get_bgp_neighbors": 86,
"napalm_opnsense/opnsense.py::OPNsenseDriver.get_dhcp_leases": 106,
@@ -56,7 +55,7 @@
"napalm_opnsense.resolver_mixin"
],
"python_file_lines": {
"napalm_opnsense/opnsense.py": 3064
"napalm_opnsense/opnsense.py": 3058
},
"untyped_public": [
"napalm_opnsense/opnsense.py::OPNsenseDriver.get_snmp_config"
+24 -1
View File
@@ -1,6 +1,11 @@
"""Matching Kea reservations and leases on address and MAC (#26)."""
from napalm_opnsense.kea_reservations import lease_held, reservation_unchanged, split_by_mac
from napalm_opnsense.kea_reservations import (
lease_held,
reservation_unchanged,
split_by_mac,
subnet_containing,
)
def _row(mac, uuid="u-1"):
@@ -65,3 +70,21 @@ class TestReservationUnchanged:
def test_the_same_reservation_is_unchanged(self):
row = dict(self.WANTED, hw_address="02-AA-BB-CC-DD-EE", subnet="172.22.8.0/24")
assert reservation_unchanged(row, self.WANTED, "172.22.8.0/24") is True
class TestSubnetContaining:
ROWS = [
{"uuid": "s-broken", "subnet": "not-a-cidr"},
{"uuid": "s-nocidr"},
{"uuid": "s-8", "subnet": " 172.22.8.0/24 "},
{"uuid": "s-wide", "subnet": "172.22.0.0/16"},
]
def test_first_subnet_holding_the_address_wins(self):
assert subnet_containing(self.ROWS, "172.22.8.253") == self.ROWS[2]
def test_rows_without_a_readable_subnet_are_skipped(self):
assert subnet_containing(self.ROWS, "172.22.9.1") == self.ROWS[3]
def test_none_when_no_subnet_holds_the_address(self):
assert subnet_containing(self.ROWS, "10.99.99.99") is None