Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [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 | """Unittests for Artifacts operations.""" |
| 6 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 7 | import os |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 8 | import pathlib |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 9 | from typing import Optional |
Mike Frysinger | 166fea0 | 2021-02-12 05:30:33 -0500 | [diff] [blame] | 10 | from unittest import mock |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 11 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 12 | from chromite.api import api_config |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 13 | from chromite.api.controller import artifacts |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 14 | from chromite.api.controller import controller_util |
Jack Neus | 26b9467 | 2022-10-27 17:33:21 +0000 | [diff] [blame] | 15 | from chromite.api.controller import image as image_controller |
| 16 | from chromite.api.controller import sysroot as sysroot_controller |
| 17 | from chromite.api.controller import test as test_controller |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 18 | from chromite.api.gen.chromite.api import artifacts_pb2 |
Jack Neus | 26b9467 | 2022-10-27 17:33:21 +0000 | [diff] [blame] | 19 | from chromite.api.gen.chromite.api import sysroot_pb2 |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 20 | from chromite.api.gen.chromiumos import common_pb2 |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 21 | from chromite.cbuildbot import commands |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 22 | from chromite.lib import chroot_lib |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 23 | from chromite.lib import constants |
| 24 | from chromite.lib import cros_build_lib |
| 25 | from chromite.lib import cros_test_lib |
| 26 | from chromite.lib import osutils |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 27 | from chromite.lib import sysroot_lib |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 28 | from chromite.service import artifacts as artifacts_svc |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 29 | |
| 30 | |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 31 | class BundleRequestMixin(object): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 32 | """Mixin to provide bundle request methods.""" |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 33 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 34 | def EmptyRequest(self): |
| 35 | return artifacts_pb2.BundleRequest() |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 36 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 37 | def BuildTargetRequest( |
| 38 | self, build_target=None, output_dir=None, chroot=None |
| 39 | ): |
| 40 | """Get a build target format request instance.""" |
| 41 | request = self.EmptyRequest() |
| 42 | if build_target: |
| 43 | request.build_target.name = build_target |
| 44 | if output_dir: |
| 45 | request.output_dir = output_dir |
| 46 | if chroot: |
| 47 | request.chroot.path = chroot |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 48 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 49 | return request |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 50 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 51 | def SysrootRequest( |
| 52 | self, sysroot=None, build_target=None, output_dir=None, chroot=None |
| 53 | ): |
| 54 | """Get a sysroot format request instance.""" |
| 55 | request = self.EmptyRequest() |
| 56 | if sysroot: |
| 57 | request.sysroot.path = sysroot |
| 58 | if build_target: |
| 59 | request.sysroot.build_target.name = build_target |
| 60 | if output_dir: |
| 61 | request.output_dir = output_dir |
| 62 | if chroot: |
| 63 | request.chroot.path = chroot |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 64 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 65 | return request |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 66 | |
| 67 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 68 | class BundleTestCase( |
| 69 | cros_test_lib.MockTempDirTestCase, |
| 70 | api_config.ApiConfigMixin, |
| 71 | BundleRequestMixin, |
| 72 | ): |
| 73 | """Basic setup for all artifacts unittests.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 74 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 75 | def setUp(self): |
| 76 | self.PatchObject(cros_build_lib, "IsInsideChroot", return_value=False) |
| 77 | self.output_dir = os.path.join(self.tempdir, "artifacts") |
| 78 | osutils.SafeMakedirs(self.output_dir) |
| 79 | self.sysroot_path = "/build/target" |
| 80 | self.sysroot = sysroot_lib.Sysroot(self.sysroot_path) |
| 81 | self.chroot_path = os.path.join(self.tempdir, "chroot") |
| 82 | full_sysroot_path = os.path.join( |
| 83 | self.chroot_path, self.sysroot_path.lstrip(os.sep) |
| 84 | ) |
| 85 | osutils.SafeMakedirs(full_sysroot_path) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 86 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 87 | # All requests use same response type. |
| 88 | self.response = artifacts_pb2.BundleResponse() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 89 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 90 | # Build target request. |
| 91 | self.target_request = self.BuildTargetRequest( |
| 92 | build_target="target", |
| 93 | output_dir=self.output_dir, |
| 94 | chroot=self.chroot_path, |
| 95 | ) |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 96 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 97 | # Sysroot request. |
| 98 | self.sysroot_request = self.SysrootRequest( |
| 99 | sysroot=self.sysroot_path, |
| 100 | build_target="target", |
| 101 | output_dir=self.output_dir, |
| 102 | chroot=self.chroot_path, |
| 103 | ) |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 104 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 105 | self.source_root = self.tempdir |
| 106 | self.PatchObject(constants, "SOURCE_ROOT", new=self.tempdir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 107 | |
| 108 | |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 109 | class BundleImageArchivesTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 110 | """BundleImageArchives tests.""" |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 111 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 112 | def testValidateOnly(self): |
| 113 | """Quick check that a validate only call does not execute any logic.""" |
| 114 | patch = self.PatchObject(artifacts_svc, "ArchiveImages") |
| 115 | artifacts.BundleImageArchives( |
| 116 | self.target_request, self.response, self.validate_only_config |
| 117 | ) |
| 118 | patch.assert_not_called() |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 119 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 120 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 121 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 122 | patch = self.PatchObject(artifacts_svc, "ArchiveImages") |
| 123 | artifacts.BundleImageArchives( |
| 124 | self.target_request, self.response, self.mock_call_config |
| 125 | ) |
| 126 | patch.assert_not_called() |
| 127 | self.assertEqual(len(self.response.artifacts), 2) |
| 128 | self.assertEqual( |
| 129 | self.response.artifacts[0].path, |
| 130 | os.path.join(self.output_dir, "path0.tar.xz"), |
| 131 | ) |
| 132 | self.assertEqual( |
| 133 | self.response.artifacts[1].path, |
| 134 | os.path.join(self.output_dir, "path1.tar.xz"), |
| 135 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 136 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 137 | def testNoBuildTarget(self): |
| 138 | """Test that no build target fails.""" |
| 139 | request = self.BuildTargetRequest(output_dir=str(self.tempdir)) |
| 140 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 141 | artifacts.BundleImageArchives( |
| 142 | request, self.response, self.api_config |
| 143 | ) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 144 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 145 | def testNoOutputDir(self): |
| 146 | """Test no output dir fails.""" |
| 147 | request = self.BuildTargetRequest(build_target="board") |
| 148 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 149 | artifacts.BundleImageArchives( |
| 150 | request, self.response, self.api_config |
| 151 | ) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 152 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 153 | def testInvalidOutputDir(self): |
| 154 | """Test invalid output dir fails.""" |
| 155 | request = self.BuildTargetRequest( |
| 156 | build_target="board", output_dir=os.path.join(self.tempdir, "DNE") |
| 157 | ) |
| 158 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 159 | artifacts.BundleImageArchives( |
| 160 | request, self.response, self.api_config |
| 161 | ) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 162 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 163 | def testOutputHandling(self): |
| 164 | """Test the artifact output handling.""" |
| 165 | expected = [os.path.join(self.output_dir, f) for f in ("a", "b", "c")] |
| 166 | self.PatchObject(artifacts_svc, "ArchiveImages", return_value=expected) |
| 167 | self.PatchObject(os.path, "exists", return_value=True) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 168 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 169 | artifacts.BundleImageArchives( |
| 170 | self.target_request, self.response, self.api_config |
| 171 | ) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 172 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 173 | self.assertCountEqual( |
| 174 | expected, [a.path for a in self.response.artifacts] |
| 175 | ) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 176 | |
| 177 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 178 | class BundleImageZipTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 179 | """Unittests for BundleImageZip.""" |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 180 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 181 | def testValidateOnly(self): |
| 182 | """Quick check that a validate only call does not execute any logic.""" |
| 183 | patch = self.PatchObject(commands, "BuildImageZip") |
| 184 | artifacts.BundleImageZip( |
| 185 | self.target_request, self.response, self.validate_only_config |
| 186 | ) |
| 187 | patch.assert_not_called() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 188 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 189 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 190 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 191 | patch = self.PatchObject(commands, "BuildImageZip") |
| 192 | artifacts.BundleImageZip( |
| 193 | self.target_request, self.response, self.mock_call_config |
| 194 | ) |
| 195 | patch.assert_not_called() |
| 196 | self.assertEqual(len(self.response.artifacts), 1) |
| 197 | self.assertEqual( |
| 198 | self.response.artifacts[0].path, |
| 199 | os.path.join(self.output_dir, "image.zip"), |
| 200 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 201 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 202 | def testBundleImageZip(self): |
| 203 | """BundleImageZip calls cbuildbot/commands with correct args.""" |
| 204 | bundle_image_zip = self.PatchObject( |
| 205 | artifacts_svc, "BundleImageZip", return_value="image.zip" |
| 206 | ) |
| 207 | self.PatchObject(os.path, "exists", return_value=True) |
| 208 | artifacts.BundleImageZip( |
| 209 | self.target_request, self.response, self.api_config |
| 210 | ) |
| 211 | self.assertEqual( |
| 212 | [artifact.path for artifact in self.response.artifacts], |
| 213 | [os.path.join(self.output_dir, "image.zip")], |
| 214 | ) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 215 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 216 | latest = os.path.join( |
| 217 | self.source_root, "src/build/images/target/latest" |
| 218 | ) |
| 219 | self.assertEqual( |
| 220 | bundle_image_zip.call_args_list, |
| 221 | [mock.call(self.output_dir, latest)], |
| 222 | ) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 223 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 224 | def testBundleImageZipNoImageDir(self): |
| 225 | """BundleImageZip dies when image dir does not exist.""" |
| 226 | self.PatchObject(os.path, "exists", return_value=False) |
| 227 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 228 | artifacts.BundleImageZip( |
| 229 | self.target_request, self.response, self.api_config |
| 230 | ) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 231 | |
| 232 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 233 | class BundleAutotestFilesTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 234 | """Unittests for BundleAutotestFiles.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 235 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 236 | def testValidateOnly(self): |
| 237 | """Quick check that a validate only call does not execute any logic.""" |
| 238 | patch = self.PatchObject(artifacts_svc, "BundleAutotestFiles") |
| 239 | artifacts.BundleAutotestFiles( |
| 240 | self.sysroot_request, self.response, self.validate_only_config |
| 241 | ) |
| 242 | patch.assert_not_called() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 243 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 244 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 245 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 246 | patch = self.PatchObject(artifacts_svc, "BundleAutotestFiles") |
| 247 | artifacts.BundleAutotestFiles( |
| 248 | self.sysroot_request, self.response, self.mock_call_config |
| 249 | ) |
| 250 | patch.assert_not_called() |
| 251 | self.assertEqual(len(self.response.artifacts), 1) |
| 252 | self.assertEqual( |
| 253 | self.response.artifacts[0].path, |
| 254 | os.path.join(self.output_dir, "autotest-a.tar.gz"), |
| 255 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 256 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 257 | def testBundleAutotestFiles(self): |
| 258 | """BundleAutotestFiles calls service correctly.""" |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 259 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 260 | files = { |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 261 | artifacts_svc.ARCHIVE_CONTROL_FILES: ( |
| 262 | "/tmp/artifacts/autotest-a.tar.gz" |
| 263 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 264 | artifacts_svc.ARCHIVE_PACKAGES: "/tmp/artifacts/autotest-b.tar.gz", |
| 265 | } |
| 266 | patch = self.PatchObject( |
| 267 | artifacts_svc, "BundleAutotestFiles", return_value=files |
| 268 | ) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 269 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 270 | artifacts.BundleAutotestFiles( |
| 271 | self.sysroot_request, self.response, self.api_config |
| 272 | ) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 273 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 274 | # Verify the arguments are being passed through. |
| 275 | patch.assert_called_with(mock.ANY, self.sysroot, self.output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 276 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 277 | # Verify the output proto is being populated correctly. |
| 278 | self.assertTrue(self.response.artifacts) |
| 279 | paths = [artifact.path for artifact in self.response.artifacts] |
| 280 | self.assertCountEqual(list(files.values()), paths) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 281 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 282 | def testInvalidOutputDir(self): |
| 283 | """Test invalid output directory argument.""" |
| 284 | request = self.SysrootRequest( |
| 285 | chroot=self.chroot_path, sysroot=self.sysroot_path |
| 286 | ) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 287 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 288 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 289 | artifacts.BundleAutotestFiles( |
| 290 | request, self.response, self.api_config |
| 291 | ) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 292 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 293 | def testInvalidSysroot(self): |
| 294 | """Test no sysroot directory.""" |
| 295 | request = self.SysrootRequest( |
| 296 | chroot=self.chroot_path, output_dir=self.output_dir |
| 297 | ) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 298 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 299 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 300 | artifacts.BundleAutotestFiles( |
| 301 | request, self.response, self.api_config |
| 302 | ) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 303 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 304 | def testSysrootDoesNotExist(self): |
| 305 | """Test dies when no sysroot does not exist.""" |
| 306 | request = self.SysrootRequest( |
| 307 | chroot=self.chroot_path, |
| 308 | sysroot="/does/not/exist", |
| 309 | output_dir=self.output_dir, |
| 310 | ) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 311 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 312 | artifacts.BundleAutotestFiles(request, self.response, self.api_config) |
| 313 | self.assertFalse(self.response.artifacts) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 314 | |
| 315 | |
| 316 | class BundleTastFilesTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 317 | """Unittests for BundleTastFiles.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 318 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 319 | def testValidateOnly(self): |
| 320 | """Quick check that a validate only call does not execute any logic.""" |
| 321 | patch = self.PatchObject(artifacts_svc, "BundleTastFiles") |
| 322 | artifacts.BundleTastFiles( |
| 323 | self.sysroot_request, self.response, self.validate_only_config |
| 324 | ) |
| 325 | patch.assert_not_called() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 326 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 327 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 328 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 329 | patch = self.PatchObject(artifacts_svc, "BundleTastFiles") |
| 330 | artifacts.BundleTastFiles( |
| 331 | self.sysroot_request, self.response, self.mock_call_config |
| 332 | ) |
| 333 | patch.assert_not_called() |
| 334 | self.assertEqual(len(self.response.artifacts), 1) |
| 335 | self.assertEqual( |
| 336 | self.response.artifacts[0].path, |
| 337 | os.path.join(self.output_dir, "tast_bundles.tar.gz"), |
| 338 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 339 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 340 | def testBundleTastFilesNoLogs(self): |
| 341 | """BundleTasteFiles succeeds when no tast files found.""" |
| 342 | self.PatchObject(commands, "BuildTastBundleTarball", return_value=None) |
| 343 | artifacts.BundleTastFiles( |
| 344 | self.sysroot_request, self.response, self.api_config |
| 345 | ) |
| 346 | self.assertFalse(self.response.artifacts) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 347 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 348 | def testBundleTastFiles(self): |
| 349 | """BundleTastFiles calls service correctly.""" |
| 350 | chroot = chroot_lib.Chroot(self.chroot_path) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 351 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 352 | expected_archive = os.path.join( |
| 353 | self.output_dir, artifacts_svc.TAST_BUNDLE_NAME |
| 354 | ) |
| 355 | # Patch the service being called. |
| 356 | bundle_patch = self.PatchObject( |
| 357 | artifacts_svc, "BundleTastFiles", return_value=expected_archive |
| 358 | ) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 359 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 360 | artifacts.BundleTastFiles( |
| 361 | self.sysroot_request, self.response, self.api_config |
| 362 | ) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 363 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 364 | # Make sure the artifact got recorded successfully. |
| 365 | self.assertTrue(self.response.artifacts) |
| 366 | self.assertEqual(expected_archive, self.response.artifacts[0].path) |
| 367 | # Make sure the service got called correctly. |
| 368 | bundle_patch.assert_called_once_with( |
| 369 | chroot, self.sysroot, self.output_dir |
| 370 | ) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 371 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 372 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 373 | class BundleFirmwareTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 374 | """Unittests for BundleFirmware.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 375 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 376 | def testValidateOnly(self): |
| 377 | """Quick check that a validate only call does not execute any logic.""" |
| 378 | patch = self.PatchObject(artifacts_svc, "BundleTastFiles") |
| 379 | artifacts.BundleFirmware( |
| 380 | self.sysroot_request, self.response, self.validate_only_config |
| 381 | ) |
| 382 | patch.assert_not_called() |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 383 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 384 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 385 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 386 | patch = self.PatchObject(artifacts_svc, "BundleTastFiles") |
| 387 | artifacts.BundleFirmware( |
| 388 | self.sysroot_request, self.response, self.mock_call_config |
| 389 | ) |
| 390 | patch.assert_not_called() |
| 391 | self.assertEqual(len(self.response.artifacts), 1) |
| 392 | self.assertEqual( |
| 393 | self.response.artifacts[0].path, |
| 394 | os.path.join(self.output_dir, "firmware.tar.gz"), |
| 395 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 396 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 397 | def testBundleFirmware(self): |
| 398 | """BundleFirmware calls cbuildbot/commands with correct args.""" |
| 399 | self.PatchObject( |
| 400 | artifacts_svc, |
| 401 | "BuildFirmwareArchive", |
| 402 | return_value=os.path.join(self.output_dir, "firmware.tar.gz"), |
| 403 | ) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 404 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 405 | artifacts.BundleFirmware( |
| 406 | self.sysroot_request, self.response, self.api_config |
| 407 | ) |
| 408 | self.assertEqual( |
| 409 | [artifact.path for artifact in self.response.artifacts], |
| 410 | [os.path.join(self.output_dir, "firmware.tar.gz")], |
| 411 | ) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 412 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 413 | def testBundleFirmwareNoLogs(self): |
| 414 | """BundleFirmware dies when no firmware found.""" |
| 415 | self.PatchObject(commands, "BuildFirmwareArchive", return_value=None) |
| 416 | artifacts.BundleFirmware( |
| 417 | self.sysroot_request, self.response, self.api_config |
| 418 | ) |
| 419 | self.assertEqual(len(self.response.artifacts), 0) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 420 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 421 | |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 422 | class BundleFpmcuUnittestsTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 423 | """Unittests for BundleFpmcuUnittests.""" |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 424 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 425 | def testValidateOnly(self): |
| 426 | """Quick check that a validate only call does not execute any logic.""" |
| 427 | patch = self.PatchObject(artifacts_svc, "BundleFpmcuUnittests") |
| 428 | artifacts.BundleFpmcuUnittests( |
| 429 | self.sysroot_request, self.response, self.validate_only_config |
| 430 | ) |
| 431 | patch.assert_not_called() |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 432 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 433 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 434 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 435 | patch = self.PatchObject(artifacts_svc, "BundleFpmcuUnittests") |
| 436 | artifacts.BundleFpmcuUnittests( |
| 437 | self.sysroot_request, self.response, self.mock_call_config |
| 438 | ) |
| 439 | patch.assert_not_called() |
| 440 | self.assertEqual(len(self.response.artifacts), 1) |
| 441 | self.assertEqual( |
| 442 | self.response.artifacts[0].path, |
| 443 | os.path.join(self.output_dir, "fpmcu_unittests.tar.gz"), |
| 444 | ) |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 445 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 446 | def testBundleFpmcuUnittests(self): |
| 447 | """BundleFpmcuUnittests calls cbuildbot/commands with correct args.""" |
| 448 | self.PatchObject( |
| 449 | artifacts_svc, |
| 450 | "BundleFpmcuUnittests", |
| 451 | return_value=os.path.join( |
| 452 | self.output_dir, "fpmcu_unittests.tar.gz" |
| 453 | ), |
| 454 | ) |
| 455 | artifacts.BundleFpmcuUnittests( |
| 456 | self.sysroot_request, self.response, self.api_config |
| 457 | ) |
| 458 | self.assertEqual( |
| 459 | [artifact.path for artifact in self.response.artifacts], |
| 460 | [os.path.join(self.output_dir, "fpmcu_unittests.tar.gz")], |
| 461 | ) |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 462 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 463 | def testBundleFpmcuUnittestsNoLogs(self): |
| 464 | """BundleFpmcuUnittests does not die when no fpmcu unittests found.""" |
| 465 | self.PatchObject( |
| 466 | artifacts_svc, "BundleFpmcuUnittests", return_value=None |
| 467 | ) |
| 468 | artifacts.BundleFpmcuUnittests( |
| 469 | self.sysroot_request, self.response, self.api_config |
| 470 | ) |
| 471 | self.assertFalse(self.response.artifacts) |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 472 | |
| 473 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 474 | class BundleEbuildLogsTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 475 | """Unittests for BundleEbuildLogs.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 476 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 477 | def testValidateOnly(self): |
| 478 | """Quick check that a validate only call does not execute any logic.""" |
| 479 | patch = self.PatchObject(commands, "BuildEbuildLogsTarball") |
| 480 | artifacts.BundleEbuildLogs( |
| 481 | self.sysroot_request, self.response, self.validate_only_config |
| 482 | ) |
| 483 | patch.assert_not_called() |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 484 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 485 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 486 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 487 | patch = self.PatchObject(commands, "BuildEbuildLogsTarball") |
| 488 | artifacts.BundleEbuildLogs( |
| 489 | self.sysroot_request, self.response, self.mock_call_config |
| 490 | ) |
| 491 | patch.assert_not_called() |
| 492 | self.assertEqual(len(self.response.artifacts), 1) |
| 493 | self.assertEqual( |
| 494 | self.response.artifacts[0].path, |
| 495 | os.path.join(self.output_dir, "ebuild-logs.tar.gz"), |
| 496 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 497 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 498 | def testBundleEbuildLogs(self): |
| 499 | """BundleEbuildLogs calls cbuildbot/commands with correct args.""" |
| 500 | bundle_ebuild_logs_tarball = self.PatchObject( |
| 501 | artifacts_svc, |
| 502 | "BundleEBuildLogsTarball", |
| 503 | return_value="ebuild-logs.tar.gz", |
| 504 | ) |
| 505 | artifacts.BundleEbuildLogs( |
| 506 | self.sysroot_request, self.response, self.api_config |
| 507 | ) |
| 508 | self.assertEqual( |
| 509 | [artifact.path for artifact in self.response.artifacts], |
| 510 | [os.path.join(self.output_dir, "ebuild-logs.tar.gz")], |
| 511 | ) |
| 512 | self.assertEqual( |
| 513 | bundle_ebuild_logs_tarball.call_args_list, |
| 514 | [mock.call(mock.ANY, self.sysroot, self.output_dir)], |
| 515 | ) |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 516 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 517 | def testBundleEbuildLogsNoLogs(self): |
| 518 | """BundleEbuildLogs dies when no logs found.""" |
| 519 | self.PatchObject(commands, "BuildEbuildLogsTarball", return_value=None) |
| 520 | artifacts.BundleEbuildLogs( |
| 521 | self.sysroot_request, self.response, self.api_config |
| 522 | ) |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 523 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 524 | self.assertFalse(self.response.artifacts) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 525 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 526 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 527 | class BundleChromeOSConfigTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 528 | """Unittests for BundleChromeOSConfig""" |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 529 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 530 | def testValidateOnly(self): |
| 531 | """Quick check that a validate only call does not execute any logic.""" |
| 532 | patch = self.PatchObject(artifacts_svc, "BundleChromeOSConfig") |
| 533 | artifacts.BundleChromeOSConfig( |
| 534 | self.sysroot_request, self.response, self.validate_only_config |
| 535 | ) |
| 536 | patch.assert_not_called() |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 537 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 538 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 539 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 540 | patch = self.PatchObject(artifacts_svc, "BundleChromeOSConfig") |
| 541 | artifacts.BundleChromeOSConfig( |
| 542 | self.sysroot_request, self.response, self.mock_call_config |
| 543 | ) |
| 544 | patch.assert_not_called() |
| 545 | self.assertEqual(len(self.response.artifacts), 1) |
| 546 | self.assertEqual( |
| 547 | self.response.artifacts[0].path, |
| 548 | os.path.join(self.output_dir, "config.yaml"), |
| 549 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 550 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 551 | def testBundleChromeOSConfigSuccess(self): |
| 552 | """Test standard success case.""" |
| 553 | bundle_chromeos_config = self.PatchObject( |
| 554 | artifacts_svc, "BundleChromeOSConfig", return_value="config.yaml" |
| 555 | ) |
| 556 | artifacts.BundleChromeOSConfig( |
| 557 | self.sysroot_request, self.response, self.api_config |
| 558 | ) |
| 559 | self.assertEqual( |
| 560 | [artifact.path for artifact in self.response.artifacts], |
| 561 | [os.path.join(self.output_dir, "config.yaml")], |
| 562 | ) |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 563 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 564 | self.assertEqual( |
| 565 | bundle_chromeos_config.call_args_list, |
| 566 | [mock.call(mock.ANY, self.sysroot, self.output_dir)], |
| 567 | ) |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 568 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 569 | def testBundleChromeOSConfigNoConfigFound(self): |
| 570 | """Empty results when the config payload isn't found.""" |
| 571 | self.PatchObject( |
| 572 | artifacts_svc, "BundleChromeOSConfig", return_value=None |
| 573 | ) |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 574 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 575 | artifacts.BundleChromeOSConfig( |
| 576 | self.sysroot_request, self.response, self.api_config |
| 577 | ) |
| 578 | self.assertFalse(self.response.artifacts) |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 579 | |
| 580 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 581 | class BundleTestUpdatePayloadsTest( |
| 582 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 583 | ): |
| 584 | """Unittests for BundleTestUpdatePayloads.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 585 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 586 | def setUp(self): |
| 587 | self.source_root = os.path.join(self.tempdir, "cros") |
| 588 | osutils.SafeMakedirs(self.source_root) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 589 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 590 | self.archive_root = os.path.join(self.tempdir, "output") |
| 591 | osutils.SafeMakedirs(self.archive_root) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 592 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 593 | self.target = "target" |
| 594 | self.image_root = os.path.join( |
| 595 | self.source_root, "src/build/images/target/latest" |
| 596 | ) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 597 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 598 | self.input_proto = artifacts_pb2.BundleRequest() |
| 599 | self.input_proto.build_target.name = self.target |
| 600 | self.input_proto.output_dir = self.archive_root |
| 601 | self.output_proto = artifacts_pb2.BundleResponse() |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 602 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 603 | self.PatchObject(constants, "SOURCE_ROOT", new=self.source_root) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 604 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 605 | def MockPayloads(image_path, archive_dir): |
| 606 | osutils.WriteFile( |
| 607 | os.path.join(archive_dir, "payload1.bin"), image_path |
| 608 | ) |
| 609 | osutils.WriteFile( |
| 610 | os.path.join(archive_dir, "payload2.bin"), image_path |
| 611 | ) |
| 612 | return [ |
| 613 | os.path.join(archive_dir, "payload1.bin"), |
| 614 | os.path.join(archive_dir, "payload2.bin"), |
| 615 | ] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 616 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 617 | self.bundle_patch = self.PatchObject( |
| 618 | artifacts_svc, "BundleTestUpdatePayloads", side_effect=MockPayloads |
| 619 | ) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 620 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 621 | def testValidateOnly(self): |
| 622 | """Quick check that a validate only call does not execute any logic.""" |
| 623 | patch = self.PatchObject(artifacts_svc, "BundleTestUpdatePayloads") |
| 624 | artifacts.BundleTestUpdatePayloads( |
| 625 | self.input_proto, self.output_proto, self.validate_only_config |
| 626 | ) |
| 627 | patch.assert_not_called() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 628 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 629 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 630 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 631 | patch = self.PatchObject(artifacts_svc, "BundleTestUpdatePayloads") |
| 632 | artifacts.BundleTestUpdatePayloads( |
| 633 | self.input_proto, self.output_proto, self.mock_call_config |
| 634 | ) |
| 635 | patch.assert_not_called() |
| 636 | self.assertEqual(len(self.output_proto.artifacts), 3) |
| 637 | self.assertEqual( |
| 638 | self.output_proto.artifacts[0].path, |
| 639 | os.path.join(self.archive_root, "payload1.bin"), |
| 640 | ) |
| 641 | self.assertEqual( |
| 642 | self.output_proto.artifacts[1].path, |
| 643 | os.path.join(self.archive_root, "payload1.json"), |
| 644 | ) |
| 645 | self.assertEqual( |
| 646 | self.output_proto.artifacts[2].path, |
| 647 | os.path.join(self.archive_root, "payload1.log"), |
| 648 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 649 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 650 | def testBundleTestUpdatePayloads(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 651 | """BundleTestUpdatePayloads calls cbuildbot/commands correctly.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 652 | image_path = os.path.join(self.image_root, constants.BASE_IMAGE_BIN) |
| 653 | osutils.WriteFile(image_path, "image!", makedirs=True) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 654 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 655 | artifacts.BundleTestUpdatePayloads( |
| 656 | self.input_proto, self.output_proto, self.api_config |
| 657 | ) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 658 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 659 | actual = [ |
| 660 | os.path.relpath(artifact.path, self.archive_root) |
| 661 | for artifact in self.output_proto.artifacts |
| 662 | ] |
| 663 | expected = ["payload1.bin", "payload2.bin"] |
| 664 | self.assertCountEqual(actual, expected) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 665 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 666 | actual = [ |
| 667 | os.path.relpath(path, self.archive_root) |
| 668 | for path in osutils.DirectoryIterator(self.archive_root) |
| 669 | ] |
| 670 | self.assertCountEqual(actual, expected) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 671 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 672 | def testBundleTestUpdatePayloadsNoImageDir(self): |
| 673 | """BundleTestUpdatePayloads dies if no image dir is found.""" |
| 674 | # Intentionally do not write image directory. |
| 675 | artifacts.BundleTestUpdatePayloads( |
| 676 | self.input_proto, self.output_proto, self.api_config |
| 677 | ) |
| 678 | self.assertFalse(self.output_proto.artifacts) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 679 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 680 | def testBundleTestUpdatePayloadsNoImage(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 681 | """BundleTestUpdatePayloads dies if no usable image found for target.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 682 | # Intentionally do not write image, but create the directory. |
| 683 | osutils.SafeMakedirs(self.image_root) |
| 684 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 685 | artifacts.BundleTestUpdatePayloads( |
| 686 | self.input_proto, self.output_proto, self.api_config |
| 687 | ) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 688 | |
| 689 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 690 | class BundleSimpleChromeArtifactsTest( |
| 691 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 692 | ): |
| 693 | """BundleSimpleChromeArtifacts tests.""" |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 694 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 695 | def setUp(self): |
| 696 | self.chroot_dir = os.path.join(self.tempdir, "chroot_dir") |
| 697 | self.sysroot_path = "/sysroot" |
| 698 | self.sysroot_dir = os.path.join(self.chroot_dir, "sysroot") |
| 699 | osutils.SafeMakedirs(self.sysroot_dir) |
| 700 | self.output_dir = os.path.join(self.tempdir, "output_dir") |
| 701 | osutils.SafeMakedirs(self.output_dir) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 702 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 703 | self.does_not_exist = os.path.join(self.tempdir, "does_not_exist") |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 704 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 705 | self.response = artifacts_pb2.BundleResponse() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 706 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 707 | def _GetRequest( |
| 708 | self, |
| 709 | chroot: Optional[str] = None, |
| 710 | sysroot: Optional[str] = None, |
| 711 | build_target: Optional[str] = None, |
| 712 | output_dir: Optional[str] = None, |
| 713 | ) -> artifacts_pb2.BundleRequest: |
| 714 | """Helper to create a request message instance. |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 715 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 716 | Args: |
Alex Klein | 611dddd | 2022-10-11 17:02:01 -0600 | [diff] [blame] | 717 | chroot: The chroot path. |
| 718 | sysroot: The sysroot path. |
| 719 | build_target: The build target name. |
| 720 | output_dir: The output directory. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 721 | """ |
| 722 | return artifacts_pb2.BundleRequest( |
| 723 | sysroot={"path": sysroot, "build_target": {"name": build_target}}, |
| 724 | chroot={"path": chroot}, |
| 725 | output_dir=output_dir, |
| 726 | ) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 727 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 728 | def testValidateOnly(self): |
| 729 | """Quick check that a validate only call does not execute any logic.""" |
| 730 | patch = self.PatchObject(artifacts_svc, "BundleSimpleChromeArtifacts") |
| 731 | request = self._GetRequest( |
| 732 | chroot=self.chroot_dir, |
| 733 | sysroot=self.sysroot_path, |
| 734 | build_target="board", |
| 735 | output_dir=self.output_dir, |
| 736 | ) |
| 737 | artifacts.BundleSimpleChromeArtifacts( |
| 738 | request, self.response, self.validate_only_config |
| 739 | ) |
| 740 | patch.assert_not_called() |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 741 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 742 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 743 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 744 | patch = self.PatchObject(artifacts_svc, "BundleSimpleChromeArtifacts") |
| 745 | request = self._GetRequest( |
| 746 | chroot=self.chroot_dir, |
| 747 | sysroot=self.sysroot_path, |
| 748 | build_target="board", |
| 749 | output_dir=self.output_dir, |
| 750 | ) |
| 751 | artifacts.BundleSimpleChromeArtifacts( |
| 752 | request, self.response, self.mock_call_config |
| 753 | ) |
| 754 | patch.assert_not_called() |
| 755 | self.assertEqual(len(self.response.artifacts), 1) |
| 756 | self.assertEqual( |
| 757 | self.response.artifacts[0].path, |
| 758 | os.path.join(self.output_dir, "simple_chrome.txt"), |
| 759 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 760 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 761 | def testNoBuildTarget(self): |
| 762 | """Test no build target fails.""" |
| 763 | request = self._GetRequest( |
| 764 | chroot=self.chroot_dir, |
| 765 | sysroot=self.sysroot_path, |
| 766 | output_dir=self.output_dir, |
| 767 | ) |
| 768 | response = self.response |
| 769 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 770 | artifacts.BundleSimpleChromeArtifacts( |
| 771 | request, response, self.api_config |
| 772 | ) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 773 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 774 | def testNoSysroot(self): |
| 775 | """Test no sysroot fails.""" |
| 776 | request = self._GetRequest( |
| 777 | build_target="board", output_dir=self.output_dir |
| 778 | ) |
| 779 | response = self.response |
| 780 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 781 | artifacts.BundleSimpleChromeArtifacts( |
| 782 | request, response, self.api_config |
| 783 | ) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 784 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 785 | def testSysrootDoesNotExist(self): |
| 786 | """Test no sysroot fails.""" |
| 787 | request = self._GetRequest( |
| 788 | build_target="board", |
| 789 | output_dir=self.output_dir, |
| 790 | sysroot=self.does_not_exist, |
| 791 | ) |
| 792 | response = self.response |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 793 | artifacts.BundleSimpleChromeArtifacts( |
| 794 | request, response, self.api_config |
| 795 | ) |
| 796 | self.assertFalse(self.response.artifacts) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 797 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 798 | def testNoOutputDir(self): |
| 799 | """Test no output dir fails.""" |
| 800 | request = self._GetRequest( |
| 801 | chroot=self.chroot_dir, |
| 802 | sysroot=self.sysroot_path, |
| 803 | build_target="board", |
| 804 | ) |
| 805 | response = self.response |
| 806 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 807 | artifacts.BundleSimpleChromeArtifacts( |
| 808 | request, response, self.api_config |
| 809 | ) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 810 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 811 | def testOutputDirDoesNotExist(self): |
| 812 | """Test no output dir fails.""" |
| 813 | request = self._GetRequest( |
| 814 | chroot=self.chroot_dir, |
| 815 | sysroot=self.sysroot_path, |
| 816 | build_target="board", |
| 817 | output_dir=self.does_not_exist, |
| 818 | ) |
| 819 | response = self.response |
| 820 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 821 | artifacts.BundleSimpleChromeArtifacts( |
| 822 | request, response, self.api_config |
| 823 | ) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 824 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 825 | def testOutputHandling(self): |
| 826 | """Test response output.""" |
| 827 | files = ["file1", "file2", "file3"] |
| 828 | expected_files = [os.path.join(self.output_dir, f) for f in files] |
| 829 | self.PatchObject( |
| 830 | artifacts_svc, |
| 831 | "BundleSimpleChromeArtifacts", |
| 832 | return_value=expected_files, |
| 833 | ) |
| 834 | request = self._GetRequest( |
| 835 | chroot=self.chroot_dir, |
| 836 | sysroot=self.sysroot_path, |
| 837 | build_target="board", |
| 838 | output_dir=self.output_dir, |
| 839 | ) |
| 840 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 841 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 842 | artifacts.BundleSimpleChromeArtifacts( |
| 843 | request, response, self.api_config |
| 844 | ) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 845 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 846 | self.assertTrue(response.artifacts) |
| 847 | self.assertCountEqual( |
| 848 | expected_files, [a.path for a in response.artifacts] |
| 849 | ) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 850 | |
| 851 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 852 | class BundleVmFilesTest( |
| 853 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 854 | ): |
| 855 | """BuildVmFiles tests.""" |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 856 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 857 | def setUp(self): |
| 858 | self.output_dir = os.path.join(self.tempdir, "output") |
| 859 | osutils.SafeMakedirs(self.output_dir) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 860 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 861 | self.response = artifacts_pb2.BundleResponse() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 862 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 863 | def _GetInput( |
| 864 | self, |
| 865 | chroot: Optional[str] = None, |
| 866 | sysroot: Optional[str] = None, |
| 867 | test_results_dir: Optional[str] = None, |
| 868 | output_dir: Optional[str] = None, |
| 869 | ) -> artifacts_pb2.BundleVmFilesRequest: |
| 870 | """Helper to build out an input message instance. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 871 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 872 | Args: |
Alex Klein | 611dddd | 2022-10-11 17:02:01 -0600 | [diff] [blame] | 873 | chroot: The chroot path. |
| 874 | sysroot: The sysroot path relative to the chroot. |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 875 | test_results_dir: The test results directory relative to the |
| 876 | sysroot. |
Alex Klein | 611dddd | 2022-10-11 17:02:01 -0600 | [diff] [blame] | 877 | output_dir: The directory where the results tarball should be saved. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 878 | """ |
| 879 | return artifacts_pb2.BundleVmFilesRequest( |
| 880 | chroot={"path": chroot}, |
| 881 | sysroot={"path": sysroot}, |
| 882 | test_results_dir=test_results_dir, |
| 883 | output_dir=output_dir, |
| 884 | ) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 885 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 886 | def testValidateOnly(self): |
| 887 | """Quick check that a validate only call does not execute any logic.""" |
| 888 | patch = self.PatchObject(artifacts_svc, "BundleVmFiles") |
| 889 | in_proto = self._GetInput( |
| 890 | chroot="/chroot/dir", |
| 891 | sysroot="/build/board", |
| 892 | test_results_dir="/test/results", |
| 893 | output_dir=self.output_dir, |
| 894 | ) |
| 895 | artifacts.BundleVmFiles( |
| 896 | in_proto, self.response, self.validate_only_config |
| 897 | ) |
| 898 | patch.assert_not_called() |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 899 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 900 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 901 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 902 | patch = self.PatchObject(artifacts_svc, "BundleVmFiles") |
| 903 | in_proto = self._GetInput( |
| 904 | chroot="/chroot/dir", |
| 905 | sysroot="/build/board", |
| 906 | test_results_dir="/test/results", |
| 907 | output_dir=self.output_dir, |
| 908 | ) |
| 909 | artifacts.BundleVmFiles(in_proto, self.response, self.mock_call_config) |
| 910 | patch.assert_not_called() |
| 911 | self.assertEqual(len(self.response.artifacts), 1) |
| 912 | self.assertEqual( |
| 913 | self.response.artifacts[0].path, |
| 914 | os.path.join(self.output_dir, "f1.tar"), |
| 915 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 916 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 917 | def testChrootMissing(self): |
| 918 | """Test error handling for missing chroot.""" |
| 919 | in_proto = self._GetInput( |
| 920 | sysroot="/build/board", |
| 921 | test_results_dir="/test/results", |
| 922 | output_dir=self.output_dir, |
| 923 | ) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 924 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 925 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 926 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 927 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 928 | def testTestResultsDirMissing(self): |
| 929 | """Test error handling for missing test results directory.""" |
| 930 | in_proto = self._GetInput( |
| 931 | chroot="/chroot/dir", |
| 932 | sysroot="/build/board", |
| 933 | output_dir=self.output_dir, |
| 934 | ) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 935 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 936 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 937 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 938 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 939 | def testOutputDirMissing(self): |
| 940 | """Test error handling for missing output directory.""" |
| 941 | in_proto = self._GetInput( |
| 942 | chroot="/chroot/dir", |
| 943 | sysroot="/build/board", |
| 944 | test_results_dir="/test/results", |
| 945 | ) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 946 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 947 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 948 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 949 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 950 | def testOutputDirDoesNotExist(self): |
| 951 | """Test error handling for output directory that does not exist.""" |
| 952 | in_proto = self._GetInput( |
| 953 | chroot="/chroot/dir", |
| 954 | sysroot="/build/board", |
| 955 | output_dir=os.path.join(self.tempdir, "dne"), |
| 956 | test_results_dir="/test/results", |
| 957 | ) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 958 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 959 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 960 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 961 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 962 | def testValidCall(self): |
| 963 | """Test image dir building.""" |
| 964 | in_proto = self._GetInput( |
| 965 | chroot="/chroot/dir", |
| 966 | sysroot="/build/board", |
| 967 | test_results_dir="/test/results", |
| 968 | output_dir=self.output_dir, |
| 969 | ) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 970 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 971 | expected_files = ["/tmp/output/f1.tar", "/tmp/output/f2.tar"] |
| 972 | patch = self.PatchObject( |
| 973 | artifacts_svc, "BundleVmFiles", return_value=expected_files |
| 974 | ) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 975 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 976 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 977 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 978 | patch.assert_called_with(mock.ANY, "/test/results", self.output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 979 | |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 980 | # Make sure we have artifacts, and that every artifact is an expected |
| 981 | # file. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 982 | self.assertTrue(self.response.artifacts) |
| 983 | for artifact in self.response.artifacts: |
| 984 | self.assertIn(artifact.path, expected_files) |
| 985 | expected_files.remove(artifact.path) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 986 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 987 | # Make sure we've seen all of the expected files. |
| 988 | self.assertFalse(expected_files) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 989 | |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 990 | |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 991 | class ExportCpeReportTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 992 | """ExportCpeReport tests.""" |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 993 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 994 | def testValidateOnly(self): |
| 995 | """Quick check validate only calls don't execute.""" |
| 996 | patch = self.PatchObject(artifacts_svc, "GenerateCpeReport") |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 997 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 998 | artifacts.ExportCpeReport( |
| 999 | self.sysroot_request, self.response, self.validate_only_config |
| 1000 | ) |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 1001 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1002 | patch.assert_not_called() |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 1003 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1004 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 1005 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1006 | patch = self.PatchObject(artifacts_svc, "GenerateCpeReport") |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 1007 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1008 | artifacts.ExportCpeReport( |
| 1009 | self.sysroot_request, self.response, self.mock_call_config |
| 1010 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 1011 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1012 | patch.assert_not_called() |
| 1013 | self.assertEqual(len(self.response.artifacts), 2) |
| 1014 | self.assertEqual( |
| 1015 | self.response.artifacts[0].path, |
| 1016 | os.path.join(self.output_dir, "cpe_report.txt"), |
| 1017 | ) |
| 1018 | self.assertEqual( |
| 1019 | self.response.artifacts[1].path, |
| 1020 | os.path.join(self.output_dir, "cpe_warnings.txt"), |
| 1021 | ) |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 1022 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1023 | def testSuccess(self): |
| 1024 | """Test success case.""" |
| 1025 | expected = artifacts_svc.CpeResult( |
| 1026 | report="/output/report.json", warnings="/output/warnings.json" |
| 1027 | ) |
| 1028 | self.PatchObject( |
| 1029 | artifacts_svc, "GenerateCpeReport", return_value=expected |
| 1030 | ) |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 1031 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1032 | artifacts.ExportCpeReport( |
| 1033 | self.sysroot_request, self.response, self.api_config |
| 1034 | ) |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 1035 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1036 | for artifact in self.response.artifacts: |
| 1037 | self.assertIn(artifact.path, [expected.report, expected.warnings]) |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 1038 | |
| 1039 | |
| 1040 | class BundleGceTarballTest(BundleTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1041 | """Unittests for BundleGceTarball.""" |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 1042 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1043 | def testValidateOnly(self): |
| 1044 | """Check that a validate only call does not execute any logic.""" |
| 1045 | patch = self.PatchObject(artifacts_svc, "BundleGceTarball") |
| 1046 | artifacts.BundleGceTarball( |
| 1047 | self.target_request, self.response, self.validate_only_config |
| 1048 | ) |
| 1049 | patch.assert_not_called() |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 1050 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1051 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 1052 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1053 | patch = self.PatchObject(artifacts_svc, "BundleGceTarball") |
| 1054 | artifacts.BundleGceTarball( |
| 1055 | self.target_request, self.response, self.mock_call_config |
| 1056 | ) |
| 1057 | patch.assert_not_called() |
| 1058 | self.assertEqual(len(self.response.artifacts), 1) |
| 1059 | self.assertEqual( |
| 1060 | self.response.artifacts[0].path, |
| 1061 | os.path.join(self.output_dir, constants.TEST_IMAGE_GCE_TAR), |
| 1062 | ) |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 1063 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1064 | def testBundleGceTarball(self): |
| 1065 | """BundleGceTarball calls cbuildbot/commands with correct args.""" |
| 1066 | bundle_gce_tarball = self.PatchObject( |
| 1067 | artifacts_svc, |
| 1068 | "BundleGceTarball", |
| 1069 | return_value=os.path.join( |
| 1070 | self.output_dir, constants.TEST_IMAGE_GCE_TAR |
| 1071 | ), |
| 1072 | ) |
| 1073 | self.PatchObject(os.path, "exists", return_value=True) |
| 1074 | artifacts.BundleGceTarball( |
| 1075 | self.target_request, self.response, self.api_config |
| 1076 | ) |
| 1077 | self.assertEqual( |
| 1078 | [artifact.path for artifact in self.response.artifacts], |
| 1079 | [os.path.join(self.output_dir, constants.TEST_IMAGE_GCE_TAR)], |
| 1080 | ) |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 1081 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1082 | latest = os.path.join( |
| 1083 | self.source_root, "src/build/images/target/latest" |
| 1084 | ) |
| 1085 | self.assertEqual( |
| 1086 | bundle_gce_tarball.call_args_list, |
| 1087 | [mock.call(self.output_dir, latest)], |
| 1088 | ) |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 1089 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1090 | def testBundleGceTarballNoImageDir(self): |
| 1091 | """BundleGceTarball dies when image dir does not exist.""" |
| 1092 | self.PatchObject(os.path, "exists", return_value=False) |
| 1093 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 1094 | artifacts.BundleGceTarball( |
| 1095 | self.target_request, self.response, self.api_config |
| 1096 | ) |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 1097 | |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 1098 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1099 | class FetchMetadataTestCase( |
| 1100 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 1101 | ): |
| 1102 | """Unittests for FetchMetadata.""" |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 1103 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1104 | sysroot_path = "/build/coral" |
| 1105 | chroot_name = "chroot" |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 1106 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1107 | def setUp(self): |
| 1108 | self.PatchObject(cros_build_lib, "IsInsideChroot", return_value=False) |
| 1109 | self.chroot_path = os.path.join(self.tempdir, "chroot") |
| 1110 | pathlib.Path(self.chroot_path).touch() |
| 1111 | self.expected_filepaths = [ |
| 1112 | os.path.join(self.chroot_path, fp) |
| 1113 | for fp in ( |
| 1114 | "build/coral/usr/local/build/autotest/autotest_metadata.pb", |
| 1115 | "build/coral/usr/share/tast/metadata/local/cros.pb", |
| 1116 | "build/coral/build/share/tast/metadata/local/crosint.pb", |
| 1117 | "usr/share/tast/metadata/remote/cros.pb", |
| 1118 | ) |
| 1119 | ] |
| 1120 | self.PatchObject(cros_build_lib, "AssertOutsideChroot") |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 1121 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1122 | def createFetchMetadataRequest( |
| 1123 | self, use_sysroot_path=True, use_chroot=True |
| 1124 | ): |
| 1125 | """Construct a FetchMetadataRequest for use in test cases.""" |
| 1126 | request = artifacts_pb2.FetchMetadataRequest() |
| 1127 | if use_sysroot_path: |
| 1128 | request.sysroot.path = self.sysroot_path |
| 1129 | if use_chroot: |
| 1130 | request.chroot.path = self.chroot_path |
| 1131 | return request |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 1132 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1133 | def testValidateOnly(self): |
| 1134 | """Check that a validate only call does not execute any logic.""" |
| 1135 | patch = self.PatchObject(controller_util, "ParseSysroot") |
| 1136 | request = self.createFetchMetadataRequest() |
| 1137 | response = artifacts_pb2.FetchMetadataResponse() |
| 1138 | artifacts.FetchMetadata(request, response, self.validate_only_config) |
| 1139 | patch.assert_not_called() |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 1140 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1141 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 1142 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1143 | patch = self.PatchObject(controller_util, "ParseSysroot") |
| 1144 | request = self.createFetchMetadataRequest() |
| 1145 | response = artifacts_pb2.FetchMetadataResponse() |
| 1146 | artifacts.FetchMetadata(request, response, self.mock_call_config) |
| 1147 | patch.assert_not_called() |
| 1148 | self.assertGreater(len(response.filepaths), 0) |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 1149 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1150 | def testNoSysrootPath(self): |
| 1151 | """Check that a request with no sysroot.path results in failure.""" |
| 1152 | request = self.createFetchMetadataRequest(use_sysroot_path=False) |
| 1153 | response = artifacts_pb2.FetchMetadataResponse() |
| 1154 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 1155 | artifacts.FetchMetadata(request, response, self.api_config) |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 1156 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1157 | def testNoChroot(self): |
| 1158 | """Check that a request with no chroot results in failure.""" |
| 1159 | request = self.createFetchMetadataRequest(use_chroot=False) |
| 1160 | response = artifacts_pb2.FetchMetadataResponse() |
| 1161 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 1162 | artifacts.FetchMetadata(request, response, self.api_config) |
| 1163 | |
| 1164 | def testSuccess(self): |
| 1165 | """Check that a well-formed request yields the expected results.""" |
| 1166 | request = self.createFetchMetadataRequest(use_chroot=True) |
| 1167 | response = artifacts_pb2.FetchMetadataResponse() |
| 1168 | artifacts.FetchMetadata(request, response, self.api_config) |
| 1169 | actual_filepaths = [fp.path.path for fp in response.filepaths] |
| 1170 | self.assertEqual( |
| 1171 | sorted(actual_filepaths), sorted(self.expected_filepaths) |
| 1172 | ) |
| 1173 | self.assertTrue( |
| 1174 | all( |
| 1175 | fp.path.location == common_pb2.Path.OUTSIDE |
| 1176 | for fp in response.filepaths |
| 1177 | ) |
| 1178 | ) |
Jack Neus | 26b9467 | 2022-10-27 17:33:21 +0000 | [diff] [blame] | 1179 | |
| 1180 | |
| 1181 | class GetTest(cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin): |
| 1182 | """Get function tests.""" |
| 1183 | |
| 1184 | def setUp(self): |
| 1185 | self.sysroot_path = "/build/target" |
| 1186 | self.sysroot = sysroot_lib.Sysroot(self.sysroot_path) |
| 1187 | |
| 1188 | def _InputProto(self): |
| 1189 | """Helper to build an input proto instance.""" |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 1190 | # pylint: disable=line-too-long |
Jack Neus | 26b9467 | 2022-10-27 17:33:21 +0000 | [diff] [blame] | 1191 | return artifacts_pb2.GetRequest( |
| 1192 | sysroot=sysroot_pb2.Sysroot(path=self.sysroot_path), |
| 1193 | artifact_info=common_pb2.ArtifactsByService( |
| 1194 | sysroot=common_pb2.ArtifactsByService.Sysroot( |
| 1195 | output_artifacts=[ |
| 1196 | common_pb2.ArtifactsByService.Sysroot.ArtifactInfo( |
| 1197 | artifact_types=[ |
| 1198 | common_pb2.ArtifactsByService.Sysroot.ArtifactType.FUZZER_SYSROOT |
| 1199 | ] |
| 1200 | ) |
| 1201 | ], |
| 1202 | ), |
| 1203 | image=common_pb2.ArtifactsByService.Image( |
| 1204 | output_artifacts=[ |
| 1205 | common_pb2.ArtifactsByService.Image.ArtifactInfo( |
| 1206 | artifact_types=[ |
| 1207 | common_pb2.ArtifactsByService.Image.ArtifactType.LICENSE_CREDITS |
| 1208 | ] |
| 1209 | ) |
| 1210 | ], |
| 1211 | ), |
| 1212 | test=common_pb2.ArtifactsByService.Test( |
| 1213 | output_artifacts=[ |
| 1214 | common_pb2.ArtifactsByService.Test.ArtifactInfo( |
| 1215 | artifact_types=[ |
| 1216 | common_pb2.ArtifactsByService.Test.ArtifactType.HWQUAL |
| 1217 | ] |
| 1218 | ) |
| 1219 | ], |
| 1220 | ), |
| 1221 | ), |
| 1222 | result_path=common_pb2.ResultPath( |
| 1223 | path=common_pb2.Path(path=str(self.tempdir)) |
| 1224 | ), |
| 1225 | ) |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 1226 | # pylint: enable=line-too-long |
Jack Neus | 26b9467 | 2022-10-27 17:33:21 +0000 | [diff] [blame] | 1227 | |
| 1228 | def _OutputProto(self): |
| 1229 | """Helper to build an output proto instance.""" |
| 1230 | return artifacts_pb2.GetResponse() |
| 1231 | |
| 1232 | def testSuccess(self): |
| 1233 | """Test Get.""" |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 1234 | # pylint: disable=line-too-long |
Jack Neus | 26b9467 | 2022-10-27 17:33:21 +0000 | [diff] [blame] | 1235 | image_mock = self.PatchObject( |
| 1236 | image_controller, |
| 1237 | "GetArtifacts", |
| 1238 | return_value=[ |
| 1239 | { |
| 1240 | "paths": ["/foo/bar/license_credits.html"], |
| 1241 | "type": common_pb2.ArtifactsByService.Image.ArtifactType.LICENSE_CREDITS, |
| 1242 | } |
| 1243 | ], |
| 1244 | ) |
| 1245 | sysroot_mock = self.PatchObject( |
| 1246 | sysroot_controller, |
| 1247 | "GetArtifacts", |
| 1248 | return_value=[ |
| 1249 | { |
| 1250 | "type": common_pb2.ArtifactsByService.Sysroot.ArtifactType.FUZZER_SYSROOT, |
| 1251 | "failed": True, |
| 1252 | "failure_reason": "Bad data!", |
| 1253 | } |
| 1254 | ], |
| 1255 | ) |
| 1256 | test_mock = self.PatchObject( |
| 1257 | test_controller, |
| 1258 | "GetArtifacts", |
| 1259 | return_value=[ |
| 1260 | { |
| 1261 | "paths": ["/foo/bar/hwqual.tar.xz"], |
| 1262 | "type": common_pb2.ArtifactsByService.Test.ArtifactType.HWQUAL, |
| 1263 | } |
| 1264 | ], |
| 1265 | ) |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 1266 | # pylint: enable=line-too-long |
Jack Neus | 26b9467 | 2022-10-27 17:33:21 +0000 | [diff] [blame] | 1267 | |
| 1268 | in_proto = self._InputProto() |
| 1269 | out_proto = self._OutputProto() |
| 1270 | artifacts.Get( |
| 1271 | in_proto, |
| 1272 | out_proto, |
| 1273 | self.api_config, |
| 1274 | ) |
| 1275 | |
| 1276 | image_mock.assert_called_once() |
| 1277 | sysroot_mock.assert_called_once() |
| 1278 | test_mock.assert_called_once() |
| 1279 | |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 1280 | # pylint: disable=line-too-long |
Jack Neus | 26b9467 | 2022-10-27 17:33:21 +0000 | [diff] [blame] | 1281 | expected = common_pb2.UploadedArtifactsByService( |
| 1282 | sysroot=common_pb2.UploadedArtifactsByService.Sysroot( |
| 1283 | artifacts=[ |
| 1284 | common_pb2.UploadedArtifactsByService.Sysroot.ArtifactPaths( |
| 1285 | artifact_type=common_pb2.ArtifactsByService.Sysroot.ArtifactType.FUZZER_SYSROOT, |
| 1286 | failed=True, |
| 1287 | failure_reason="Bad data!", |
| 1288 | ) |
| 1289 | ] |
| 1290 | ), |
| 1291 | image=common_pb2.UploadedArtifactsByService.Image( |
| 1292 | artifacts=[ |
| 1293 | common_pb2.UploadedArtifactsByService.Image.ArtifactPaths( |
| 1294 | artifact_type=common_pb2.ArtifactsByService.Image.ArtifactType.LICENSE_CREDITS, |
| 1295 | paths=[ |
| 1296 | common_pb2.Path( |
| 1297 | path="/foo/bar/license_credits.html", |
| 1298 | location=common_pb2.Path.OUTSIDE, |
| 1299 | ) |
| 1300 | ], |
| 1301 | ) |
| 1302 | ] |
| 1303 | ), |
| 1304 | test=common_pb2.UploadedArtifactsByService.Test( |
| 1305 | artifacts=[ |
| 1306 | common_pb2.UploadedArtifactsByService.Test.ArtifactPaths( |
| 1307 | artifact_type=common_pb2.ArtifactsByService.Test.ArtifactType.HWQUAL, |
| 1308 | paths=[ |
| 1309 | common_pb2.Path( |
| 1310 | path="/foo/bar/hwqual.tar.xz", |
| 1311 | location=common_pb2.Path.OUTSIDE, |
| 1312 | ) |
| 1313 | ], |
| 1314 | ) |
| 1315 | ] |
| 1316 | ), |
| 1317 | ) |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 1318 | # pylint: enable=line-too-long |
Jack Neus | 26b9467 | 2022-10-27 17:33:21 +0000 | [diff] [blame] | 1319 | self.assertEqual(out_proto.artifacts, expected) |