xref: /aosp_15_r20/external/autotest/client/site_tests/autoupdate_UrlSwitch/autoupdate_UrlSwitch.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2# Copyright 2018 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
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, payload_url):
14        """
15        Tests to see whether the update_engine can successfully switch to a
16        different URL if one fails.
17
18        @param image_url: The URL of the update payload.
19
20        """
21        with nebraska_wrapper.NebraskaWrapper(
22            log_dir=self.resultsdir, payload_url=payload_url) as nebraska:
23
24            # Start the update that will return two Urls. This matches what test
25            # and production omaha does today.
26            self._check_for_update(
27                nebraska.get_update_url(failures_per_url=1, num_urls=2,
28                                        critical_update=True))
29            self._wait_for_progress(0.2)
30
31            # Pull the network cable so the update fails.
32            self._disable_internet()
33
34            # It will retry 21 times before giving up.
35            self._wait_for_update_to_fail()
36
37            # Check that we are moving to the next Url.
38            self._enable_internet()
39            self._check_update_engine_log_for_entry(
40                'Reached max number of failures for Url',
41                raise_error=True)
42
43            # The next update attempt should resume and finish successfully.
44            self._check_for_update(
45                nebraska.get_update_url(critical_update=True))
46            self._wait_for_update_to_complete()
47            self._check_update_engine_log_for_entry(
48                'Resuming an update that was previously started.',
49                raise_error=True)
50