blob: 84ea03e09356b74c756eec55c2e6a7a8e4af4ce8 [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 """
33 while True:
David Haddock2fd9aec2018-04-23 19:17:46 -070034 status = self._get_update_engine_status(timeout=10)
David Haddock95e7fbe2017-12-01 17:49:53 -080035
36 # During reboot, status will be None
37 if status is not None:
David Haddock80e3b8f2018-04-10 17:44:43 -070038 if self._UPDATE_STATUS_IDLE == status[self._CURRENT_OP]:
David Haddock95e7fbe2017-12-01 17:49:53 -080039 break
40 time.sleep(1)
41
42
David Haddock2fd9aec2018-04-23 19:17:46 -070043 def run_once(self, full_payload=True, cellular=False,
David Haddock0bad4a32018-02-02 13:05:26 -080044 interrupt=False, max_updates=1, job_repo_url=None):
45 """
46 Runs a forced autoupdate during ChromeOS OOBE.
47
48 @param host: The DUT that we are running on.
49 @param full_payload: True for a full payload. False for delta.
50 @param cellular: True to do the update over a cellualar connection.
51 Requires that the DUT have a sim card slot.
52 @param interrupt: True to interrupt the update in the middle.
53 @param max_updates: Used to tell the test how many times it is
54 expected to ping its omaha server.
55 @param job_repo_url: Used for debugging locally. This is used to figure
56 out the current build and the devserver to use.
57 The test will read this from a host argument
58 when run in the lab.
59
60 """
David Haddock3a8f5722018-04-13 16:24:16 -070061 tpm_utils.ClearTPMOwnerRequest(self._host)
David Haddock463faf42018-01-23 14:21:11 -080062
63 # veyron_rialto is a medical device with a different OOBE that auto
64 # completes so this test is not valid on that device.
65 if 'veyron_rialto' in self._host.get_board():
66 raise error.TestNAError('Rialto has a custom OOBE. Skipping test.')
67
David Haddock50dbfee2018-01-12 12:43:12 -080068 update_url = self.get_update_url_for_test(job_repo_url,
David Haddock463faf42018-01-23 14:21:11 -080069 full_payload=full_payload,
David Haddockac210892018-02-05 20:36:27 -080070 critical_update=True,
David Haddock80e3b8f2018-04-10 17:44:43 -070071 public=cellular,
David Haddock0bad4a32018-02-02 13:05:26 -080072 max_updates=max_updates)
David Haddock95e7fbe2017-12-01 17:49:53 -080073 before = self._get_chromeos_version()
David Haddockac210892018-02-05 20:36:27 -080074 payload_info = None
75 if cellular:
David Haddock2fd9aec2018-04-23 19:17:46 -070076 self._change_cellular_setting_in_update_engine(True)
David Haddockac210892018-02-05 20:36:27 -080077 # Get the payload's information (size, SHA256 etc) since we will be
78 # setting up our own omaha instance on the DUT. We pass this to
79 # the client test.
80 payload = self._get_payload_url(full_payload=full_payload)
81 staged_url = self._stage_payload_by_uri(payload)
82 payload_info = self._get_staged_file_info(staged_url)
David Haddock95e7fbe2017-12-01 17:49:53 -080083
84 # Call client test to start the forced OOBE update.
David Haddock80e3b8f2018-04-10 17:44:43 -070085 self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate',
86 image_url=update_url,
David Haddock2fd9aec2018-04-23 19:17:46 -070087 cellular=cellular,
David Haddock80e3b8f2018-04-10 17:44:43 -070088 payload_info=payload_info,
89 full_payload=full_payload)
David Haddock95e7fbe2017-12-01 17:49:53 -080090
David Haddock95e7fbe2017-12-01 17:49:53 -080091
David Haddock0bad4a32018-02-02 13:05:26 -080092 if interrupt:
David Haddock80e3b8f2018-04-10 17:44:43 -070093 # Choose a random downloaded progress to interrupt the update.
94 progress = random.uniform(0.1, 0.8)
95 logging.debug('Progress when we will interrupt: %f', progress)
96 self._wait_for_progress(progress)
David Haddock0bad4a32018-02-02 13:05:26 -080097 logging.info('We will start interrupting the update.')
David Haddock80e3b8f2018-04-10 17:44:43 -070098 completed = self._get_update_progress()
David Haddock0bad4a32018-02-02 13:05:26 -080099
100 # Reboot the DUT during the update.
101 self._host.reboot()
102 if not self._update_continued_where_it_left_off(completed):
103 raise error.TestFail('The update did not continue where it '
104 'left off before rebooting.')
David Haddock80e3b8f2018-04-10 17:44:43 -0700105 completed = self._get_update_progress()
David Haddock0bad4a32018-02-02 13:05:26 -0800106
David Haddock80e3b8f2018-04-10 17:44:43 -0700107 self._disconnect_then_reconnect_network(update_url)
David Haddock0bad4a32018-02-02 13:05:26 -0800108 if not self._update_continued_where_it_left_off(completed):
109 raise error.TestFail('The update did not continue where it '
110 'left off before disconnecting network.')
David Haddock80e3b8f2018-04-10 17:44:43 -0700111 completed = self._get_update_progress()
David Haddock0bad4a32018-02-02 13:05:26 -0800112
113 # Suspend / Resume
David Haddock80e3b8f2018-04-10 17:44:43 -0700114 self._suspend_then_resume()
David Haddock0bad4a32018-02-02 13:05:26 -0800115 if not self._update_continued_where_it_left_off(completed):
116 raise error.TestFail('The update did not continue where it '
117 'left off after suspend/resume.')
118
David Haddock80e3b8f2018-04-10 17:44:43 -0700119 self._wait_for_oobe_update_to_complete()
David Haddock95e7fbe2017-12-01 17:49:53 -0800120
David Haddockac210892018-02-05 20:36:27 -0800121 if cellular:
122 # We didn't have a devserver so we cannot check the hostlog to
123 # ensure the update completed successfully. Instead we can check
124 # that the second-to-last update engine log has the successful
125 # update message. Second to last because its the one before OOBE
126 # rebooted.
David Haddock2fd9aec2018-04-23 19:17:46 -0700127 before_reboot_file = self._get_second_last_update_engine_log()
David Haddockac210892018-02-05 20:36:27 -0800128 self._check_for_cellular_entries_in_update_log(before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800129 success = 'Update successfully applied, waiting to reboot.'
David Haddock2fd9aec2018-04-23 19:17:46 -0700130 self._check_update_engine_log_for_entry(success,
131 raise_error=True,
132 update_engine_log=
133 before_reboot_file)
David Haddockac210892018-02-05 20:36:27 -0800134 return
135
David Haddock95e7fbe2017-12-01 17:49:53 -0800136 # Verify that the update completed successfully by checking hostlog.
137 rootfs_hostlog, reboot_hostlog = self._create_hostlog_files()
138 self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog)
139 self.verify_update_events(self._CUSTOM_LSB_VERSION, reboot_hostlog,
140 self._CUSTOM_LSB_VERSION)
141
142 after = self._get_chromeos_version()
143 logging.info('Successfully force updated from %s to %s.', before, after)