1# Lint as: python2, python3
2# Copyright 2021 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.cros import kernel_utils
7from autotest_lib.server.cros.update_engine import update_engine_test
8
9
10class autoupdate_RejectDuplicateUpdate(update_engine_test.UpdateEngineTest):
11    """Tests to see if duplicate consecutive updates are rejected. """
12    version = 1
13
14    def cleanup(self):
15        """Clean up the test state."""
16        # Disable repeated updates using update_engine_client.
17        self._set_feature(feature_name=self._REPEATED_UPDATES_FEATURE,
18                          enable=False)
19
20    def run_once(self, job_repo_url=None, running_at_desk=False):
21        """
22        @param job_repo_url: A url pointing to the devserver where the autotest
23            package for this build should be staged.
24        @param running_at_desk: indicates test is run locally from a workstation.
25
26        """
27        # Enable repeated updates using update_engine_client.
28        self._set_feature(feature_name=self._REPEATED_UPDATES_FEATURE,
29                          enable=True)
30        # Get a payload to use for the test.
31        payload_url = self.get_payload_for_nebraska(
32                job_repo_url,
33                full_payload=False,
34                public_bucket=running_at_desk)
35
36        # Record DUT state before the update.
37        _, inactive = kernel_utils.get_kernel_state(self._host)
38
39        # Perform an update.
40        self._run_client_test_and_check_result(self._CLIENT_TEST,
41                                               payload_url=payload_url)
42
43        self._wait_for_update_to_complete()
44
45        # Perform another update. This is a duplicate update and should fail.
46        self._run_client_test_and_check_result(self._CLIENT_TEST,
47                                               payload_url=payload_url,
48                                               allow_failure=True)
49
50        # Check logs to make sure it failed with the correct error.
51        self._check_update_engine_log_for_entry(
52                'finished OmahaRequestAction with code '
53                'ErrorCode::kRepeatedFpFromOmahaError',
54                raise_error=True)
55
56        # Verify the first update can still complete and reboot.
57        self._host.reboot()
58        kernel_utils.verify_boot_expectations(inactive, host=self._host)
59