• 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.client.bin import utils
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.common_lib.cros import chrome
10from autotest_lib.client.cros.update_engine import nano_omaha_devserver
11from autotest_lib.client.cros.update_engine import update_engine_test
12
13class autoupdate_EOL(update_engine_test.UpdateEngineTest):
14    """Tests end of life (EOL) behaviour."""
15    version = 1
16
17    _EXPECTED_EOL_STATUS = 'EOL_STATUS=eol'
18    _EOL_NOTIFICATION_TITLE = 'This device is no longer supported'
19
20    def cleanup(self):
21        self._save_extra_update_engine_logs()
22        super(autoupdate_EOL, self).cleanup()
23
24
25    def _check_eol_status(self):
26        """Checks update_engines eol status."""
27        result = utils.run('update_engine_client --eol_status').stdout.strip()
28        if result != self._EXPECTED_EOL_STATUS:
29            raise error.TestFail('Expected status %s. Actual: %s' %
30                                 (self._EXPECTED_EOL_STATUS, result))
31
32
33    def _check_eol_notification(self):
34        """Checks that we are showing an EOL notification to the user."""
35        with chrome.Chrome(autotest_ext=True, logged_in=True) as cr:
36            def find_notification():
37                notifications = cr.get_visible_notifications()
38                if notifications is None:
39                    return False
40                else:
41                    logging.debug(notifications)
42                    for n in notifications:
43                        if n['title'] == self._EOL_NOTIFICATION_TITLE:
44                            return True
45
46            utils.poll_for_condition(condition=lambda: find_notification(),
47                                     desc='Notification is found',
48                                     timeout=5,
49                                     sleep_interval=1)
50
51
52    def run_once(self):
53        # Start a devserver to return a response with eol entry.
54        self._omaha = nano_omaha_devserver.NanoOmahaDevserver(eol=True)
55        self._omaha.start()
56
57        # Try to update using the omaha server. It will fail with noupdate.
58        self._check_for_update(port=self._omaha.get_port(), ignore_status=True,
59                               wait_for_completion=True)
60
61        self._check_eol_status()
62        self._check_eol_notification()
63