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 6 7from autotest_lib.client.common_lib import error 8from autotest_lib.client.common_lib.cros import kernel_utils 9from autotest_lib.server.cros.update_engine import update_engine_test 10 11 12class autoupdate_WithDLC(update_engine_test.UpdateEngineTest): 13 """Tests basic DLC installation and n-to-n updating. """ 14 15 version = 1 16 _CLIENT_TEST = 'autoupdate_InstallAndUpdateDLC' 17 18 def initialize(self, host=None): 19 """Remove all DLCs on the DUT before starting the test. """ 20 super(autoupdate_WithDLC, self).initialize(host=host) 21 installed = self._dlc_util.list().keys() 22 for dlc_id in installed: 23 self._dlc_util.purge(dlc_id) 24 # DLCs may be present but not mounted, so they won't be purged above. 25 self._dlc_util.purge(self._dlc_util._SAMPLE_DLC_ID, ignore_status=True) 26 27 28 def cleanup(self): 29 self._save_extra_update_engine_logs(number_of_logs=2) 30 super(autoupdate_WithDLC, self).cleanup() 31 32 33 def run_once(self, full_payload=True, job_repo_url=None): 34 """ 35 Tests that we can successfully install a DLC, and then update it along 36 with the OS. 37 38 @param full_payload: True for a full payload. False for delta. 39 @param job_repo_url: Used for debugging locally. This is used to figure 40 out the current build and the devserver to use. 41 The test will read this from a host argument 42 when run in the lab. 43 44 """ 45 payload_urls = [] 46 47 # Payload URL for the platform (OS) update 48 payload_urls.append( 49 self.get_payload_for_nebraska(job_repo_url=job_repo_url, 50 full_payload=full_payload)) 51 52 # Payload URLs for sample-dlc, a test DLC package. 53 # We'll always need a full payload for DLC installation, 54 # and optionally a delta payload if required by the test. 55 payload_urls.append( 56 self.get_payload_for_nebraska(job_repo_url=job_repo_url, 57 full_payload=True, is_dlc=True)) 58 if not full_payload: 59 payload_urls.append( 60 self.get_payload_for_nebraska( 61 job_repo_url=job_repo_url, full_payload=False, 62 is_dlc=True)) 63 64 active, inactive = kernel_utils.get_kernel_state(self._host) 65 66 # Install and update sample-dlc, a DLC package made for test purposes. 67 self._run_client_test_and_check_result(self._CLIENT_TEST, 68 payload_urls=payload_urls, 69 full_payload=full_payload) 70 71 self._host.reboot() 72 73 # Verify the update was successful by checking hostlog and kernel. 74 rootfs_hostlog, _ = self._create_hostlog_files() 75 dlc_rootfs_hostlog, _ = self._create_dlc_hostlog_files() 76 77 logging.info('Checking platform update events') 78 self.verify_update_events(self._FORCED_UPDATE, rootfs_hostlog) 79 80 logging.info('Checking DLC update events') 81 self.verify_update_events( 82 self._FORCED_UPDATE, 83 dlc_rootfs_hostlog[self._dlc_util._SAMPLE_DLC_ID]) 84 85 kernel_utils.verify_boot_expectations(inactive, host=self._host) 86 87 # After the update and reboot, the DLC will be installed but not yet 88 # mounted. If the DLC was updated correctly, calling 89 # |dlcservice_util --install| in this state should mount the DLC 90 # without hitting Omaha. We can verify this by checking: 91 # 1. the DLC is not being preloaded (|dlcservice_util --install| will 92 # show the same behavior if the DLC is preloaded) 93 # 2. the install doesn't hit Omaha/Nebraska, by using a bad omaha_url 94 self._dlc_util.remove_preloaded(self._dlc_util._SAMPLE_DLC_ID) 95 self._dlc_util.install(self._dlc_util._SAMPLE_DLC_ID, 96 omaha_url='fake_url') 97 if not self._dlc_util.is_installed(self._dlc_util._SAMPLE_DLC_ID): 98 raise error.TestFail('Dummy DLC was not installed.') 99