apply_dhcp_subnetset called apply_dhcp_subnet for every add and update and committed only at the end. A refused write raised out of the generator before commit_dhcp_subnets(): the subnets written ahead of it stayed saved but inactive, and because the device then reports them as configured, the next diff was empty and nothing ever committed them.
Fix
The subnet apply now behaves like apply_dhcp_reservationset since 4.35.1:
a refused subnet gets a [failed] <cidr>: <device message> line and the others are still written (adds, then updates, as before);
any non-empty diff is committed, even one whose every write was refused, so writes an earlier interrupted run saved take effect;
then DhcpApplyError(failed, attempted, "subnet") is raised.
An empty diff still does not commit. DhcpApplyError gains an optional kind (default "reservation", so existing callers and messages are unchanged) that its message names: "1 of 3 DHCP subnet change(s) were refused". It stays a RuntimeError.
CHANGELOG under [Unreleased] → Fixed; no version bump.
Tests
Fixtures only. tests/test_dhcp_subnet_diff_apply.py, a fake server refusing chosen CIDRs:
a refused subnet does not stop the others;
what was written is committed; a set whose every write is refused still commits;
the exact progress lines ([add], [failed] with the reason, [update] with its fields, commit counts), and the error's failed/attempted and message;
a refused update is counted like an add.
All five failed before the change (the first refusal raised RuntimeError out of the generator, nothing was committed). Full suite 1637 passed, 3 skipped, coverage 96.9 %; ruff, mypy, napalm-standard check and ratchet green.
## What was wrong
`apply_dhcp_subnetset` called `apply_dhcp_subnet` for every add and update and committed only at the end. A refused write raised out of the generator before `commit_dhcp_subnets()`: the subnets written ahead of it stayed saved but inactive, and because the device then reports them as configured, the next diff was empty and nothing ever committed them.
## Fix
The subnet apply now behaves like `apply_dhcp_reservationset` since 4.35.1:
- a refused subnet gets a `[failed] <cidr>: <device message>` line and the others are still written (adds, then updates, as before);
- any non-empty diff is committed, even one whose every write was refused, so writes an earlier interrupted run saved take effect;
- then `DhcpApplyError(failed, attempted, "subnet")` is raised.
An empty diff still does not commit. `DhcpApplyError` gains an optional `kind` (default `"reservation"`, so existing callers and messages are unchanged) that its message names: "1 of 3 DHCP subnet change(s) were refused". It stays a `RuntimeError`.
CHANGELOG under `[Unreleased]` → Fixed; no version bump.
## Tests
Fixtures only. `tests/test_dhcp_subnet_diff_apply.py`, a fake server refusing chosen CIDRs:
- a refused subnet does not stop the others;
- what was written is committed; a set whose every write is refused still commits;
- the exact progress lines (`[add]`, `[failed]` with the reason, `[update]` with its fields, commit counts), and the error's `failed`/`attempted` and message;
- a refused update is counted like an add.
All five failed before the change (the first refusal raised `RuntimeError` out of the generator, nothing was committed). Full suite 1637 passed, 3 skipped, coverage 96.9 %; ruff, mypy, `napalm-standard check` and `ratchet` green.
Closes #113
apply_dhcp_subnetset called apply_dhcp_subnet for each add and update
and committed only at the end, so one refused write raised before the
commit: the subnets written ahead of it stayed saved but inactive, and
as the device reports them as configured, no later diff committed them.
It now behaves like apply_dhcp_reservationset since 4.35.1: a refused
subnet gets a [failed] line, the others are written, any non-empty diff
is committed, then DhcpApplyError is raised. DhcpApplyError takes an
optional kind ("reservation" by default) for its message.
Closes#113
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What was wrong
apply_dhcp_subnetsetcalledapply_dhcp_subnetfor every add and update and committed only at the end. A refused write raised out of the generator beforecommit_dhcp_subnets(): the subnets written ahead of it stayed saved but inactive, and because the device then reports them as configured, the next diff was empty and nothing ever committed them.Fix
The subnet apply now behaves like
apply_dhcp_reservationsetsince 4.35.1:[failed] <cidr>: <device message>line and the others are still written (adds, then updates, as before);DhcpApplyError(failed, attempted, "subnet")is raised.An empty diff still does not commit.
DhcpApplyErrorgains an optionalkind(default"reservation", so existing callers and messages are unchanged) that its message names: "1 of 3 DHCP subnet change(s) were refused". It stays aRuntimeError.CHANGELOG under
[Unreleased]→ Fixed; no version bump.Tests
Fixtures only.
tests/test_dhcp_subnet_diff_apply.py, a fake server refusing chosen CIDRs:[add],[failed]with the reason,[update]with its fields, commit counts), and the error'sfailed/attemptedand message;All five failed before the change (the first refusal raised
RuntimeErrorout of the generator, nothing was committed). Full suite 1637 passed, 3 skipped, coverage 96.9 %; ruff, mypy,napalm-standard checkandratchetgreen.Closes #113
apply_dhcp_subnetset called apply_dhcp_subnet for each add and update and committed only at the end, so one refused write raised before the commit: the subnets written ahead of it stayed saved but inactive, and as the device reports them as configured, no later diff committed them. It now behaves like apply_dhcp_reservationset since 4.35.1: a refused subnet gets a [failed] line, the others are written, any non-empty diff is committed, then DhcpApplyError is raised. DhcpApplyError takes an optional kind ("reservation" by default) for its message. Closes #113