fix(ping): parse each reply into results

The probe pattern expected "from" after icmp_seq, but iputils prints
"bytes from <ip>: icmp_seq=... time=... ms", so results was always
empty. Replies by name ("from host (ip)") and over IPv6 are read too.

Closes #12
This commit is contained in:
Christian Manivong committed 2026-11-01 21:57:36 +01:00
1 parent 29ed59c8d1
commit 10cf788b86
3 files changed
+34 -3

No files matched your search

+25
View File
@@ -175,6 +175,31 @@ class TestPing:
assert result["success"]["packet_loss"] == 0
assert result["success"]["rtt_min"] == pytest.approx(10.5, abs=0.01)
def test_every_reply_is_a_result(self, driver):
"""iputils puts "from <ip>" before icmp_seq (napalm-proxmox#12)."""
driver._node_api().execute.post.return_value = {"data": self.PING_SUCCESS}
result = driver.ping("8.8.8.8")
assert result["success"]["results"] == [
{"ip_address": "8.8.8.8", "rtt": 10.5},
{"ip_address": "8.8.8.8", "rtt": 11.2},
]
def test_a_reply_by_name_and_over_ipv6(self, driver):
output = (
"PING dns.google (8.8.4.4) 56(84) bytes of data.\n"
"64 bytes from dns.google (8.8.4.4): icmp_seq=1 ttl=118 time=123 ms\n"
"64 bytes from 2001:db8::1: icmp_seq=2 ttl=64 time=0.045 ms\n"
"--- dns.google ping statistics ---\n"
"2 packets transmitted, 2 received, 0% packet loss, time 1001ms\n"
"rtt min/avg/max/mdev = 0.045/61.5/123.0/61.4 ms\n"
)
driver._node_api().execute.post.return_value = {"data": output}
result = driver.ping("dns.google")
assert result["success"]["results"] == [
{"ip_address": "8.8.4.4", "rtt": 123.0},
{"ip_address": "2001:db8::1", "rtt": 0.045},
]
def test_failure(self, driver):
driver._node_api().execute.post.return_value = {"data": self.PING_FAIL}
result = driver.ping("badhost")