1# 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. 4 5import logging 6 7from autotest_lib.client.bin import utils 8from autotest_lib.client.common_lib import error 9from autotest_lib.client.common_lib import lsbrelease_utils 10from autotest_lib.client.common_lib.cros import chrome 11from autotest_lib.client.cros.cellular import test_environment 12from autotest_lib.client.cros.update_engine import nebraska_wrapper 13from autotest_lib.client.cros.update_engine import update_engine_test 14 15class autoupdate_StartOOBEUpdate(update_engine_test.UpdateEngineTest): 16 """Starts a forced update at OOBE. 17 18 Chrome OS will restart when the update is complete so this test will just 19 start the update. The rest of the processing will be done in a server 20 side test. 21 """ 22 version = 1 23 24 25 def initialize(self): 26 """Test setup.""" 27 super(autoupdate_StartOOBEUpdate, self).initialize() 28 self._clear_custom_lsb_release() 29 30 31 def _skip_to_oobe_update_screen(self): 32 """Skips to the OOBE update check screen.""" 33 self._oobe.WaitForJavaScriptCondition("typeof Oobe == 'function' && " 34 "Oobe.readyForTesting", 35 timeout=30) 36 self._oobe.ExecuteJavaScript('Oobe.skipToUpdateForTesting()') 37 38 39 def _start_oobe_update(self, update_url, critical_update, full_payload): 40 """ 41 Jump to the update check screen at OOBE and wait for update to start. 42 43 @param update_url: The omaha update URL we expect to call. 44 @param critical_update: True if the update is critical. 45 @param full_payload: Whether we want the full payload or delta. 46 47 """ 48 self._create_custom_lsb_release(update_url, 49 critical_update=critical_update, 50 full_payload=full_payload) 51 # Start chrome instance to interact with OOBE. 52 extra_browser_args = [] 53 if lsbrelease_utils.get_device_type() != 'CHROMEBOOK': 54 extra_browser_args.append('--disable-hid-detection-on-oobe') 55 self._chrome = chrome.Chrome(auto_login=False, 56 extra_browser_args=extra_browser_args) 57 self._oobe = self._chrome.browser.oobe 58 self._skip_to_oobe_update_screen() 59 60 timeout = 180 61 err_str = 'Update did not start within %d seconds.' % timeout 62 try: 63 utils.poll_for_condition(self._is_update_started, 64 error.TestFail(err_str), 65 timeout=timeout) 66 except error.TestFail as e: 67 if critical_update: 68 if not self._get_update_requests(): 69 raise error.TestFail('%s There were no update requests in' 70 ' update_engine.log. OOBE update' 71 ' screen was missed.' % err_str) 72 err_code = self._get_last_error_string() 73 if err_code is not None: 74 raise error.TestFail('%s %s' % (err_str, err_code)) 75 else: 76 raise e 77 78 79 def run_once(self, update_url=None, payload_url=None, cellular=False, 80 critical_update=True, full_payload=None, 81 interrupt_network=False, interrupt_progress=0.0): 82 """ 83 Test that will start a forced update at OOBE. 84 85 @param update_url: The omaha URL to call from the OOBE update screen. 86 @param payload_url: Payload url to pass to Nebraska for non-critical 87 and cellular tests. 88 @param cellular: True if we should run this test using a sim card. 89 @param critical_update: True if we should have deadline:now in omaha 90 response. 91 @param full_payload: Whether the payload is full or delta. None if we 92 don't have to care about it. 93 @param interrupt_network: True to cause a network interruption after 94 starting the update. Should only be used 95 during a critical update. 96 @param interrupt_progress: If interrupt_network is True, we will wait 97 for the update progress to reach this 98 value before interrupting. Should be 99 expressed as a number between 0 and 1. 100 101 """ 102 103 if critical_update and not cellular: 104 self._start_oobe_update(update_url, critical_update, full_payload) 105 if interrupt_network: 106 self._wait_for_progress(interrupt_progress) 107 self._take_screenshot(self._BEFORE_INTERRUPT_FILENAME) 108 completed = self._get_update_progress() 109 self._disconnect_reconnect_network_test(update_url) 110 self._take_screenshot(self._AFTER_INTERRUPT_FILENAME) 111 112 if self._is_update_engine_idle(): 113 raise error.TestFail( 114 'The update was IDLE after interrupt.') 115 if not self._update_continued_where_it_left_off(completed): 116 raise error.TestFail('The update did not continue where ' 117 'it left off after interruption.') 118 119 # Remove screenshots since the interrupt test succeeded. 120 self._remove_screenshots() 121 return 122 123 # Setup a Nebraska instance on the DUT for cellular tests and 124 # non-critical updates. Ceullar tests cannot reach devservers. 125 # Non-critical tests don't need a devserver. 126 with nebraska_wrapper.NebraskaWrapper( 127 log_dir=self.resultsdir, payload_url=payload_url) as nebraska: 128 129 update_url = nebraska.get_update_url( 130 critical_update=critical_update) 131 if not cellular: 132 self._start_oobe_update(update_url, critical_update, None) 133 return 134 135 try: 136 with test_environment.CellularOTATestEnvironment() as test_env: 137 service = test_env.shill.wait_for_cellular_service_object() 138 if not service: 139 raise error.TestError('No cellular service found.') 140 connect_timeout = 120 141 test_env.shill.connect_service_synchronous(service, 142 connect_timeout) 143 144 self._start_oobe_update(update_url, critical_update, None) 145 146 # Remove the custom omaha server from lsb release because 147 # after we reboot it will no longer be running. 148 self._clear_custom_lsb_release() 149 150 # Need to return from this client test before OOBE reboots 151 # or the server test will hang. Cannot return immediately 152 # when the OOBE update starts because all code for cellular 153 # connections is client side and the test will switch to 154 # ethernet. So wait for FINALIZING so payload is downloaded 155 # via cellular and won't ping omaha again. After reboot, 156 # there is a final ping to omaha and login screen is shown. 157 self._wait_for_update_status( 158 self._UPDATE_STATUS_FINALIZING) 159 except error.TestError as e: 160 logging.error('Failure setting up sim card.') 161 raise error.TestFail(e) 162