• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5import logging
6
7from autotest_lib.server.cros.update_engine import update_engine_test
8
9class autoupdate_OmahaResponse(update_engine_test.UpdateEngineTest):
10    """
11    This server test is used just to get the URL of the payload to use. It
12    will then call into a client side test to test different things in
13    the omaha response (e.g switching between two urls, bad hash, bad SHA256).
14    """
15    version = 1
16
17    def cleanup(self):
18        """Cleans up after the test."""
19        super(autoupdate_OmahaResponse, self).cleanup()
20        self._host.reboot()
21
22    def run_once(self, job_repo_url=None, full_payload=True,
23                 running_at_desk=False, switch_urls=False, bad_sha256=False,
24                 bad_metadata_size=False, test_backoff=False, backoff=False):
25        """
26        Runs the Omaha response test. This test can be configured to respond
27        to an update client in variaty of ways.
28
29        @param job_repo_url: A url pointing to the devserver where the autotest
30            package for this build should be staged.
31        @param full_payload: True if the payload should be full.
32        @param running_at_desk: True if the test is being run locally.
33        @param switch_urls: True if we want to test URL switch capability of
34            update_engine.
35        @param bad_sha256: True if the response should have invalid SHA256.
36        @param bad_metadata_size: True if the response should have invalid
37            metadta size.
38        @param test_backoff: True if we want to test the backoff functionality.
39        @param backoff: Whether the backoff is enabled or not.
40
41        """
42
43        self._job_repo_url = job_repo_url
44
45        # Reboot DUT if a previous test left update_engine not idle.
46        status = self._get_update_engine_status()
47        if self._UPDATE_STATUS_IDLE != status[self._CURRENT_OP]:
48            self._host.reboot()
49
50        # Figure out the payload to use for the current build.
51        payload = self._get_payload_url(full_payload=full_payload)
52        image_url, _ = self._stage_payload_by_uri(payload)
53
54        if running_at_desk:
55            image_url = self._copy_payload_to_public_bucket(payload)
56            logging.info('We are running from a workstation. Putting URL on a '
57                         'public location: %s', image_url)
58
59        if switch_urls:
60            self._run_client_test_and_check_result('autoupdate_UrlSwitch',
61                                                   image_url=image_url)
62
63        if bad_sha256 or bad_metadata_size:
64            self._run_client_test_and_check_result(
65                'autoupdate_BadMetadata',
66                image_url=image_url,
67                bad_metadata_size=bad_metadata_size,
68                bad_sha256=bad_sha256)
69
70        if test_backoff:
71            self._run_client_test_and_check_result('autoupdate_Backoff',
72                                                   image_url=image_url,
73                                                   backoff=backoff)
74