Skip to content

Commit 08713d0

Browse files
committed
Update traceroute test
1 parent 7e7f6ae commit 08713d0

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

salt/modules/network.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,17 @@ def traceroute(host):
937937
"""
938938
ret = []
939939
cmd = "traceroute {}".format(__utils__["network.sanitize_host"](host))
940-
out = __salt__["cmd.run"](cmd)
940+
# Bound the wall-clock time so callers aren't blocked indefinitely when
941+
# every hop times out (30 hops × 3 probes × 5 s = 450 s by default).
942+
# 120 s is enough for a well-routed destination and still returns partial
943+
# results (already-seen hops) for unreachable destinations.
944+
out = __salt__["cmd.run"](cmd, timeout=120)
945+
946+
# When cmd.run hits its timeout it returns the exception message as stdout
947+
# rather than actual traceroute output. Detect that and bail early so the
948+
# parser below doesn't try to interpret the error string as hop data.
949+
if "Timed out after" in out:
950+
return ret
941951

942952
# Parse version of traceroute
943953
if __utils__["platform.is_sunos"]() or __utils__["platform.is_aix"]():
@@ -1041,7 +1051,7 @@ def traceroute(host):
10411051
# Parse anything else
10421052
else:
10431053
comps = line.split()
1044-
if len(comps) >= 8:
1054+
if len(comps) >= 9:
10451055
result = {
10461056
"count": comps[0],
10471057
"hostname": comps[1],

tests/pytests/functional/modules/test_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_network_netstat(network):
5757

5858
@pytest.mark.skip_if_binaries_missing("traceroute")
5959
@pytest.mark.slow_test
60-
@pytest.mark.timeout(300)
60+
@pytest.mark.timeout(150)
6161
def test_network_traceroute(network, url):
6262
"""
6363
network.traceroute

0 commit comments

Comments
 (0)