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.common_lib import error
7from autotest_lib.client.common_lib.cros import tpm_utils
8from autotest_lib.server.cros.update_engine import update_engine_test
9
10class autoupdate_NonBlockingOOBEUpdate(update_engine_test.UpdateEngineTest):
11    """Try a non-critical (non-blocking) update at OOBE which should fail."""
12    version = 1
13
14    _NON_CRITICAL_ERROR = 'finished OmahaRequestAction with code ' \
15                          'ErrorCode::kNonCriticalUpdateInOOBE'
16
17    def cleanup(self):
18        """Remove the custom lsb-release used by the test."""
19        self._clear_custom_lsb_release()
20        super(autoupdate_NonBlockingOOBEUpdate, self).cleanup()
21
22
23    def run_once(self,
24                 full_payload=True,
25                 job_repo_url=None,
26                 running_at_desk=False):
27        """
28        Tries an autoupdate during ChromeOS OOBE without a deadline.
29
30        An Omaha response to update with a deadline attribute is considered
31        critical and should be performed during OOBE. Non critical updates do
32        not have a deadline and should not be executed.
33
34        @param full_payload: True for a full payload. False for delta.
35        @param job_repo_url: Used for debugging locally. This is used to figure
36                             out the current build and the devserver to use.
37                             The test will read this from a host argument
38                             when run in the lab.
39        @param running_at_desk: Indicates test is run locally from a
40                                workstation.
41
42        """
43        tpm_utils.ClearTPMOwnerRequest(self._host)
44        payload_url = self.get_payload_for_nebraska(
45                job_repo_url,
46                full_payload=full_payload,
47                public_bucket=running_at_desk)
48        self._run_client_test_and_check_result('autoupdate_StartOOBEUpdate',
49                                               payload_url=payload_url,
50                                               full_payload=full_payload,
51                                               critical_update=False)
52
53        # Check that the update failed as expected.
54        if self._check_update_engine_log_for_entry(self._NON_CRITICAL_ERROR):
55            return
56
57        err_str = "The update was expected to fail with error code " \
58                  "'kNonCriticalUpdateInOOBE' because the update response " \
59                  "was not critical and we are still at OOBE. This didn't " \
60                  "happen."
61
62        # Is there an update in progress?
63        if not self._is_update_engine_idle():
64            raise error.TestFail('An update was in progress when it should '
65                                 'not have started. %s' % err_str)
66        # Were any update requests fired?
67        elif not self._get_update_requests():
68            raise error.TestFail('There were no update requests in '
69                                 'update_engine.log. OOBE update screen was '
70                                 'missed. %s' % err_str)
71        else:
72            err_code = self._get_last_error_string()
73            if err_code is not None:
74                err_str = '%s Actual Error: %s' % (err_str, err_code)
75            raise error.TestFail(err_str)
76