blob: 561a2d15103b1faf76cc582c92d9019231b3c03b [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,
David Haddock95c74c02019-09-16 11:06:33 -070062 interrupt=None, max_updates=1, job_repo_url=None,
63 moblab=False):
David Haddock0bad4a32018-02-02 13:05:26 -080064 """
65 Runs a forced autoupdate during ChromeOS OOBE.
66
David Haddock0bad4a32018-02-02 13:05:26 -080067 @param full_payload: True for a full payload. False for delta.
68 @param cellular: True to do the update over a cellualar connection.
69 Requires that the DUT have a sim card slot.
David Haddock8efca4d2019-07-23 19:08:03 -070070 @param interrupt: Type of interrupt to try: [reboot, network, suspend]
David Haddock0bad4a32018-02-02 13:05:26 -080071 @param max_updates: Used to tell the test how many times it is
72 expected to ping its omaha server.
73 @param job_repo_url: Used for debugging locally. This is used to figure
74 out the current build and the devserver to use.
75 The test will read this from a host argument
76 when run in the lab.
David Haddock95c74c02019-09-16 11:06:33 -070077 @param moblab: True if we are running on moblab.
David Haddock0bad4a32018-02-02 13:05:26 -080078
79 """
David Haddock463faf42018-01-23 14:21:11 -080080 # veyron_rialto is a medical device with a different OOBE that auto
81 # completes so this test is not valid on that device.
82 if 'veyron_rialto' in self._host.get_board():
83 raise error.TestNAError('Rialto has a custom OOBE. Skipping test.')
84
David Haddock8efca4d2019-07-23 19:08:03 -070085 tpm_utils.ClearTPMOwnerRequest(self._host)
David Haddock50dbfee2018-01-12 12:43:12 -080086 update_url = self.get_update_url_for_test(job_repo_url,
David Haddock463faf42018-01-23 14:21:11 -080087 full_payload=full_payload,
David Haddockac210892018-02-05 20:36:27 -080088 critical_update=True,
David Haddock80e3b8f2018-04-10 17:44:43 -070089 public=cellular,
David Haddock95c74c02019-09-16 11:06:33 -070090 max_updates=max_updates,
91 moblab=moblab)
David Haddock95e7fbe2017-12-01 17:49:53 -080092 before = self._get_chromeos_version()
David Haddockac210892018-02-05 20:36:27 -080093 payload_info = None
94 if cellular:
David Haddock2fd9aec2018-04-23 19:17:46 -070095 self._change_cellular_setting_in_update_engine(True)
David Haddockac210892018-02-05 20:36:27 -080096 # Get the payload's information (size, SHA256 etc) since we will be
97 # setting up our own omaha instance on the DUT. We pass this to
98 # the client test.
99 payload = self._get_payload_url(full_payload=full_payload)
Amin Hassani8100ba42019-08-28 22:46:33 -0700100 staged_url, _ = self._stage_payload_by_uri(payload)
David Haddockac210892018-02-05 20:36:27 -0800101 payload_info = self._get_staged_file_info(staged_url)
David Haddock95e7fbe2017-12-01 17:49:53 -0800102
103 # Call client test to start the forced OOBE update.
David Haddock80e3b8f2018-04-10 17:44:43 -0700104 self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate',
105 image_url=update_url,
David Haddock2fd9aec2018-04-23 19:17:46 -0700106 cellular=cellular,
David Haddock80e3b8f2018-04-10 17:44:43 -0700107 payload_info=payload_info,
108 full_payload=full_payload)
David Haddock95e7fbe2017-12-01 17:49:53 -0800109
David Haddock8efca4d2019-07-23 19:08:03 -0700110 if interrupt is not None:
David Haddock80e3b8f2018-04-10 17:44:43 -0700111 # Choose a random downloaded progress to interrupt the update.
David Haddock8efca4d2019-07-23 19:08:03 -0700112 progress = random.uniform(0.1, 0.6)
113 logging.info('Progress when we will interrupt: %f', progress)
David Haddock80e3b8f2018-04-10 17:44:43 -0700114 self._wait_for_progress(progress)
David Haddock8efca4d2019-07-23 19:08:03 -0700115 logging.info('We will now start interrupting the update.')
116 self._take_screenshot('before_interrupt.png')
David Haddocked70eef2018-07-19 16:40:54 -0700117 completed = self._get_update_progress()
David Haddock8efca4d2019-07-23 19:08:03 -0700118
119 if interrupt is 'reboot':
120 self._host.reboot()
121 elif interrupt is 'network':
122 self._disconnect_then_reconnect_network(update_url)
123 elif interrupt is 'suspend':
124 self._suspend_then_resume()
125 else:
126 raise error.TestFail('Unknown interrupt type: %s' % interrupt)
127 # Screenshot to check that OOBE was not skipped by interruption.
128 self._take_screenshot('after_interrupt.png')
129
David Haddockafdfa5b2018-08-10 16:10:01 -0700130 if self._is_update_engine_idle():
David Haddock8efca4d2019-07-23 19:08:03 -0700131 raise error.TestFail('The update was IDLE after interrupt.')
David Haddock0bad4a32018-02-02 13:05:26 -0800132 if not self._update_continued_where_it_left_off(completed):
133 raise error.TestFail('The update did not continue where it '
David Haddock8efca4d2019-07-23 19:08:03 -0700134 'left off after interruption.')
David Haddock0bad4a32018-02-02 13:05:26 -0800135
David Haddock80e3b8f2018-04-10 17:44:43 -0700136 self._wait_for_oobe_update_to_complete()
David Haddock95e7fbe2017-12-01 17:49:53 -0800137
David Haddockac210892018-02-05 20:36:27 -0800138 if cellular:
139 # We didn't have a devserver so we cannot check the hostlog to
140 # ensure the update completed successfully. Instead we can check
141 # that the second-to-last update engine log has the successful
142 # update message. Second to last because its the one before OOBE
143 # rebooted.
David Haddock2fd9aec2018-04-23 19:17:46 -0700144 before_reboot_file = self._get_second_last_update_engine_log()
David Haddockac210892018-02-05 20:36:27 -0800145 self._check_for_cellular_entries_in_update_log(before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800146 success = 'Update successfully applied, waiting to reboot.'
David Haddock2fd9aec2018-04-23 19:17:46 -0700147 self._check_update_engine_log_for_entry(success,
148 raise_error=True,
149 update_engine_log=
150 before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800151 return
152
David Haddock95e7fbe2017-12-01 17:49:53 -0800153 # Verify that the update completed successfully by checking hostlog.
154 rootfs_hostlog, reboot_hostlog = self._create_hostlog_files()
155 self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog)
156 self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog,
157 self._CUSTOM_LSB_VERSION)
158
159 after = self._get_chromeos_version()
160 logging.info('Successfully force updated from %s to %s.', before, after)