aboutsummaryrefslogtreecommitdiff
path: root/server/site_tests/network_WiFi_ChaosConfigSniffer/network_WiFi_ChaosConfigSniffer.py
blob: 62976405052d0d617d3f046594213e3040265b82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Lint as: python2, python3
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import logging
import os
import pprint

from autotest_lib.client.common_lib import error
from autotest_lib.client.common_lib.cros.network import iw_runner
from autotest_lib.server import test

class network_WiFi_ChaosConfigSniffer(test.test):
    """ Test to grab debugging info about chaos configuration falures. """

    version = 1


    def run_once(self, wifi_client=None, ssids=None):
        if ssids is None:
            ssids = []
        missing_ssids = []
        for ssid in ssids:
            logging.info('Scanning for SSID: %s', ssid)
            networks = wifi_client.iw_runner.wait_for_scan_result(
                wifi_client._wifi_if, ssids=[ssid], timeout_seconds=60)
            if networks == None:
                missing_ssids.append(ssid)
            else:
                path = os.path.join(self.outputdir, str('%s.txt' % ssid))
                network = networks[0]
                f = open(path, 'wb')
                f.write('Scan information:\n')
                f.write(pprint.pformat(network))
                f.write('\n\n\nInfo to be added to the config file:\n')
                f.write('[%s]\n' % network.bss)
                f.write('brand = <Enter AP brand>\n')
                f.write('wan_hostname = <Enter hostname, do not '
                        'include .cros>\n')
                f.write('ssid = %s\n' % network.ssid)
                f.write('frequency = %s\n' % network.frequency)
                f.write('rpm_managed = True\n')
                if network.frequency > 2484:
                    f.write('bss5 = %s\n' % network.bss)
                else:
                    f.write('bss = %s\n' % network.bss)
                f.write('wan mac = <Enter WAN MAC address>\n')
                f.write('model = <Enter model>\n')
                f.write('security = %s\n' % network.security)
                if (network.security == iw_runner.SECURITY_WPA or
                    network.security == iw_runner.SECURITY_WPA2 or
                    network.security == iw_runner.SECURITY_MIXED):
                    f.write('psk = chromeos\n')
                f.write('class_name = StaticAPConfigurator\n')
                f.close()
        if len(missing_ssids) > 0:
            logging.error('The following SSIDs could not be found:')
            for ssid in missing_ssids:
                logging.error('\t%s', ssid)
            raise error.TestError('Some SSIDs could not be found, please check '
                                  'the configuration on the APs.')