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): |
Mike Frysinger | c0780a6 | 2022-08-29 04:41:56 -0400 | [diff] [blame] | 209 | self.device.agent.remote_sh_output = json.dumps(vartree_pkgs) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 210 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 211 | def SetupBintree(self, bintree_pkgs): |
| 212 | bintree = PortageTreeFake(DbApiFake(bintree_pkgs)) |
| 213 | build_root = os.path.join(self._BUILD_ROOT, "") |
| 214 | portage_db = {build_root: {"bintree": bintree}} |
| 215 | self.PatchObject(portage, "create_trees", return_value=portage_db) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 216 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 217 | def ValidatePkgs(self, actual, expected, constraints=None): |
| 218 | # Containing exactly the same packages. |
| 219 | self.assertEqual(sorted(expected), sorted(actual)) |
| 220 | # Packages appear in the right order. |
| 221 | if constraints is not None: |
| 222 | for needs, needed in constraints: |
| 223 | self.assertGreater(actual.index(needs), actual.index(needed)) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 224 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 225 | def testRunUpdatedVersion(self): |
| 226 | self.SetupVartree(self._VARTREE) |
| 227 | app1 = "foo/app1-1.2.5-r4" |
| 228 | self.SetupBintree( |
| 229 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 230 | (app1, "0", "foo/app2 !foo/app3", "1413309336", "cros-debug"), |
| 231 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 232 | ] |
| 233 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 234 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 235 | self.device, "/", ["app1"], True, True, True |
| 236 | ) |
| 237 | self.ValidatePkgs(installs, [app1]) |
| 238 | self.ValidatePkgs(listed, [app1]) |
| 239 | self.assertEqual(num_updates, 1) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 240 | |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 241 | def testRunUpdatedVersionWithUseMismatch(self): |
| 242 | self.SetupVartree(self._VARTREE) |
| 243 | app1 = "foo/app1-1.2.5-r4" |
| 244 | # Setup the bintree with packages that don't have USE=cros-debug. |
| 245 | self.SetupBintree( |
| 246 | [ |
| 247 | (app1, "0", "foo/app2 !foo/app3", "1413309336", ""), |
| 248 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", ""), |
| 249 | ] |
| 250 | ) |
| 251 | with self.assertLogs(level="WARN") as cm: |
| 252 | installs, listed, num_updates, _, _ = self.scanner.Run( |
| 253 | self.device, "/", ["app1"], True, True, True |
| 254 | ) |
| 255 | self.ValidatePkgs(installs, [app1]) |
| 256 | self.ValidatePkgs(listed, [app1]) |
| 257 | self.assertEqual(num_updates, 1) |
| 258 | testline = "USE flags for package foo/app1 do not match" |
| 259 | matching_logs = [ |
| 260 | logline for logline in cm.output if testline in logline |
| 261 | ] |
| 262 | self.assertTrue( |
| 263 | matching_logs, "Failed to detect USE flag mismatch." |
| 264 | ) |
| 265 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 266 | def testRunUpdatedBuildTime(self): |
| 267 | self.SetupVartree(self._VARTREE) |
| 268 | app1 = "foo/app1-1.2.3-r4" |
| 269 | self.SetupBintree( |
| 270 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 271 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 272 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 273 | ] |
| 274 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 275 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 276 | self.device, "/", ["app1"], True, True, True |
| 277 | ) |
| 278 | self.ValidatePkgs(installs, [app1]) |
| 279 | self.ValidatePkgs(listed, [app1]) |
| 280 | self.assertEqual(num_updates, 1) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 281 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 282 | def testRunExistingDepUpdated(self): |
| 283 | self.SetupVartree(self._VARTREE) |
| 284 | app1 = "foo/app1-1.2.5-r2" |
| 285 | app2 = "foo/app2-4.5.8-r3" |
| 286 | self.SetupBintree( |
| 287 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 288 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 289 | (app2, "0", "", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 290 | ] |
| 291 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 292 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 293 | self.device, "/", ["app1"], True, True, True |
| 294 | ) |
| 295 | self.ValidatePkgs(installs, [app1, app2], constraints=[(app1, app2)]) |
| 296 | self.ValidatePkgs(listed, [app1]) |
| 297 | self.assertEqual(num_updates, 2) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 298 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 299 | def testRunMissingDepUpdated(self): |
| 300 | self.SetupVartree(self._VARTREE) |
| 301 | app1 = "foo/app1-1.2.5-r2" |
| 302 | app6 = "foo/app6-1.0.0-r1" |
| 303 | self.SetupBintree( |
| 304 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 305 | ( |
| 306 | app1, |
| 307 | "0", |
| 308 | "foo/app2 !foo/app3 foo/app6", |
| 309 | "1413309350", |
| 310 | "cros-debug", |
| 311 | ), |
| 312 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", "cros-debug"), |
| 313 | (app6, "0", "", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 314 | ] |
| 315 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 316 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 317 | self.device, "/", ["app1"], True, True, True |
| 318 | ) |
| 319 | self.ValidatePkgs(installs, [app1, app6], constraints=[(app1, app6)]) |
| 320 | self.ValidatePkgs(listed, [app1]) |
| 321 | self.assertEqual(num_updates, 1) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 322 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 323 | def testRunExistingRevDepUpdated(self): |
| 324 | self.SetupVartree(self._VARTREE) |
| 325 | app1 = "foo/app1-1.2.5-r2" |
| 326 | app4 = "foo/app4-2.0.1-r3" |
| 327 | self.SetupBintree( |
| 328 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 329 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 330 | (app4, "0", "foo/app1 foo/app5", "1413309350", "cros-debug"), |
| 331 | ("foo/app5-3.0.7-r3", "0", "", "1413309336", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 332 | ] |
| 333 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 334 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 335 | self.device, "/", ["app1"], True, True, True |
| 336 | ) |
| 337 | self.ValidatePkgs(installs, [app1, app4], constraints=[(app4, app1)]) |
| 338 | self.ValidatePkgs(listed, [app1]) |
| 339 | self.assertEqual(num_updates, 2) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 340 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 341 | def testRunMissingRevDepNotUpdated(self): |
| 342 | self.SetupVartree(self._VARTREE) |
| 343 | app1 = "foo/app1-1.2.5-r2" |
| 344 | app6 = "foo/app6-1.0.0-r1" |
| 345 | self.SetupBintree( |
| 346 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 347 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 348 | (app6, "0", "foo/app1", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 349 | ] |
| 350 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 351 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 352 | self.device, "/", ["app1"], True, True, True |
| 353 | ) |
| 354 | self.ValidatePkgs(installs, [app1]) |
| 355 | self.ValidatePkgs(listed, [app1]) |
| 356 | self.assertEqual(num_updates, 1) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 357 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 358 | def testRunTransitiveDepsUpdated(self): |
| 359 | self.SetupVartree(self._VARTREE) |
| 360 | app1 = "foo/app1-1.2.5-r2" |
| 361 | app2 = "foo/app2-4.5.8-r3" |
| 362 | app4 = "foo/app4-2.0.0-r1" |
| 363 | app5 = "foo/app5-3.0.8-r2" |
| 364 | self.SetupBintree( |
| 365 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 366 | (app1, "0", "foo/app2 !foo/app3", "1413309350", "cros-debug"), |
| 367 | (app2, "0", "", "1413309350", "cros-debug"), |
| 368 | (app4, "0", "foo/app1 foo/app5", "1413309350", "cros-debug"), |
| 369 | (app5, "0", "", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 370 | ] |
| 371 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 372 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 373 | self.device, "/", ["app1"], True, True, True |
| 374 | ) |
| 375 | self.ValidatePkgs( |
| 376 | installs, |
| 377 | [app1, app2, app4, app5], |
| 378 | constraints=[(app1, app2), (app4, app1), (app4, app5)], |
| 379 | ) |
| 380 | self.ValidatePkgs(listed, [app1]) |
| 381 | self.assertEqual(num_updates, 4) |
David Pursell | 9476bf4 | 2015-03-30 13:34:27 -0700 | [diff] [blame] | 382 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 383 | def testRunDisjunctiveDepsExistingUpdated(self): |
| 384 | self.SetupVartree(self._VARTREE) |
| 385 | app1 = "foo/app1-1.2.5-r2" |
| 386 | self.SetupBintree( |
| 387 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 388 | ( |
| 389 | app1, |
| 390 | "0", |
| 391 | "|| ( foo/app6 foo/app2 ) !foo/app3", |
| 392 | "1413309350", |
| 393 | "cros-debug", |
| 394 | ), |
| 395 | ("foo/app2-4.5.6-r7", "0", "", "1413309336", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 396 | ] |
| 397 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 398 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 399 | self.device, "/", ["app1"], True, True, True |
| 400 | ) |
| 401 | self.ValidatePkgs(installs, [app1]) |
| 402 | self.ValidatePkgs(listed, [app1]) |
| 403 | self.assertEqual(num_updates, 1) |
| 404 | |
| 405 | def testRunDisjunctiveDepsDefaultUpdated(self): |
| 406 | self.SetupVartree(self._VARTREE) |
| 407 | app1 = "foo/app1-1.2.5-r2" |
| 408 | app7 = "foo/app7-1.0.0-r1" |
| 409 | self.SetupBintree( |
| 410 | [ |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 411 | ( |
| 412 | app1, |
| 413 | "0", |
| 414 | "|| ( foo/app6 foo/app7 ) !foo/app3", |
| 415 | "1413309350", |
| 416 | "cros-debug", |
| 417 | ), |
| 418 | (app7, "0", "", "1413309350", "cros-debug"), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 419 | ] |
| 420 | ) |
Tim Bain | e4a783b | 2023-04-21 20:05:51 +0000 | [diff] [blame] | 421 | installs, listed, num_updates, _, _ = self.scanner.Run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 422 | self.device, "/", ["app1"], True, True, True |
| 423 | ) |
| 424 | self.ValidatePkgs(installs, [app1, app7], constraints=[(app1, app7)]) |
| 425 | self.ValidatePkgs(listed, [app1]) |
| 426 | self.assertEqual(num_updates, 1) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 427 | |
| 428 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 429 | class TestDeploy( |
| 430 | cros_test_lib.ProgressBarTestCase, cros_test_lib.MockTempDirTestCase |
| 431 | ): |
| 432 | """Test deploy.Deploy.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 433 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 434 | @staticmethod |
| 435 | def FakeGetPackagesByCPV(cpvs, _strip, _sysroot): |
| 436 | return ["/path/to/%s.tbz2" % cpv.pv for cpv in cpvs] |
Gilad Arnold | 0e1b1da | 2015-06-10 06:41:05 -0700 | [diff] [blame] | 437 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 438 | def setUp(self): |
| 439 | # Fake being root to avoid running filesystem commands with sudo_run. |
| 440 | self.PatchObject(osutils, "IsRootUser", return_value=True) |
| 441 | self._sysroot = os.path.join(self.tempdir, "sysroot") |
| 442 | osutils.SafeMakedirs(self._sysroot) |
| 443 | self.device = ChromiumOSDeviceHandlerFake() |
| 444 | self.PatchObject( |
| 445 | remote_access, "ChromiumOSDeviceHandler", return_value=self.device |
| 446 | ) |
| 447 | self.PatchObject(cros_build_lib, "GetBoard", return_value=None) |
| 448 | self.PatchObject( |
| 449 | build_target_lib, |
| 450 | "get_default_sysroot_path", |
| 451 | return_value=self._sysroot, |
| 452 | ) |
| 453 | self.package_scanner = self.PatchObject( |
| 454 | deploy, "_InstallPackageScanner" |
| 455 | ) |
| 456 | self.get_packages_paths = self.PatchObject( |
| 457 | deploy, "_GetPackagesByCPV", side_effect=self.FakeGetPackagesByCPV |
| 458 | ) |
| 459 | self.emerge = self.PatchObject(deploy, "_Emerge", return_value=None) |
| 460 | self.unmerge = self.PatchObject(deploy, "_Unmerge", return_value=None) |
| 461 | self.PatchObject(deploy, "_GetDLCInfo", return_value=(None, None)) |
| 462 | # Avoid running the portageq command. |
| 463 | sysroot_lib.Sysroot(self._sysroot).WriteConfig( |
| 464 | 'ARCH="amd64"\nPORTDIR_OVERLAY="%s"' % "/nothing/here" |
| 465 | ) |
| 466 | # make.conf needs to exist to correctly read back config. |
| 467 | unittest_lib.create_stub_make_conf(self._sysroot) |
Brian Norris | 2eee889 | 2021-04-06 16:23:23 -0700 | [diff] [blame] | 468 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 469 | def testDeployEmerge(self): |
| 470 | """Test that deploy._Emerge is called for each package.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 471 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 472 | _BINPKG = "/path/to/bar-1.2.5.tbz2" |
Gilad Arnold | 0e1b1da | 2015-06-10 06:41:05 -0700 | [diff] [blame] | 473 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 474 | def FakeIsFile(fname): |
| 475 | return fname == _BINPKG |
Gilad Arnold | 0e1b1da | 2015-06-10 06:41:05 -0700 | [diff] [blame] | 476 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 477 | packages = ["some/foo-1.2.3", _BINPKG, "some/foobar-2.0"] |
| 478 | cpvs = ["some/foo-1.2.3", "to/bar-1.2.5", "some/foobar-2.0"] |
| 479 | self.package_scanner.return_value = PackageScannerFake( |
| 480 | packages, |
| 481 | {"some/foo-1.2.3": {}, _BINPKG: {}, "some/foobar-2.0": {}}, |
| 482 | cpvs, |
| 483 | ) |
| 484 | self.PatchObject(os.path, "isfile", side_effect=FakeIsFile) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 485 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 486 | deploy.Deploy(None, ["package"], force=True, clean_binpkg=False) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 487 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 488 | # Check that package names were correctly resolved into binary packages. |
| 489 | self.get_packages_paths.assert_called_once_with( |
| 490 | [package_info.SplitCPV(p) for p in cpvs], True, self._sysroot |
| 491 | ) |
| 492 | # Check that deploy._Emerge is called the right number of times. |
| 493 | self.emerge.assert_called_once_with( |
| 494 | mock.ANY, |
| 495 | [ |
| 496 | "/path/to/foo-1.2.3.tbz2", |
| 497 | "/path/to/bar-1.2.5.tbz2", |
| 498 | "/path/to/foobar-2.0.tbz2", |
| 499 | ], |
| 500 | "/", |
| 501 | extra_args=None, |
| 502 | ) |
| 503 | self.assertEqual(self.unmerge.call_count, 0) |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 504 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 505 | def testDeployEmergeDLC(self): |
| 506 | """Test that deploy._Emerge installs images for DLC packages.""" |
| 507 | packages = ["some/foodlc-1.0", "some/bardlc-2.0"] |
| 508 | cpvs = ["some/foodlc-1.0", "some/bardlc-2.0"] |
| 509 | self.package_scanner.return_value = PackageScannerFake( |
| 510 | packages, {"some/foodlc-1.0": {}, "some/bardlc-2.0": {}}, cpvs |
| 511 | ) |
| 512 | self.PatchObject( |
| 513 | deploy, "_GetDLCInfo", return_value=("foo_id", "foo_package") |
| 514 | ) |
Xiaochu Liu | 2726e7c | 2019-07-18 10:28:10 -0700 | [diff] [blame] | 515 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 516 | deploy.Deploy(None, ["package"], force=True, clean_binpkg=False) |
| 517 | # Check that dlcservice is restarted (DLC modules are deployed). |
| 518 | self.assertTrue(["restart", "dlcservice"] in self.device.device.cmds) |
Xiaochu Liu | 2726e7c | 2019-07-18 10:28:10 -0700 | [diff] [blame] | 519 | |
Jae Hoon Kim | df22085 | 2023-04-14 19:20:13 +0000 | [diff] [blame] | 520 | def testDeployDLCLoadPinMissingDeviceDigests(self): |
| 521 | """Test that _DeployDLCLoadPin works with missing device digests.""" |
| 522 | osutils.WriteFile( |
| 523 | self.tempdir |
| 524 | / dlc_lib.DLC_META_DIR |
| 525 | / dlc_lib.DLC_LOADPIN_TRUSTED_VERITY_DIGESTS, |
| 526 | LOADPIN_TRUSTED_VERITY_ROOT_DIGESTS, |
| 527 | makedirs=True, |
| 528 | ) |
| 529 | with self.device as d: |
| 530 | deploy._DeployDLCLoadPin(self.tempdir, d) |
| 531 | self.assertEqual( |
| 532 | d.copy_store.splitlines()[0], dlc_lib.DLC_LOADPIN_FILE_HEADER |
| 533 | ) |
| 534 | self.assertFalse(DLC_LOADPIN_DIGEST in d.copy_store.splitlines()) |
| 535 | self.assertTrue( |
| 536 | "75a799de83eee0ef0f028ea94643d1b2021261e77b8f76fee1d5749847fef431" |
| 537 | in d.copy_store.splitlines() |
| 538 | ) |
| 539 | |
| 540 | def testDeployDLCLoadPinFeedNewDigests(self): |
| 541 | """Test that _DeployDLCLoadPin works with digest format file.""" |
| 542 | osutils.WriteFile( |
| 543 | self.tempdir |
| 544 | / dlc_lib.DLC_META_DIR |
| 545 | / dlc_lib.DLC_LOADPIN_TRUSTED_VERITY_DIGESTS, |
| 546 | LOADPIN_TRUSTED_VERITY_ROOT_DIGESTS, |
| 547 | makedirs=True, |
| 548 | ) |
| 549 | with self.device as d: |
| 550 | d.cat_file_output = DLC_LOADPIN_DIGEST |
| 551 | deploy._DeployDLCLoadPin(self.tempdir, d) |
| 552 | self.assertEqual( |
| 553 | d.copy_store.splitlines()[0], dlc_lib.DLC_LOADPIN_FILE_HEADER |
| 554 | ) |
| 555 | self.assertTrue(DLC_LOADPIN_DIGEST in d.copy_store.splitlines()) |
| 556 | self.assertTrue( |
| 557 | "75a799de83eee0ef0f028ea94643d1b2021261e77b8f76fee1d5749847fef431" |
| 558 | in d.copy_store.splitlines() |
| 559 | ) |
| 560 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 561 | def testDeployEmergeSELinux(self): |
| 562 | """Test deploy progress when the device has SELinux""" |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 563 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 564 | _BINPKG = "/path/to/bar-1.2.5.tbz2" |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 565 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 566 | def FakeIsFile(fname): |
| 567 | return fname == _BINPKG |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 568 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 569 | def GetRestoreconCommand(pkgfile): |
| 570 | remote_path = os.path.join("/testdir/packages/to/", pkgfile) |
| 571 | return [ |
| 572 | [ |
| 573 | "cd", |
| 574 | "/", |
| 575 | "&&", |
| 576 | "tar", |
| 577 | "tf", |
| 578 | remote_path, |
| 579 | "|", |
| 580 | "restorecon", |
| 581 | "-i", |
| 582 | "-f", |
| 583 | "-", |
| 584 | ] |
| 585 | ] |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 586 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 587 | self.device.device.selinux_available = True |
| 588 | packages = ["some/foo-1.2.3", _BINPKG, "some/foobar-2.0"] |
| 589 | cpvs = ["some/foo-1.2.3", "to/bar-1.2.5", "some/foobar-2.0"] |
| 590 | self.package_scanner.return_value = PackageScannerFake( |
| 591 | packages, |
| 592 | {"some/foo-1.2.3": {}, _BINPKG: {}, "some/foobar-2.0": {}}, |
| 593 | cpvs, |
| 594 | ) |
| 595 | self.PatchObject(os.path, "isfile", side_effect=FakeIsFile) |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 596 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 597 | deploy.Deploy(None, ["package"], force=True, clean_binpkg=False) |
Qijiang Fan | 8a94503 | 2019-04-25 20:53:29 +0900 | [diff] [blame] | 598 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 599 | # Check that package names were correctly resolved into binary packages. |
| 600 | self.get_packages_paths.assert_called_once_with( |
| 601 | [package_info.SplitCPV(p) for p in cpvs], True, self._sysroot |
| 602 | ) |
| 603 | # Check that deploy._Emerge is called the right number of times. |
| 604 | self.assertEqual(self.emerge.call_count, 1) |
| 605 | self.assertEqual(self.unmerge.call_count, 0) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 606 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 607 | self.assertEqual( |
| 608 | self.device.device.cmds, |
| 609 | [["setenforce", "0"]] |
| 610 | + GetRestoreconCommand("foo-1.2.3.tbz2") |
| 611 | + GetRestoreconCommand("bar-1.2.5.tbz2") |
| 612 | + GetRestoreconCommand("foobar-2.0.tbz2") |
| 613 | + [["setenforce", "1"]], |
| 614 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 615 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 616 | def testDeployUnmerge(self): |
| 617 | """Test that deploy._Unmerge is called for each package.""" |
| 618 | packages = ["foo", "bar", "foobar", "foodlc"] |
| 619 | self.package_scanner.return_value = PackageScannerFake( |
| 620 | packages, |
| 621 | { |
| 622 | "foo": {}, |
| 623 | "bar": {}, |
| 624 | "foobar": {}, |
| 625 | "foodlc": { |
| 626 | deploy._DLC_ID: "foodlc", |
| 627 | deploy._DLC_PACKAGE: "foopackage", |
| 628 | }, |
| 629 | }, |
| 630 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 631 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 632 | deploy.Deploy( |
| 633 | None, ["package"], force=True, clean_binpkg=False, emerge=False |
| 634 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 635 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 636 | # Check that deploy._Unmerge is called the right number of times. |
| 637 | self.assertEqual(self.emerge.call_count, 0) |
| 638 | self.unmerge.assert_called_once_with(mock.ANY, packages, "/") |
Xiaochu Liu | 2726e7c | 2019-07-18 10:28:10 -0700 | [diff] [blame] | 639 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 640 | self.assertEqual( |
| 641 | self.device.device.cmds, |
| 642 | [ |
| 643 | ["dlcservice_util", "--uninstall", "--id=foodlc"], |
| 644 | ["restart", "dlcservice"], |
| 645 | ], |
| 646 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 647 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 648 | def testDeployMergeWithProgressBar(self): |
| 649 | """Test that BrilloDeployOperation.Run() is called for merge.""" |
| 650 | packages = ["foo", "bar", "foobar"] |
| 651 | self.package_scanner.return_value = PackageScannerFake( |
| 652 | packages, {"foo": {}, "bar": {}, "foobar": {}} |
| 653 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 654 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 655 | run = self.PatchObject( |
| 656 | deploy.BrilloDeployOperation, "Run", return_value=None |
| 657 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 658 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 659 | self.PatchObject(command, "UseProgressBar", return_value=True) |
| 660 | deploy.Deploy(None, ["package"], force=True, clean_binpkg=False) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 661 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 662 | # Check that BrilloDeployOperation.Run was called. |
| 663 | self.assertTrue(run.called) |
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 testDeployUnmergeWithProgressBar(self): |
| 666 | """Test that BrilloDeployOperation.Run() is called for unmerge.""" |
| 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( |
| 678 | None, ["package"], force=True, clean_binpkg=False, emerge=False |
| 679 | ) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 680 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 681 | # Check that BrilloDeployOperation.Run was called. |
| 682 | self.assertTrue(run.called) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 683 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 684 | def testBrilloDeployMergeOperation(self): |
| 685 | """Test that BrilloDeployOperation works for merge.""" |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 686 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 687 | def func(queue): |
| 688 | for event in op.MERGE_EVENTS: |
| 689 | queue.get() |
| 690 | print(event) |
| 691 | sys.stdout.flush() |
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 | queue = multiprocessing.Queue() |
| 694 | # Emerge one package. |
| 695 | op = BrilloDeployOperationFake(True, queue) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 696 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 697 | with self.OutputCapturer(): |
| 698 | op.Run(func, queue) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 699 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 700 | # Check that the progress bar prints correctly. |
| 701 | self.AssertProgressBarAllEvents(len(op.MERGE_EVENTS)) |
Ralph Nathan | e01ccf1 | 2015-04-16 10:40:32 -0700 | [diff] [blame] | 702 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 703 | def testBrilloDeployUnmergeOperation(self): |
| 704 | """Test that BrilloDeployOperation works for unmerge.""" |
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 | def func(queue): |
| 707 | for event in op.UNMERGE_EVENTS: |
| 708 | queue.get() |
| 709 | print(event) |
| 710 | sys.stdout.flush() |
| 711 | |
| 712 | queue = multiprocessing.Queue() |
| 713 | # Unmerge one package. |
| 714 | op = BrilloDeployOperationFake(False, queue) |
| 715 | |
| 716 | with self.OutputCapturer(): |
| 717 | op.Run(func, queue) |
| 718 | |
| 719 | # Check that the progress bar prints correctly. |
| 720 | self.AssertProgressBarAllEvents(len(op.UNMERGE_EVENTS)) |