1# Lint as: python2, python3 2# Copyright 2018 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import logging 7import random 8 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.common_lib import utils 11from autotest_lib.client.common_lib.cros import kernel_utils 12from autotest_lib.server.cros.update_engine import update_engine_test 13 14class autoupdate_Interruptions(update_engine_test.UpdateEngineTest): 15 """Ensures an update completes with multiple user interruptions.""" 16 version = 1 17 18 def cleanup(self): 19 self._save_extra_update_engine_logs(number_of_logs=2) 20 21 # Clean up the nebraska usr dir. 22 self._clear_nebraska_dir() 23 24 super(autoupdate_Interruptions, self).cleanup() 25 26 27 def run_once(self, full_payload=True, interrupt=None, job_repo_url=None): 28 """ 29 Runs an update with interruptions from the user. 30 31 @param full_payload: True for a full payload. False for delta. 32 @param interrupt: The interrupt to perform: See _SUPPORTED_INTERRUPTS. 33 @param job_repo_url: Used for debugging locally. This is used to figure 34 out the current build and the devserver to use. 35 The test will read this from a host argument 36 when run in the lab. 37 38 """ 39 if interrupt and interrupt not in self._SUPPORTED_INTERRUPTS: 40 raise error.TestFail('Unknown interrupt type: %s' % interrupt) 41 42 # Clear any previously started updates. 43 self._remove_update_engine_pref(self._UPDATE_CHECK_RESPONSE_HASH) 44 self._restart_update_engine(ignore_status=True) 45 46 payload_url = self.get_payload_for_nebraska(job_repo_url, 47 full_payload=full_payload) 48 chromeos_version = self._host.get_release_version() 49 active, inactive = kernel_utils.get_kernel_state(self._host) 50 # Choose a random downloaded progress to interrupt the update. 51 progress = random.uniform(0.1, 0.6) 52 logging.info('Progress when we will begin interruptions: %f', progress) 53 54 # Login, start the update, logout 55 self._run_client_test_and_check_result( 56 'autoupdate_LoginStartUpdateLogout', 57 payload_url=payload_url, 58 progress_to_complete=progress, 59 full_payload=full_payload, 60 interrupt_network=interrupt == self._NETWORK_INTERRUPT) 61 62 if interrupt in [self._REBOOT_INTERRUPT, self._SUSPEND_INTERRUPT]: 63 if self._is_update_finished_downloading(): 64 raise error.TestFail( 65 'Update finished before %s interrupt started. Interrupt ' 66 'was supposed to be at %f' % (interrupt, progress)) 67 self._wait_for_progress(progress) 68 completed = self._get_update_progress() 69 70 if interrupt == self._REBOOT_INTERRUPT: 71 self._host.reboot() 72 utils.poll_for_condition(self._get_update_engine_status, 73 desc='update engine to start') 74 # The client test created a nebraska startup config, so 75 # nebraska will be up after the reboot. 76 self._check_for_update(self._get_nebraska_update_url()) 77 elif interrupt == self._SUSPEND_INTERRUPT: 78 self._suspend_then_resume() 79 80 if self._is_update_engine_idle(): 81 raise error.TestFail( 82 'The update was IDLE after interrupt. Last error: %s' % 83 self._get_last_error_string()) 84 if not self._update_continued_where_it_left_off( 85 completed, 86 reboot_interrupt=interrupt == self._REBOOT_INTERRUPT): 87 raise error.TestFail('The update did not continue where it ' 88 'left off after interruption.') 89 90 self._wait_for_update_to_complete() 91 self._edit_nebraska_startup_config(no_update=True) 92 self._host.reboot() 93 # Check that update engine is ready after reboot. 94 utils.poll_for_condition(self._get_update_engine_status, 95 desc='update engine to start') 96 # Do a final update check with no_update=True to get post reboot event. 97 self._check_for_update(self._get_nebraska_update_url()) 98 99 # Verify the update was successful by checking hostlog and kernel. 100 rootfs_hostlog, reboot_hostlog = self._create_hostlog_files() 101 self.verify_update_events(chromeos_version, rootfs_hostlog) 102 self.verify_update_events(chromeos_version, reboot_hostlog, 103 chromeos_version) 104 kernel_utils.verify_boot_expectations(inactive, host=self._host) 105