blob: ebf5f9cf106d3e226ecfb45901e0e758801935e1 [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 Haddock5e2ef312018-06-12 12:59:31 -070038 # 20 minute timeout.
39 timeout_minutes = 20
40 timeout = time.time() + 60 * timeout_minutes
David Haddock95e7fbe2017-12-01 17:49:53 -080041 while True:
David Haddock2fd9aec2018-04-23 19:17:46 -070042 status = self._get_update_engine_status(timeout=10)
David Haddock95e7fbe2017-12-01 17:49:53 -080043
44 # During reboot, status will be None
45 if status is not None:
David Haddock80e3b8f2018-04-10 17:44:43 -070046 if self._UPDATE_STATUS_IDLE == status[self._CURRENT_OP]:
David Haddock95e7fbe2017-12-01 17:49:53 -080047 break
48 time.sleep(1)
David Haddock5e2ef312018-06-12 12:59:31 -070049 if time.time() > timeout:
50 raise error.TestFail('OOBE update did not finish in %d '
51 'minutes.' % timeout_minutes)
David Haddock95e7fbe2017-12-01 17:49:53 -080052
53
David Haddock2fd9aec2018-04-23 19:17:46 -070054 def run_once(self, full_payload=True, cellular=False,
David Haddock0bad4a32018-02-02 13:05:26 -080055 interrupt=False, max_updates=1, job_repo_url=None):
56 """
57 Runs a forced autoupdate during ChromeOS OOBE.
58
David Haddock0bad4a32018-02-02 13:05:26 -080059 @param full_payload: True for a full payload. False for delta.
60 @param cellular: True to do the update over a cellualar connection.
61 Requires that the DUT have a sim card slot.
62 @param interrupt: True to interrupt the update in the middle.
63 @param max_updates: Used to tell the test how many times it is
64 expected to ping its omaha server.
65 @param job_repo_url: Used for debugging locally. This is used to figure
66 out the current build and the devserver to use.
67 The test will read this from a host argument
68 when run in the lab.
69
70 """
David Haddock3a8f5722018-04-13 16:24:16 -070071 tpm_utils.ClearTPMOwnerRequest(self._host)
David Haddock463faf42018-01-23 14:21:11 -080072
73 # veyron_rialto is a medical device with a different OOBE that auto
74 # completes so this test is not valid on that device.
75 if 'veyron_rialto' in self._host.get_board():
76 raise error.TestNAError('Rialto has a custom OOBE. Skipping test.')
77
David Haddock50dbfee2018-01-12 12:43:12 -080078 update_url = self.get_update_url_for_test(job_repo_url,
David Haddock463faf42018-01-23 14:21:11 -080079 full_payload=full_payload,
David Haddockac210892018-02-05 20:36:27 -080080 critical_update=True,
David Haddock80e3b8f2018-04-10 17:44:43 -070081 public=cellular,
David Haddock0bad4a32018-02-02 13:05:26 -080082 max_updates=max_updates)
David Haddock95e7fbe2017-12-01 17:49:53 -080083 before = self._get_chromeos_version()
David Haddockac210892018-02-05 20:36:27 -080084 payload_info = None
85 if cellular:
David Haddock2fd9aec2018-04-23 19:17:46 -070086 self._change_cellular_setting_in_update_engine(True)
David Haddockac210892018-02-05 20:36:27 -080087 # Get the payload's information (size, SHA256 etc) since we will be
88 # setting up our own omaha instance on the DUT. We pass this to
89 # the client test.
90 payload = self._get_payload_url(full_payload=full_payload)
91 staged_url = self._stage_payload_by_uri(payload)
92 payload_info = self._get_staged_file_info(staged_url)
David Haddock95e7fbe2017-12-01 17:49:53 -080093
94 # Call client test to start the forced OOBE update.
David Haddock80e3b8f2018-04-10 17:44:43 -070095 self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate',
96 image_url=update_url,
David Haddock2fd9aec2018-04-23 19:17:46 -070097 cellular=cellular,
David Haddock80e3b8f2018-04-10 17:44:43 -070098 payload_info=payload_info,
99 full_payload=full_payload)
David Haddock95e7fbe2017-12-01 17:49:53 -0800100
David Haddock95e7fbe2017-12-01 17:49:53 -0800101
David Haddock0bad4a32018-02-02 13:05:26 -0800102 if interrupt:
David Haddock80e3b8f2018-04-10 17:44:43 -0700103 # Choose a random downloaded progress to interrupt the update.
104 progress = random.uniform(0.1, 0.8)
105 logging.debug('Progress when we will interrupt: %f', progress)
106 self._wait_for_progress(progress)
David Haddock0bad4a32018-02-02 13:05:26 -0800107 logging.info('We will start interrupting the update.')
David Haddock0bad4a32018-02-02 13:05:26 -0800108
109 # Reboot the DUT during the update.
David Haddock57c0d152018-08-06 10:56:52 -0700110 self._take_screenshot('before_reboot.png')
David Haddocked70eef2018-07-19 16:40:54 -0700111 completed = self._get_update_progress()
David Haddock0bad4a32018-02-02 13:05:26 -0800112 self._host.reboot()
David Haddocked70eef2018-07-19 16:40:54 -0700113 # Screenshot to check that if OOBE was not skipped by interruption.
114 self._take_screenshot('after_reboot.png')
115 if self._is_update_finished_downloading():
116 raise error.TestError('Reboot interrupt: Update finished '
117 'downloading before any more '
118 'interruptions. Started interrupting '
119 'at: %f' % progress)
David Haddockafdfa5b2018-08-10 16:10:01 -0700120 if self._is_update_engine_idle():
121 raise error.TestFail('The update was IDLE after reboot.')
David Haddock0bad4a32018-02-02 13:05:26 -0800122
David Haddocked70eef2018-07-19 16:40:54 -0700123 # Disconnect / Reconnect network.
124 completed = self._get_update_progress()
David Haddock80e3b8f2018-04-10 17:44:43 -0700125 self._disconnect_then_reconnect_network(update_url)
David Haddocked70eef2018-07-19 16:40:54 -0700126 self._take_screenshot('after_network.png')
127 if self._is_update_finished_downloading():
128 raise error.TestError('Network interrupt: Update finished '
129 'downloading before any more '
130 'interruptions. Started interrupting '
131 'at: %f' % progress)
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 '
134 'left off before disconnecting network.')
135
David Haddocked70eef2018-07-19 16:40:54 -0700136 # Suspend / Resume.
137 completed = self._get_update_progress()
David Haddock80e3b8f2018-04-10 17:44:43 -0700138 self._suspend_then_resume()
David Haddocked70eef2018-07-19 16:40:54 -0700139 self._take_screenshot('after_suspend.png')
140 if self._is_update_finished_downloading():
141 raise error.TestError('Suspend interrupt: Update finished '
142 'downloading before any more '
143 'interruptions. Started interrupting '
144 'at: %f' % progress)
David Haddock0bad4a32018-02-02 13:05:26 -0800145 if not self._update_continued_where_it_left_off(completed):
146 raise error.TestFail('The update did not continue where it '
147 'left off after suspend/resume.')
148
David Haddock80e3b8f2018-04-10 17:44:43 -0700149 self._wait_for_oobe_update_to_complete()
David Haddock95e7fbe2017-12-01 17:49:53 -0800150
David Haddockac210892018-02-05 20:36:27 -0800151 if cellular:
152 # We didn't have a devserver so we cannot check the hostlog to
153 # ensure the update completed successfully. Instead we can check
154 # that the second-to-last update engine log has the successful
155 # update message. Second to last because its the one before OOBE
156 # rebooted.
David Haddock2fd9aec2018-04-23 19:17:46 -0700157 before_reboot_file = self._get_second_last_update_engine_log()
David Haddockac210892018-02-05 20:36:27 -0800158 self._check_for_cellular_entries_in_update_log(before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800159 success = 'Update successfully applied, waiting to reboot.'
David Haddock2fd9aec2018-04-23 19:17:46 -0700160 self._check_update_engine_log_for_entry(success,
161 raise_error=True,
162 update_engine_log=
163 before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800164 return
165
David Haddock95e7fbe2017-12-01 17:49:53 -0800166 # Verify that the update completed successfully by checking hostlog.
167 rootfs_hostlog, reboot_hostlog = self._create_hostlog_files()
168 self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog)
169 self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog,
170 self._CUSTOM_LSB_VERSION)
171
172 after = self._get_chromeos_version()
173 logging.info('Successfully force updated from %s to %s.', before, after)