summaryrefslogtreecommitdiff
diff options
authorPMR <pmr@pmr-lander>2019-07-22 08:59:16 +0000
committerPMR <pmr@pmr-lander>2019-07-22 08:59:16 +0000
commit47519cf5d86e38f2403fea500ee42d88448ad226 (patch)
tree81ff412790c8bdb2a33a1eb8ff6845964e65954b
parent056a790abebdf2eff84ba8bd51aef31f36285de1 (diff)
parent424d45b736f6477d88bb1cc94acc9bbff8902abf (diff)
Merge #370384 from ~jocave/plainbox-provider-checkbox:netplan-wait-for-routable
-rwxr-xr-xbin/wifi_client_test_netplan.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/bin/wifi_client_test_netplan.py b/bin/wifi_client_test_netplan.py
index 1f7e5f4..c74320e 100755
--- a/bin/wifi_client_test_netplan.py
+++ b/bin/wifi_client_test_netplan.py
@@ -23,6 +23,7 @@ import time
import shutil
from struct import pack
from socket import inet_ntoa
+import sys
print = functools.partial(print, flush=True)
@@ -188,10 +189,39 @@ def netplan_apply_config():
retcode = sp.call(cmd, shell=True, env=env)
if retcode != 0:
print("ERROR: failed netplan apply call")
+ print()
return False
+ print()
return True
+def _get_networkctl_state(interface):
+ cmd = 'networkctl status --no-pager --no-legend {}'.format(interface)
+ output = sp.check_output(cmd, shell=True)
+ for line in output.decode(sys.stdout.encoding).splitlines():
+ key, val = line.strip().split(':', maxsplit=1)
+ if key == "State":
+ return val
+
+
+def wait_for_routable(interface, max_wait=15):
+ routable = False
+ attempts = 0
+ while not routable and attempts < max_wait:
+ state = _get_networkctl_state(interface)
+ print(state)
+ if "routable" in state:
+ routable = True
+ break
+ time.sleep(1)
+ attempts += 1
+ if routable:
+ print("Reached routable state")
+ else:
+ print("WARN: did not reach routable state")
+ print()
+
+
def perform_ping_test(interface):
cmd = 'gateway_ping_test -v --interface={}'.format(interface)
print_cmd(cmd)
@@ -204,6 +234,7 @@ def print_journal_entries(start):
cmd = ('journalctl -q --no-pager '
'-u systemd-networkd.service '
'-u wpa_supplicant.service '
+ ' -u netplan-* '
'--since "{}" '.format(start.strftime('%Y-%m-%d %H:%M:%S')))
print_cmd(cmd)
sp.call(cmd, shell=True)
@@ -258,9 +289,11 @@ def main():
netplan_config_restore()
print_journal_entries(start_time)
raise SystemExit(1)
- print()
time.sleep(20)
+ print_head("Wait for interface to be routable")
+ wait_for_routable(args.interface)
+
# Check connection by ping or link status
print_head("Perform a ping test")
test_result = perform_ping_test(args.interface)