From 698a66ae3cf33a1130ae053e078e972b2b039613 Mon Sep 17 00:00:00 2001 From: Sylvain Pineau Date: Thu, 17 Dec 2020 14:04:37 +0100 Subject: bin:wifi_nmcli_test.py: Add a timeout (200s) to the 'nmcli up' subprocess --- bin/wifi_nmcli_test.py | 22 ++++++++++++++++++++-- 1 file 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") -- cgit v1.2.3