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