diff options
author | Jonathan Cave <jonathan.cave@canonical.com> | 2019-02-20 11:05:41 +0000 |
---|---|---|
committer | Jonathan Cave <jonathan.cave@canonical.com> | 2019-02-20 14:24:36 +0000 |
commit | e5ae9128ec358fd417433ba181faf522a55bdf16 (patch) | |
tree | ef94cf53f01b935441cc984b25fbeefc4bab9977 | |
parent | 36f0620a97cc56a069fb2773bd559f5ce990981c (diff) |
wireless: sleep on failure to request rescan
In wifi_nmcli_test on recent nmcli versions a rescan is requested to ensure an up-to-date list of APs is available. However this request can fail if NM has already started a scan, but we immediately attempt the connection. This should let the background scan complete.
-rwxr-xr-x | bin/wifi_nmcli_test.py (renamed from bin/wifi_nmcli_test) | 36 | ||||
-rw-r--r-- | units/wireless/jobs.pxu | 14 |
2 files changed, 30 insertions, 20 deletions
diff --git a/bin/wifi_nmcli_test b/bin/wifi_nmcli_test.py index b89a525..45b8624 100755 --- a/bin/wifi_nmcli_test +++ b/bin/wifi_nmcli_test.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright 2017-2018 Canonical Ltd. +# Copyright 2017-2019 Canonical Ltd. # All rights reserved. # # Written by: @@ -13,6 +13,7 @@ import argparse import functools import subprocess as sp import sys +import time from distutils.version import LooseVersion @@ -61,7 +62,13 @@ def device_rescan(): print_head("Calling a rescan") cmd = "nmcli d wifi rescan" print_cmd(cmd) - sp.call(cmd, shell=True) + retcode = sp.call(cmd, shell=True) + if retcode != 0: + # Most often the rescan request fails because NM has itself started + # a scan in recent past, we should let these operations complete before + # attempting a connection + print('Scan request failed, allow other operations to complete (15s)') + time.sleep(15) print() @@ -73,7 +80,8 @@ def list_aps(args): cmd = "nmcli -t -f {} d wifi list iface {}".format(fields, args.device) else: fields = "SSID,CHAN,FREQ,SIGNAL" - cmd = "nmcli -t -f {} d wifi list ifname {}".format(fields, args.device) + cmd = "nmcli -t -f {} d wifi list ifname {}".format( + fields, args.device) print_cmd(cmd) output = sp.check_output(cmd, shell=True) for line in output.decode(sys.stdout.encoding).splitlines(): @@ -108,10 +116,11 @@ def open_connection(args): print_cmd(cmd) sp.call(cmd, shell=True) if legacy_nmcli(): - cmd_part = "nmcli -m tabular -t -f GENERAL d list | " - cmd = cmd_part + "grep {} | awk -F: '{{print $15}}'".format(args.device) + cmd = ("nmcli -m tabular -t -f GENERAL d list | grep {} | " + "awk -F: '{{print $15}}'".format(args.device)) else: - cmd = "nmcli -m tabular -t -f GENERAL.STATE d show {}".format(args.device) + cmd = "nmcli -m tabular -t -f GENERAL.STATE d show {}".format( + args.device) print_cmd(cmd) output = sp.check_output(cmd, shell=True) state = output.decode(sys.stdout.encoding).strip() @@ -126,18 +135,19 @@ def open_connection(args): def secured_connection(args): print_head("Connection attempt") if legacy_nmcli(): - cmd = "nmcli d wifi connect {} password {} iface {} name TEST_CON".format( - args.essid, args.psk, args.device) + cmd = ("nmcli d wifi connect {} password {} iface {} name " + "TEST_CON".format(args.essid, args.psk, args.device)) else: - cmd = "nmcli d wifi connect {} password {} ifname {} name TEST_CON".format( - args.essid, args.psk, args.device) + cmd = ("nmcli d wifi connect {} password {} ifname {} name " + "TEST_CON".format(args.essid, args.psk, args.device)) print_cmd(cmd) sp.call(cmd, shell=True) if legacy_nmcli(): - cmd_part = "nmcli -m tabular -t -f GENERAL d list | " - cmd = cmd_part + "grep {} | awk -F: '{{print $15}}'".format(args.device) + cmd = ("nmcli -m tabular -t -f GENERAL d list | " + "grep {} | awk -F: '{{print $15}}'".format(args.device)) else: - cmd = "nmcli -m tabular -t -f GENERAL.STATE d show {}".format(args.device) + cmd = "nmcli -m tabular -t -f GENERAL.STATE d show {}".format( + args.device) print_cmd(cmd) output = sp.check_output(cmd, shell=True) state = output.decode(sys.stdout.encoding).strip() diff --git a/units/wireless/jobs.pxu b/units/wireless/jobs.pxu index 9c25c71..a186979 100644 --- a/units/wireless/jobs.pxu +++ b/units/wireless/jobs.pxu @@ -7,7 +7,7 @@ id: wireless/wireless_scanning_{{ interface }} _summary: Test system can discover Wi-Fi networks on {{ interface }} command: net_driver_info $NET_DRIVER_INFO - wifi_nmcli_test scan {{ interface }} + wifi_nmcli_test.py scan {{ interface }} plugin: shell category_id: com.canonical.plainbox::wireless estimated_duration: 6 @@ -31,7 +31,7 @@ _purpose: plugin: shell command: net_driver_info $NET_DRIVER_INFO - wifi_nmcli_test secured {{ interface }} "$WPA_BG_SSID" "$WPA_BG_PSK" + wifi_nmcli_test.py secured {{ interface }} "$WPA_BG_SSID" "$WPA_BG_PSK" category_id: com.canonical.plainbox::wireless estimated_duration: 30.0 flags: preserve-locale also-after-suspend also-after-suspend-manual @@ -52,7 +52,7 @@ _purpose: plugin: shell command: net_driver_info $NET_DRIVER_INFO - wifi_nmcli_test open {{ interface }} "$OPEN_BG_SSID" + wifi_nmcli_test.py open {{ interface }} "$OPEN_BG_SSID" category_id: com.canonical.plainbox::wireless estimated_duration: 30.0 flags: preserve-locale also-after-suspend also-after-suspend-manual @@ -73,7 +73,7 @@ _purpose: plugin: shell command: net_driver_info $NET_DRIVER_INFO - wifi_nmcli_test secured {{ interface }} "$WPA_N_SSID" "$WPA_N_PSK" + wifi_nmcli_test.py secured {{ interface }} "$WPA_N_SSID" "$WPA_N_PSK" category_id: com.canonical.plainbox::wireless estimated_duration: 30.0 flags: preserve-locale also-after-suspend also-after-suspend-manual @@ -94,7 +94,7 @@ _purpose: plugin: shell command: net_driver_info $NET_DRIVER_INFO - wifi_nmcli_test open {{ interface }} "$OPEN_N_SSID" + wifi_nmcli_test.py open {{ interface }} "$OPEN_N_SSID" category_id: com.canonical.plainbox::wireless estimated_duration: 30.0 flags: preserve-locale also-after-suspend also-after-suspend-manual @@ -115,7 +115,7 @@ _purpose: plugin: shell command: net_driver_info $NET_DRIVER_INFO - wifi_nmcli_test secured {{ interface }} "$WPA_AC_SSID" "$WPA_AC_PSK" + wifi_nmcli_test.py secured {{ interface }} "$WPA_AC_SSID" "$WPA_AC_PSK" category_id: com.canonical.plainbox::wireless estimated_duration: 30.0 flags: preserve-locale also-after-suspend also-after-suspend-manual @@ -137,7 +137,7 @@ _purpose: plugin: shell command: net_driver_info $NET_DRIVER_INFO - wifi_nmcli_test open {{ interface }} "$OPEN_AC_SSID" + wifi_nmcli_test.py open {{ interface }} "$OPEN_AC_SSID" category_id: com.canonical.plainbox::wireless estimated_duration: 30.0 flags: preserve-locale also-after-suspend also-after-suspend-manual |