driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 57s
driver / test (3.12) (pull_request) Successful in 58s
driver / test (3.13) (pull_request) Successful in 51s
driver / lowest (pull_request) Successful in 26s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Successful in 2m23s
driver / publish (pull_request) Skipped
netOrk keeps one list of NTP servers and a time zone per site and aligns a device that differs (NetOrk/netork#2360). A Windows host takes part through w32time and its time zone, in one PowerShell script per read. The servers and the mode are read from w32time's registry values, group policy's first, not from w32tm /query /configuration, whose text is in the host's language; synchronised is the leap indicator on the first line of w32tm /query /status, which reads the same in any language. The servers are written the way w32tm /config /manualpeerlist /syncfromflags:manual writes them (NtpServer with 0x8, Type NTP), followed by w32tm /config /update: no value passes a native command line, whose quoting Windows PowerShell 5.1 mangles. A domain member that takes its time from the domain hierarchy (NT5DS, AllSync) and a host whose w32time comes from group policy refuse the write: their time is set elsewhere, and a local write would be overridden or break the domain's time. Windows keeps a Windows zone, which stands for several IANA zones, so Europe/Vienna written would read back as Europe/Berlin and the poll would align the host forever. The IANA name written is kept beside it in HKLM\SOFTWARE\napalm-windows and read back while the host is still in that Windows zone. The zone is read from the registry, which [TimeZoneInfo]::Local caches for the life of the remote session. The zone table is now CLDR's windowsZones.xml (release 49) both ways, generated by tools/windows_zones.py with tzdata's links and committed with its source and checksum; nothing is fetched at runtime. CLDR's old names (Asia/Calcutta) read as their current ones (Asia/Kolkata). Writes the host already has are skipped. Needs napalm-device-types 4.35.0. Refs NetOrk/netork#2367
63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
"""tools/windows_zones.py: the generator of napalm_windows/_windows_zones.py."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
from pathlib import Path
|
|
|
|
TOOL = Path(__file__).parent.parent / "tools" / "windows_zones.py"
|
|
_spec = importlib.util.spec_from_file_location("windows_zones_tool", TOOL)
|
|
assert _spec is not None and _spec.loader is not None
|
|
tool = importlib.util.module_from_spec(_spec)
|
|
_spec.loader.exec_module(tool)
|
|
|
|
XML = """<?xml version="1.0" encoding="UTF-8" ?>
|
|
<supplementalData><windowsZones><mapTimezones>
|
|
<mapZone other="India Standard Time" territory="001" type="Asia/Calcutta"/>
|
|
<mapZone other="India Standard Time" territory="IN" type="Asia/Calcutta"/>
|
|
<mapZone other="Greenwich Standard Time" territory="001" type="Atlantic/Reykjavik"/>
|
|
<mapZone other="Greenwich Standard Time" territory="CI" type="Africa/Abidjan"/>
|
|
<mapZone other="UTC" territory="001" type="Etc/UTC"/>
|
|
<mapZone other="UTC" territory="ZZ" type="Etc/UTC Etc/GMT"/>
|
|
</mapTimezones></windowsZones></supplementalData>
|
|
"""
|
|
|
|
TZDATA = """# version 2026e
|
|
Z Etc/UTC 0 - UTC
|
|
L Asia/Kolkata Asia/Calcutta
|
|
L Africa/Abidjan Atlantic/Reykjavik
|
|
L Etc/UTC UTC
|
|
"""
|
|
|
|
|
|
def _tables(tmp_path: Path) -> tuple[dict[str, str], dict[str, str]]:
|
|
(tmp_path / "w.xml").write_text(XML)
|
|
(tmp_path / "tzdata.zi").write_text(TZDATA)
|
|
primary, to_windows, _ = tool.read_cldr(tmp_path / "w.xml")
|
|
return tool.build(primary, to_windows, tool.read_links(tmp_path / "tzdata.zi"))
|
|
|
|
|
|
def test_a_renamed_zone_reads_as_its_new_name(tmp_path):
|
|
windows_to_iana, iana_to_windows = _tables(tmp_path)
|
|
assert windows_to_iana["India Standard Time"] == "Asia/Kolkata"
|
|
assert iana_to_windows["Asia/Kolkata"] == iana_to_windows["Asia/Calcutta"]
|
|
|
|
|
|
def test_a_merged_zone_keeps_its_name(tmp_path):
|
|
windows_to_iana, _ = _tables(tmp_path)
|
|
assert windows_to_iana["Greenwich Standard Time"] == "Atlantic/Reykjavik"
|
|
|
|
|
|
def test_links_to_a_mapped_zone_are_mapped(tmp_path):
|
|
_, iana_to_windows = _tables(tmp_path)
|
|
assert iana_to_windows["UTC"] == "UTC"
|
|
assert iana_to_windows["Etc/GMT"] == "UTC"
|
|
|
|
|
|
def test_the_module_names_its_sources(tmp_path):
|
|
text = tool.render(*_tables(tmp_path), "release-49", "abc", "2026e")
|
|
assert "CLDR release-49" in text and "sha256 abc" in text and "2026e" in text
|
|
namespace: dict[str, object] = {}
|
|
exec(compile(text, "generated", "exec"), namespace)
|
|
assert namespace["WINDOWS_TO_IANA"] == _tables(tmp_path)[0]
|