Home | History | Annotate | Download | only in network_WiFi_ChaosConfigSniffer
      1 # Copyright 2015 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import logging
      6 import os
      7 import pprint
      8 
      9 from autotest_lib.client.common_lib import error
     10 from autotest_lib.client.common_lib.cros.network import iw_runner
     11 from autotest_lib.server import test
     12 
     13 class network_WiFi_ChaosConfigSniffer(test.test):
     14     """ Test to grab debugging info about chaos configuration falures. """
     15 
     16     version = 1
     17 
     18 
     19     def run_once(self, wifi_client=None, ssids=[]):
     20         missing_ssids = []
     21         for ssid in ssids:
     22             logging.info('Scanning for SSID: %s', ssid)
     23             networks = wifi_client.iw_runner.wait_for_scan_result(
     24                 wifi_client._wifi_if, ssids=[ssid], timeout_seconds=60)
     25             if networks == None:
     26                 missing_ssids.append(ssid)
     27             else:
     28                 path = os.path.join(self.outputdir, str('%s.txt' % ssid))
     29                 network = networks[0]
     30                 f = open(path, 'wb')
     31                 f.write('Scan information:\n')
     32                 f.write(pprint.pformat(network))
     33                 f.write('\n\n\nInfo to be added to the config file:\n')
     34                 f.write('[%s]\n' % network.bss)
     35                 f.write('brand = <Enter AP brand>\n')
     36                 f.write('wan_hostname = <Enter hostname, do not '
     37                         'include .cros>\n')
     38                 f.write('ssid = %s\n' % network.ssid)
     39                 f.write('frequency = %s\n' % network.frequency)
     40                 f.write('rpm_managed = True\n')
     41                 if network.frequency > 2484:
     42                     f.write('bss5 = %s\n' % network.bss)
     43                 else:
     44                     f.write('bss = %s\n' % network.bss)
     45                 f.write('wan mac = <Enter WAN MAC address>\n')
     46                 f.write('model = <Enter model>\n')
     47                 f.write('security = %s\n' % network.security)
     48                 if (network.security == iw_runner.SECURITY_WPA or
     49                     network.security == iw_runner.SECURITY_WPA2 or
     50                     network.security == iw_runner.SECURITY_MIXED):
     51                     f.write('psk = chromeos\n')
     52                 f.write('class_name = StaticAPConfigurator\n')
     53                 f.close()
     54         if len(missing_ssids) > 0:
     55             logging.error('The following SSIDs could not be found:')
     56             for ssid in missing_ssids:
     57                 logging.error('\t%s', ssid)
     58             raise error.TestError('Some SSIDs could not be found, please check '
     59                                   'the configuration on the APs.')
     60