summaryrefslogtreecommitdiff
diff options
authorSylvain Pineau <sylvain.pineau@canonical.com>2020-12-17 14:04:37 +0100
committerSylvain Pineau <sylvain.pineau@canonical.com>2020-12-17 17:13:28 +0100
commit698a66ae3cf33a1130ae053e078e972b2b039613 (patch)
tree1f8f9c3ed7d90a084a9537c7e568e3b0efc4dc8c
parente53ecca2db755d98daddbc28375570694d7af52c (diff)
bin:wifi_nmcli_test.py: Add a timeout (200s) to the 'nmcli up' subprocess
-rwxr-xr-xbin/wifi_nmcli_test.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/bin/wifi_nmcli_test.py b/bin/wifi_nmcli_test.py
index a6bbd8f..6f77376 100755
--- a/bin/wifi_nmcli_test.py
+++ b/bin/wifi_nmcli_test.py
@@ -17,11 +17,23 @@ import subprocess as sp
import sys
import time
+from distutils.version import LooseVersion
from gateway_ping_test import ping
print = functools.partial(print, flush=True)
+def legacy_nmcli():
+ cmd = "nmcli -v"
+ output = sp.check_output(cmd, shell=True)
+ version = LooseVersion(output.strip().split()[-1].decode())
+ # check if using the 16.04 nmcli because of this bug
+ # https://bugs.launchpad.net/plano/+bug/1896806
+ if version < LooseVersion("1.9.9"):
+ return True
+ return False
+
+
def print_head(txt):
print("##", txt)
@@ -159,7 +171,10 @@ def open_connection(args):
# Make sure the connection is brought up
cmd = "nmcli c up TEST_CON"
print_cmd(cmd)
- sp.call(cmd, shell=True)
+ try:
+ sp.call(cmd, shell=True, timeout=200 if legacy_nmcli() else None)
+ except sp.TimeoutExpired:
+ print("Connection activation failed\n")
print()
print_head("Ensure interface is connected")
@@ -206,7 +221,10 @@ def secured_connection(args):
# Make sure the connection is brought up
cmd = "nmcli c up TEST_CON"
print_cmd(cmd)
- sp.call(cmd, shell=True)
+ try:
+ sp.call(cmd, shell=True, timeout=200 if legacy_nmcli() else None)
+ except sp.TimeoutExpired:
+ print("Connection activation failed\n")
print()
print_head("Ensure interface is connected")