1# Copyright 2014 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 5from autotest_lib.client.common_lib import error 6from autotest_lib.client.common_lib.cros.network import apmanager_constants 7from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes 8from autotest_lib.server.cros.network import apmanager_service_provider 9from autotest_lib.server.cros.network import wifi_cell_test_base 10 11 12class apmanager_SimpleConnect(wifi_cell_test_base.WiFiCellTestBase): 13 """Test that the DUT can connect to an AP created by apmanager.""" 14 version = 1 15 16 XMLRPC_BRINGUP_TIMEOUT_SECONDS = 60 17 18 def parse_additional_arguments(self, commandline_args, additional_params): 19 """Hook into super class to take control files parameters. 20 21 @param commandline_args dict of parsed parameters from the autotest. 22 @param additional_params dict of AP configuration parameters. 23 24 """ 25 self._configurations = additional_params 26 27 28 def run_once(self): 29 """Sets up a router, connects to it, pings it.""" 30 # Setup bridge mode test environments if AP is configured to operate in 31 # bridge mode. 32 if (apmanager_constants.CONFIG_OPERATION_MODE in self._configurations 33 and self._configurations[apmanager_constants.CONFIG_OPERATION_MODE] 34 == apmanager_constants.OPERATION_MODE_BRIDGE): 35 # Setup DHCP server on the other side of the bridge. 36 self.context.router.setup_bridge_mode_dhcp_server() 37 self._configurations[apmanager_constants.CONFIG_BRIDGE_INTERFACE] =\ 38 self.context.router.get_bridge_interface() 39 40 ssid = self.context.router.build_unique_ssid() 41 self._configurations[apmanager_constants.CONFIG_SSID] = ssid 42 with apmanager_service_provider.ApmanagerServiceProvider( 43 self.context.router, self._configurations): 44 assoc_params = xmlrpc_datatypes.AssociationParameters() 45 assoc_params.ssid = ssid 46 self.context.assert_connect_wifi(assoc_params) 47 self.context.assert_ping_from_server() 48 # AP is terminated, wait for client to become disconnected. 49 success, state, elapsed_seconds = \ 50 self.context.client.wait_for_service_states( 51 ssid, ( 'idle', ), 30) 52 if not success: 53 raise error.TestFail('Failed to disconnect from %s after AP was ' 54 'terminated for %f seconds (state=%s)' % 55 (ssid, elapsed_seconds, state)) 56