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