summaryrefslogtreecommitdiff
path: root/bin
diff options
authorJonathan Cave <jonathan.cave@canonical.com>2020-06-29 18:01:32 +0100
committerJonathan Cave <jonathan.cave@canonical.com>2020-06-29 18:01:32 +0100
commitdbcf4c2f421605963e0c1780967c6f5261ab0505 (patch)
tree829d0f95650371ebbca3a32ba8b577deed926bf2 /bin
parentdb58a899837a943991956b98749f7bb40ab994f4 (diff)
gateway_ping_test: fix crash when using networkctl
When the information is available networkctl will include the manufacturer in the gateway status field in brackets. This handles that situation and problems splitting the line better.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/gateway_ping_test11
1 files changed, 6 insertions, 5 deletions
diff --git a/bin/gateway_ping_test b/bin/gateway_ping_test
index 7bac0f8..47dcfda 100755
--- a/bin/gateway_ping_test
+++ b/bin/gateway_ping_test
@@ -138,11 +138,12 @@ def get_host_to_ping(interface=None, verbose=False, default=None):
try:
output = subprocess.check_output(cmd, shell=True)
for line in output.decode(sys.stdout.encoding).splitlines():
- key, val = line.strip().split(':', maxsplit=1)
- if key == "Gateway":
- subprocess.check_output(["ping", "-q", "-c", "1", val],
- stderr=subprocess.STDOUT)
- break
+ vals = line.strip().split(' ')
+ if len(vals) >= 2:
+ if vals[0] == 'Gateway:':
+ subprocess.check_output(["ping", "-q", "-c", "1", vals[1]],
+ stderr=subprocess.STDOUT)
+ break
except subprocess.CalledProcessError:
pass
ARP_POPULATE_TRIES = 10