Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2015 The ChromiumOS Authors |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Unit tests for the deploy module.""" |
| 6 | |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 7 | import json |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 8 | import multiprocessing |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 9 | import os |
Mike Frysinger | 050fa5a | 2019-12-01 16:16:29 -0500 | [diff] [blame] | 10 | import sys |
Mike Frysinger | 166fea0 | 2021-02-12 05:30:33 -0500 | [diff] [blame] | 11 | from unittest import mock |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 12 | |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 13 | from chromite.cli import command |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 14 | from chromite.cli import deploy |
Mike Frysinger | 06a51c8 | 2021-04-06 11:39:17 -0400 | [diff] [blame] | 15 | from chromite.lib import build_target_lib |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 16 | from chromite.lib import cros_build_lib |
| 17 | from chromite.lib import cros_test_lib |
Jae Hoon Kim | df22085 | 2023-04-14 19:20:13 +0000 | [diff] [blame] | 18 | from chromite.lib import dlc_lib |
Brian Norris | 2eee889 | 2021-04-06 16:23:23 -0700 | [diff] [blame] | 19 | from chromite.lib import osutils |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 20 | from chromite.lib import remote_access |
Brian Norris | 2eee889 | 2021-04-06 16:23:23 -0700 | [diff] [blame] | 21 | from chromite.lib import sysroot_lib |
Sloan Johnson | a85640f | 2021-10-01 22:32:40 +0000 | [diff] [blame] | 22 | from chromite.lib import unittest_lib |
Alex Klein | 18a60af | 2020-06-11 12:08:47 -0600 | [diff] [blame] | 23 | from chromite.lib.parser import package_info |
Alex Klein | 32223fd | 2023-08-22 11:19:25 -0600 | [diff] [blame] | 24 | from chromite.utils import os_util |
Mike Frysinger | 40ffb53 | 2021-02-12 07:36:08 -0500 | [diff] [blame] | 25 | |
Greg Edelston | a4c9b3b | 2020-01-07 17:51:13 -0700 | [diff] [blame] | 26 | |
Chris McDonald | 186b9ee | 2020-04-16 05:56:49 -0600 | [diff] [blame] | 27 | pytestmark = [cros_test_lib.pytestmark_inside_only] |
Greg Edelston | a4c9b3b | 2020-01-07 17:51:13 -0700 | [diff] [blame] | 28 | |
| 29 | |
| 30 | if cros_build_lib.IsInsideChroot(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 31 | import portage # pylint: disable=import-error |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 32 | |
| 33 | |
| 34 | # pylint: disable=protected-access |
| 35 | |
| 36 | |
Jae Hoon Kim | df22085 | 2023-04-14 19:20:13 +0000 | [diff] [blame] | 37 | # Example DLC LoadPin digests to test with. |
| 38 | LOADPIN_TRUSTED_VERITY_ROOT_DIGESTS = """# LOADPIN_TRUSTED_VERITY_ROOT_DIGESTS |
| 39 | 75a799de83eee0ef0f028ea94643d1b2021261e77b8f76fee1d5749847fef431 |
| 40 | """ |
| 41 | |
| 42 | # An example LoadPin digest. |
| 43 | DLC_LOADPIN_DIGEST = ( |
| 44 | "feeddeadc0de0000000000000000000000000000000000000000000000000000" |
| 45 | ) |
| 46 | |
| 47 | |
Alex Klein | 074f94f | 2023-06-22 10:32:06 -0600 | [diff] [blame] | 48 | class ChromiumOSDeviceFake: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 49 | """Fake for device.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 50 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 51 | def __init__(self): |
| 52 | self.board = "board" |
| 53 | self.hostname = None |
| 54 | self.username = None |
| 55 | self.port = None |
| 56 | self.lsb_release = None |
| 57 | self.cmds = [] |
| 58 | self.work_dir = "/testdir/" |
| 59 | self.selinux_available = False |
Jae Hoon Kim | df22085 | 2023-04-14 19:20:13 +0000 | [diff] [blame] | 60 | self.copy_store = None |
| 61 | self.cat_file_output = "" |
Yuanpeng Ni | 81c944a | 2023-06-10 17:48:05 -0700 | [diff] [blame^] | 62 | self.cmd_disallowed = [] |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 63 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 64 | def MountRootfsReadWrite(self): |
| 65 | return True |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 66 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 67 | def IsSELinuxAvailable(self): |
| 68 | return self.selinux_available |
Ben Pastene | 5f03b05 | 2019-08-12 18:03:24 -0700 | [diff] [blame] | 69 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 70 | def IsSELinuxEnforced(self): |
| 71 | return True |
Ben Pastene | 5f03b05 | 2019-08-12 18:03:24 -0700 | [diff] [blame] | 72 | |
Mike Frysinger | 445f6bf | 2023-06-27 11:43:33 -0400 | [diff] [blame] | 73 | def mkdir(self, _path): |
| 74 | return None |
| 75 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 76 | def run(self, cmd, **_kwargs): |
Yuanpeng Ni | 81c944a | 2023-06-10 17:48:05 -0700 | [diff] [blame^] | 77 | if cmd in self.cmd_disallowed: |
| 78 | raise cros_build_lib.RunCommandError("Command disallowed") |
| 79 | else: |
| 80 | self.cmds.append(cmd) |
Andrew | c7e1c6b | 2020-02-27 16:03:53 -0800 | [diff] [blame] | 81 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 82 | def CopyToDevice(self, _src, _dest, _mode="rsync", **_kwargs): |
Jae Hoon Kim | df22085 | 2023-04-14 19:20:13 +0000 | [diff] [blame] | 83 | if os.path.exists(_src): |
| 84 | self.copy_store = osutils.ReadFile(_src) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 85 | return True |
Andrew | c7e1c6b | 2020-02-27 16:03:53 -0800 | [diff] [blame] | 86 | |
Jae Hoon Kim | df22085 | 2023-04-14 19:20:13 +0000 | [diff] [blame] | 87 | def CatFile(self, _src): |
| 88 | return self.cat_file_output |
| 89 | |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 90 | |
Alex Klein | 074f94f | 2023-06-22 10:32:06 -0600 | [diff] [blame] | 91 | class ChromiumOSDeviceHandlerFake: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 92 | """Fake for chromite.lib.remote_access.ChomiumOSDeviceHandler.""" |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 93 | |
Alex Klein | 074f94f | 2023-06-22 10:32:06 -0600 | [diff] [blame] | 94 | class RemoteAccessFake: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 95 | """Fake for chromite.lib.remote_access.RemoteAccess.""" |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 96 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 97 | def __init__(self): |
| 98 | self.remote_sh_output = None |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 99 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 100 | def RemoteSh(self, *_args, **_kwargs): |
| 101 | return cros_build_lib.CompletedProcess(stdout=self.remote_sh_output) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 102 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 103 | def __init__(self, *_args, **_kwargs): |
| 104 | self._agent = self.RemoteAccessFake() |
| 105 | self.device = ChromiumOSDeviceFake() |
David Pursell | 67a8276 | 2015-04-30 17:26:59 -0700 | [diff] [blame] | 106 | |
Mike Frysinger | c0780a6 | 2022-08-29 04:41:56 -0400 | [diff] [blame] | 107 | @property |
| 108 | def agent(self): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 109 | return self._agent |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 110 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 111 | def __exit__(self, _type, _value, _traceback): |
| 112 | pass |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 113 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 114 | def __enter__(self): |
| 115 | return self.device |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 116 | |
| 117 | |
| 118 | class BrilloDeployOperationFake(deploy.BrilloDeployOperation): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 119 | """Fake for deploy.BrilloDeployOperation.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 120 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 121 | def __init__(self, emerge, queue): |
| 122 | super().__init__(emerge) |
| 123 | self._queue = queue |
| 124 | |
| 125 | def ParseOutput(self, output=None): |
| 126 | super().ParseOutput(output) |
| 127 | self._queue.put("advance") |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 128 | |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 129 | |
Alex Klein | 074f94f | 2023-06-22 10:32:06 -0600 | [diff] [blame] | 130 | class DbApiFake: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 131 | """Fake for Portage dbapi.""" |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 132 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 133 | def __init__(self, pkgs): |
| 134 | self.pkg_db = {} |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 135 | for cpv, slot, rdeps_raw, build_time, use in pkgs: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 136 | self.pkg_db[cpv] = { |
| 137 | "SLOT": slot, |
| 138 | "RDEPEND": rdeps_raw, |
| 139 | "BUILD_TIME": build_time, |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 140 | "USE": use, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 141 | } |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 142 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 143 | def cpv_all(self): |
| 144 | return list(self.pkg_db) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 145 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 146 | def aux_get(self, cpv, keys): |
| 147 | pkg_info = self.pkg_db[cpv] |
| 148 | return [pkg_info[key] for key in keys] |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 149 | |
| 150 | |
Alex Klein | 074f94f | 2023-06-22 10:32:06 -0600 | [diff] [blame] | 151 | class PackageScannerFake: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 152 | """Fake for PackageScanner.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 153 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 154 | def __init__(self, packages, pkgs_attrs, packages_cpvs=None): |
| 155 | self.pkgs = packages |
| 156 | self.cpvs = packages_cpvs or packages |
| 157 | self.listed = [] |
| 158 | self.num_updates = 0 |
| 159 | self.pkgs_attrs = pkgs_attrs |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 160 | self.warnings_shown = False |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 161 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 162 | def Run(self, _device, _root, _packages, _update, _deep, _deep_rev): |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 163 | return ( |
| 164 | self.cpvs, |
| 165 | self.listed, |
| 166 | self.num_updates, |
| 167 | self.pkgs_attrs, |
| 168 | self.warnings_shown, |
| 169 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 170 | |
| 171 | |
Alex Klein | 074f94f | 2023-06-22 10:32:06 -0600 | [diff] [blame] | 172 | class PortageTreeFake: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 173 | """Fake for Portage tree.""" |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 174 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 175 | def __init__(self, dbapi): |
| 176 | self.dbapi = dbapi |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 177 | |
| 178 | |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 179 | class TestInstallPackageScanner(cros_test_lib.MockOutputTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 180 | """Test the update package scanner.""" |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 181 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 182 | _BOARD = "foo_board" |
| 183 | _BUILD_ROOT = "/build/%s" % _BOARD |
| 184 | _VARTREE = [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 185 | ( |
| 186 | "foo/app1-1.2.3-r4", |
| 187 | "0", |
| 188 | "foo/app2 !foo/app3", |
| 189 | "1413309336", |
| 190 | "cros-debug", |
| 191 | ), |
| 192 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", "cros-debug"), |
| 193 | ( |
| 194 | "foo/app4-2.0.0-r1", |
| 195 | "0", |
| 196 | "foo/app1 foo/app5", |
| 197 | "1413309336", |
| 198 | "cros-debug", |
| 199 | ), |
| 200 | ("foo/app5-3.0.7-r3", "0", "", "1413309336", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 201 | ] |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 202 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 203 | def setUp(self): |
| 204 | """Patch imported modules.""" |
| 205 | self.PatchObject(cros_build_lib, "GetChoice", return_value=0) |
| 206 | self.device = ChromiumOSDeviceHandlerFake() |
| 207 | self.scanner = deploy._InstallPackageScanner(self._BUILD_ROOT) |
| 208 | self.PatchObject(deploy, "_GetDLCInfo", return_value=(None, None)) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 209 | self.PatchObject( |
| 210 | deploy, "_ConfirmUpdateDespiteWarnings", return_value=True |
| 211 | ) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 212 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 213 | def SetupVartree(self, vartree_pkgs): |
Jack Rosenthal | 2aff1af | 2023-07-13 18:34:28 -0600 | [diff] [blame] | 214 | self.PatchObject( |
| 215 | self.scanner, |
| 216 | "_get_portage_interpreter", |
| 217 | return_value="FAKE_PYTHON", |
| 218 | ) |
Mike Frysinger | c0780a6 | 2022-08-29 04:41:56 -0400 | [diff] [blame] | 219 | self.device.agent.remote_sh_output = json.dumps(vartree_pkgs) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 220 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 221 | def SetupBintree(self, bintree_pkgs): |
| 222 | bintree = PortageTreeFake(DbApiFake(bintree_pkgs)) |
| 223 | build_root = os.path.join(self._BUILD_ROOT, "") |
| 224 | portage_db = {build_root: {"bintree": bintree}} |
| 225 | self.PatchObject(portage, "create_trees", return_value=portage_db) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 226 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 227 | def ValidatePkgs(self, actual, expected, constraints=None): |
| 228 | # Containing exactly the same packages. |
| 229 | self.assertEqual(sorted(expected), sorted(actual)) |
| 230 | # Packages appear in the right order. |
| 231 | if constraints is not None: |
| 232 | for needs, needed in constraints: |
| 233 | self.assertGreater(actual.index(needs), actual.index(needed)) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 234 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 235 | def testRunUpdatedVersion(self): |
| 236 | self.SetupVartree(self._VARTREE) |
| 237 | app1 = "foo/app1-1.2.5-r4" |
| 238 | self.SetupBintree( |
| 239 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 240 | (app1, "0", "foo/app2 !foo/app3", "1413309336", "cros-debug"), |
| 241 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 242 | ] |
| 243 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 244 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 245 | self.device, "/", ["app1"], True, True, True |
| 246 | ) |
| 247 | self.ValidatePkgs(installs, [app1]) |
| 248 | self.ValidatePkgs(listed, [app1]) |
| 249 | self.assertEqual(num_updates, 1) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 250 | |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 251 | def testRunUpdatedVersionWithUseMismatch(self): |
| 252 | self.SetupVartree(self._VARTREE) |
| 253 | app1 = "foo/app1-1.2.5-r4" |
| 254 | # Setup the bintree with packages that don't have USE=cros-debug. |
| 255 | self.SetupBintree( |
| 256 | [ |
| 257 | (app1, "0", "foo/app2 !foo/app3", "1413309336", ""), |
| 258 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", ""), |
| 259 | ] |
| 260 | ) |
| 261 | with self.assertLogs(level="WARN") as cm: |
| 262 | installs, listed, num_updates, _, _ = self.scanner.Run( |
| 263 | self.device, "/", ["app1"], True, True, True |
| 264 | ) |
| 265 | self.ValidatePkgs(installs, [app1]) |
| 266 | self.ValidatePkgs(listed, [app1]) |
| 267 | self.assertEqual(num_updates, 1) |
| 268 | testline = "USE flags for package foo/app1 do not match" |
| 269 | matching_logs = [ |
| 270 | logline for logline in cm.output if testline in logline |
| 271 | ] |
| 272 | self.assertTrue( |
| 273 | matching_logs, "Failed to detect USE flag mismatch." |
| 274 | ) |
| 275 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 276 | def testRunUpdatedBuildTime(self): |
| 277 | self.SetupVartree(self._VARTREE) |
| 278 | app1 = "foo/app1-1.2.3-r4" |
| 279 | self.SetupBintree( |
| 280 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 281 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 282 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 283 | ] |
| 284 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 285 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 286 | self.device, "/", ["app1"], True, True, True |
| 287 | ) |
| 288 | self.ValidatePkgs(installs, [app1]) |
| 289 | self.ValidatePkgs(listed, [app1]) |
| 290 | self.assertEqual(num_updates, 1) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 291 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 292 | def testRunExistingDepUpdated(self): |
| 293 | self.SetupVartree(self._VARTREE) |
| 294 | app1 = "foo/app1-1.2.5-r2" |
| 295 | app2 = "foo/app2-4.5.8-r3" |
| 296 | self.SetupBintree( |
| 297 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 298 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 299 | (app2, "0", "", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 300 | ] |
| 301 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 302 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 303 | self.device, "/", ["app1"], True, True, True |
| 304 | ) |
| 305 | self.ValidatePkgs(installs, [app1, app2], constraints=[(app1, app2)]) |
| 306 | self.ValidatePkgs(listed, [app1]) |
| 307 | self.assertEqual(num_updates, 2) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 308 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 309 | def testRunMissingDepUpdated(self): |
| 310 | self.SetupVartree(self._VARTREE) |
| 311 | app1 = "foo/app1-1.2.5-r2" |
| 312 | app6 = "foo/app6-1.0.0-r1" |
| 313 | self.SetupBintree( |
| 314 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 315 | ( |
| 316 | app1, |
| 317 | "0", |
| 318 | "foo/app2 !foo/app3 foo/app6", |
| 319 | "1413309350", |
| 320 | "cros-debug", |
| 321 | ), |
| 322 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", "cros-debug"), |
| 323 | (app6, "0", "", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 324 | ] |
| 325 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 326 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 327 | self.device, "/", ["app1"], True, True, True |
| 328 | ) |
| 329 | self.ValidatePkgs(installs, [app1, app6], constraints=[(app1, app6)]) |
| 330 | self.ValidatePkgs(listed, [app1]) |
| 331 | self.assertEqual(num_updates, 1) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 332 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 333 | def testRunExistingRevDepUpdated(self): |
| 334 | self.SetupVartree(self._VARTREE) |
| 335 | app1 = "foo/app1-1.2.5-r2" |
| 336 | app4 = "foo/app4-2.0.1-r3" |
| 337 | self.SetupBintree( |
| 338 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 339 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 340 | (app4, "0", "foo/app1 foo/app5", "1413309350", "cros-debug"), |
| 341 | ("foo/app5-3.0.7-r3", "0", "", "1413309336", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 342 | ] |
| 343 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 344 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 345 | self.device, "/", ["app1"], True, True, True |
| 346 | ) |
| 347 | self.ValidatePkgs(installs, [app1, app4], constraints=[(app4, app1)]) |
| 348 | self.ValidatePkgs(listed, [app1]) |
| 349 | self.assertEqual(num_updates, 2) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 350 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 351 | def testRunMissingRevDepNotUpdated(self): |
| 352 | self.SetupVartree(self._VARTREE) |
| 353 | app1 = "foo/app1-1.2.5-r2" |
| 354 | app6 = "foo/app6-1.0.0-r1" |
| 355 | self.SetupBintree( |
| 356 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 357 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 358 | (app6, "0", "foo/app1", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 359 | ] |
| 360 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 361 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 362 | self.device, "/", ["app1"], True, True, True |
| 363 | ) |
| 364 | self.ValidatePkgs(installs, [app1]) |
| 365 | self.ValidatePkgs(listed, [app1]) |
| 366 | self.assertEqual(num_updates, 1) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 367 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 368 | def testRunTransitiveDepsUpdated(self): |
| 369 | self.SetupVartree(self._VARTREE) |
| 370 | app1 = "foo/app1-1.2.5-r2" |
| 371 | app2 = "foo/app2-4.5.8-r3" |
| 372 | app4 = "foo/app4-2.0.0-r1" |
| 373 | app5 = "foo/app5-3.0.8-r2" |
| 374 | self.SetupBintree( |
| 375 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 376 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 377 | (app2, "0", "", "1413309350", "cros-debug"), |
| 378 | (app4, "0", "foo/app1 foo/app5", "1413309350", "cros-debug"), |
| 379 | (app5, "0", "", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 380 | ] |
| 381 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 382 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 383 | self.device, "/", ["app1"], True, True, True |
| 384 | ) |
| 385 | self.ValidatePkgs( |
| 386 | installs, |
| 387 | [app1, app2, app4, app5], |
| 388 | constraints=[(app1, app2), (app4, app1), (app4, app5)], |
| 389 | ) |
| 390 | self.ValidatePkgs(listed, [app1]) |
| 391 | self.assertEqual(num_updates, 4) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 392 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 393 | def testRunDisjunctiveDepsExistingUpdated(self): |
| 394 | self.SetupVartree(self._VARTREE) |
| 395 | app1 = "foo/app1-1.2.5-r2" |
| 396 | self.SetupBintree( |
| 397 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 398 | ( |
| 399 | app1, |
| 400 | "0", |
| 401 | "|| ( foo/app6 foo/app2 ) !foo/app3", |
| 402 | "1413309350", |
| 403 | "cros-debug", |
| 404 | ), |
| 405 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 406 | ] |
| 407 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 408 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 409 | self.device, "/", ["app1"], True, True, True |
| 410 | ) |
| 411 | self.ValidatePkgs(installs, [app1]) |
| 412 | self.ValidatePkgs(listed, [app1]) |
| 413 | self.assertEqual(num_updates, 1) |
| 414 | |
| 415 | def testRunDisjunctiveDepsDefaultUpdated(self): |
| 416 | self.SetupVartree(self._VARTREE) |
| 417 | app1 = "foo/app1-1.2.5-r2" |
| 418 | app7 = "foo/app7-1.0.0-r1" |
| 419 | self.SetupBintree( |
| 420 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 421 | ( |
| 422 | app1, |
| 423 | "0", |
| 424 | "|| ( foo/app6 foo/app7 ) !foo/app3", |
| 425 | "1413309350", |
| 426 | "cros-debug", |
| 427 | ), |
| 428 | (app7, "0", "", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 429 | ] |
| 430 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 431 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 432 | self.device, "/", ["app1"], True, True, True |
| 433 | ) |
| 434 | self.ValidatePkgs(installs, [app1, app7], constraints=[(app1, app7)]) |
| 435 | self.ValidatePkgs(listed, [app1]) |
| 436 | self.assertEqual(num_updates, 1) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 437 | |
Jack Rosenthal | 2aff1af | 2023-07-13 18:34:28 -0600 | [diff] [blame] | 438 | def test_get_portage_interpreter(self): |
| 439 | """Test getting the portage interpreter from the device.""" |
| 440 | self.device.agent.remote_sh_output = """\ |
| 441 | /usr/lib/python-exec/python3.6/emerge |
| 442 | /usr/lib/python-exec/python3.8/emerge |
| 443 | /usr/lib/python-exec/python3.11/emerge |
| 444 | """ |
| 445 | self.assertEqual( |
| 446 | self.scanner._get_portage_interpreter(self.device), |
| 447 | "python3.11", |
| 448 | ) |
| 449 | |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 450 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 451 | class TestDeploy( |
| 452 | cros_test_lib.ProgressBarTestCase, cros_test_lib.MockTempDirTestCase |
| 453 | ): |
| 454 | """Test deploy.Deploy.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 455 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 456 | @staticmethod |
| 457 | def FakeGetPackagesByCPV(cpvs, _strip, _sysroot): |
| 458 | return ["/path/to/%s.tbz2" % cpv.pv for cpv in cpvs] |
Gilad Arnold | 0e1b1da | 2015-06-10 06:41:05 -0700 | [diff] [blame] | 459 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 460 | def setUp(self): |
| 461 | # Fake being root to avoid running filesystem commands with sudo_run. |
Alex Klein | 32223fd | 2023-08-22 11:19:25 -0600 | [diff] [blame] | 462 | self.PatchObject(os_util, "is_root_user", return_value=True) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 463 | self._sysroot = os.path.join(self.tempdir, "sysroot") |
| 464 | osutils.SafeMakedirs(self._sysroot) |
| 465 | self.device = ChromiumOSDeviceHandlerFake() |
| 466 | self.PatchObject( |
| 467 | remote_access, "ChromiumOSDeviceHandler", return_value=self.device |
| 468 | ) |
| 469 | self.PatchObject(cros_build_lib, "GetBoard", return_value=None) |
| 470 | self.PatchObject( |
| 471 | build_target_lib, |
| 472 | "get_default_sysroot_path", |
| 473 | return_value=self._sysroot, |
| 474 | ) |
| 475 | self.package_scanner = self.PatchObject( |
| 476 | deploy, "_InstallPackageScanner" |
| 477 | ) |
| 478 | self.get_packages_paths = self.PatchObject( |
| 479 | deploy, "_GetPackagesByCPV", side_effect=self.FakeGetPackagesByCPV |
| 480 | ) |
| 481 | self.emerge = self.PatchObject(deploy, "_Emerge", return_value=None) |
| 482 | self.unmerge = self.PatchObject(deploy, "_Unmerge", return_value=None) |
| 483 | self.PatchObject(deploy, "_GetDLCInfo", return_value=(None, None)) |
| 484 | # Avoid running the portageq command. |
| 485 | sysroot_lib.Sysroot(self._sysroot).WriteConfig( |
| 486 | 'ARCH="amd64"\nPORTDIR_OVERLAY="%s"' % "/nothing/here" |
| 487 | ) |
| 488 | # make.conf needs to exist to correctly read back config. |
| 489 | unittest_lib.create_stub_make_conf(self._sysroot) |
Brian Norris | 2eee889 | 2021-04-06 16:23:23 -0700 | [diff] [blame] | 490 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 491 | def testDeployEmerge(self): |
| 492 | """Test that deploy._Emerge is called for each package.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 493 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 494 | _BINPKG = "/path/to/bar-1.2.5.tbz2" |
Gilad Arnold | 0e1b1da | 2015-06-10 06:41:05 -0700 | [diff] [blame] | 495 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 496 | def FakeIsFile(fname): |
| 497 | return fname == _BINPKG |
Gilad Arnold | 0e1b1da | 2015-06-10 06:41:05 -0700 | [diff] [blame] | 498 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 499 | packages = ["some/foo-1.2.3", _BINPKG, "some/foobar-2.0"] |
| 500 | cpvs = ["some/foo-1.2.3", "to/bar-1.2.5", "some/foobar-2.0"] |
| 501 | self.package_scanner.return_value = PackageScannerFake( |
| 502 | packages, |
| 503 | {"some/foo-1.2.3": {}, _BINPKG: {}, "some/foobar-2.0": {}}, |
| 504 | cpvs, |
| 505 | ) |
| 506 | self.PatchObject(os.path, "isfile", side_effect=FakeIsFile) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 507 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 508 | deploy.Deploy(None, ["package"], force=True, clean_binpkg=False) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 509 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 510 | # Check that package names were correctly resolved into binary packages. |
| 511 | self.get_packages_paths.assert_called_once_with( |
| 512 | [package_info.SplitCPV(p) for p in cpvs], True, self._sysroot |
| 513 | ) |
| 514 | # Check that deploy._Emerge is called the right number of times. |
| 515 | self.emerge.assert_called_once_with( |
| 516 | mock.ANY, |
| 517 | [ |
| 518 | "/path/to/foo-1.2.3.tbz2", |
| 519 | "/path/to/bar-1.2.5.tbz2", |
| 520 | "/path/to/foobar-2.0.tbz2", |
| 521 | ], |
| 522 | "/", |
| 523 | extra_args=None, |
| 524 | ) |
| 525 | self.assertEqual(self.unmerge.call_count, 0) |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 526 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 527 | def testDeployEmergeDLC(self): |
| 528 | """Test that deploy._Emerge installs images for DLC packages.""" |
| 529 | packages = ["some/foodlc-1.0", "some/bardlc-2.0"] |
| 530 | cpvs = ["some/foodlc-1.0", "some/bardlc-2.0"] |
| 531 | self.package_scanner.return_value = PackageScannerFake( |
| 532 | packages, {"some/foodlc-1.0": {}, "some/bardlc-2.0": {}}, cpvs |
| 533 | ) |
Yuanpeng Ni | 81c944a | 2023-06-10 17:48:05 -0700 | [diff] [blame^] | 534 | dlc_id = "foo_id" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 535 | self.PatchObject( |
Yuanpeng Ni | 81c944a | 2023-06-10 17:48:05 -0700 | [diff] [blame^] | 536 | deploy, "_GetDLCInfo", return_value=(dlc_id, "foo_package") |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 537 | ) |
Xiaochu Liu | 2726e7c | 2019-07-18 10:28:10 -0700 | [diff] [blame] | 538 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 539 | deploy.Deploy(None, ["package"], force=True, clean_binpkg=False) |
| 540 | # Check that dlcservice is restarted (DLC modules are deployed). |
Yuanpeng Ni | 81c944a | 2023-06-10 17:48:05 -0700 | [diff] [blame^] | 541 | self.assertTrue( |
| 542 | ["dlcservice_util", "--deploy", f"--id={dlc_id}"] |
| 543 | in self.device.device.cmds |
| 544 | ) |
| 545 | self.assertTrue(["restart", "dlcservice"] in self.device.device.cmds) |
| 546 | |
| 547 | def testDeployEmergeDLCFallback(self): |
| 548 | """Test that deploy._Emerge installs images for DLC packages.""" |
| 549 | packages = ["some/foodlc-1.0", "some/bardlc-2.0"] |
| 550 | cpvs = ["some/foodlc-1.0", "some/bardlc-2.0"] |
| 551 | self.package_scanner.return_value = PackageScannerFake( |
| 552 | packages, {"some/foodlc-1.0": {}, "some/bardlc-2.0": {}}, cpvs |
| 553 | ) |
| 554 | dlc_id = "foo_id" |
| 555 | self.PatchObject( |
| 556 | deploy, "_GetDLCInfo", return_value=(dlc_id, "foo_package") |
| 557 | ) |
| 558 | deploy_cmd = ["dlcservice_util", "--deploy", f"--id={dlc_id}"] |
| 559 | # Fails to run the dlcservice_util command to trigger fallback. |
| 560 | self.device.device.cmd_disallowed.append(deploy_cmd) |
| 561 | |
| 562 | deploy.Deploy(None, ["package"], force=True, clean_binpkg=False) |
| 563 | # Check that dlcservice is restarted (DLC modules are deployed). |
| 564 | self.assertFalse(deploy_cmd in self.device.device.cmds) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 565 | self.assertTrue(["restart", "dlcservice"] in self.device.device.cmds) |
Xiaochu Liu | 2726e7c | 2019-07-18 10:28:10 -0700 | [diff] [blame] | 566 | |
Jae Hoon Kim | df22085 | 2023-04-14 19:20:13 +0000 | [diff] [blame] | 567 | def testDeployDLCLoadPinMissingDeviceDigests(self): |
| 568 | """Test that _DeployDLCLoadPin works with missing device digests.""" |
| 569 | osutils.WriteFile( |
| 570 | self.tempdir |
| 571 | / dlc_lib.DLC_META_DIR |
| 572 | / dlc_lib.DLC_LOADPIN_TRUSTED_VERITY_DIGESTS, |
| 573 | LOADPIN_TRUSTED_VERITY_ROOT_DIGESTS, |
| 574 | makedirs=True, |
| 575 | ) |
| 576 | with self.device as d: |
| 577 | deploy._DeployDLCLoadPin(self.tempdir, d) |
| 578 | self.assertEqual( |
| 579 | d.copy_store.splitlines()[0], dlc_lib.DLC_LOADPIN_FILE_HEADER |
| 580 | ) |
| 581 | self.assertFalse(DLC_LOADPIN_DIGEST in d.copy_store.splitlines()) |
| 582 | self.assertTrue( |
| 583 | "75a799de83eee0ef0f028ea94643d1b2021261e77b8f76fee1d5749847fef431" |
| 584 | in d.copy_store.splitlines() |
| 585 | ) |
| 586 | |
| 587 | def testDeployDLCLoadPinFeedNewDigests(self): |
| 588 | """Test that _DeployDLCLoadPin works with digest format file.""" |
| 589 | osutils.WriteFile( |
| 590 | self.tempdir |
| 591 | / dlc_lib.DLC_META_DIR |
| 592 | / dlc_lib.DLC_LOADPIN_TRUSTED_VERITY_DIGESTS, |
| 593 | LOADPIN_TRUSTED_VERITY_ROOT_DIGESTS, |
| 594 | makedirs=True, |
| 595 | ) |
| 596 | with self.device as d: |
| 597 | d.cat_file_output = DLC_LOADPIN_DIGEST |
| 598 | deploy._DeployDLCLoadPin(self.tempdir, d) |
| 599 | self.assertEqual( |
| 600 | d.copy_store.splitlines()[0], dlc_lib.DLC_LOADPIN_FILE_HEADER |
| 601 | ) |
| 602 | self.assertTrue(DLC_LOADPIN_DIGEST in d.copy_store.splitlines()) |
| 603 | self.assertTrue( |
| 604 | "75a799de83eee0ef0f028ea94643d1b2021261e77b8f76fee1d5749847fef431" |
| 605 | in d.copy_store.splitlines() |
| 606 | ) |
| 607 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 608 | def testDeployEmergeSELinux(self): |
| 609 | """Test deploy progress when the device has SELinux""" |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 610 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 611 | _BINPKG = "/path/to/bar-1.2.5.tbz2" |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 612 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 613 | def FakeIsFile(fname): |
| 614 | return fname == _BINPKG |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 615 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 616 | def GetRestoreconCommand(pkgfile): |
| 617 | remote_path = os.path.join("/testdir/packages/to/", pkgfile) |
| 618 | return [ |
| 619 | [ |
| 620 | "cd", |
| 621 | "/", |
| 622 | "&&", |
| 623 | "tar", |
| 624 | "tf", |
| 625 | remote_path, |
| 626 | "|", |
| 627 | "restorecon", |
| 628 | "-i", |
| 629 | "-f", |
| 630 | "-", |
| 631 | ] |
| 632 | ] |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 633 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 634 | self.device.device.selinux_available = True |
| 635 | packages = ["some/foo-1.2.3", _BINPKG, "some/foobar-2.0"] |
| 636 | cpvs = ["some/foo-1.2.3", "to/bar-1.2.5", "some/foobar-2.0"] |
| 637 | self.package_scanner.return_value = PackageScannerFake( |
| 638 | packages, |
| 639 | {"some/foo-1.2.3": {}, _BINPKG: {}, "some/foobar-2.0": {}}, |
| 640 | cpvs, |
| 641 | ) |
| 642 | self.PatchObject(os.path, "isfile", side_effect=FakeIsFile) |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 643 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 644 | deploy.Deploy(None, ["package"], force=True, clean_binpkg=False) |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 645 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 646 | # Check that package names were correctly resolved into binary packages. |
| 647 | self.get_packages_paths.assert_called_once_with( |
| 648 | [package_info.SplitCPV(p) for p in cpvs], True, self._sysroot |
| 649 | ) |
| 650 | # Check that deploy._Emerge is called the right number of times. |
| 651 | self.assertEqual(self.emerge.call_count, 1) |
| 652 | self.assertEqual(self.unmerge.call_count, 0) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 653 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 654 | self.assertEqual( |
| 655 | self.device.device.cmds, |
| 656 | [["setenforce", "0"]] |
| 657 | + GetRestoreconCommand("foo-1.2.3.tbz2") |
| 658 | + GetRestoreconCommand("bar-1.2.5.tbz2") |
| 659 | + GetRestoreconCommand("foobar-2.0.tbz2") |
| 660 | + [["setenforce", "1"]], |
| 661 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 662 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 663 | def testDeployUnmerge(self): |
| 664 | """Test that deploy._Unmerge is called for each package.""" |
| 665 | packages = ["foo", "bar", "foobar", "foodlc"] |
| 666 | self.package_scanner.return_value = PackageScannerFake( |
| 667 | packages, |
| 668 | { |
| 669 | "foo": {}, |
| 670 | "bar": {}, |
| 671 | "foobar": {}, |
| 672 | "foodlc": { |
| 673 | deploy._DLC_ID: "foodlc", |
| 674 | deploy._DLC_PACKAGE: "foopackage", |
| 675 | }, |
| 676 | }, |
| 677 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 678 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 679 | deploy.Deploy( |
| 680 | None, ["package"], force=True, clean_binpkg=False, emerge=False |
| 681 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 682 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 683 | # Check that deploy._Unmerge is called the right number of times. |
| 684 | self.assertEqual(self.emerge.call_count, 0) |
| 685 | self.unmerge.assert_called_once_with(mock.ANY, packages, "/") |
Xiaochu Liu | 2726e7c | 2019-07-18 10:28:10 -0700 | [diff] [blame] | 686 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 687 | self.assertEqual( |
| 688 | self.device.device.cmds, |
| 689 | [ |
| 690 | ["dlcservice_util", "--uninstall", "--id=foodlc"], |
| 691 | ["restart", "dlcservice"], |
| 692 | ], |
| 693 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 694 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 695 | def testDeployMergeWithProgressBar(self): |
| 696 | """Test that BrilloDeployOperation.Run() is called for merge.""" |
| 697 | packages = ["foo", "bar", "foobar"] |
| 698 | self.package_scanner.return_value = PackageScannerFake( |
| 699 | packages, {"foo": {}, "bar": {}, "foobar": {}} |
| 700 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 701 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 702 | run = self.PatchObject( |
| 703 | deploy.BrilloDeployOperation, "Run", return_value=None |
| 704 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 705 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 706 | self.PatchObject(command, "UseProgressBar", return_value=True) |
| 707 | deploy.Deploy(None, ["package"], force=True, clean_binpkg=False) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 708 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 709 | # Check that BrilloDeployOperation.Run was called. |
| 710 | self.assertTrue(run.called) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 711 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 712 | def testDeployUnmergeWithProgressBar(self): |
| 713 | """Test that BrilloDeployOperation.Run() is called for unmerge.""" |
| 714 | packages = ["foo", "bar", "foobar"] |
| 715 | self.package_scanner.return_value = PackageScannerFake( |
| 716 | packages, {"foo": {}, "bar": {}, "foobar": {}} |
| 717 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 718 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 719 | run = self.PatchObject( |
| 720 | deploy.BrilloDeployOperation, "Run", return_value=None |
| 721 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 722 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 723 | self.PatchObject(command, "UseProgressBar", return_value=True) |
| 724 | deploy.Deploy( |
| 725 | None, ["package"], force=True, clean_binpkg=False, emerge=False |
| 726 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 727 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 728 | # Check that BrilloDeployOperation.Run was called. |
| 729 | self.assertTrue(run.called) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 730 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 731 | def testBrilloDeployMergeOperation(self): |
| 732 | """Test that BrilloDeployOperation works for merge.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 733 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 734 | def func(queue): |
| 735 | for event in op.MERGE_EVENTS: |
| 736 | queue.get() |
| 737 | print(event) |
| 738 | sys.stdout.flush() |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 739 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 740 | queue = multiprocessing.Queue() |
| 741 | # Emerge one package. |
| 742 | op = BrilloDeployOperationFake(True, queue) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 743 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 744 | with self.OutputCapturer(): |
| 745 | op.Run(func, queue) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 746 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 747 | # Check that the progress bar prints correctly. |
| 748 | self.AssertProgressBarAllEvents(len(op.MERGE_EVENTS)) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 749 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 750 | def testBrilloDeployUnmergeOperation(self): |
| 751 | """Test that BrilloDeployOperation works for unmerge.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 752 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 753 | def func(queue): |
| 754 | for event in op.UNMERGE_EVENTS: |
| 755 | queue.get() |
| 756 | print(event) |
| 757 | sys.stdout.flush() |
| 758 | |
| 759 | queue = multiprocessing.Queue() |
| 760 | # Unmerge one package. |
| 761 | op = BrilloDeployOperationFake(False, queue) |
| 762 | |
| 763 | with self.OutputCapturer(): |
| 764 | op.Run(func, queue) |
| 765 | |
| 766 | # Check that the progress bar prints correctly. |
| 767 | self.AssertProgressBarAllEvents(len(op.UNMERGE_EVENTS)) |