1# Lint as: python2, python3 2# Copyright 2014 The Chromium OS 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 time 8 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.bin import test 11from autotest_lib.client.cros.networking.chrome_testing \ 12 import chrome_networking_test_context as cntc 13from autotest_lib.client.cros.networking.chrome_testing \ 14 import chrome_networking_test_api as cnta 15from autotest_lib.client.common_lib.cros.network \ 16 import chrome_net_constants 17 18class network_RoamWifiEndToEnd(test.test): 19 """ 20 Tests the following with chrome.networkingPrivate APIs: 21 1. Tests that the DUT can see and connect to the configured AP. 22 2. Tests the DUT can Roam/Failover between networks with same SSID. 23 24 """ 25 version = 1 26 27 28 def _find_configured_network(self): 29 """Check if the required network is in the networks_found list. 30 31 @return Service list of the required network; None if network not found 32 33 """ 34 networks = self.chrome_networking.get_wifi_networks() 35 36 for service in networks: 37 if service['Name'] == self.SSID: 38 return service 39 return None 40 41 42 def _find_and_connect_to_configured_network(self): 43 """Find all networks in range and connect to the required network.""" 44 45 network = self._find_configured_network() 46 47 if network is None: 48 raise error.TestFail('Network with ssid=%s is not found', self.SSID) 49 self.chrome_networking.connect_to_network(network) 50 51 52 def _verify_device_roamed(self): 53 """Verify that the device has roamed between networks. 54 55 @raises error.TestFail if connect to second AP has failed. 56 57 """ 58 # Give the DUT some time to roam to the other AP and connect. 59 time.sleep(self.chrome_networking.SHORT_TIMEOUT) 60 required_network_service_list = self._find_configured_network() 61 62 # Check if the network exists and it is in connected state. 63 if required_network_service_list is None: 64 raise error.TestFail('Network with ssid=%s is not found', self.SSID) 65 66 if required_network_service_list['ConnectionState'] != 'Connected': 67 raise error.TestFail( 68 'DUT failed to roam/connect to the second network') 69 70 if required_network_service_list['ConnectionState'] == 'Connected': 71 logging.info('DUT successfully roamed to the other Open network') 72 73 74 def run_once(self, ssid, test): 75 """Run the test. 76 77 @param ssid: SSID of the APs. 78 @param test: Set by the server test control file depending on the test 79 that is being run. 80 81 """ 82 self.SSID = ssid 83 84 with cntc.ChromeNetworkingTestContext() as testing_context: 85 self.chrome_networking = cnta.ChromeNetworkProvider(testing_context) 86 enabled_devices = self.chrome_networking.get_enabled_devices() 87 if (self.chrome_networking.WIFI_DEVICE not in 88 enabled_devices): 89 self.chrome_networking.enable_network_device( 90 self.chrome_networking.WIFI_DEVICE) 91 92 self.chrome_networking.scan_for_networks() 93 if test == chrome_net_constants.OPEN_CONNECT: 94 self._find_and_connect_to_configured_network() 95 elif test == chrome_net_constants.OPEN_ROAM: 96 self._verify_device_roamed() 97