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.common_lib import error
6from autotest_lib.server import autotest, test
7import time
8
9class platform_CompromisedStatefulPartition(test.test):
10    """Tests how the system recovers with the corrupted stateful partition.
11    """
12    version = 2
13
14    CMD_CORRUPT = 'rm -fr /mnt/stateful_partition/*.*'
15    OOBE_FILE = '/home/chronos/.oobe_completed'
16    _WAIT_DELAY = 2
17    FILES_LIST = [
18        '/mnt/stateful_partition/dev_image',
19        '/mnt/stateful_partition/encrypted.key',
20        '/mnt/stateful_partition/encrypted.block',
21        '/mnt/stateful_partition/unencrypted',
22    ]
23
24
25    def run_once(self, host, client_autotest):
26        """This test verify that user should get OOBE after booting
27        the device with corrupted statefull partition.
28        Test fails if not able to recover the device with corrupted
29        stateful partition.
30        """
31        if host.get_board_type() == 'OTHER':
32            raise error.TestNAError('Test can not processed on OTHER board type devices')
33        autotest_client = autotest.Autotest(host)
34        host.reboot()
35        autotest_client.run_test(client_autotest,
36                                 exit_without_logout=True)
37        if not host.run(self.CMD_CORRUPT,
38                        ignore_status=True).exit_status == 0:
39             raise error.TestFail('Unable to corrupt stateful partition')
40        host.run('sync', ignore_status=True)
41        time.sleep(self._WAIT_DELAY)
42        host.reboot()
43        host.run('sync', ignore_status=True)
44        time.sleep(self._WAIT_DELAY)
45        if host.path_exists(self.OOBE_FILE):
46            raise error.TestFail('Did not get OOBE screen after '
47                                 'rebooting the device with '
48                                 'corrupted statefull partition')
49        autotest_client.run_test(client_autotest,
50                                 exit_without_logout=True)
51        time.sleep(self._WAIT_DELAY)
52        for new_file in self.FILES_LIST:
53            if not host.path_exists(new_file):
54                raise error.TestFail('%s is missing after rebooting '
55                                     'the device with corrupted '
56                                     'statefull partition' % new_file)
57
58