1# Copyright 2018 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 5from autotest_lib.client.common_lib import autotemp 6from autotest_lib.client.cros.update_engine import nebraska_wrapper 7from autotest_lib.client.cros.update_engine import update_engine_test 8 9class autoupdate_UrlSwitch(update_engine_test.UpdateEngineTest): 10 """Tests that we can continue with the second url when the first fails.""" 11 version = 1 12 13 def run_once(self, image_url): 14 """ 15 Runs the URL switch test. 16 17 Test to see whether the update_engine can successfully switch to a 18 different URL if one fails. 19 20 @param image_url: The URL of the update payload. 21 """ 22 23 # Get payload properties file so we can run Nebraska with it. 24 metadata_dir = autotemp.tempdir() 25 self._get_payload_properties_file(image_url, metadata_dir.name) 26 base_url = ''.join(image_url.rpartition('/')[0:2]) 27 with nebraska_wrapper.NebraskaWrapper( 28 log_dir=self.resultsdir, 29 update_metadata_dir=metadata_dir.name, 30 update_payloads_address=base_url) as nebraska: 31 32 # Start the update that will return two Urls. This matches what test 33 # and production omaha does today. 34 self._check_for_update(port=nebraska.get_port(), num_urls=2, 35 critical_update=True) 36 self._wait_for_progress(0.2) 37 38 # Pull the network cable so the update fails. 39 self._disable_internet() 40 41 # It will retry 21 times before giving up. 42 self._wait_for_update_to_fail() 43 44 # Check that we are moving to the next Url. 45 self._enable_internet() 46 self._check_update_engine_log_for_entry( 47 'Reached max number of failures for Url') 48 49 # The next update attempt should resume and finish successfully. 50 self._check_for_update(port=nebraska.get_port(), 51 critical_update=True) 52 self._wait_for_update_to_complete() 53 self._check_update_engine_log_for_entry( 54 'Resuming an update that was previously started.') 55