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