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 initialize(self, host, image=None, local=False): 18 """Setup image path. 19 20 @param host: Host object representing DUT to be re-imaged. 21 @param image_url: URL of a test image to be installed. 22 @param local: bool indicating it's a local run with an image already 23 on the usb stick of the servo 24 """ 25 self.local = local 26 if not self.local: 27 self.image = image 28 if not self.image: 29 raise error.TestFail('No image path provided, and not run ' 30 'with .local flag to indicate image ' 31 'already on the stick.') 32 33 def run_once(self, host): 34 """Install recovery image on |host|. 35 36 @param host: Host object representing DUT to be re-imaged. 37 """ 38 if self.local: 39 # This indicates the image is already on the stick before 40 # the test starts, so the only thing required is to boot 41 # in recovery. 42 host.servo.boot_in_recovery_mode() 43 else: 44 # In this phase, the image is a provided path. 45 host.servo.install_recovery_image(self.image, 46 make_image_noninteractive=True) 47 logging.info('Running the recovery process on the DUT. ' 48 'Will wait up to %d seconds for recovery to ' 49 'complete.', self._RECOVERY_INSTALL_DELAY) 50 start_time = time.time() 51 # Wait for the host to come up. 52 if host.ping_wait_up(timeout=self._RECOVERY_INSTALL_DELAY): 53 logging.info('Recovery process completed successfully in ' 54 '%d seconds.', time.time() - start_time) 55 else: 56 raise error.TestFail('Host failed to come back up after ' 57 '%d seconds.' % self._RECOVERY_INSTALL_DELAY) 58 logging.info('Removing the usb key from the DUT.') 59 host.servo.switch_usbkey('host') 60