blob: 4f890605f9cb96e2fc1a26c94185f69faaecb79f [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 Haddock50dbfee2018-01-12 12:43:12 -080024 super(autoupdate_ForcedOOBEUpdate, self).cleanup()
David Haddock95e7fbe2017-12-01 17:49:53 -080025
David Haddock95e7fbe2017-12-01 17:49:53 -080026
David Haddock80e3b8f2018-04-10 17:44:43 -070027 def _wait_for_oobe_update_to_complete(self):
David Haddock95e7fbe2017-12-01 17:49:53 -080028 """Wait for the update that started to complete.
29
30 Repeated check status of update. It should move from DOWNLOADING to
David Haddock80e3b8f2018-04-10 17:44:43 -070031 FINALIZING to COMPLETE (then reboot) to IDLE.
David Haddock95e7fbe2017-12-01 17:49:53 -080032 """
David Haddock5e2ef312018-06-12 12:59:31 -070033 # 20 minute timeout.
34 timeout_minutes = 20
35 timeout = time.time() + 60 * timeout_minutes
David Haddock95e7fbe2017-12-01 17:49:53 -080036 while True:
David Haddock2fd9aec2018-04-23 19:17:46 -070037 status = self._get_update_engine_status(timeout=10)
David Haddock95e7fbe2017-12-01 17:49:53 -080038
39 # During reboot, status will be None
40 if status is not None:
David Haddock80e3b8f2018-04-10 17:44:43 -070041 if self._UPDATE_STATUS_IDLE == status[self._CURRENT_OP]:
David Haddock95e7fbe2017-12-01 17:49:53 -080042 break
43 time.sleep(1)
David Haddock5e2ef312018-06-12 12:59:31 -070044 if time.time() > timeout:
45 raise error.TestFail('OOBE update did not finish in %d '
46 'minutes.' % timeout_minutes)
David Haddock95e7fbe2017-12-01 17:49:53 -080047
48
David Haddock2fd9aec2018-04-23 19:17:46 -070049 def run_once(self, full_payload=True, cellular=False,
David Haddock0bad4a32018-02-02 13:05:26 -080050 interrupt=False, max_updates=1, job_repo_url=None):
51 """
52 Runs a forced autoupdate during ChromeOS OOBE.
53
David Haddock0bad4a32018-02-02 13:05:26 -080054 @param full_payload: True for a full payload. False for delta.
55 @param cellular: True to do the update over a cellualar connection.
56 Requires that the DUT have a sim card slot.
57 @param interrupt: True to interrupt the update in the middle.
58 @param max_updates: Used to tell the test how many times it is
59 expected to ping its omaha server.
60 @param job_repo_url: Used for debugging locally. This is used to figure
61 out the current build and the devserver to use.
62 The test will read this from a host argument
63 when run in the lab.
64
65 """
David Haddock3a8f5722018-04-13 16:24:16 -070066 tpm_utils.ClearTPMOwnerRequest(self._host)
David Haddock463faf42018-01-23 14:21:11 -080067
68 # veyron_rialto is a medical device with a different OOBE that auto
69 # completes so this test is not valid on that device.
70 if 'veyron_rialto' in self._host.get_board():
71 raise error.TestNAError('Rialto has a custom OOBE. Skipping test.')
72
David Haddock50dbfee2018-01-12 12:43:12 -080073 update_url = self.get_update_url_for_test(job_repo_url,
David Haddock463faf42018-01-23 14:21:11 -080074 full_payload=full_payload,
David Haddockac210892018-02-05 20:36:27 -080075 critical_update=True,
David Haddock80e3b8f2018-04-10 17:44:43 -070076 public=cellular,
David Haddock0bad4a32018-02-02 13:05:26 -080077 max_updates=max_updates)
David Haddock95e7fbe2017-12-01 17:49:53 -080078 before = self._get_chromeos_version()
David Haddockac210892018-02-05 20:36:27 -080079 payload_info = None
80 if cellular:
David Haddock2fd9aec2018-04-23 19:17:46 -070081 self._change_cellular_setting_in_update_engine(True)
David Haddockac210892018-02-05 20:36:27 -080082 # Get the payload's information (size, SHA256 etc) since we will be
83 # setting up our own omaha instance on the DUT. We pass this to
84 # the client test.
85 payload = self._get_payload_url(full_payload=full_payload)
86 staged_url = self._stage_payload_by_uri(payload)
87 payload_info = self._get_staged_file_info(staged_url)
David Haddock95e7fbe2017-12-01 17:49:53 -080088
89 # Call client test to start the forced OOBE update.
David Haddock80e3b8f2018-04-10 17:44:43 -070090 self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate',
91 image_url=update_url,
David Haddock2fd9aec2018-04-23 19:17:46 -070092 cellular=cellular,
David Haddock80e3b8f2018-04-10 17:44:43 -070093 payload_info=payload_info,
94 full_payload=full_payload)
David Haddock95e7fbe2017-12-01 17:49:53 -080095
David Haddock95e7fbe2017-12-01 17:49:53 -080096
David Haddock0bad4a32018-02-02 13:05:26 -080097 if interrupt:
David Haddock80e3b8f2018-04-10 17:44:43 -070098 # Choose a random downloaded progress to interrupt the update.
99 progress = random.uniform(0.1, 0.8)
100 logging.debug('Progress when we will interrupt: %f', progress)
101 self._wait_for_progress(progress)
David Haddock0bad4a32018-02-02 13:05:26 -0800102 logging.info('We will start interrupting the update.')
David Haddock80e3b8f2018-04-10 17:44:43 -0700103 completed = self._get_update_progress()
David Haddock0bad4a32018-02-02 13:05:26 -0800104
105 # Reboot the DUT during the update.
106 self._host.reboot()
107 if not self._update_continued_where_it_left_off(completed):
108 raise error.TestFail('The update did not continue where it '
109 'left off before rebooting.')
David Haddock80e3b8f2018-04-10 17:44:43 -0700110 completed = self._get_update_progress()
David Haddock0bad4a32018-02-02 13:05:26 -0800111
David Haddock80e3b8f2018-04-10 17:44:43 -0700112 self._disconnect_then_reconnect_network(update_url)
David Haddock0bad4a32018-02-02 13:05:26 -0800113 if not self._update_continued_where_it_left_off(completed):
114 raise error.TestFail('The update did not continue where it '
115 'left off before disconnecting network.')
David Haddock80e3b8f2018-04-10 17:44:43 -0700116 completed = self._get_update_progress()
David Haddock0bad4a32018-02-02 13:05:26 -0800117
118 # Suspend / Resume
David Haddock80e3b8f2018-04-10 17:44:43 -0700119 self._suspend_then_resume()
David Haddock0bad4a32018-02-02 13:05:26 -0800120 if not self._update_continued_where_it_left_off(completed):
121 raise error.TestFail('The update did not continue where it '
122 'left off after suspend/resume.')
123
David Haddock80e3b8f2018-04-10 17:44:43 -0700124 self._wait_for_oobe_update_to_complete()
David Haddock95e7fbe2017-12-01 17:49:53 -0800125
David Haddockac210892018-02-05 20:36:27 -0800126 if cellular:
127 # We didn't have a devserver so we cannot check the hostlog to
128 # ensure the update completed successfully. Instead we can check
129 # that the second-to-last update engine log has the successful
130 # update message. Second to last because its the one before OOBE
131 # rebooted.
David Haddock2fd9aec2018-04-23 19:17:46 -0700132 before_reboot_file = self._get_second_last_update_engine_log()
David Haddockac210892018-02-05 20:36:27 -0800133 self._check_for_cellular_entries_in_update_log(before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800134 success = 'Update successfully applied, waiting to reboot.'
David Haddock2fd9aec2018-04-23 19:17:46 -0700135 self._check_update_engine_log_for_entry(success,
136 raise_error=True,
137 update_engine_log=
138 before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800139 return
140
David Haddock95e7fbe2017-12-01 17:49:53 -0800141 # Verify that the update completed successfully by checking hostlog.
142 rootfs_hostlog, reboot_hostlog = self._create_hostlog_files()
143 self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog)
144 self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog,
145 self._CUSTOM_LSB_VERSION)
146
147 after = self._get_chromeos_version()
148 logging.info('Successfully force updated from %s to %s.', before, after)