summaryrefslogtreecommitdiff
diff options
authorMaciej Kisielewski <maciej.kisielewski@canonical.com>2021-04-07 15:56:52 +0200
committerMaciej Kisielewski <maciej.kisielewski@canonical.com>2021-04-07 15:56:52 +0200
commit02868be6982326997a840f5d5480dec608721fae (patch)
tree560a8ad4ce332b2377224b2a280fb567107a3ec2
parentd6368d8712e8106902c7f9a9a8bf8cb0eecaf596 (diff)
Add: better information when GW ping fails
When the gateway ping test fails due to SO_BINDTODEVICE error it is easy to see the real cause of failure. This patch makes the wrapper look for this information and explains why the test failed.
-rwxr-xr-xbin/gateway_ping_test.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/bin/gateway_ping_test.py b/bin/gateway_ping_test.py
index dc2e165..59f43d3 100755
--- a/bin/gateway_ping_test.py
+++ b/bin/gateway_ping_test.py
@@ -189,7 +189,8 @@ def ping(host, interface, count, deadline, verbose=False):
r".*([0-9]*\.?[0-9]*.)% packet loss")
ping_summary = {'transmitted': 0, 'received': 0, 'pct_loss': 0}
try:
- output = subprocess.check_output(command, universal_newlines=True)
+ output = subprocess.check_output(
+ command, universal_newlines=True, stderr=subprocess.PIPE)
except OSError as exc:
if exc.errno == errno.ENOENT:
# No ping command present;
@@ -200,6 +201,11 @@ def ping(host, interface, count, deadline, verbose=False):
except subprocess.CalledProcessError as excp:
# Ping returned fail exit code
print(_("ERROR: ping result: {0}").format(excp))
+ if excp.stderr:
+ print(excp.stderr)
+ if 'SO_BINDTODEVICE' in excp.stderr:
+ ping_summary['cause'] = (
+ "Could not bind to the {} interface.".format(interface))
else:
if verbose:
print(output)
@@ -277,6 +283,8 @@ def main(args):
args.deadline, args.verbose)
if ping_summary is None or ping_summary['received'] == 0:
print(_("No Internet connection"))
+ if ping_summary.get('cause'):
+ print("Possible cause: {}".format(ping_summary['cause']))
return 1
elif ping_summary['transmitted'] != ping_summary['received']:
print(_("Connection established, but lost {0}% of packets").format(