Home | History | Annotate | Download | only in network_DefaultProfileCreation
      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 errno
      6 import logging
      7 import os
      8 import time
      9 
     10 from autotest_lib.client.bin import test
     11 from autotest_lib.client.common_lib import error
     12 from autotest_lib.client.cros.networking import shill_context
     13 from autotest_lib.client.cros.networking import shill_proxy
     14 
     15 class network_DefaultProfileCreation(test.test):
     16     """The Default Profile Creation class.
     17 
     18     Wipe the default profile, start shill, and check that a default
     19     profile has been created.
     20 
     21     Test that the default profile contains default values for properties
     22     that should have them.
     23 
     24     """
     25     DEFAULT_PROFILE_PATH = '/var/cache/shill/default.profile'
     26     EXPECTED_SETTINGS = [
     27         # From DefaultProfile::LoadManagerProperties
     28         'CheckPortalList=ethernet,wifi,cellular',
     29         'IgnoredDNSSearchPaths=gateway.2wire.net',
     30         'LinkMonitorTechnologies=wifi',
     31         'PortalURL=http://www.gstatic.com/generate_204',
     32         'PortalCheckInterval=30',
     33         ]
     34     PROFILE_LOAD_TIMEOUT_SECONDS = 5
     35     version = 1
     36 
     37 
     38     def run_once(self):
     39         """Test main loop."""
     40         with shill_context.stopped_shill():
     41             try:
     42                 os.remove(self.DEFAULT_PROFILE_PATH)
     43             except OSError as e:
     44                 if e.errno != errno.ENOENT:
     45                     raise e
     46         shill = shill_proxy.ShillProxy.get_proxy()
     47         start_time = time.time()
     48         profile = None
     49         while time.time() - start_time < self.PROFILE_LOAD_TIMEOUT_SECONDS:
     50             if shill.get_profiles():
     51                 with open(self.DEFAULT_PROFILE_PATH) as f:
     52                     profile = f.read()
     53                     if profile:
     54                         break
     55 
     56             time.sleep(1)
     57         else:
     58             if profile is None:
     59                 raise error.TestFail('shill should load a profile within '
     60                                      '%d seconds.' %
     61                                      self.PROFILE_LOAD_TIMEOUT_SECONDS)
     62             else:
     63                 raise error.TestFail('shill profile is still empty after '
     64                                      '%d seconds.' %
     65                                      self.PROFILE_LOAD_TIMEOUT_SECONDS)
     66 
     67         logging.info('Profile contents after %d seconds:\%s',
     68                      time.time() - start_time, profile)
     69         for setting in self.EXPECTED_SETTINGS:
     70             if setting not in profile:
     71                 logging.error('Did not find setting %s', setting)
     72                 logging.error('Full profile contents are:\n%s', profile)
     73                 raise error.TestFail('Missing setting(s) in default profile.')
     74