David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 1 | # Copyright 2017 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. |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 4 | |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 5 | import logging |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 6 | import random |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 7 | import time |
| 8 | |
David Haddock | 463faf4 | 2018-01-23 14:21:11 -0800 | [diff] [blame] | 9 | from autotest_lib.client.common_lib import error |
David Haddock | 3a8f572 | 2018-04-13 16:24:16 -0700 | [diff] [blame] | 10 | from autotest_lib.client.common_lib.cros import tpm_utils |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 11 | from autotest_lib.server.cros.update_engine import update_engine_test |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 12 | |
| 13 | class autoupdate_ForcedOOBEUpdate(update_engine_test.UpdateEngineTest): |
| 14 | """Runs a forced autoupdate during OOBE.""" |
| 15 | version = 1 |
| 16 | |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 17 | |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 18 | def cleanup(self): |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 19 | self._host.run('rm %s' % self._CUSTOM_LSB_RELEASE, ignore_status=True) |
| 20 | |
| 21 | # Get the last two update_engine logs: before and after reboot. |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame] | 22 | self._save_extra_update_engine_logs() |
| 23 | self._change_cellular_setting_in_update_engine(False) |
David Haddock | 50dbfee | 2018-01-12 12:43:12 -0800 | [diff] [blame] | 24 | super(autoupdate_ForcedOOBEUpdate, self).cleanup() |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 25 | |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 26 | |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 27 | def _wait_for_oobe_update_to_complete(self): |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 28 | """Wait for the update that started to complete. |
| 29 | |
| 30 | Repeated check status of update. It should move from DOWNLOADING to |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 31 | FINALIZING to COMPLETE (then reboot) to IDLE. |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 32 | """ |
David Haddock | 5e2ef31 | 2018-06-12 12:59:31 -0700 | [diff] [blame] | 33 | # 20 minute timeout. |
| 34 | timeout_minutes = 20 |
| 35 | timeout = time.time() + 60 * timeout_minutes |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 36 | while True: |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame] | 37 | status = self._get_update_engine_status(timeout=10) |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 38 | |
| 39 | # During reboot, status will be None |
| 40 | if status is not None: |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 41 | if self._UPDATE_STATUS_IDLE == status[self._CURRENT_OP]: |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 42 | break |
| 43 | time.sleep(1) |
David Haddock | 5e2ef31 | 2018-06-12 12:59:31 -0700 | [diff] [blame] | 44 | if time.time() > timeout: |
| 45 | raise error.TestFail('OOBE update did not finish in %d ' |
| 46 | 'minutes.' % timeout_minutes) |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 47 | |
| 48 | |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame] | 49 | def run_once(self, full_payload=True, cellular=False, |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 50 | interrupt=False, max_updates=1, job_repo_url=None): |
| 51 | """ |
| 52 | Runs a forced autoupdate during ChromeOS OOBE. |
| 53 | |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 54 | @param full_payload: True for a full payload. False for delta. |
| 55 | @param cellular: True to do the update over a cellualar connection. |
| 56 | Requires that the DUT have a sim card slot. |
| 57 | @param interrupt: True to interrupt the update in the middle. |
| 58 | @param max_updates: Used to tell the test how many times it is |
| 59 | expected to ping its omaha server. |
| 60 | @param job_repo_url: Used for debugging locally. This is used to figure |
| 61 | out the current build and the devserver to use. |
| 62 | The test will read this from a host argument |
| 63 | when run in the lab. |
| 64 | |
| 65 | """ |
David Haddock | 3a8f572 | 2018-04-13 16:24:16 -0700 | [diff] [blame] | 66 | tpm_utils.ClearTPMOwnerRequest(self._host) |
David Haddock | 463faf4 | 2018-01-23 14:21:11 -0800 | [diff] [blame] | 67 | |
| 68 | # veyron_rialto is a medical device with a different OOBE that auto |
| 69 | # completes so this test is not valid on that device. |
| 70 | if 'veyron_rialto' in self._host.get_board(): |
| 71 | raise error.TestNAError('Rialto has a custom OOBE. Skipping test.') |
| 72 | |
David Haddock | 50dbfee | 2018-01-12 12:43:12 -0800 | [diff] [blame] | 73 | update_url = self.get_update_url_for_test(job_repo_url, |
David Haddock | 463faf4 | 2018-01-23 14:21:11 -0800 | [diff] [blame] | 74 | full_payload=full_payload, |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 75 | critical_update=True, |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 76 | public=cellular, |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 77 | max_updates=max_updates) |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 78 | before = self._get_chromeos_version() |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 79 | payload_info = None |
| 80 | if cellular: |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame] | 81 | self._change_cellular_setting_in_update_engine(True) |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 82 | # Get the payload's information (size, SHA256 etc) since we will be |
| 83 | # setting up our own omaha instance on the DUT. We pass this to |
| 84 | # the client test. |
| 85 | payload = self._get_payload_url(full_payload=full_payload) |
| 86 | staged_url = self._stage_payload_by_uri(payload) |
| 87 | payload_info = self._get_staged_file_info(staged_url) |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 88 | |
| 89 | # Call client test to start the forced OOBE update. |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 90 | self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate', |
| 91 | image_url=update_url, |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame] | 92 | cellular=cellular, |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 93 | payload_info=payload_info, |
| 94 | full_payload=full_payload) |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 95 | |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 96 | |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 97 | if interrupt: |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 98 | # Choose a random downloaded progress to interrupt the update. |
| 99 | progress = random.uniform(0.1, 0.8) |
| 100 | logging.debug('Progress when we will interrupt: %f', progress) |
| 101 | self._wait_for_progress(progress) |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 102 | logging.info('We will start interrupting the update.') |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 103 | |
| 104 | # Reboot the DUT during the update. |
David Haddock | 57c0d15 | 2018-08-06 10:56:52 -0700 | [diff] [blame] | 105 | self._take_screenshot('before_reboot.png') |
David Haddock | ed70eef | 2018-07-19 16:40:54 -0700 | [diff] [blame] | 106 | completed = self._get_update_progress() |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 107 | self._host.reboot() |
David Haddock | ed70eef | 2018-07-19 16:40:54 -0700 | [diff] [blame] | 108 | # Screenshot to check that if OOBE was not skipped by interruption. |
| 109 | self._take_screenshot('after_reboot.png') |
| 110 | if self._is_update_finished_downloading(): |
| 111 | raise error.TestError('Reboot interrupt: Update finished ' |
| 112 | 'downloading before any more ' |
| 113 | 'interruptions. Started interrupting ' |
| 114 | 'at: %f' % progress) |
David Haddock | afdfa5b | 2018-08-10 16:10:01 -0700 | [diff] [blame^] | 115 | if self._is_update_engine_idle(): |
| 116 | raise error.TestFail('The update was IDLE after reboot.') |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 117 | |
David Haddock | ed70eef | 2018-07-19 16:40:54 -0700 | [diff] [blame] | 118 | # Disconnect / Reconnect network. |
| 119 | completed = self._get_update_progress() |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 120 | self._disconnect_then_reconnect_network(update_url) |
David Haddock | ed70eef | 2018-07-19 16:40:54 -0700 | [diff] [blame] | 121 | self._take_screenshot('after_network.png') |
| 122 | if self._is_update_finished_downloading(): |
| 123 | raise error.TestError('Network interrupt: Update finished ' |
| 124 | 'downloading before any more ' |
| 125 | 'interruptions. Started interrupting ' |
| 126 | 'at: %f' % progress) |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 127 | if not self._update_continued_where_it_left_off(completed): |
| 128 | raise error.TestFail('The update did not continue where it ' |
| 129 | 'left off before disconnecting network.') |
| 130 | |
David Haddock | ed70eef | 2018-07-19 16:40:54 -0700 | [diff] [blame] | 131 | # Suspend / Resume. |
| 132 | completed = self._get_update_progress() |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 133 | self._suspend_then_resume() |
David Haddock | ed70eef | 2018-07-19 16:40:54 -0700 | [diff] [blame] | 134 | self._take_screenshot('after_suspend.png') |
| 135 | if self._is_update_finished_downloading(): |
| 136 | raise error.TestError('Suspend interrupt: Update finished ' |
| 137 | 'downloading before any more ' |
| 138 | 'interruptions. Started interrupting ' |
| 139 | 'at: %f' % progress) |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 140 | if not self._update_continued_where_it_left_off(completed): |
| 141 | raise error.TestFail('The update did not continue where it ' |
| 142 | 'left off after suspend/resume.') |
| 143 | |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 144 | self._wait_for_oobe_update_to_complete() |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 145 | |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 146 | if cellular: |
| 147 | # We didn't have a devserver so we cannot check the hostlog to |
| 148 | # ensure the update completed successfully. Instead we can check |
| 149 | # that the second-to-last update engine log has the successful |
| 150 | # update message. Second to last because its the one before OOBE |
| 151 | # rebooted. |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame] | 152 | before_reboot_file = self._get_second_last_update_engine_log() |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 153 | self._check_for_cellular_entries_in_update_log(before_reboot_file) |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 154 | success = 'Update successfully applied, waiting to reboot.' |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame] | 155 | self._check_update_engine_log_for_entry(success, |
| 156 | raise_error=True, |
| 157 | update_engine_log= |
| 158 | before_reboot_file) |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 159 | return |
| 160 | |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 161 | # Verify that the update completed successfully by checking hostlog. |
| 162 | rootfs_hostlog, reboot_hostlog = self._create_hostlog_files() |
| 163 | self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog) |
| 164 | self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog, |
| 165 | self._CUSTOM_LSB_VERSION) |
| 166 | |
| 167 | after = self._get_chromeos_version() |
| 168 | logging.info('Successfully force updated from %s to %s.', before, after) |