test(time-sync): follow napalm-device-types 4.36.0, which keeps DHCP's servers

napalm-device-types 4.36.0 (released after main's last CI run) changed
PosixTimeSyncMixin: get_time_sync() reports DHCP-provided servers apart
(dhcp_ntp_servers), and configure_time_sync() no longer comments out the
DHCP client's chrony sourcedir; it gives back one that 4.35.0 took out
(NetOrk/netork#2380). CI installs the newest release, so five time-sync
tests failed on every branch.

The tests now expect that behaviour, read DHCP's servers apart, and check
that a node 4.35.0 aligned gets its DHCP sourcedir back. The floor moves
to 4.36.0, so the lowest-versions job tests the same behaviour; README,
CHANGELOG and the module docstring say what a write leaves alone.
This commit is contained in:
Christian Manivong committed 2026-11-13 08:55:37 +01:00
1 parent a67e8492ee
commit 83d1ef780e
5 files changed
+59 -18

No files matched your search

+45 -6
View File
@@ -69,12 +69,19 @@ _MARK = "#napalm-time-sync: "
def _reading(
zone: str = "Europe/Berlin", *, servers: tuple[str, ...] = (), timedatectl: bool = True
zone: str = "Europe/Berlin",
*,
servers: tuple[str, ...] = (),
dhcp: tuple[str, ...] = (),
deaf_to_dhcp: bool = False,
timedatectl: bool = True,
) -> str:
"""What the reading prints; *servers* in netOrk's sources file, the vendor's pool
commented out with it (as a write leaves the host)."""
commented out with it (as a write leaves the host), *dhcp* in the DHCP client's
sources file. *deaf_to_dhcp* is a host napalm-device-types 4.35.0 aligned: its write
commented out the DHCP ``sourcedir`` too."""
written = bool(servers)
conf = _CHRONY_CONF.format(pool=_MARK if written else "", dhcp=_MARK if written else "")
conf = _CHRONY_CONF.format(pool=_MARK if written else "", dhcp=_MARK if deaf_to_dhcp else "")
parts = ["@@ts timedatectl"]
if timedatectl:
parts += [
@@ -89,6 +96,10 @@ def _reading(
parts += ["@@ts zone", zone if timedatectl else ""]
parts += ["@@ts active", _ACTIVE_CHRONY, "@@ts timesync", "@@ts chronyc", _CHRONYC_SYNCED]
parts += ["@@ts chrony 0 main /etc/chrony/chrony.conf", conf, ""]
if dhcp:
parts += ["@@ts chrony 11 sourcedir /run/chrony-dhcp/vmbr0.sources"]
parts += [f"server {s} iburst" for s in dhcp]
parts += [""]
if written:
parts += ["@@ts chrony 14 sourcedir /etc/chrony/sources.d/netork.sources"]
parts += [f"{'pool' if '.pool.' in s else 'server'} {s} iburst" for s in servers]
@@ -169,6 +180,7 @@ def test_pve_reads_chrony_and_the_zone_in_one_round_trip() -> None:
assert driver.get_time_sync() == {
"ntp_servers": ["2.debian.pool.ntp.org"],
"dhcp_ntp_servers": [],
"timezone": "Europe/Berlin",
"synchronized": True,
"daemon": "chrony",
@@ -183,6 +195,7 @@ def test_pbs_reads_chrony_and_the_zone() -> None:
assert driver.get_time_sync() == {
"ntp_servers": ["10.0.0.1"],
"dhcp_ntp_servers": [],
"timezone": "Europe/Vienna",
"synchronized": True,
"daemon": "chrony",
@@ -191,6 +204,17 @@ def test_pbs_reads_chrony_and_the_zone() -> None:
assert not [c for c in api.calls if c[0] != "GET"]
def test_servers_from_dhcp_are_read_apart_from_the_configured_ones() -> None:
"""A node that gets its time giver by DHCP (option 42): chrony reads the DHCP
client's sources file, and those servers are not the node's own (NetOrk/netork#2380)."""
driver, _, _ = _pve(_reading(dhcp=("192.168.1.1",)))
reading = driver.get_time_sync()
assert reading["ntp_servers"] == ["2.debian.pool.ntp.org"]
assert reading["dhcp_ntp_servers"] == ["192.168.1.1"]
def test_a_host_without_a_zone_of_its_own_reads_the_apis() -> None:
"""No timedatectl and no /etc/timezone or /etc/localtime link: the API's word."""
driver, api, _ = _pve(_reading(timedatectl=False))
@@ -315,10 +339,25 @@ def test_servers_go_to_chronys_sources_d_and_the_vendor_pool_stops_counting(make
assert any(
"/etc/chrony/sources.d/netork.sources" in c and c.startswith("install") for c in root
)
# line 8 is the vendor's pool, line 11 the DHCP sourcedir: both in the main file,
# which chronyd reads only when it starts.
# line 8 is the vendor's pool, in the main file, which chronyd reads only when it
# starts. Line 11, the DHCP client's sourcedir, stays: DHCP's servers count.
sed = next(c for c in root if c.startswith("sed -i"))
assert "8{" in sed and "11{" in sed and sed.endswith("/etc/chrony/chrony.conf")
assert "8{" in sed and "11{" not in sed and sed.endswith("/etc/chrony/chrony.conf")
assert root[-1] == "systemctl restart chrony.service"
def test_a_write_gives_back_the_dhcp_sourcedir_an_earlier_write_took() -> None:
"""A node napalm-device-types 4.35.0 aligned hears DHCP again (NetOrk/netork#2380)."""
servers = ("10.0.0.1",)
driver, _, shell = _pve(_reading(servers=servers, deaf_to_dhcp=True), _reading(servers=servers))
result = driver.configure_time_sync(ntp_servers=list(servers))
assert result["success"], result["output"]
root = shell.root()
sed = next(c for c in root if c.startswith("sed -i"))
assert "11{s/^#napalm-time-sync: (sourcedir" in sed
assert sed.endswith("/etc/chrony/chrony.conf")
assert root[-1] == "systemctl restart chrony.service"