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 | """ |
| 33 | while True: |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame^] | 34 | status = self._get_update_engine_status(timeout=10) |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 35 | |
| 36 | # During reboot, status will be None |
| 37 | if status is not None: |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 38 | if self._UPDATE_STATUS_IDLE == status[self._CURRENT_OP]: |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 39 | break |
| 40 | time.sleep(1) |
| 41 | |
| 42 | |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame^] | 43 | def run_once(self, full_payload=True, cellular=False, |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 44 | interrupt=False, max_updates=1, job_repo_url=None): |
| 45 | """ |
| 46 | Runs a forced autoupdate during ChromeOS OOBE. |
| 47 | |
| 48 | @param host: The DUT that we are running on. |
| 49 | @param full_payload: True for a full payload. False for delta. |
| 50 | @param cellular: True to do the update over a cellualar connection. |
| 51 | Requires that the DUT have a sim card slot. |
| 52 | @param interrupt: True to interrupt the update in the middle. |
| 53 | @param max_updates: Used to tell the test how many times it is |
| 54 | expected to ping its omaha server. |
| 55 | @param job_repo_url: Used for debugging locally. This is used to figure |
| 56 | out the current build and the devserver to use. |
| 57 | The test will read this from a host argument |
| 58 | when run in the lab. |
| 59 | |
| 60 | """ |
David Haddock | 3a8f572 | 2018-04-13 16:24:16 -0700 | [diff] [blame] | 61 | tpm_utils.ClearTPMOwnerRequest(self._host) |
David Haddock | 463faf4 | 2018-01-23 14:21:11 -0800 | [diff] [blame] | 62 | |
| 63 | # veyron_rialto is a medical device with a different OOBE that auto |
| 64 | # completes so this test is not valid on that device. |
| 65 | if 'veyron_rialto' in self._host.get_board(): |
| 66 | raise error.TestNAError('Rialto has a custom OOBE. Skipping test.') |
| 67 | |
David Haddock | 50dbfee | 2018-01-12 12:43:12 -0800 | [diff] [blame] | 68 | update_url = self.get_update_url_for_test(job_repo_url, |
David Haddock | 463faf4 | 2018-01-23 14:21:11 -0800 | [diff] [blame] | 69 | full_payload=full_payload, |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 70 | critical_update=True, |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 71 | public=cellular, |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 72 | max_updates=max_updates) |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 73 | before = self._get_chromeos_version() |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 74 | payload_info = None |
| 75 | if cellular: |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame^] | 76 | self._change_cellular_setting_in_update_engine(True) |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 77 | # Get the payload's information (size, SHA256 etc) since we will be |
| 78 | # setting up our own omaha instance on the DUT. We pass this to |
| 79 | # the client test. |
| 80 | payload = self._get_payload_url(full_payload=full_payload) |
| 81 | staged_url = self._stage_payload_by_uri(payload) |
| 82 | payload_info = self._get_staged_file_info(staged_url) |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 83 | |
| 84 | # Call client test to start the forced OOBE update. |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 85 | self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate', |
| 86 | image_url=update_url, |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame^] | 87 | cellular=cellular, |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 88 | payload_info=payload_info, |
| 89 | full_payload=full_payload) |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 90 | |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 91 | |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 92 | if interrupt: |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 93 | # Choose a random downloaded progress to interrupt the update. |
| 94 | progress = random.uniform(0.1, 0.8) |
| 95 | logging.debug('Progress when we will interrupt: %f', progress) |
| 96 | self._wait_for_progress(progress) |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 97 | logging.info('We will start interrupting the update.') |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 98 | completed = self._get_update_progress() |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 99 | |
| 100 | # Reboot the DUT during the update. |
| 101 | self._host.reboot() |
| 102 | if not self._update_continued_where_it_left_off(completed): |
| 103 | raise error.TestFail('The update did not continue where it ' |
| 104 | 'left off before rebooting.') |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 105 | completed = self._get_update_progress() |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 106 | |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 107 | self._disconnect_then_reconnect_network(update_url) |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 108 | if not self._update_continued_where_it_left_off(completed): |
| 109 | raise error.TestFail('The update did not continue where it ' |
| 110 | 'left off before disconnecting network.') |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 111 | completed = self._get_update_progress() |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 112 | |
| 113 | # Suspend / Resume |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 114 | self._suspend_then_resume() |
David Haddock | 0bad4a3 | 2018-02-02 13:05:26 -0800 | [diff] [blame] | 115 | if not self._update_continued_where_it_left_off(completed): |
| 116 | raise error.TestFail('The update did not continue where it ' |
| 117 | 'left off after suspend/resume.') |
| 118 | |
David Haddock | 80e3b8f | 2018-04-10 17:44:43 -0700 | [diff] [blame] | 119 | self._wait_for_oobe_update_to_complete() |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 120 | |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 121 | if cellular: |
| 122 | # We didn't have a devserver so we cannot check the hostlog to |
| 123 | # ensure the update completed successfully. Instead we can check |
| 124 | # that the second-to-last update engine log has the successful |
| 125 | # update message. Second to last because its the one before OOBE |
| 126 | # rebooted. |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame^] | 127 | before_reboot_file = self._get_second_last_update_engine_log() |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 128 | self._check_for_cellular_entries_in_update_log(before_reboot_file) |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 129 | success = 'Update successfully applied, waiting to reboot.' |
David Haddock | 2fd9aec | 2018-04-23 19:17:46 -0700 | [diff] [blame^] | 130 | self._check_update_engine_log_for_entry(success, |
| 131 | raise_error=True, |
| 132 | update_engine_log= |
| 133 | before_reboot_file) |
David Haddock | ac21089 | 2018-02-05 20:36:27 -0800 | [diff] [blame] | 134 | return |
| 135 | |
David Haddock | 95e7fbe | 2017-12-01 17:49:53 -0800 | [diff] [blame] | 136 | # Verify that the update completed successfully by checking hostlog. |
| 137 | rootfs_hostlog, reboot_hostlog = self._create_hostlog_files() |
| 138 | self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog) |
| 139 | self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog, |
| 140 | self._CUSTOM_LSB_VERSION) |
| 141 | |
| 142 | after = self._get_chromeos_version() |
| 143 | logging.info('Successfully force updated from %s to %s.', before, after) |