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 5import dbus 6import logging 7import time 8 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.cros import dhcp_test_base 11 12class network_DhcpFailureWithStaticIP(dhcp_test_base.DhcpTestBase): 13 """The DHCP Negotiation Timeout class. 14 15 Sets up a virtual ethernet pair, and stops the DHCP server on the 16 pair. Static IP parameters are configured on the interface using 17 shill's StaticIP configuration. Ensure that these parameters are 18 immediately applied to the ipconfig. 19 20 After the DHCP timeout interval, check to make sure that the same 21 IP config remains applied. 22 23 """ 24 SHILL_DHCP_TIMEOUT_SECONDS = 30 25 26 27 def check_static_ip_config(self, ipconfig, static_ip_address, name_servers): 28 """Checks that the static IP configuration is applied to the 29 interface ipconfig. 30 31 @param ipconfig object representing the DBus IPConfig entity to check. 32 @param static_ip_address string IP address we expect to be configured. 33 @param name_servers list of string name servers we expect to be 34 configured on the interface. 35 36 """ 37 ipconfig_properties = self.shill_proxy.dbus2primitive( 38 ipconfig.GetProperties(utf8_strings=True)) 39 40 logging.info('IPConfig properties are %r', ipconfig_properties) 41 if static_ip_address != ipconfig_properties['Address']: 42 raise error.TestFail('Expected address %r but got %r' % 43 (static_ip_address, 44 ipconfig_properties['Address'])) 45 46 if name_servers != ipconfig_properties['NameServers']: 47 raise error.TestFail('Expected name servers %r but got %r' % 48 (name_servers, 49 ipconfig_properties['NameServers'])) 50 51 52 def get_ipconfig(self): 53 """Returns the first IPConfig object associated with the peer device.""" 54 ipconfig_objects = ( 55 self.get_interface_ipconfig_objects( 56 self.ethernet_pair.peer_interface_name)) 57 if len(ipconfig_objects) == 0: 58 raise error.TestFail('Failed to retrieve DHCP ipconfig object ' 59 'from shill.') 60 return ipconfig_objects[0] 61 62 63 def test_body(self): 64 """Test main loop.""" 65 self.server.stop() 66 service = self.find_ethernet_service( 67 self.ethernet_pair.peer_interface_name) 68 69 static_ip_address = '192.168.1.101' 70 name_servers = [ '10.10.10.10', '10.10.11.11' ] 71 config = {'Address' : static_ip_address, 72 'Prefixlen' : 23, 73 'NameServers' : name_servers} 74 service.SetProperty(self.shill_proxy.SERVICE_PROPERTY_STATIC_IP_CONFIG, 75 dbus.Dictionary(config, signature='sv')) 76 77 ipconfig = self.get_ipconfig() 78 self.check_static_ip_config(ipconfig, static_ip_address, name_servers) 79 80 # Make sure configuration is still correct after DHCP timeout. 81 time.sleep(self.SHILL_DHCP_TIMEOUT_SECONDS + 2) 82 ipconfig = self.get_ipconfig() 83 self.check_static_ip_config(ipconfig, static_ip_address, name_servers) 84