1# Copyright 2022 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.common_lib import error 8from autotest_lib.client.common_lib.cros import kernel_utils 9from autotest_lib.client.common_lib.cros import dev_server 10from autotest_lib.server.cros.minios import minios_test 11 12 13class nbr_EndToEndTest(minios_test.MiniOsTest): 14 """Test network based recovery of a DUT.""" 15 version = 1 16 17 def run_once(self, 18 job_repo_url=None, 19 n2m=True, 20 corrupt_partitions=False, 21 network_name='Ethernet', 22 network_password=None, 23 running_at_desk=False): 24 """ 25 Validates the network based recovery flow. 26 27 @param job_repo_url: A url pointing to the devserver where the autotest 28 package for this build should be staged. 29 @param n2m: Perform recovery from ToT to current stable version. 30 @param corrupt_partitions: Corrupt the kernel and rootfs partition before 31 attempting recovery. 32 @param network_name: The name of the network to connect to for recovery. 33 @param network_password: Optional password for the network. 34 @param running_at_desk: indicates test is run locally from a workstation. 35 36 """ 37 update_url = job_repo_url 38 if n2m: 39 build_name = self._get_latest_serving_stable_build() 40 logging.debug('stable build name is %s', build_name) 41 42 # Determine the URL for the stable build. 43 autotest_devserver = dev_server.ImageServer.resolve( 44 build_name, self._host.hostname) 45 update_url = autotest_devserver.get_update_url(build_name) 46 47 logging.info('Performing recovery with update url: %s', update_url) 48 payload_url = self.get_payload_for_nebraska( 49 update_url, full_payload=True, public_bucket=running_at_desk) 50 51 logging.info("Booting into MiniOS") 52 self._boot_minios() 53 54 # Install testing dependencies into MiniOS. 55 logging.info("Successfully booted into MiniOS.") 56 self._install_test_dependencies(public_bucket=running_at_desk) 57 58 old_boot_id = self._host.get_boot_id() 59 self._start_nebraska(payload_url=payload_url) 60 cmd = [ 61 self._MINIOS_CLIENT_CMD, '--start_recovery', 62 f'--network_name={network_name}', '--watch' 63 ] 64 if network_password: 65 cmd += [f'--network_password={network_password}'] 66 logging.info(f'Performing network based recovery with cmd: {cmd}.') 67 self._run(cmd) 68 logging.info('Recovery complete. Grabbing logs.') 69 70 # Generate host log. 71 minios_hostlog = self._create_minios_hostlog() 72 self._verify_reboot(old_boot_id) 73 74 # NBR always recovers into partition A. 75 kernel_utils.verify_boot_expectations(kernel_utils._KERNEL_A, 76 host=self._host) 77 # Verify the update engine events that happened during the recovery. 78 self.verify_update_events(self._RECOVERY_VERSION, minios_hostlog) 79 80 # Restore the stateful partition. 81 logging.info('Verification complete. Restoring stateful.') 82 self._restore_stateful(public_bucket=running_at_desk) 83