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 | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 103 | completed = self._get_update_progress() |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 104 | |
| 105 | # Reboot the DUT during the update. |
| 106 | self._host.reboot() |
| 107 | if not self._update_continued_where_it_left_off(completed): |
| 108 | raise error.TestFail('The update did not continue where it ' |
| 109 | 'left off before rebooting.') |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 110 | completed = self._get_update_progress() |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 111 | |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 112 | self._disconnect_then_reconnect_network(update_url) |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 113 | if not self._update_continued_where_it_left_off(completed): |
| 114 | raise error.TestFail('The update did not continue where it ' |
| 115 | 'left off before disconnecting network.') |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 116 | completed = self._get_update_progress() |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 117 | |
| 118 | # Suspend / Resume |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 119 | self._suspend_then_resume() |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 120 | if not self._update_continued_where_it_left_off(completed): |
| 121 | raise error.TestFail('The update did not continue where it ' |
| 122 | 'left off after suspend/resume.') |
| 123 | |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 124 | self._wait_for_oobe_update_to_complete() |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 125 | |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 126 | if cellular: |
| 127 | # We didn't have a devserver so we cannot check the hostlog to |
| 128 | # ensure the update completed successfully. Instead we can check |
| 129 | # that the second-to-last update engine log has the successful |
| 130 | # update message. Second to last because its the one before OOBE |
| 131 | # rebooted. |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame] | 132 | before_reboot_file = self._get_second_last_update_engine_log() |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 133 | self._check_for_cellular_entries_in_update_log(before_reboot_file) |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 134 | success = 'Update successfully applied, waiting to reboot.' |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame] | 135 | self._check_update_engine_log_for_entry(success, |
| 136 | raise_error=True, |
| 137 | update_engine_log= |
| 138 | before_reboot_file) |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 139 | return |
| 140 | |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 141 | # Verify that the update completed successfully by checking hostlog. |
| 142 | rootfs_hostlog, reboot_hostlog = self._create_hostlog_files() |
| 143 | self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog) |
| 144 | self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog, |
| 145 | self._CUSTOM_LSB_VERSION) |
| 146 | |
| 147 | after = self._get_chromeos_version() |
| 148 | logging.info('Successfully force updated from %s to %s.', before, after) |