test: documentation names and addresses in fixtures
driver / types (pull_request) Successful in 1m0s
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 15s
driver / test (3.12) (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 1m3s
driver / lowest (pull_request) Successful in 32s
driver / build (pull_request) Successful in 44s
driver / security (pull_request) Successful in 1m19s
CI / driver (pull_request) Successful in 2m56s
driver / publish (pull_request) Skipped

Fixtures, docstring examples and the README use neutral host names
(ap-01, ap-02) and addresses from the documentation ranges 192.0.2.0/24,
198.51.100.0/24 and 203.0.113.0/24, mapped one to one so every test
keeps its meaning: the management network test still has its address
inside that network, a route still covers its prefix. Loopback, the
wildcard address and netmasks are unchanged.
This commit is contained in:
Christian Manivong committed 2026-11-12 19:21:54 +01:00
1 parent 780b635174
commit e4ae42fea0
10 files changed
+125 -123

No files matched your search

+30 -28
View File
@@ -45,14 +45,14 @@ system.ntp.enable_server='0'
system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org' '2.openwrt.pool.ntp.org' '3.openwrt.pool.ntp.org'
"""
# An AP configured through LuCI (the get_system_config fixture of netOrk#164).
# An AP configured through LuCI (the reading of the get_system_config fixture in test_driver.py).
LUCI_BERLIN = """\
system.@system[0]=system
system.@system[0].hostname='ap-eze-Garten'
system.@system[0].hostname='ap-01'
system.@system[0].timezone='CET-1CEST,M3.5.0,M10.5.0/3'
system.@system[0].zonename='Europe/Berlin'
system.@system[0].log_remote='1'
system.@system[0].log_ip='10.10.40.2'
system.@system[0].log_ip='192.0.2.40'
system.ntp=timeserver
system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org'
"""
@@ -63,7 +63,7 @@ system.@system[0]=system
system.@system[0].timezone='EST5EDT,M3.2.0,M11.1.0'
system.@system[0].zonename='America/New York'
system.ntp=timeserver
system.ntp.server='10.0.0.1'
system.ntp.server='203.0.113.10'
"""
# netOrk#1849: the IANA name written as the rule. libc cannot read it; the AP runs on UTC.
@@ -72,7 +72,7 @@ system.@system[0]=system
system.@system[0].timezone='Europe/Berlin'
system.@system[0].zonename='Europe/Berlin'
system.ntp=timeserver
system.ntp.server='10.0.0.1'
system.ntp.server='203.0.113.10'
"""
# A server list kept as one option, the servers apart by spaces: sysntpd splits it.
@@ -96,7 +96,7 @@ def _interface(name: str, ntpserver: str | None = None, **more: Any) -> dict[str
LEASE = {
"interface": [
_interface("lan", proto="static"),
_interface("wan", "192.168.1.1 192.168.1.2", leasetime=43200),
_interface("wan", "192.0.2.1 192.0.2.2", leasetime=43200),
_interface("wan6", proto="dhcpv6"),
]
}
@@ -250,7 +250,7 @@ def test_the_read_is_one_round_trip_as_the_login_user():
def test_a_lease_s_ntp_servers_are_read_apart_from_the_configured_ones():
reading = _read(STOCK, LEASE)
assert reading["dhcp_ntp_servers"] == ["192.168.1.1", "192.168.1.2"]
assert reading["dhcp_ntp_servers"] == ["192.0.2.1", "192.0.2.2"]
assert reading["ntp_servers"] == [
"0.openwrt.pool.ntp.org",
"1.openwrt.pool.ntp.org",
@@ -262,38 +262,38 @@ def test_a_lease_s_ntp_servers_are_read_apart_from_the_configured_ones():
def test_every_interface_s_lease_counts_in_netifd_s_order_each_once():
dump = {
"interface": [
_interface("wan", "192.168.1.1"),
_interface("iot", "10.40.100.1 192.168.1.1"),
_interface("wan", "192.0.2.1"),
_interface("iot", "198.51.100.1 192.0.2.1"),
]
}
assert _read(STOCK, dump)["dhcp_ntp_servers"] == ["192.168.1.1", "10.40.100.1"]
assert _read(STOCK, dump)["dhcp_ntp_servers"] == ["192.0.2.1", "198.51.100.1"]
def test_an_interface_without_a_lease_or_with_an_odd_one_brings_nothing():
dump = {
"interface": [
"wan",
{"interface": "wan", "data": "192.168.1.1"},
{"interface": "wan", "data": {"ntpserver": ["192.168.1.1"]}},
{"interface": "wan", "data": "192.0.2.1"},
{"interface": "wan", "data": {"ntpserver": ["192.0.2.1"]}},
{"interface": "wan"},
_interface("iot", "10.40.100.1"),
_interface("iot", "198.51.100.1"),
]
}
assert _read(STOCK, dump)["dhcp_ntp_servers"] == ["10.40.100.1"]
assert _read(STOCK, dump)["dhcp_ntp_servers"] == ["198.51.100.1"]
def test_dhcp_interface_names_the_interfaces_whose_leases_count():
show = STOCK + "system.ntp.dhcp_interface='iot'\n"
dump = {
"interface": [
_interface("wan", "192.168.1.1"),
_interface("iot", "10.40.100.1"),
_interface("wan", "192.0.2.1"),
_interface("iot", "198.51.100.1"),
]
}
assert _read(show, dump)["dhcp_ntp_servers"] == ["10.40.100.1"]
assert _read(show, dump)["dhcp_ntp_servers"] == ["198.51.100.1"]
def test_use_dhcp_off_takes_nothing_from_a_lease():
@@ -442,11 +442,11 @@ def test_get_ntp_servers_of_a_disabled_client_is_empty():
def test_the_servers_replace_the_list_and_ntpd_restarts():
uci = _Uci(STOCK)
result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1", "ntp.example.org"])
result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10", "ntp.example.org"])
assert result["success"] is True, result["output"]
assert [s["step"] for s in result["steps"]] == ["ntp_servers", "verify"]
assert uci._section("ntp")["server"] == ["10.0.0.1", "ntp.example.org"]
assert uci._section("ntp")["server"] == ["203.0.113.10", "ntp.example.org"]
(write,) = uci.writes()
assert write.endswith(
"uci commit system && /etc/init.d/sysntpd enable && /etc/init.d/sysntpd restart"
@@ -457,7 +457,7 @@ def test_the_servers_replace_the_list_and_ntpd_restarts():
def test_writing_servers_leaves_the_ones_dhcp_brings():
# DHCP option 42 counts (NetOrk/netork#2380): sysntpd keeps adding a lease's servers.
uci = _Uci(STOCK, dump=LEASE)
result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"])
result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"])
assert result["success"] is True, result["output"]
assert "use_dhcp" not in uci._section("ntp")
@@ -466,7 +466,7 @@ def test_writing_servers_leaves_the_ones_dhcp_brings():
def test_writing_servers_keeps_use_dhcp_as_the_router_has_it():
uci = _Uci(STOCK + "system.ntp.use_dhcp='0'\n")
result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"])
result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"])
assert result["success"] is True, result["output"]
assert uci._section("ntp")["use_dhcp"] == "0"
@@ -485,7 +485,7 @@ def test_the_same_servers_with_dhcp_on_write_nothing():
def test_writing_servers_enables_a_disabled_client():
uci = _Uci(STOCK.replace("system.ntp.enabled='1'", "system.ntp.enabled='0'"))
result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"])
result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"])
assert result["success"] is True, result["output"]
assert uci._section("ntp")["enabled"] == "1"
@@ -494,7 +494,7 @@ def test_writing_servers_enables_a_disabled_client():
def test_a_missing_ntp_section_is_made():
uci = _Uci("system.@system[0]=system\nsystem.@system[0].timezone='UTC'\n")
result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"])
result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"])
assert result["success"] is True, result["output"]
assert ("ntp", "timeserver") in [(s[0], s[1]) for s in uci.sections]
@@ -505,10 +505,10 @@ def test_the_same_servers_again_write_nothing():
# netOrk aligns on every poll: an aligned router must not restart ntpd each time.
uci = _Uci(STOCK)
drv = _driver(uci)
drv.configure_time_sync(ntp_servers=["10.0.0.1", "10.0.0.2"])
drv.configure_time_sync(ntp_servers=["203.0.113.10", "203.0.113.11"])
uci.ran.clear()
result = drv.configure_time_sync(ntp_servers=["10.0.0.1", "10.0.0.2"])
result = drv.configure_time_sync(ntp_servers=["203.0.113.10", "203.0.113.11"])
assert result["success"] is True
assert uci.writes() == []
@@ -526,7 +526,7 @@ def test_the_same_servers_in_another_order_are_written():
def test_a_refused_uci_write_restarts_nothing():
uci = _Uci(STOCK, fail="uci commit system")
result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"])
result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"])
assert result["success"] is False
assert result["steps"][-1]["step"] == "ntp_servers"
@@ -540,7 +540,7 @@ def test_a_login_other_than_root_writes_nothing():
drv._check_privilege(k.get("privileged", False)) or uci(c, **k)
)
result = drv.configure_time_sync(ntp_servers=["10.0.0.1"])
result = drv.configure_time_sync(ntp_servers=["203.0.113.10"])
assert result["success"] is False
assert "no sudo" in result["output"]
@@ -621,7 +621,9 @@ def test_a_zone_twice_writes_once():
def test_both_values_in_one_run():
uci = _Uci(STOCK)
result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"], timezone="Europe/Berlin")
result = _driver(uci).configure_time_sync(
ntp_servers=["203.0.113.10"], timezone="Europe/Berlin"
)
assert result["success"] is True, result["output"]
assert [s["step"] for s in result["steps"]] == ["ntp_servers", "timezone", "verify"]