• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2010 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 logging, os, time
6from autotest_lib.client.bin import test, utils
7from autotest_lib.client.common_lib import error
8
9
10PROCESS_WHITELIST = (
11    # TODO(dalecurtis): Remove once http://crosbug.com/15697 is fixed.
12    'cryptohom',
13    'chapsd',
14)
15
16SHUTDOWN_CRYPTOHOME_UMOUNT_FAIL = '/var/log/shutdown_cryptohome_umount_failure'
17SHUTDOWN_STATEFUL_UMOUNT_FAIL = '/var/log/shutdown_stateful_umount_failure'
18SHUTDOWN_KILLED_PROCESSES_LOG = '/var/log/shutdown_force_kill_processes'
19
20
21class platform_CleanShutdown(test.test):
22    version = 1
23
24
25    def _log_remove_if_exists(self, filename, message):
26        if not os.path.exists(filename):
27            return
28
29        contents = utils.read_file(filename).strip()
30        os.remove(filename)
31
32        if filename == SHUTDOWN_KILLED_PROCESSES_LOG:
33            # Remove all killed processes listed in the white list. An example
34            # log is included below:
35            #
36            #    COMMAND     PID    USER  FD   TYPE DEVICE SIZE/OFF   NODE NAME
37            #    cryptohom  [........]
38            #
39            filtered_contents = filter(
40                lambda line: not line.startswith(PROCESS_WHITELIST),
41                contents.splitlines())
42
43            # If there are no lines left but the header, return nothing.
44            if len(filtered_contents) <= 1:
45                return
46            else:
47                contents = '\n'.join(filtered_contents)
48
49        logging.error('Last shutdown problem: %s. Detailed output was:\n%s' %
50                      (message, contents))
51        self._errors.append(message)
52
53
54    def run_once(self):
55        self._errors = []
56        # Problems during shutdown are brought out in /var/log files
57        # which we show here.
58        self._log_remove_if_exists(SHUTDOWN_CRYPTOHOME_UMOUNT_FAIL,
59                                   'cryptohome unmount failed')
60        self._log_remove_if_exists(SHUTDOWN_STATEFUL_UMOUNT_FAIL,
61                                   'stateful unmount failed')
62        self._log_remove_if_exists(SHUTDOWN_KILLED_PROCESSES_LOG,
63                                   'force killed processes')
64        if self._errors:
65            raise error.TestFail(
66                'Last shutdown problems: %s' % ' and '.join(self._errors))
67