fix: leave an unchanged Kea reservation and Kea alone
CI / test (3.10) (push) Successful in 35s
CI / test (3.11) (push) Successful in 32s
CI / test (3.12) (push) Successful in 34s
CI / test (3.10) (pull_request) Successful in 31s
CI / test (3.11) (pull_request) Successful in 30s
CI / test (3.12) (pull_request) Successful in 34s
CI / test (3.10) (push) Successful in 35s
CI / test (3.11) (push) Successful in 32s
CI / test (3.12) (push) Successful in 34s
CI / test (3.10) (pull_request) Successful in 31s
CI / test (3.11) (pull_request) Successful in 30s
CI / test (3.12) (pull_request) Successful in 34s
create_dhcp_reservation rewrote an existing reservation and called service/reconfigure even when it already held exactly what was asked, e.g. on a retried provisioning job. reconfigure stops and starts Kea (the Kea service controller keeps reconfigureForceRestart() = true and configd has no reload action), which once left a firewall without DHCP. A reservation whose subnet, MAC (normalised), IP, hostname and description already match is now left alone. Refs NetOrk/netork#1187
This commit is contained in:
1 parent
6a91f43fc3
commit
59796b3fa1
2 files changed
+115
-2
No files matched your search
@@ -1787,6 +1787,83 @@ class TestCreateDhcpReservation:
|
||||
== "https://opnsense.example.com/api/kea/dhcpv4/setReservation/existing-uuid-456"
|
||||
)
|
||||
|
||||
# A reconfigure stops and starts Kea (ApiMutableServiceControllerBase,
|
||||
# reconfigureForceRestart() is true for Kea). Writing a reservation that
|
||||
# is already there, and restarting the daemon for it, once left a
|
||||
# firewall without DHCP (#1187) -- so an unchanged one is not touched.
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"subnet",
|
||||
["172.22.8.0/24", "6854cab3-ebb5-4031-b987-0edcc6723546"],
|
||||
ids=["subnet-as-cidr", "subnet-as-uuid"],
|
||||
)
|
||||
def test_unchanged_reservation_is_neither_written_nor_reconfigured(self, driver, subnet):
|
||||
driver.session.get.return_value = _make_json_response(KEA_SUBNETS_RESPONSE)
|
||||
driver.session.post.side_effect = [
|
||||
_make_json_response(
|
||||
{
|
||||
"rows": [
|
||||
{
|
||||
"uuid": "existing-uuid-456",
|
||||
"subnet": subnet,
|
||||
"ip_address": "172.22.8.253",
|
||||
# Kea keeps the MAC as it was entered -- case and
|
||||
# separator do not make it a different reservation.
|
||||
"hw_address": "02-AA-BB-CC-DD-EE",
|
||||
"hostname": "new-vm",
|
||||
"description": "[netork]",
|
||||
}
|
||||
]
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
driver.create_dhcp_reservation(
|
||||
mac="02:aa:bb:cc:dd:ee", ip="172.22.8.253", hostname="new-vm"
|
||||
)
|
||||
|
||||
# searchReservation only -- no setReservation, no service/reconfigure.
|
||||
assert driver.session.post.call_count == 1
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"field, live_value",
|
||||
[
|
||||
("hw_address", "02:aa:bb:cc:dd:ff"),
|
||||
("hostname", "old-vm"),
|
||||
("description", "made by hand"),
|
||||
("subnet", "172.22.0.0/24"),
|
||||
],
|
||||
)
|
||||
def test_reservation_differing_in_one_field_is_written_and_reconfigured(
|
||||
self, driver, field, live_value
|
||||
):
|
||||
row = {
|
||||
"uuid": "existing-uuid-456",
|
||||
"subnet": "172.22.8.0/24",
|
||||
"ip_address": "172.22.8.253",
|
||||
"hw_address": "02:aa:bb:cc:dd:ee",
|
||||
"hostname": "new-vm",
|
||||
"description": "[netork]",
|
||||
}
|
||||
row[field] = live_value
|
||||
driver.session.get.return_value = _make_json_response(KEA_SUBNETS_RESPONSE)
|
||||
driver.session.post.side_effect = [
|
||||
_make_json_response({"rows": [row]}),
|
||||
_make_json_response({"result": "saved", "uuid": "existing-uuid-456"}),
|
||||
_make_json_response({"status": "ok"}),
|
||||
]
|
||||
|
||||
driver.create_dhcp_reservation(
|
||||
mac="02:aa:bb:cc:dd:ee", ip="172.22.8.253", hostname="new-vm"
|
||||
)
|
||||
|
||||
paths = [c.args[0] for c in driver.session.post.call_args_list]
|
||||
assert paths == [
|
||||
"https://opnsense.example.com/api/kea/dhcpv4/searchReservation",
|
||||
"https://opnsense.example.com/api/kea/dhcpv4/setReservation/existing-uuid-456",
|
||||
"https://opnsense.example.com/api/kea/service/reconfigure",
|
||||
]
|
||||
|
||||
def test_raises_when_ip_not_in_any_kea_subnet(self, driver):
|
||||
driver.session.get.return_value = _make_json_response(KEA_SUBNETS_RESPONSE)
|
||||
|
||||
|
||||
Reference in new issue
Block a user