test_devices.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env python2
  2. #
  3. # Show/check devices
  4. # Copyright (c) 2016, Tieto Corporation
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import time
  9. import traceback
  10. import config
  11. import os
  12. import sys
  13. import getopt
  14. import re
  15. import logging
  16. logger = logging.getLogger()
  17. import rutils
  18. from remotehost import Host
  19. from wpasupplicant import WpaSupplicant
  20. import hostapd
  21. def show_devices(devices, setup_params):
  22. """Show/check available devices"""
  23. print "Devices:"
  24. for device in devices:
  25. host = rutils.get_host(devices, device['name'])
  26. # simple check if authorized_keys works correctly
  27. status, buf = host.execute(["id"])
  28. if status != 0:
  29. print "[" + host.name + "] - ssh communication: FAILED"
  30. continue
  31. else:
  32. print "[" + host.name + "] - ssh communication: OK"
  33. # check setup_hw works correctly
  34. rutils.setup_hw_host(host, setup_params)
  35. # show uname
  36. status, buf = host.execute(["uname", "-s", "-n", "-r", "-m", "-o"])
  37. print "\t" + buf
  38. # show ifconfig
  39. ifaces = re.split('; | |, ', host.ifname)
  40. for iface in ifaces:
  41. status, buf = host.execute(["ifconfig", iface])
  42. if status != 0:
  43. print "\t" + iface + " failed\n"
  44. continue
  45. lines = buf.splitlines()
  46. for line in lines:
  47. print "\t" + line
  48. # check hostapd, wpa_supplicant, iperf exist
  49. status, buf = host.execute([setup_params['wpa_supplicant'], "-v"])
  50. if status != 0:
  51. print "\t" + setup_params['wpa_supplicant'] + " not find\n"
  52. continue
  53. lines = buf.splitlines()
  54. for line in lines:
  55. print "\t" + line
  56. print ""
  57. status, buf = host.execute([setup_params['hostapd'], "-v"])
  58. if status != 1:
  59. print "\t" + setup_params['hostapd'] + " not find\n"
  60. continue
  61. lines = buf.splitlines()
  62. for line in lines:
  63. print "\t" + line
  64. print ""
  65. status, buf = host.execute([setup_params['iperf'], "-v"])
  66. if status != 0 and status != 1:
  67. print "\t" + setup_params['iperf'] + " not find\n"
  68. continue
  69. lines = buf.splitlines()
  70. for line in lines:
  71. print "\t" + line
  72. print ""
  73. def check_device(devices, setup_params, dev_name, monitor=False):
  74. host = rutils.get_host(devices, dev_name)
  75. # simple check if authorized_keys works correctly
  76. status, buf = host.execute(["id"])
  77. if status != 0:
  78. raise Exception(dev_name + " - ssh communication FAILED: " + buf)
  79. rutils.setup_hw_host(host, setup_params)
  80. ifaces = re.split('; | |, ', host.ifname)
  81. # check interfaces (multi for monitor)
  82. for iface in ifaces:
  83. status, buf = host.execute(["ifconfig", iface])
  84. if status != 0:
  85. raise Exception(dev_name + " ifconfig " + iface + " failed: " + buf)
  86. # monitor doesn't need wpa_supplicant/hostapd ...
  87. if monitor == True:
  88. return
  89. status, buf = host.execute(["ls", "-l", setup_params['wpa_supplicant']])
  90. if status != 0:
  91. raise Exception(dev_name + " - wpa_supplicant: " + buf)
  92. status, buf = host.execute(["ls", "-l", setup_params['hostapd']])
  93. if status != 0:
  94. raise Exception(dev_name + " - hostapd: " + buf)
  95. status, buf = host.execute(["which", setup_params['iperf']])
  96. if status != 0:
  97. raise Exception(dev_name + " - iperf: " + buf)
  98. status, buf = host.execute(["which", "tshark"])
  99. if status != 0:
  100. logger.debug(dev_name + " - tshark: " + buf)
  101. def check_devices(devices, setup_params, refs, duts, monitors):
  102. """Check duts/refs/monitors devices"""
  103. for dut in duts:
  104. check_device(devices, setup_params, dut)
  105. for ref in refs:
  106. check_device(devices, setup_params, ref)
  107. for monitor in monitors:
  108. if monitor == "all":
  109. continue
  110. check_device(devices, setup_params, monitor, monitor=True)