blob: 7a47ab1440226d9616946996fe4b6371d584b814 [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 Haddock8efca4d2019-07-23 19:08:03 -070055 interrupt=None, max_updates=1, job_repo_url=None):
David Haddock0bad4a32018-02-02 13:05:26 -080056 """
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.
David Haddock8efca4d2019-07-23 19:08:03 -070062 @param interrupt: Type of interrupt to try: [reboot, network, suspend]
David Haddock0bad4a32018-02-02 13:05:26 -080063 @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 Haddock463faf42018-01-23 14:21:11 -080071 # veyron_rialto is a medical device with a different OOBE that auto
72 # completes so this test is not valid on that device.
73 if 'veyron_rialto' in self._host.get_board():
74 raise error.TestNAError('Rialto has a custom OOBE. Skipping test.')
75
David Haddock8efca4d2019-07-23 19:08:03 -070076 tpm_utils.ClearTPMOwnerRequest(self._host)
David Haddock50dbfee2018-01-12 12:43:12 -080077 update_url = self.get_update_url_for_test(job_repo_url,
David Haddock463faf42018-01-23 14:21:11 -080078 full_payload=full_payload,
David Haddockac210892018-02-05 20:36:27 -080079 critical_update=True,
David Haddock80e3b8f2018-04-10 17:44:43 -070080 public=cellular,
David Haddock0bad4a32018-02-02 13:05:26 -080081 max_updates=max_updates)
David Haddock95e7fbe2017-12-01 17:49:53 -080082 before = self._get_chromeos_version()
David Haddockac210892018-02-05 20:36:27 -080083 payload_info = None
84 if cellular:
David Haddock2fd9aec2018-04-23 19:17:46 -070085 self._change_cellular_setting_in_update_engine(True)
David Haddockac210892018-02-05 20:36:27 -080086 # Get the payload's information (size, SHA256 etc) since we will be
87 # setting up our own omaha instance on the DUT. We pass this to
88 # the client test.
89 payload = self._get_payload_url(full_payload=full_payload)
90 staged_url = self._stage_payload_by_uri(payload)
91 payload_info = self._get_staged_file_info(staged_url)
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,
David Haddock2fd9aec2018-04-23 19:17:46 -070096 cellular=cellular,
David Haddock80e3b8f2018-04-10 17:44:43 -070097 payload_info=payload_info,
98 full_payload=full_payload)
David Haddock95e7fbe2017-12-01 17:49:53 -080099
David Haddock8efca4d2019-07-23 19:08:03 -0700100 if interrupt is not None:
David Haddock80e3b8f2018-04-10 17:44:43 -0700101 # Choose a random downloaded progress to interrupt the update.
David Haddock8efca4d2019-07-23 19:08:03 -0700102 progress = random.uniform(0.1, 0.6)
103 logging.info('Progress when we will interrupt: %f', progress)
David Haddock80e3b8f2018-04-10 17:44:43 -0700104 self._wait_for_progress(progress)
David Haddock8efca4d2019-07-23 19:08:03 -0700105 logging.info('We will now start interrupting the update.')
106 self._take_screenshot('before_interrupt.png')
David Haddocked70eef2018-07-19 16:40:54 -0700107 completed = self._get_update_progress()
David Haddock8efca4d2019-07-23 19:08:03 -0700108
109 if interrupt is 'reboot':
110 self._host.reboot()
111 elif interrupt is 'network':
112 self._disconnect_then_reconnect_network(update_url)
113 elif interrupt is 'suspend':
114 self._suspend_then_resume()
115 else:
116 raise error.TestFail('Unknown interrupt type: %s' % interrupt)
117 # Screenshot to check that OOBE was not skipped by interruption.
118 self._take_screenshot('after_interrupt.png')
119
David Haddockafdfa5b2018-08-10 16:10:01 -0700120 if self._is_update_engine_idle():
David Haddock8efca4d2019-07-23 19:08:03 -0700121 raise error.TestFail('The update was IDLE after interrupt.')
David Haddock0bad4a32018-02-02 13:05:26 -0800122 if not self._update_continued_where_it_left_off(completed):
123 raise error.TestFail('The update did not continue where it '
David Haddock8efca4d2019-07-23 19:08:03 -0700124 'left off after interruption.')
David Haddock0bad4a32018-02-02 13:05:26 -0800125
David Haddock80e3b8f2018-04-10 17:44:43 -0700126 self._wait_for_oobe_update_to_complete()
David Haddock95e7fbe2017-12-01 17:49:53 -0800127
David Haddockac210892018-02-05 20:36:27 -0800128 if cellular:
129 # We didn't have a devserver so we cannot check the hostlog to
130 # ensure the update completed successfully. Instead we can check
131 # that the second-to-last update engine log has the successful
132 # update message. Second to last because its the one before OOBE
133 # rebooted.
David Haddock2fd9aec2018-04-23 19:17:46 -0700134 before_reboot_file = self._get_second_last_update_engine_log()
David Haddockac210892018-02-05 20:36:27 -0800135 self._check_for_cellular_entries_in_update_log(before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800136 success = 'Update successfully applied, waiting to reboot.'
David Haddock2fd9aec2018-04-23 19:17:46 -0700137 self._check_update_engine_log_for_entry(success,
138 raise_error=True,
139 update_engine_log=
140 before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800141 return
142
David Haddock95e7fbe2017-12-01 17:49:53 -0800143 # Verify that the update completed successfully by checking hostlog.
144 rootfs_hostlog, reboot_hostlog = self._create_hostlog_files()
145 self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog)
146 self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog,
147 self._CUSTOM_LSB_VERSION)
148
149 after = self._get_chromeos_version()
150 logging.info('Successfully force updated from %s to %s.', before, after)