blob: 5198e6d8a79fb4970138d0472335154d9a228e42 [file] [log] [blame]
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import time
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import dhcp_test_base
class network_DhcpFailureWithStaticIP(dhcp_test_base.DhcpTestBase):
"""The DHCP Negotiation Timeout class.
Sets up a virtual ethernet pair, and stops the DHCP server on the
pair. Static IP parameters are configured on the interface using
shill's StaticIP configuration. Ensure that these parameters are
immediately applied to the ipconfig.
After the DHCP timeout interval, check to make sure that the same
IP config remains applied.
def check_static_ip_config(self, ipconfig, static_ip_address, name_servers):
"""Checks that the static IP configuration is applied to the
interface ipconfig.
@param ipconfig object representing the DBus IPConfig entity to check.
@param static_ip_address string IP address we expect to be configured.
@param name_servers list of string name servers we expect to be
configured on the interface.
ipconfig_properties = self.shill_proxy.dbus2primitive(
ipconfig.GetProperties(utf8_strings=True))'IPConfig properties are %r', ipconfig_properties)
if static_ip_address != ipconfig_properties['Address']:
raise error.TestFail('Expected address %r but got %r' %
if name_servers != ipconfig_properties['NameServers']:
raise error.TestFail('Expected name servers %r but got %r' %
def get_ipconfig(self):
"""Returns the first IPConfig object associated with the peer device."""
ipconfig_objects = (
if len(ipconfig_objects) == 0:
raise error.TestFail('Failed to retrieve DHCP ipconfig object '
'from shill.')
return ipconfig_objects[0]
def test_body(self):
"""Test main loop."""
service = self.find_ethernet_service(
static_ip_address = ''
prefix_len = 23
service.SetProperty('StaticIP.Address', static_ip_address)
service.SetProperty('StaticIP.Prefixlen', prefix_len)
name_servers = [ '', '' ]
ipconfig = self.get_ipconfig()
self.check_static_ip_config(ipconfig, static_ip_address, name_servers)
# Make sure configuration is still correct after DHCP timeout.
time.sleep(self.SHILL_DHCP_TIMEOUT_SECONDS + 2)
ipconfig = self.get_ipconfig()
self.check_static_ip_config(ipconfig, static_ip_address, name_servers)