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 5 import logging 6 7 from autotest_lib.client.common_lib import error 8 from autotest_lib.server import test 9 from autotest_lib.server.cros import autoupdate_utils 10 11 POWERWASH_COMMAND = 'safe fast keepimg' 12 POWERWASH_MARKER_FILE = '/mnt/stateful_partition/factory_install_reset' 13 STATEFUL_MARKER_FILE = '/mnt/stateful_partition/autoupdate_Rollback_flag' 14 15 class autoupdate_Rollback(test.test): 16 """Test that updates the machine and performs rollback.""" 17 version = 1 18 19 def _powerwash(self, host): 20 """ 21 Powerwashes DUT. 22 23 @param host: The DUT we are testing on. 24 25 """ 26 logging.info('Powerwashing device before rollback.') 27 host.run('echo car > %s' % STATEFUL_MARKER_FILE) 28 host.run("echo '%s' > %s" % (POWERWASH_COMMAND, POWERWASH_MARKER_FILE)) 29 host.reboot() 30 marker = host.run('[ -e %s ]' % STATEFUL_MARKER_FILE, 31 ignore_status=True, ignore_timeout=True) 32 if marker is None or marker.exit_status == 0: 33 raise error.TestFail("Powerwash cycle didn't remove the marker " 34 "file on the stateful partition.") 35 36 37 def run_once(self, host, job_repo_url=None, 38 powerwash_before_rollback=False): 39 """Runs the test. 40 41 @param host: A host object representing the DUT. 42 @param job_repo_url: URL to get the image. 43 44 @raise error.TestError if anything went wrong with setting up the test; 45 error.TestFail if any part of the test has failed. 46 47 """ 48 updater = autoupdate_utils.get_updater_from_repo_url(host, job_repo_url) 49 50 initial_kernel, updated_kernel = updater.get_kernel_state() 51 logging.info('Initial device state: active kernel %s, ' 52 'inactive kernel %s.', initial_kernel, updated_kernel) 53 54 logging.info('Performing an update.') 55 updater.update_image() 56 host.reboot() 57 58 # We should be booting from the new partition. 59 error_message = 'Failed to set up test by updating DUT.' 60 updater.verify_boot_expectations(updated_kernel, error_message) 61 62 if powerwash_before_rollback: 63 self._powerwash(host) 64 65 logging.info('Update verified, initiating rollback.') 66 # Powerwash is tested separately from rollback. 67 updater.rollback_rootfs(powerwash=False) 68 host.reboot() 69 70 # We should be back on our initial partition. 71 error_message = ('Autoupdate reported that rollback succeeded but we ' 72 'did not boot into the correct partition.') 73 updater.verify_boot_expectations(initial_kernel, error_message) 74 logging.info('We successfully rolled back to initial kernel.') 75