blob: 9c0013cf7cb6fe5d0c0edcb22412f80f9de2dcf7 [file] [log] [blame]
David Haddock95e7fbe2017-12-01 17:49:53 -08001# 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 Haddock80e3b8f2018-04-10 17:44:43 -07004
David Haddock95e7fbe2017-12-01 17:49:53 -08005import logging
David Haddock0bad4a32018-02-02 13:05:26 -08006import random
David Haddock95e7fbe2017-12-01 17:49:53 -08007import time
8
David Haddock463faf42018-01-23 14:21:11 -08009from autotest_lib.client.common_lib import error
David Haddock3a8f5722018-04-13 16:24:16 -070010from autotest_lib.client.common_lib.cros import tpm_utils
David Haddock95e7fbe2017-12-01 17:49:53 -080011from autotest_lib.server.cros.update_engine import update_engine_test
David Haddock95e7fbe2017-12-01 17:49:53 -080012
13class autoupdate_ForcedOOBEUpdate(update_engine_test.UpdateEngineTest):
14 """Runs a forced autoupdate during OOBE."""
15 version = 1
16
David Haddock95e7fbe2017-12-01 17:49:53 -080017
David Haddock95e7fbe2017-12-01 17:49:53 -080018 def cleanup(self):
David Haddock95e7fbe2017-12-01 17:49:53 -080019 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 Haddock2fd9aec2018-04-23 19:17:46 -070022 self._save_extra_update_engine_logs()
23 self._change_cellular_setting_in_update_engine(False)
David Haddockb1733c82018-09-07 09:43:57 -070024
25 # Cancel any update still in progress.
26 if not self._is_update_engine_idle():
27 logging.debug('Canceling the in-progress update.')
28 self._host.run('restart update-engine')
David Haddock50dbfee2018-01-12 12:43:12 -080029 super(autoupdate_ForcedOOBEUpdate, self).cleanup()
David Haddock95e7fbe2017-12-01 17:49:53 -080030
David Haddock95e7fbe2017-12-01 17:49:53 -080031
David Haddock80e3b8f2018-04-10 17:44:43 -070032 def _wait_for_oobe_update_to_complete(self):
David Haddock95e7fbe2017-12-01 17:49:53 -080033 """Wait for the update that started to complete.
34
35 Repeated check status of update. It should move from DOWNLOADING to
David Haddock80e3b8f2018-04-10 17:44:43 -070036 FINALIZING to COMPLETE (then reboot) to IDLE.
David Haddock95e7fbe2017-12-01 17:49:53 -080037 """
David Haddockeb311422019-07-22 17:14:58 -070038 timeout_minutes = 10
David Haddock5e2ef312018-06-12 12:59:31 -070039 timeout = time.time() + 60 * timeout_minutes
David Haddockeb311422019-07-22 17:14:58 -070040 boot_id = self._host.get_boot_id()
41
David Haddock95e7fbe2017-12-01 17:49:53 -080042 while True:
David Haddock3ffa1342019-12-10 19:35:32 -080043 try:
44 self._get_update_engine_status(timeout=10,
45 ignore_timeout=False)
46 except error.AutoservRunError as e:
47 # Check if command timed out because update-engine was taking
48 # a while or if the command didn't even start.
49 query = 'Querying Update Engine status...'
50 if query not in e.result_obj.stderr:
51 # Command did not start. DUT rebooted at end of update.
52 self._host.test_wait_for_boot(boot_id)
53 break
David Haddock95e7fbe2017-12-01 17:49:53 -080054
David Haddock95e7fbe2017-12-01 17:49:53 -080055 time.sleep(1)
David Haddock5e2ef312018-06-12 12:59:31 -070056 if time.time() > timeout:
57 raise error.TestFail('OOBE update did not finish in %d '
58 'minutes.' % timeout_minutes)
David Haddock95e7fbe2017-12-01 17:49:53 -080059
60
David Haddock2fd9aec2018-04-23 19:17:46 -070061 def run_once(self, full_payload=True, cellular=False,
Amin Hassanif56f5c62020-02-14 16:31:31 -080062 interrupt=None, job_repo_url=None, moblab=False):
David Haddock0bad4a32018-02-02 13:05:26 -080063 """
64 Runs a forced autoupdate during ChromeOS OOBE.
65
David Haddock0bad4a32018-02-02 13:05:26 -080066 @param full_payload: True for a full payload. False for delta.
67 @param cellular: True to do the update over a cellualar connection.
68 Requires that the DUT have a sim card slot.
David Haddock8efca4d2019-07-23 19:08:03 -070069 @param interrupt: Type of interrupt to try: [reboot, network, suspend]
David Haddock0bad4a32018-02-02 13:05:26 -080070 @param job_repo_url: Used for debugging locally. This is used to figure
71 out the current build and the devserver to use.
72 The test will read this from a host argument
73 when run in the lab.
David Haddock95c74c02019-09-16 11:06:33 -070074 @param moblab: True if we are running on moblab.
David Haddock0bad4a32018-02-02 13:05:26 -080075
76 """
David Haddock463faf42018-01-23 14:21:11 -080077 # veyron_rialto is a medical device with a different OOBE that auto
78 # completes so this test is not valid on that device.
79 if 'veyron_rialto' in self._host.get_board():
80 raise error.TestNAError('Rialto has a custom OOBE. Skipping test.')
81
David Haddock8efca4d2019-07-23 19:08:03 -070082 tpm_utils.ClearTPMOwnerRequest(self._host)
David Haddock50dbfee2018-01-12 12:43:12 -080083 update_url = self.get_update_url_for_test(job_repo_url,
David Haddock463faf42018-01-23 14:21:11 -080084 full_payload=full_payload,
David Haddockac210892018-02-05 20:36:27 -080085 critical_update=True,
David Haddock80e3b8f2018-04-10 17:44:43 -070086 public=cellular,
David Haddock95c74c02019-09-16 11:06:33 -070087 moblab=moblab)
David Haddock95e7fbe2017-12-01 17:49:53 -080088 before = self._get_chromeos_version()
David Haddockac210892018-02-05 20:36:27 -080089 payload_info = None
90 if cellular:
David Haddock2fd9aec2018-04-23 19:17:46 -070091 self._change_cellular_setting_in_update_engine(True)
David Haddock95e7fbe2017-12-01 17:49:53 -080092
93 # Call client test to start the forced OOBE update.
David Haddock80e3b8f2018-04-10 17:44:43 -070094 self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate',
95 image_url=update_url,
Amin Hassani151b73b2020-01-30 16:44:52 -080096 cellular=cellular)
David Haddock95e7fbe2017-12-01 17:49:53 -080097
David Haddock8efca4d2019-07-23 19:08:03 -070098 if interrupt is not None:
David Haddock80e3b8f2018-04-10 17:44:43 -070099 # Choose a random downloaded progress to interrupt the update.
David Haddock8efca4d2019-07-23 19:08:03 -0700100 progress = random.uniform(0.1, 0.6)
101 logging.info('Progress when we will interrupt: %f', progress)
David Haddock80e3b8f2018-04-10 17:44:43 -0700102 self._wait_for_progress(progress)
David Haddock8efca4d2019-07-23 19:08:03 -0700103 logging.info('We will now start interrupting the update.')
104 self._take_screenshot('before_interrupt.png')
David Haddocked70eef2018-07-19 16:40:54 -0700105 completed = self._get_update_progress()
David Haddock8efca4d2019-07-23 19:08:03 -0700106
107 if interrupt is 'reboot':
108 self._host.reboot()
109 elif interrupt is 'network':
110 self._disconnect_then_reconnect_network(update_url)
111 elif interrupt is 'suspend':
112 self._suspend_then_resume()
113 else:
114 raise error.TestFail('Unknown interrupt type: %s' % interrupt)
115 # Screenshot to check that OOBE was not skipped by interruption.
116 self._take_screenshot('after_interrupt.png')
117
David Haddockafdfa5b2018-08-10 16:10:01 -0700118 if self._is_update_engine_idle():
David Haddock8efca4d2019-07-23 19:08:03 -0700119 raise error.TestFail('The update was IDLE after interrupt.')
David Haddock0bad4a32018-02-02 13:05:26 -0800120 if not self._update_continued_where_it_left_off(completed):
121 raise error.TestFail('The update did not continue where it '
David Haddock8efca4d2019-07-23 19:08:03 -0700122 'left off after interruption.')
David Haddock0bad4a32018-02-02 13:05:26 -0800123
Amin Hassanif56f5c62020-02-14 16:31:31 -0800124 # We create a new lsb-release file with no_update=True so there won't be
125 # any more actual updates happen.
126 self._create_custom_lsb_release(update_url, no_update=True)
127
David Haddock80e3b8f2018-04-10 17:44:43 -0700128 self._wait_for_oobe_update_to_complete()
David Haddock95e7fbe2017-12-01 17:49:53 -0800129
David Haddockac210892018-02-05 20:36:27 -0800130 if cellular:
131 # We didn't have a devserver so we cannot check the hostlog to
132 # ensure the update completed successfully. Instead we can check
133 # that the second-to-last update engine log has the successful
134 # update message. Second to last because its the one before OOBE
135 # rebooted.
David Haddock2fd9aec2018-04-23 19:17:46 -0700136 before_reboot_file = self._get_second_last_update_engine_log()
David Haddockac210892018-02-05 20:36:27 -0800137 self._check_for_cellular_entries_in_update_log(before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800138 success = 'Update successfully applied, waiting to reboot.'
David Haddock2fd9aec2018-04-23 19:17:46 -0700139 self._check_update_engine_log_for_entry(success,
140 raise_error=True,
141 update_engine_log=
142 before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800143 return
144
David Haddock95e7fbe2017-12-01 17:49:53 -0800145 # Verify that the update completed successfully by checking hostlog.
146 rootfs_hostlog, reboot_hostlog = self._create_hostlog_files()
147 self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog)
148 self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog,
149 self._CUSTOM_LSB_VERSION)
150
151 after = self._get_chromeos_version()
152 logging.info('Successfully force updated from %s to %s.', before, after)