Skip to content

Commit 1343496

Browse files
committed
fix(kea driver): fix reservation removal using list.pop instead of remove
list.pop() expects an index, not a value; passing the reservation dict raised TypeError, silently swallowed by the broad except clause, so clean_dhcp_opts never actually removed reservations.
1 parent 64462f6 commit 1343496

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

python/ironic-understack/ironic_understack/dhcp/kea.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _update_host_reservation(self, hw_address, boot_file_prefix=None, remove=Fal
120120
reservation["client-classes"] = ["BOOTSRV_A"]
121121
else:
122122
print(f"REMOVING RESERVATION: {reservation}")
123-
reservations.pop(reservation)
123+
reservations.remove(reservation)
124124
found = True
125125
break
126126
if not found:

python/ironic-understack/ironic_understack/tests/test_dhcp_kea.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,28 @@ def test_make_request_succeeds_on_first_attempt(kea, mocker):
6868

6969
assert result == {"result": 0}
7070
assert post.call_count == 1
71+
72+
73+
def test_update_host_reservation_removes_existing_entry(kea, mocker):
74+
other_reservation = {
75+
"hw-address": "aa:aa:aa:aa:aa:aa",
76+
"client-classes": ["BOOTSRV_A"],
77+
}
78+
target_reservation = {
79+
"hw-address": "bb:bb:bb:bb:bb:bb",
80+
"client-classes": ["BOOTSRV_A"],
81+
}
82+
config = {
83+
"arguments": {
84+
"hash": "somehash",
85+
"Dhcp4": {"reservations": [other_reservation, target_reservation]},
86+
}
87+
}
88+
mocker.patch.object(kea, "get_config", return_value=config)
89+
set_config = mocker.patch.object(kea, "set_config")
90+
91+
result = kea._update_host_reservation("bb:bb:bb:bb:bb:bb", remove=True)
92+
93+
assert result is True
94+
sent_config = set_config.call_args[0][0]
95+
assert sent_config["Dhcp4"]["reservations"] == [other_reservation]

0 commit comments

Comments
 (0)