• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2014 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
5from autotest_lib.client.bin import test
6from autotest_lib.client.common_lib import error
7from autotest_lib.client.common_lib import utils
8
9class network_TwoShills(test.test):
10    """Test that only one shill runs at a time"""
11    SHILL_EXIT_TIMEOUT_SECONDS = 10
12    version = 1
13
14
15    @staticmethod
16    def is_shill_running():
17        """
18        Check if shill is running.
19
20        @return True or False.
21
22        """
23        return utils.get_service_pid("shill") != 0
24
25
26    @staticmethod
27    def get_default_netdev():
28        """
29        Get the name of the network device with the default route.
30
31        @return A string such as "eth0" or "wlan0".
32
33        """
34        cmd_result = utils.run(
35            "ip route show default match 0/0 | awk '{print $5}'")
36        return cmd_result.stdout
37
38
39    def run_once(self):
40        """Test main loop."""
41        if not self.is_shill_running():
42            raise error.TestFail("shill not running at start")
43
44        default_netdev = self.get_default_netdev()
45        if len(default_netdev) < 1:
46            raise error.TestFail("unable to determine default network device")
47
48        try:
49            # Run shill, expecting it to abort quickly. If the new
50            # process does not exit within the allotted time,
51            # utils.run() will kill the new process
52            # explicitly. (First with SIGTERM, then SIGKILL.)
53            cmd_result = utils.run(
54                "shill --foreground --device-black-list=%s" % default_netdev,
55                timeout=self.SHILL_EXIT_TIMEOUT_SECONDS,
56                ignore_status = True)
57        except error.CmdTimeoutError:
58            raise error.TestFail("shill did not exit within %d seconds" %
59                                 self.SHILL_EXIT_TIMEOUT_SECONDS)
60