feat(time-sync): DHCP-provided NTP servers count and are read apart (4.36.0) #105

Merged
christianmanivong merged 2 commits from feat/time-sync-dhcp-ntp-2380 into main 2026-11-11 21:25:28 +00:00
Owner

Summary

DHCP option 42 counts (NetOrk/netork#2380, decided 2026-11-11): a device that gets the site's time giver by DHCP is aligned, so the drivers stop switching DHCP-provided NTP off, and the reading tells configured and DHCP-provided servers apart.

  • TimeSyncDict.dhcp_ntp_servers: NotRequired[list[str] | None] -- the servers the device got by DHCP and uses, in its order; [] = none; absent/None = the driver cannot tell. ntp_servers stays "configured on the device" and no longer holds DHCP's.
  • PosixTimeSyncMixin reads them:
    • chrony: the files in the DHCP client's sourcedir (CHRONY_DHCP_DIRS, default /run/chrony-dhcp, /var/run/chrony-dhcp) in the order chronyd reads them -- the files, not chronyc -n sources, because chronyc cannot say which source came from which directory. A DHCP sourcedir that is commented out prints no files, so it reads [].
    • systemd-timesyncd: LinkNTPServers of timedatectl show-timesync (timesyncd_link_servers, public). timesyncd_servers now returns runtime + system servers only; the fallback only while there is no server at all, a link's included.
    • ntpd / OpenNTPD: None (their DHCP hooks keep a configuration of their own that is not read); no client: [].
  • Writing chrony: only server / pool / peer lines are commented out; no sourcedir line any more, and the DHCP client's files are left alone. systemd-timesyncd: a link's servers stay and no longer fail verify.
  • Repair of 4.35.0 writes: a #napalm-time-sync: sourcedir <dhcp dir> line in the main configuration is uncommented on the next write (restore_command, a sed on that line number), and chronyd restarts since its main configuration changed. A non-DHCP sourcedir 4.35.0 took out stays out -- its sources would be commented out now anyway.
  • time_sync.py drops from __future__ import annotations: TypedDict only recognises NotRequired from an evaluated annotation.
  • Version 4.36.0, CHANGELOG, README.

Related Issue

Part of NetOrk/netork#2380 (epic NetOrk/netork#2360). napalm-openwrt's PR builds on this and needs the 4.36.0 release.

Testing

TDD: contract tests (__optional_keys__, verify ignores DHCP servers) and POSIX tests (real sh, sed, install over a directory tree) written first and seen red.

  • pytest -q --cov: 1608 passed, 2 skipped, total coverage 97%; _chrony.py, _time_sync_reading.py, time_sync.py, time_sync_posix.py at 100%.
  • ruff format --check, ruff check, mypy --strict: clean.
  • napalm-standard check: meets the standard; napalm-standard ratchet: within the baseline.
## Summary DHCP option 42 counts (NetOrk/netork#2380, decided 2026-11-11): a device that gets the site's time giver by DHCP is aligned, so the drivers stop switching DHCP-provided NTP off, and the reading tells configured and DHCP-provided servers apart. - `TimeSyncDict.dhcp_ntp_servers: NotRequired[list[str] | None]` -- the servers the device got by DHCP and uses, in its order; `[]` = none; absent/None = the driver cannot tell. `ntp_servers` stays "configured on the device" and no longer holds DHCP's. - `PosixTimeSyncMixin` reads them: - chrony: the files in the DHCP client's `sourcedir` (`CHRONY_DHCP_DIRS`, default `/run/chrony-dhcp`, `/var/run/chrony-dhcp`) in the order chronyd reads them -- the files, not `chronyc -n sources`, because chronyc cannot say which source came from which directory. A DHCP `sourcedir` that is commented out prints no files, so it reads `[]`. - systemd-timesyncd: `LinkNTPServers` of `timedatectl show-timesync` (`timesyncd_link_servers`, public). `timesyncd_servers` now returns runtime + system servers only; the fallback only while there is no server at all, a link's included. - ntpd / OpenNTPD: None (their DHCP hooks keep a configuration of their own that is not read); no client: `[]`. - Writing chrony: only `server` / `pool` / `peer` lines are commented out; no `sourcedir` line any more, and the DHCP client's files are left alone. systemd-timesyncd: a link's servers stay and no longer fail `verify`. - Repair of 4.35.0 writes: a `#napalm-time-sync: sourcedir <dhcp dir>` line in the main configuration is uncommented on the next write (`restore_command`, a `sed` on that line number), and chronyd restarts since its main configuration changed. A non-DHCP `sourcedir` 4.35.0 took out stays out -- its sources would be commented out now anyway. - `time_sync.py` drops `from __future__ import annotations`: TypedDict only recognises `NotRequired` from an evaluated annotation. - Version 4.36.0, CHANGELOG, README. ## Related Issue Part of NetOrk/netork#2380 (epic NetOrk/netork#2360). napalm-openwrt's PR builds on this and needs the 4.36.0 release. ## Testing TDD: contract tests (`__optional_keys__`, verify ignores DHCP servers) and POSIX tests (real `sh`, `sed`, `install` over a directory tree) written first and seen red. - `pytest -q --cov`: 1608 passed, 2 skipped, total coverage 97%; `_chrony.py`, `_time_sync_reading.py`, `time_sync.py`, `time_sync_posix.py` at 100%. - `ruff format --check`, `ruff check`, `mypy --strict`: clean. - `napalm-standard check`: meets the standard; `napalm-standard ratchet`: within the baseline.
christianmanivong added 1 commit 2026-11-11 21:09:10 +00:00
feat(time-sync): DHCP-provided NTP servers count and are read apart
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 31s
driver / types (pull_request) Successful in 1m16s
driver / test (3.13) (pull_request) Successful in 1m29s
driver / test (3.12) (pull_request) Successful in 1m33s
driver / lowest (pull_request) Successful in 41s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m5s
CI / driver (pull_request) Successful in 3m22s
driver / publish (pull_request) Skipped
ac38c68feb
A device that gets the site's time giver through DHCP option 42 is
aligned (NetOrk/netork#2380): most clients already learn it that way.
4.35.0 switched that off on every write -- chrony's DHCP sourcedir was
commented out, and systemd-timesyncd's link servers failed the verify
step -- and folded DHCP's servers into ntp_servers, so an application
could not tell configured from DHCP-provided servers.

TimeSyncDict gains dhcp_ntp_servers (not required): the servers the
device got by DHCP and uses, in its order; [] for none, absent or None
where the driver cannot tell. ntp_servers keeps only the configured ones.

PosixTimeSyncMixin reads chrony's sources from the DHCP client's
sourcedir (CHRONY_DHCP_DIRS, /run/chrony-dhcp by default) as chronyd
reads them, and systemd-timesyncd's LinkNTPServers; ntpd and OpenNTPD
keep DHCP's servers in a configuration of their own, so there it is
unknown. A chrony write now comments out only server, pool and peer
lines and leaves every sourcedir and the DHCP client's files alone. A
DHCP sourcedir that 4.35.0 commented out behind the mark is given back
on the next write, with a restart, so hosts it aligned hear DHCP again.

Version 4.36.0.
christianmanivong added 1 commit 2026-11-11 21:21:35 +00:00
Merge remote-tracking branch 'origin/main' into feat/time-sync-dhcp-ntp-2380
driver / lint (pull_request) Successful in 15s
driver / standard (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m34s
driver / test (3.13) (pull_request) Successful in 1m32s
driver / test (3.12) (pull_request) Successful in 1m52s
driver / lowest (pull_request) Successful in 1m3s
driver / build (pull_request) Successful in 48s
driver / security (pull_request) Successful in 1m26s
CI / driver (pull_request) Successful in 3m17s
driver / publish (pull_request) Skipped
bc47220318
# Conflicts:
#	CHANGELOG.md
#	pyproject.toml
christianmanivong merged commit aaa9f0504a into main 2026-11-11 21:25:28 +00:00
christianmanivong deleted branch feat/time-sync-dhcp-ntp-2380 2026-11-11 21:25:28 +00:00
Sign in to join this conversation.