blob: 48834a5e78a46f78fa49eafc60e679f5e5f2ddfb [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 Haddock95c74c02019-09-16 11:06:33 -070061 interrupt=None, max_updates=1, job_repo_url=None,
62 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 max_updates: Used to tell the test how many times it is
71 expected to ping its omaha server.
72 @param job_repo_url: Used for debugging locally. This is used to figure
73 out the current build and the devserver to use.
74 The test will read this from a host argument
75 when run in the lab.
David Haddock95c74c02019-09-16 11:06:33 -070076 @param moblab: True if we are running on moblab.
David Haddock0bad4a32018-02-02 13:05:26 -080077
78 """
David Haddock463faf42018-01-23 14:21:11 -080079 # veyron_rialto is a medical device with a different OOBE that auto
80 # completes so this test is not valid on that device.
81 if 'veyron_rialto' in self._host.get_board():
82 raise error.TestNAError('Rialto has a custom OOBE. Skipping test.')
83
David Haddock8efca4d2019-07-23 19:08:03 -070084 tpm_utils.ClearTPMOwnerRequest(self._host)
David Haddock50dbfee2018-01-12 12:43:12 -080085 update_url = self.get_update_url_for_test(job_repo_url,
David Haddock463faf42018-01-23 14:21:11 -080086 full_payload=full_payload,
David Haddockac210892018-02-05 20:36:27 -080087 critical_update=True,
David Haddock80e3b8f2018-04-10 17:44:43 -070088 public=cellular,
David Haddock95c74c02019-09-16 11:06:33 -070089 max_updates=max_updates,
90 moblab=moblab)
David Haddock95e7fbe2017-12-01 17:49:53 -080091 before = self._get_chromeos_version()
David Haddockac210892018-02-05 20:36:27 -080092 payload_info = None
93 if cellular:
David Haddock2fd9aec2018-04-23 19:17:46 -070094 self._change_cellular_setting_in_update_engine(True)
David Haddockac210892018-02-05 20:36:27 -080095 # Get the payload's information (size, SHA256 etc) since we will be
96 # setting up our own omaha instance on the DUT. We pass this to
97 # the client test.
98 payload = self._get_payload_url(full_payload=full_payload)
Amin Hassani8100ba42019-08-28 22:46:33 -070099 staged_url, _ = self._stage_payload_by_uri(payload)
David Haddockac210892018-02-05 20:36:27 -0800100 payload_info = self._get_staged_file_info(staged_url)
David Haddock95e7fbe2017-12-01 17:49:53 -0800101
102 # Call client test to start the forced OOBE update.
David Haddock80e3b8f2018-04-10 17:44:43 -0700103 self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate',
104 image_url=update_url,
David Haddock2fd9aec2018-04-23 19:17:46 -0700105 cellular=cellular,
David Haddock80e3b8f2018-04-10 17:44:43 -0700106 payload_info=payload_info,
107 full_payload=full_payload)
David Haddock95e7fbe2017-12-01 17:49:53 -0800108
David Haddock8efca4d2019-07-23 19:08:03 -0700109 if interrupt is not None:
David Haddock80e3b8f2018-04-10 17:44:43 -0700110 # Choose a random downloaded progress to interrupt the update.
David Haddock8efca4d2019-07-23 19:08:03 -0700111 progress = random.uniform(0.1, 0.6)
112 logging.info('Progress when we will interrupt: %f', progress)
David Haddock80e3b8f2018-04-10 17:44:43 -0700113 self._wait_for_progress(progress)
David Haddock8efca4d2019-07-23 19:08:03 -0700114 logging.info('We will now start interrupting the update.')
115 self._take_screenshot('before_interrupt.png')
David Haddocked70eef2018-07-19 16:40:54 -0700116 completed = self._get_update_progress()
David Haddock8efca4d2019-07-23 19:08:03 -0700117
118 if interrupt is 'reboot':
119 self._host.reboot()
120 elif interrupt is 'network':
121 self._disconnect_then_reconnect_network(update_url)
122 elif interrupt is 'suspend':
123 self._suspend_then_resume()
124 else:
125 raise error.TestFail('Unknown interrupt type: %s' % interrupt)
126 # Screenshot to check that OOBE was not skipped by interruption.
127 self._take_screenshot('after_interrupt.png')
128
David Haddockafdfa5b2018-08-10 16:10:01 -0700129 if self._is_update_engine_idle():
David Haddock8efca4d2019-07-23 19:08:03 -0700130 raise error.TestFail('The update was IDLE after interrupt.')
David Haddock0bad4a32018-02-02 13:05:26 -0800131 if not self._update_continued_where_it_left_off(completed):
132 raise error.TestFail('The update did not continue where it '
David Haddock8efca4d2019-07-23 19:08:03 -0700133 'left off after interruption.')
David Haddock0bad4a32018-02-02 13:05:26 -0800134
David Haddock80e3b8f2018-04-10 17:44:43 -0700135 self._wait_for_oobe_update_to_complete()
David Haddock95e7fbe2017-12-01 17:49:53 -0800136
David Haddockac210892018-02-05 20:36:27 -0800137 if cellular:
138 # We didn't have a devserver so we cannot check the hostlog to
139 # ensure the update completed successfully. Instead we can check
140 # that the second-to-last update engine log has the successful
141 # update message. Second to last because its the one before OOBE
142 # rebooted.
David Haddock2fd9aec2018-04-23 19:17:46 -0700143 before_reboot_file = self._get_second_last_update_engine_log()
David Haddockac210892018-02-05 20:36:27 -0800144 self._check_for_cellular_entries_in_update_log(before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800145 success = 'Update successfully applied, waiting to reboot.'
David Haddock2fd9aec2018-04-23 19:17:46 -0700146 self._check_update_engine_log_for_entry(success,
147 raise_error=True,
148 update_engine_log=
149 before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800150 return
151
David Haddock95e7fbe2017-12-01 17:49:53 -0800152 # Verify that the update completed successfully by checking hostlog.
153 rootfs_hostlog, reboot_hostlog = self._create_hostlog_files()
154 self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog)
155 self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog,
156 self._CUSTOM_LSB_VERSION)
157
158 after = self._get_chromeos_version()
159 logging.info('Successfully force updated from %s to %s.', before, after)