driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 56s
driver / test (3.12) (pull_request) Successful in 1m16s
driver / test (3.13) (pull_request) Successful in 1m4s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m45s
driver / publish (pull_request) Skipped
create_dhcp_reservation and delete_dhcp_reservation_and_lease looked a reservation up by its address alone. A reservation another MAC held for the address, made by hand or left from an earlier host, was overwritten on create and removed on delete, together with that host's lease. Create now raises instead of taking it over, and delete leaves another MAC's reservation and lease in place and names that MAC in the new reservation_other_mac field. The matching lives in kea_reservations, a module under strict typing. Closes #26
68 lines
2.7 KiB
Python
68 lines
2.7 KiB
Python
"""Matching Kea reservations and leases on address and MAC (#26)."""
|
|
|
|
from napalm_opnsense.kea_reservations import lease_held, reservation_unchanged, split_by_mac
|
|
|
|
|
|
def _row(mac, uuid="u-1"):
|
|
return {"uuid": uuid, "ip_address": "172.22.8.253", "hw_address": mac}
|
|
|
|
|
|
class TestSplitByMac:
|
|
def test_no_rows_is_neither_own_nor_other(self):
|
|
assert split_by_mac([], "02:aa:bb:cc:dd:ee") == (None, "")
|
|
|
|
def test_own_row_matches_whatever_the_mac_spelling(self):
|
|
row = _row("02-AA-BB-CC-DD-EE")
|
|
assert split_by_mac([row], "02:aa:bb:cc:dd:ee") == (row, "")
|
|
|
|
def test_another_hosts_row_is_reported_by_its_mac(self):
|
|
assert split_by_mac([_row("02-11-22-33-44-55")], "02:aa:bb:cc:dd:ee") == (
|
|
None,
|
|
"02:11:22:33:44:55",
|
|
)
|
|
|
|
def test_a_row_without_mac_is_no_ones(self):
|
|
"""It cannot be shown to be the caller's, so it is never taken as such."""
|
|
row = {"uuid": "u-1", "ip_address": "172.22.8.253"}
|
|
assert split_by_mac([row], "02:aa:bb:cc:dd:ee") == (None, "")
|
|
|
|
def test_another_hosts_mac_is_found_behind_a_row_without_one(self):
|
|
rows = [{"uuid": "u-0", "ip_address": "172.22.8.253"}, _row("02:11:22:33:44:55")]
|
|
assert split_by_mac(rows, "02:aa:bb:cc:dd:ee") == (None, "02:11:22:33:44:55")
|
|
|
|
|
|
class TestLeaseHeld:
|
|
def test_os_kea_lease_of_the_mac(self):
|
|
rows = [{"address": "172.22.8.253", "hwaddr": "02:AA:BB:CC:DD:EE"}]
|
|
assert lease_held(rows, "172.22.8.253", "02:aa:bb:cc:dd:ee") is True
|
|
|
|
def test_plain_kea_lease_of_the_mac(self):
|
|
rows = [{"ip-address": "172.22.8.253", "hw-address": "02:aa:bb:cc:dd:ee"}]
|
|
assert lease_held(rows, "172.22.8.253", "02:aa:bb:cc:dd:ee") is True
|
|
|
|
def test_lease_of_another_mac(self):
|
|
rows = [{"address": "172.22.8.253", "hwaddr": "02:11:22:33:44:55"}]
|
|
assert lease_held(rows, "172.22.8.253", "02:aa:bb:cc:dd:ee") is False
|
|
|
|
def test_lease_of_another_address(self):
|
|
rows = [{"address": "172.22.8.254", "hwaddr": "02:aa:bb:cc:dd:ee"}]
|
|
assert lease_held(rows, "172.22.8.253", "02:aa:bb:cc:dd:ee") is False
|
|
|
|
|
|
class TestReservationUnchanged:
|
|
WANTED = {
|
|
"subnet": "subnet-uuid",
|
|
"ip_address": "172.22.8.253",
|
|
"hw_address": "02:aa:bb:cc:dd:ee",
|
|
"hostname": "new-vm",
|
|
"description": "[netork]",
|
|
}
|
|
|
|
def test_a_different_mac_is_a_change(self):
|
|
row = dict(self.WANTED, hw_address="02:11:22:33:44:55")
|
|
assert reservation_unchanged(row, self.WANTED, "172.22.8.0/24") is False
|
|
|
|
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
|