Home | History | Annotate | Download | only in network
      1 # Copyright (c) 2013 The Chromium OS 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 
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.client.common_lib import utils
      9 from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
     10 from autotest_lib.client.cros import constants
     11 from autotest_lib.server import test
     12 from autotest_lib.site_utils import lxc
     13 from autotest_lib.server.cros.network import wifi_test_context_manager
     14 
     15 class WiFiCellTestBase(test.test):
     16     """An abstract base class for autotests in WiFi cells.
     17 
     18     WiFiCell tests refer to participants in the test as client, router, and
     19     server.  The client is just the DUT and the router is a nearby AP which we
     20     configure in various ways to test the ability of the client to connect.
     21     There is a third entity called a server which is distinct from the autotest
     22     server.  In WiFiTests, the server is a host which the client can only talk
     23     to over the WiFi network.
     24 
     25     WiFiTests have a notion of the control network vs the WiFi network.  The
     26     control network refers to the network between the machine running the
     27     autotest server and the various machines involved in the test.  The WiFi
     28     network is the subnet(s) formed by WiFi routers between the server and the
     29     client.
     30 
     31     """
     32 
     33     def initialize(self, host):
     34         if utils.host_could_be_in_afe(host.hostname):
     35             # There are some DUTs that have different types of wifi modules.
     36             # In order to generate separate performance graphs, a variant
     37             # name is needed.  Writing this key will generate results with
     38             # the name of <board>-<variant>.
     39             info = host.host_info_store.get()
     40             variant_name = info.get_label_value('variant')
     41             if variant_name:
     42                 self.write_test_keyval({constants.VARIANT_KEY: variant_name})
     43 
     44     @property
     45     def context(self):
     46         """@return the WiFi context for this test."""
     47         return self._wifi_context
     48 
     49 
     50     def parse_additional_arguments(self, commandline_args, additional_params):
     51         """Parse additional arguments for use in test.
     52 
     53         Subclasses should override this method do any other commandline parsing
     54         and setting grabbing that they need to do.  For test clarity, do not
     55         parse additional settings in the body of run_once.
     56 
     57         @param commandline_args dict of argument key, value pairs.
     58         @param additional_params object defined by test control file.
     59 
     60         """
     61         pass
     62 
     63 
     64     def warmup(self, host, raw_cmdline_args, additional_params=None):
     65         """
     66         Use the additional_params argument to pass in custom test data from
     67         control file to reuse test logic.  This object will be passed down via
     68         parse_additional_arguments.
     69 
     70         @param host host object representing the client DUT.
     71         @param raw_cmdline_args raw input from autotest.
     72         @param additional_params object passed in from control file.
     73 
     74         """
     75         cmdline_args = utils.args_to_dict(raw_cmdline_args)
     76         logging.info('Running wifi test with commandline arguments: %r',
     77                      cmdline_args)
     78         self._wifi_context = wifi_test_context_manager.WiFiTestContextManager(
     79                 self.__class__.__name__,
     80                 host,
     81                 cmdline_args,
     82                 self.debugdir)
     83 
     84         self._wifi_context.setup()
     85         self.parse_additional_arguments(cmdline_args, additional_params)
     86 
     87         msg = '======= WiFi autotest setup complete. Starting test... ======='
     88         self._wifi_context.client.shill_debug_log(msg)
     89 
     90 
     91     def cleanup(self):
     92         msg = '======= WiFi autotest complete. Cleaning up... ======='
     93         self._wifi_context.client.shill_debug_log(msg)
     94         # If we fail during initialization, we might not have a context.
     95         if hasattr(self, '_wifi_context'):
     96             self._wifi_context.teardown()
     97 
     98 
     99     def configure_and_connect_to_ap(self, configuration_parameters):
    100         """
    101         Configure the router as an AP with the given parameters and connect
    102         the DUT to it.
    103 
    104         @param configuration_parameters HostapConfig object.
    105 
    106         @return name of the configured AP
    107         """
    108         self.context.configure(configuration_parameters)
    109         ap_ssid = self.context.router.get_ssid()
    110         assoc_params = xmlrpc_datatypes.AssociationParameters(ssid=ap_ssid)
    111         self.context.assert_connect_wifi(assoc_params)
    112         return ap_ssid
    113