1# Copyright (c) 2013 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 6 7from autotest_lib.server import test 8from autotest_lib.server.cros import autoupdate_utils 9 10 11class autoupdate_Rollback(test.test): 12 """Test that updates the machine and performs rollback.""" 13 version = 1 14 15 16 def run_once(self, host, job_repo_url=None): 17 """Runs the test. 18 19 @param host: A host object representing the DUT. 20 @param job_repo_url: URL to get the image. 21 22 @raise error.TestError if anything went wrong with setting up the test; 23 error.TestFail if any part of the test has failed. 24 25 """ 26 updater = autoupdate_utils.get_updater_from_repo_url(host, job_repo_url) 27 28 initial_kernel, updated_kernel = updater.get_kernel_state() 29 logging.info('Initial device state: active kernel %s, ' 30 'inactive kernel %s.', initial_kernel, updated_kernel) 31 32 logging.info('Performing an update.') 33 updater.update_rootfs() 34 host.reboot() 35 36 # We should be booting from the new partition. 37 error_message = 'Failed to set up test by updating DUT.' 38 updater.verify_boot_expectations(expected_kernel_state=updated_kernel, 39 rollback_message=error_message) 40 logging.info('Update verified, initiating rollback.') 41 42 # Powerwash is tested separately from rollback. 43 updater.rollback_rootfs(powerwash=False) 44 host.reboot() 45 46 # We should be back on our initial partition. 47 error_message = ('Autoupdate reported that rollback succeeded but we ' 48 'did not boot into the correct partition.') 49 updater.verify_boot_expectations(expected_kernel_state=initial_kernel, 50 rollback_message=error_message) 51 logging.info('We successfully rolled back to initial kernel.') 52