blob: 1f1446b467f00d3f8660da09d4bb7c97fd8e5e03 [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 Haddock2fd9aec2018-04-23 19:17:46 -070043 status = self._get_update_engine_status(timeout=10)
David Haddock95e7fbe2017-12-01 17:49:53 -080044
45 # During reboot, status will be None
David Haddockeb311422019-07-22 17:14:58 -070046 if status is None:
47 # Checking only for the status to change to IDLE can hide
48 # errors that occurred between status checks. When the forced
49 # update is complete, it will automatically reboot the device.
50 # So we wait for an explict reboot. We will verify that the
51 # update completed successfully later in verify_update_events()
52 self._host.test_wait_for_boot(boot_id)
53 break
David Haddock95e7fbe2017-12-01 17:49:53 -080054 time.sleep(1)
David Haddock5e2ef312018-06-12 12:59:31 -070055 if time.time() > timeout:
56 raise error.TestFail('OOBE update did not finish in %d '
57 'minutes.' % timeout_minutes)
David Haddock95e7fbe2017-12-01 17:49:53 -080058
59
David Haddock2fd9aec2018-04-23 19:17:46 -070060 def run_once(self, full_payload=True, cellular=False,
David Haddock8efca4d2019-07-23 19:08:03 -070061 interrupt=None, max_updates=1, job_repo_url=None):
David Haddock0bad4a32018-02-02 13:05:26 -080062 """
63 Runs a forced autoupdate during ChromeOS OOBE.
64
David Haddock0bad4a32018-02-02 13:05:26 -080065 @param full_payload: True for a full payload. False for delta.
66 @param cellular: True to do the update over a cellualar connection.
67 Requires that the DUT have a sim card slot.
David Haddock8efca4d2019-07-23 19:08:03 -070068 @param interrupt: Type of interrupt to try: [reboot, network, suspend]
David Haddock0bad4a32018-02-02 13:05:26 -080069 @param max_updates: Used to tell the test how many times it is
70 expected to ping its omaha server.
71 @param job_repo_url: Used for debugging locally. This is used to figure
72 out the current build and the devserver to use.
73 The test will read this from a host argument
74 when run in the lab.
75
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 Haddock0bad4a32018-02-02 13:05:26 -080087 max_updates=max_updates)
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 Haddockac210892018-02-05 20:36:27 -080092 # Get the payload's information (size, SHA256 etc) since we will be
93 # setting up our own omaha instance on the DUT. We pass this to
94 # the client test.
95 payload = self._get_payload_url(full_payload=full_payload)
96 staged_url = self._stage_payload_by_uri(payload)
97 payload_info = self._get_staged_file_info(staged_url)
David Haddock95e7fbe2017-12-01 17:49:53 -080098
99 # Call client test to start the forced OOBE update.
David Haddock80e3b8f2018-04-10 17:44:43 -0700100 self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate',
101 image_url=update_url,
David Haddock2fd9aec2018-04-23 19:17:46 -0700102 cellular=cellular,
David Haddock80e3b8f2018-04-10 17:44:43 -0700103 payload_info=payload_info,
104 full_payload=full_payload)
David Haddock95e7fbe2017-12-01 17:49:53 -0800105
David Haddock8efca4d2019-07-23 19:08:03 -0700106 if interrupt is not None:
David Haddock80e3b8f2018-04-10 17:44:43 -0700107 # Choose a random downloaded progress to interrupt the update.
David Haddock8efca4d2019-07-23 19:08:03 -0700108 progress = random.uniform(0.1, 0.6)
109 logging.info('Progress when we will interrupt: %f', progress)
David Haddock80e3b8f2018-04-10 17:44:43 -0700110 self._wait_for_progress(progress)
David Haddock8efca4d2019-07-23 19:08:03 -0700111 logging.info('We will now start interrupting the update.')
112 self._take_screenshot('before_interrupt.png')
David Haddocked70eef2018-07-19 16:40:54 -0700113 completed = self._get_update_progress()
David Haddock8efca4d2019-07-23 19:08:03 -0700114
115 if interrupt is 'reboot':
116 self._host.reboot()
117 elif interrupt is 'network':
118 self._disconnect_then_reconnect_network(update_url)
119 elif interrupt is 'suspend':
120 self._suspend_then_resume()
121 else:
122 raise error.TestFail('Unknown interrupt type: %s' % interrupt)
123 # Screenshot to check that OOBE was not skipped by interruption.
124 self._take_screenshot('after_interrupt.png')
125
David Haddockafdfa5b2018-08-10 16:10:01 -0700126 if self._is_update_engine_idle():
David Haddock8efca4d2019-07-23 19:08:03 -0700127 raise error.TestFail('The update was IDLE after interrupt.')
David Haddock0bad4a32018-02-02 13:05:26 -0800128 if not self._update_continued_where_it_left_off(completed):
129 raise error.TestFail('The update did not continue where it '
David Haddock8efca4d2019-07-23 19:08:03 -0700130 'left off after interruption.')
David Haddock0bad4a32018-02-02 13:05:26 -0800131
David Haddock80e3b8f2018-04-10 17:44:43 -0700132 self._wait_for_oobe_update_to_complete()
David Haddock95e7fbe2017-12-01 17:49:53 -0800133
David Haddockac210892018-02-05 20:36:27 -0800134 if cellular:
135 # We didn't have a devserver so we cannot check the hostlog to
136 # ensure the update completed successfully. Instead we can check
137 # that the second-to-last update engine log has the successful
138 # update message. Second to last because its the one before OOBE
139 # rebooted.
David Haddock2fd9aec2018-04-23 19:17:46 -0700140 before_reboot_file = self._get_second_last_update_engine_log()
David Haddockac210892018-02-05 20:36:27 -0800141 self._check_for_cellular_entries_in_update_log(before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800142 success = 'Update successfully applied, waiting to reboot.'
David Haddock2fd9aec2018-04-23 19:17:46 -0700143 self._check_update_engine_log_for_entry(success,
144 raise_error=True,
145 update_engine_log=
146 before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800147 return
148
David Haddock95e7fbe2017-12-01 17:49:53 -0800149 # Verify that the update completed successfully by checking hostlog.
150 rootfs_hostlog, reboot_hostlog = self._create_hostlog_files()
151 self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog)
152 self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog,
153 self._CUSTOM_LSB_VERSION)
154
155 after = self._get_chromeos_version()
156 logging.info('Successfully force updated from %s to %s.', before, after)