1# Copyright (c) 2012 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
6import time
7
8from autotest_lib.server import test
9from autotest_lib.client.common_lib import error
10
11class platform_InstallRecoveryImage(test.test):
12    """Installs a specified recovery image onto a servo-connected DUT."""
13    version = 1
14
15    _RECOVERY_INSTALL_DELAY = 540
16
17    def run_once(self, host, image):
18        host.servo.install_recovery_image(image,
19                                          make_image_noninteractive=True)
20        logging.info('Running the recovery process on the DUT. '
21                     'Will wait up to %d seconds for recovery to '
22                     'complete.', self._RECOVERY_INSTALL_DELAY)
23        start_time = time.time()
24        # Wait for the host to come up.
25        if host.ping_wait_up(timeout=self._RECOVERY_INSTALL_DELAY):
26            logging.info('Recovery process completed successfully in '
27                         '%d seconds.', time.time() - start_time)
28        else:
29            raise error.TestFail('Host failed to come back up after '
30                                 '%d seconds.' % self._RECOVERY_INSTALL_DELAY)
31        logging.info('Removing the usb key from the DUT.')
32        host.servo.switch_usbkey('host')
33