fix: switch fingerprints, request timeouts, ping (#4, #3, #2) #12

Merged
christianmanivong merged 3 commits from fix/bugs-2026-11 into main 2026-11-01 22:00:49 +00:00
4 changed files with 46 additions and 23 deletions
Showing only changes of commit fcee6d7ddd - Show all commits

No files matched your search

+4
View File
@@ -22,6 +22,10 @@ All notable changes to this driver. The format follows
- Every HTTP request to the gateway carries the driver's `timeout`. It was set on
the session, where requests ignores it, so an unresponsive gateway could hang a
call indefinitely (#3).
- `ping()` no longer reports every target as alive. The DAL only acknowledges a
`PINGTEST` request and never says whether the target answered, so `ping()` now
returns an error and the driver opts out of ping sweeps (`SUPPORTS_PING = False`):
a LAN scan through this gateway marked every address alive (#2).
## [0.3.0] - 2026-10-23
+3 -1
View File
@@ -43,7 +43,6 @@ with driver("192.0.2.1", "admin", "secret", optional_args={"use_tls": True}) as
| `get_port_forwards`, `get_nat_translations` | DAL `NAT_PORTMAP`, else the status page |
| `get_wireless_clients`, `get_ssids`, `get_radio_status` | DAL, else the wireless page |
| `get_diagnostics` | DAL `DIAGNOSTICS` |
| `ping` | DAL `PINGTEST` |
| `is_alive` | TCP connect to the web port |
| `reboot_host` | DAL `REBOOT` |
| `restart_wifi` | DAL `WIFI_RESTART` |
@@ -54,6 +53,9 @@ Configuration changes (`load_merge_candidate` and `load_replace_candidate` raise
`NotImplementedError`), `get_config`, LLDP, BGP, NTP, SNMP, users, routes, MAC address
table, optics, environment, traceroute, VPN tunnels and the CLI.
`ping` returns an error and `SUPPORTS_PING` is `False`: the DAL accepts a `PINGTEST`
request but does not report whether the target answered.
## Development
The rules are in [STANDARDS.md](https://git.netork.io/NAPALM/driver-standard/src/branch/main/STANDARDS.md).
+11 -22
View File
@@ -33,6 +33,8 @@ from napalm_device_types.models import (
WirelessClientDict,
)
_PING_UNSUPPORTED = "Not supported on Zyxel VMG: the DAL does not report ping replies"
class ZyxelCrypto:
"""AES-256-CBC encryption wrapper for Zyxel DAL protocol payloads."""
@@ -96,6 +98,9 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
HTTP_FINGERPRINT = [
FingerprintRule("zyxel", weight=7.0, mandatory=True),
]
#: The DAL accepts a PINGTEST request but its answer carries no reply count or
#: round-trip time, so this driver cannot tell an answering host from a silent one.
SUPPORTS_PING = False
_LOGIN_PATH = "UserLogin"
_LOGOUT_PATH = "cgi-bin/UserLogout"
@@ -390,28 +395,12 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
vrf: str = "",
source_interface: str = "",
) -> dict[str, Any]:
"""Ping a destination via the device's DAL diagnostics."""
result = self._dal_query(
"PINGTEST",
{
"ProtocolVersion": "IPv4",
"Host": destination,
"DiagnosticsState": "Requested",
"DNSServer": "",
"NumberOfRepetitions": count,
"type": 0,
},
)
if result is None:
return {"success": {}, "error": "Ping not supported via DAL"}
return {
"success": {
"results": [{"rtt": 0}],
"probes_sent": count,
"probes_received": count,
},
"error": "",
}
"""Not supported: the DAL does not report whether a target answered.
Returns NAPALM's ``error`` reply without contacting the gateway; see
:attr:`SUPPORTS_PING`.
"""
return {"error": _PING_UNSUPPORTED}
def traceroute(
self,
+28
View File
@@ -477,3 +477,31 @@ class TestEveryRequestHasATimeout:
driver._dal_query("LAN_HOSTS")
driver._fetch_page("Status.htm")
assert self._timeouts(session) == {7}
class TestPingReportsNoTargetAlive:
"""The DAL PINGTEST call only acknowledges the request; it carries no reply count."""
def _connected_driver(self):
driver = ZyxelVMGDriver("192.168.1.1", "admin", "password")
driver._session = MagicMock(spec=requests.Session)
driver._session.put.return_value = MockResponse({})
driver._sessionkey = "1"
driver._crypto = MagicMock()
driver._crypto.decrypt_response.return_value = {"result": "ZCFG_SUCCESS"}
return driver
def test_the_driver_opts_out_of_ping_sweeps(self):
assert ZyxelVMGDriver.supports_ping() is False
def test_an_accepted_request_is_not_a_reply(self):
driver = self._connected_driver()
reply = driver.ping("192.0.2.77")
assert "success" not in reply
assert reply["error"]
assert driver._parse_ping_reply("192.0.2.77", reply)["alive"] is False
def test_ping_starts_no_diagnostic_on_the_gateway(self):
driver = self._connected_driver()
driver.ping("192.0.2.77")
driver._session.put.assert_not_called()