4 # Copyright (c) 2016, Tieto Corporation
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
18 logger = logging.getLogger()
21 from remotehost import Host
22 from wpasupplicant import WpaSupplicant
25 def show_devices(devices, setup_params):
26 """Show/check available devices"""
28 for device in devices:
29 host = rutils.get_host(devices, device['name'])
30 # simple check if authorized_keys works correctly
31 status, buf = host.execute(["id"])
33 print "[" + host.name + "] - ssh communication: FAILED"
36 print "[" + host.name + "] - ssh communication: OK"
37 # check setup_hw works correctly
38 rutils.setup_hw_host(host, setup_params)
41 status, buf = host.execute(["uname", "-s", "-n", "-r", "-m", "-o"])
44 ifaces = re.split('; | |, ', host.ifname)
46 status, buf = host.execute(["ifconfig", iface])
48 print "\t" + iface + " failed\n"
50 lines = buf.splitlines()
53 # check hostapd, wpa_supplicant, iperf exist
54 status, buf = host.execute([setup_params['wpa_supplicant'], "-v"])
56 print "\t" + setup_params['wpa_supplicant'] + " not find\n"
58 lines = buf.splitlines()
62 status, buf = host.execute([setup_params['hostapd'], "-v"])
64 print "\t" + setup_params['hostapd'] + " not find\n"
66 lines = buf.splitlines()
70 status, buf = host.execute([setup_params['iperf'], "-v"])
71 if status != 0 and status != 1:
72 print "\t" + setup_params['iperf'] + " not find\n"
74 lines = buf.splitlines()
79 def check_device(devices, setup_params, dev_name, monitor=False):
80 host = rutils.get_host(devices, dev_name)
81 # simple check if authorized_keys works correctly
82 status, buf = host.execute(["id"])
84 raise Exception(dev_name + " - ssh communication FAILED: " + buf)
86 rutils.setup_hw_host(host, setup_params)
88 ifaces = re.split('; | |, ', host.ifname)
89 # check interfaces (multi for monitor)
91 status, buf = host.execute(["ifconfig", iface])
93 raise Exception(dev_name + " ifconfig " + iface + " failed: " + buf)
95 # monitor doesn't need wpa_supplicant/hostapd ...
99 status, buf = host.execute(["ls", "-l", setup_params['wpa_supplicant']])
101 raise Exception(dev_name + " - wpa_supplicant: " + buf)
103 status, buf = host.execute(["ls", "-l", setup_params['hostapd']])
105 raise Exception(dev_name + " - hostapd: " + buf)
107 status, buf = host.execute(["which", setup_params['iperf']])
109 raise Exception(dev_name + " - iperf: " + buf)
111 status, buf = host.execute(["which", "tshark"])
113 logger.debug(dev_name + " - tshark: " + buf)
115 def check_devices(devices, setup_params, refs, duts, monitors):
116 """Check duts/refs/monitors devices"""
118 check_device(devices, setup_params, dut)
120 check_device(devices, setup_params, ref)
121 for monitor in monitors:
124 check_device(devices, setup_params, monitor, monitor=True)