Home | History | Annotate | Download | only in network_WiFi_DisconnectClearsIP
      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 import time
      7 
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
     10 from autotest_lib.server.cros.network import hostap_config
     11 from autotest_lib.server.cros.network import wifi_cell_test_base
     12 
     13 
     14 class network_WiFi_DisconnectClearsIP(wifi_cell_test_base.WiFiCellTestBase):
     15     """Check that we remove our IP after disconnection from a WiFi network."""
     16 
     17     version = 1
     18 
     19     IP_CHECK_ATTEMPTS = 10
     20 
     21     def run_once(self):
     22         """Test body."""
     23         ap_config = hostap_config.HostapConfig(
     24                 frequency=2412,
     25                 mode=hostap_config.HostapConfig.MODE_11G)
     26         client_config = xmlrpc_datatypes.AssociationParameters()
     27         self.context.configure(ap_config)
     28         client_config.ssid = self.context.router.get_ssid()
     29         self.context.assert_connect_wifi(client_config)
     30         if self.context.client.wifi_ip is None:
     31             raise error.TestFail('After connecting, we should have an IP.')
     32 
     33         self.context.assert_ping_from_dut()
     34         disconnect_check = self.context.client.shill.disconnect(
     35             self.context.router.get_ssid())
     36         if not disconnect_check:
     37             raise error.TestFail('Failed to disconnect from the network')
     38         logging.info('Successfully disconnected.')
     39 
     40         for _ in range(0, self.IP_CHECK_ATTEMPTS):
     41             wifi_ip = self.context.client.wifi_ip
     42             if wifi_ip is None:
     43                 return
     44             logging.info('IP was still set: %s', wifi_ip)
     45             time.sleep(1)
     46         else:
     47             raise error.TestFail('After disconnecting, we should '
     48                                  'not have an IP.')
     49