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 time 6 7from autotest_lib.client.common_lib import error 8from autotest_lib.client.common_lib import utils 9from autotest_lib.client.cros import dhcp_test_base 10 11class network_DhcpNegotiationTimeout(dhcp_test_base.DhcpTestBase): 12 """The DHCP Negotiation Timeout class. 13 14 Sets up a virtual ethernet pair, stops the DHCP server on the pair, 15 restarts shill, and waits for DHCP to timeout. 16 17 After the timeout interval, checks if the same shill process is 18 running. If not, report failure. 19 20 """ 21 SHILL_DHCP_TIMEOUT_SECONDS = 30 22 23 24 @staticmethod 25 def get_daemon_pid(daemon_name): 26 """ 27 Get the PID of a running daemon. 28 29 @return The PID as an integer. 30 31 """ 32 pid = utils.get_service_pid(daemon_name) 33 if pid == 0: 34 raise error.TestFail('Failed to get the pid of %s' % daemon_name) 35 return pid 36 37 def test_body(self): 38 """Test main loop.""" 39 self.server.stop() 40 utils.restart_service("shill") 41 start_pid = self.get_daemon_pid("shill") 42 43 time.sleep(self.SHILL_DHCP_TIMEOUT_SECONDS + 2) 44 end_pid = self.get_daemon_pid("shill") 45 if end_pid != start_pid: 46 raise error.TestFail("shill restarted (probably crashed)") 47