• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 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
6import os
7
8from autotest_lib.client.bin import utils
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.cros.update_engine import nebraska_wrapper
11from autotest_lib.client.cros.update_engine import update_engine_test
12
13
14class autoupdate_PeriodicCheck(update_engine_test.UpdateEngineTest):
15    """Tests update_engine's periodic update check mechanism."""
16    version = 1
17
18    _PERIODIC_INTERVAL_PREF = 'test-update-check-interval-timeout'
19    _PERIODIC_LOG = ('Unofficial build, but periodic update check interval '
20                     'timeout is defined, so update is not blocked.')
21
22    def cleanup(self):
23        """Cleans up the state and extra files this test created."""
24        self._remove_update_engine_pref(self._PERIODIC_INTERVAL_PREF)
25        self._clear_custom_lsb_release()
26        super(autoupdate_PeriodicCheck, self).cleanup()
27
28    def run_once(self, payload_url, periodic_interval):
29        """
30        Tests update_engine's periodic update check.
31
32        @param payload_url: The payload url.
33        @param periodic_interval: Seconds between periodic update checks.
34
35        """
36        # Setup the DUT for the test.
37        pref_file = os.path.join(self._UPDATE_ENGINE_PREFS_DIR,
38                                 self._PERIODIC_INTERVAL_PREF)
39        utils.run(['echo', str(periodic_interval), '>', pref_file])
40        utils.run(['touch', '/home/chronos/.oobe_completed'])
41
42        with nebraska_wrapper.NebraskaWrapper(
43                log_dir=self.resultsdir, payload_url=payload_url) as nebraska:
44
45            logging.info('Setting first update response to return no update.')
46            self._create_custom_lsb_release(
47                    nebraska.get_update_url(no_update=True))
48            self._restart_update_engine()
49
50            # Wait for the first update check.
51            try:
52                utils.poll_for_condition(
53                    lambda: len(self._get_update_requests()) == 1,
54                    desc='1st periodic update check.',
55                    timeout=1.5 * periodic_interval)
56            except utils.TimeoutError:
57                raise error.TestFail('1st periodic check not found.')
58            self._check_update_engine_log_for_entry(self._PERIODIC_LOG,
59                                                    raise_error=True)
60            logging.info('First periodic update was initiated.')
61
62            logging.info('Setting the next update response to be an update.')
63            self._create_custom_lsb_release(nebraska.get_update_url())
64
65            # Wait for the second update check.
66            try:
67                utils.poll_for_condition(
68                    lambda: len(self._get_update_requests()) == 2,
69                    desc='2nd periodic update check.',
70                    timeout=2 * periodic_interval)
71            except utils.TimeoutError:
72                raise error.TestFail('2nd periodic check not found.')
73            logging.info('Second periodic update was initiated.')
74            self._wait_for_update_to_complete()
75