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