fix(dhcp): a refused subnet no longer stops the rest of the set #114

Merged
christianmanivong merged 1 commits from fix/dhcp-subnet-apply-tolerance into main 2026-11-12 19:06:13 +00:00
Owner

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

## 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
christianmanivong added 1 commit 2026-11-12 18:19:13 +00:00
fix(dhcp): a refused subnet no longer stops the rest of the set
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m19s
driver / test (3.12) (pull_request) Successful in 1m32s
driver / test (3.13) (pull_request) Successful in 1m16s
driver / lowest (pull_request) Successful in 41s
driver / build (pull_request) Successful in 35s
driver / security (pull_request) Successful in 1m13s
CI / driver (pull_request) Successful in 3m15s
driver / publish (pull_request) Skipped
65991d0930
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
christianmanivong merged commit 1b04818982 into main 2026-11-12 19:06:13 +00:00
christianmanivong deleted branch fix/dhcp-subnet-apply-tolerance 2026-11-12 19:06:13 +00:00
Sign in to join this conversation.