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.bin import utils 7from autotest_lib.client.common_lib import error 8from autotest_lib.client.common_lib.cros import chrome 9from autotest_lib.client.cros.update_engine import nebraska_wrapper 10from autotest_lib.client.cros.update_engine import update_engine_test 11 12class autoupdate_LoginStartUpdateLogout(update_engine_test.UpdateEngineTest): 13 """ 14 Logs in, starts an update, then logs out. 15 16 This test is used as part of the server test autoupdate_Interruptions. 17 18 """ 19 version = 1 20 21 def run_once(self, 22 payload_url, 23 progress_to_complete, 24 full_payload=True, 25 interrupt_network=False): 26 """ 27 Login, start an update, and logout. If specified, this test will also 28 disconnect the internet upon reaching a target update progress, 29 wait a while, and reconnect the internet before logging out. 30 31 @param payload_url: Payload url to pass to Nebraska. 32 @param progress_to_complete: If interrupt_network is 33 True, the internet will be disconnected 34 when the update reaches this progress. 35 This should be a number between 0 and 1. 36 @param full_payload: True for a full payload. False for delta. 37 @param interrupt_network: True to cause a network interruption when 38 update progress reaches 39 progress_to_complete. False to logout after 40 the update starts. 41 42 """ 43 # Login as regular user. Start an update. Then Logout 44 45 with nebraska_wrapper.NebraskaWrapper( 46 log_dir=self.resultsdir, 47 payload_url=payload_url, 48 persist_metadata=True) as nebraska: 49 50 config = {'critical_update': True, 'full_payload': full_payload} 51 nebraska.update_config(**config) 52 update_url = nebraska.get_update_url() 53 # Create a nebraska config, which causes nebraska to start up 54 # before update_engine. This will allow nebraska to be up right 55 # after system startup so it can be used in the reboot 56 # interruption test. 57 nebraska.create_startup_config(**config) 58 59 with chrome.Chrome(logged_in=True): 60 self._check_for_update(update_url) 61 # Wait for the update to start. 62 utils.poll_for_condition(self._is_update_started, timeout=30) 63 64 if interrupt_network: 65 self._wait_for_progress(progress_to_complete) 66 completed = self._get_update_progress() 67 self._disconnect_reconnect_network_test() 68 69 if self._is_update_engine_idle(): 70 raise error.TestFail( 71 'The update was IDLE after interrupt.') 72 if not self._update_continued_where_it_left_off(completed): 73 raise error.TestFail( 74 'The update did not continue where ' 75 'it left off after interruption.') 76 77 # Log in and out with a new user during the update. 78 with chrome.Chrome(logged_in=True, dont_override_profile=False): 79 pass 80