Home | History | Annotate | Download | only in network_BasicProfileProperties
      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.bin import test
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.client.common_lib.cros.network import interface
     10 from autotest_lib.client.cros import shill_temporary_profile
     11 from autotest_lib.client.cros.networking import wifi_proxy
     12 
     13 class network_BasicProfileProperties(test.test):
     14     """Test that shill's DBus properties for profiles work."""
     15 
     16     version = 1
     17 
     18     PROFILE_NAME = 'test'
     19     PROFILE_PROPERTY_NAME = 'Name'
     20     PROFILE_PROPERTY_ENTRIES = 'Entries'
     21 
     22 
     23     @staticmethod
     24     def get_field_from_properties(properties, field):
     25         """Get a field from a dictionary of properties.
     26 
     27         Raises an exception on failure.
     28 
     29         @param properties dict of properties (presumably from some
     30                 DBus object).
     31         @param field string key to search for in |properties|.
     32         @return value of properties[field].
     33 
     34         """
     35         if not field in properties:
     36             raise error.TestFail('No %s field in properties %r?' %
     37                                  (field, properties))
     38 
     39         return properties[field]
     40 
     41 
     42     def run_once(self):
     43         """Test body."""
     44         shill = wifi_proxy.WifiProxy.get_proxy()
     45         with shill_temporary_profile.ShillTemporaryProfile(
     46                 shill.manager, profile_name=self.PROFILE_NAME):
     47             profiles = shill.get_profiles()
     48             logging.info('Got profiles %r', profiles)
     49             # The last profile should be the one we just created.
     50             profile = profiles[-1]
     51             profile_properties = shill.dbus2primitive(
     52                     profile.GetProperties(utf8_strings=True))
     53             logging.debug('Profile properties: %r.', profile_properties)
     54             profile_name = self.get_field_from_properties(
     55                     profile_properties, self.PROFILE_PROPERTY_NAME)
     56             if profile_name != self.PROFILE_NAME:
     57                 raise error.TestFail('Found unexpected top profile with name '
     58                                      '%r.' % profile_name)
     59 
     60             entries = shill.dbus2primitive(self.get_field_from_properties(
     61                     profile_properties, self.PROFILE_PROPERTY_ENTRIES))
     62             logging.info('Found entries: %r', entries)
     63             ethernet_if = interface.Interface.get_connected_ethernet_interface()
     64             mac = ethernet_if.mac_address.replace(':', '').lower()
     65             ethernet_entry_key = 'ethernet_%s' % mac
     66             if not ethernet_entry_key in entries:
     67                 raise error.TestFail('Missing ethernet entry %s from profile.' %
     68                                      ethernet_entry_key)
     69 
     70             entry = profile.GetEntry(ethernet_entry_key)
     71