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