Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Unittests for Artifacts operations.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 10 | import collections |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 11 | import os |
| 12 | |
Mike Frysinger | 6db648e | 2018-07-24 19:57:58 -0400 | [diff] [blame] | 13 | import mock |
| 14 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 15 | from chromite.api import api_config |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 16 | from chromite.api.controller import artifacts |
| 17 | from chromite.api.gen.chromite.api import artifacts_pb2 |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 18 | from chromite.api.gen.chromite.api import toolchain_pb2 |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 19 | from chromite.cbuildbot import commands |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 20 | from chromite.lib import chroot_lib |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 21 | from chromite.lib import constants |
| 22 | from chromite.lib import cros_build_lib |
| 23 | from chromite.lib import cros_test_lib |
| 24 | from chromite.lib import osutils |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 25 | from chromite.lib import sysroot_lib |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 26 | from chromite.service import artifacts as artifacts_svc |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 27 | |
| 28 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 29 | PinnedGuestImage = collections.namedtuple('PinnedGuestImage', |
| 30 | ['filename', 'uri']) |
| 31 | |
| 32 | |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 33 | class BundleRequestMixin(object): |
| 34 | """Mixin to provide bundle request methods.""" |
| 35 | |
| 36 | def EmptyRequest(self): |
| 37 | return artifacts_pb2.BundleRequest() |
| 38 | |
| 39 | def BuildTargetRequest(self, build_target=None, output_dir=None, chroot=None): |
| 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 |
| 48 | |
| 49 | return request |
| 50 | |
| 51 | def SysrootRequest(self, |
| 52 | sysroot=None, |
| 53 | build_target=None, |
| 54 | output_dir=None, |
| 55 | chroot=None): |
| 56 | """Get a sysroot format request instance.""" |
| 57 | request = self.EmptyRequest() |
| 58 | if sysroot: |
| 59 | request.sysroot.path = sysroot |
| 60 | if build_target: |
| 61 | request.sysroot.build_target.name = build_target |
| 62 | if output_dir: |
| 63 | request.output_dir = output_dir |
| 64 | if chroot: |
| 65 | request.chroot.path = chroot |
| 66 | |
| 67 | return request |
| 68 | |
| 69 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 70 | class BundleTestCase(cros_test_lib.MockTempDirTestCase, |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 71 | api_config.ApiConfigMixin, BundleRequestMixin): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 72 | """Basic setup for all artifacts unittests.""" |
| 73 | |
| 74 | def setUp(self): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 75 | self.output_dir = os.path.join(self.tempdir, 'artifacts') |
| 76 | osutils.SafeMakedirs(self.output_dir) |
| 77 | self.sysroot_path = '/build/target' |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 78 | self.sysroot = sysroot_lib.Sysroot(self.sysroot_path) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 79 | self.chroot_path = os.path.join(self.tempdir, 'chroot') |
| 80 | full_sysroot_path = os.path.join(self.chroot_path, |
| 81 | self.sysroot_path.lstrip(os.sep)) |
| 82 | osutils.SafeMakedirs(full_sysroot_path) |
| 83 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 84 | # All requests use same response type. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 85 | self.response = artifacts_pb2.BundleResponse() |
| 86 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 87 | # Build target request. |
| 88 | self.target_request = self.BuildTargetRequest( |
| 89 | build_target='target', |
| 90 | output_dir=self.output_dir, |
| 91 | chroot=self.chroot_path) |
| 92 | |
| 93 | # Sysroot request. |
| 94 | self.sysroot_request = self.SysrootRequest( |
| 95 | sysroot=self.sysroot_path, |
| 96 | build_target='target', |
| 97 | output_dir=self.output_dir, |
| 98 | chroot=self.chroot_path) |
| 99 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 100 | self.source_root = self.tempdir |
| 101 | self.PatchObject(constants, 'SOURCE_ROOT', new=self.tempdir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 102 | |
| 103 | |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 104 | class BundleImageArchivesTest(BundleTestCase): |
| 105 | """BundleImageArchives tests.""" |
| 106 | |
| 107 | def testValidateOnly(self): |
| 108 | """Sanity check that a validate only call does not execute any logic.""" |
| 109 | patch = self.PatchObject(artifacts_svc, 'ArchiveImages') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 110 | artifacts.BundleImageArchives(self.target_request, self.response, |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 111 | self.validate_only_config) |
| 112 | patch.assert_not_called() |
| 113 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 114 | def testMockCall(self): |
| 115 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 116 | patch = self.PatchObject(artifacts_svc, 'ArchiveImages') |
| 117 | artifacts.BundleImageArchives(self.target_request, self.response, |
| 118 | self.mock_call_config) |
| 119 | patch.assert_not_called() |
| 120 | self.assertEqual(len(self.response.artifacts), 2) |
| 121 | self.assertEqual(self.response.artifacts[0].path, |
| 122 | os.path.join(self.output_dir, 'path0.tar.xz')) |
| 123 | self.assertEqual(self.response.artifacts[1].path, |
| 124 | os.path.join(self.output_dir, 'path1.tar.xz')) |
| 125 | |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 126 | def testNoBuildTarget(self): |
| 127 | """Test that no build target fails.""" |
| 128 | request = self.BuildTargetRequest(output_dir=self.tempdir) |
| 129 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 130 | artifacts.BundleImageArchives(request, self.response, self.api_config) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 131 | |
| 132 | def testNoOutputDir(self): |
| 133 | """Test no output dir fails.""" |
| 134 | request = self.BuildTargetRequest(build_target='board') |
| 135 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 136 | artifacts.BundleImageArchives(request, self.response, self.api_config) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 137 | |
| 138 | def testInvalidOutputDir(self): |
| 139 | """Test invalid output dir fails.""" |
| 140 | request = self.BuildTargetRequest( |
| 141 | build_target='board', output_dir=os.path.join(self.tempdir, 'DNE')) |
| 142 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 143 | artifacts.BundleImageArchives(request, self.response, self.api_config) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 144 | |
| 145 | def testOutputHandling(self): |
| 146 | """Test the artifact output handling.""" |
| 147 | expected = [os.path.join(self.output_dir, f) for f in ('a', 'b', 'c')] |
| 148 | self.PatchObject(artifacts_svc, 'ArchiveImages', return_value=expected) |
| 149 | self.PatchObject(os.path, 'exists', return_value=True) |
| 150 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 151 | artifacts.BundleImageArchives(self.target_request, self.response, |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 152 | self.api_config) |
| 153 | |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 154 | self.assertCountEqual(expected, [a.path for a in self.response.artifacts]) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 155 | |
| 156 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 157 | class BundleImageZipTest(BundleTestCase): |
| 158 | """Unittests for BundleImageZip.""" |
| 159 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 160 | def testValidateOnly(self): |
| 161 | """Sanity check that a validate only call does not execute any logic.""" |
| 162 | patch = self.PatchObject(commands, 'BuildImageZip') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 163 | artifacts.BundleImageZip(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 164 | self.validate_only_config) |
| 165 | patch.assert_not_called() |
| 166 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 167 | def testMockCall(self): |
| 168 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 169 | patch = self.PatchObject(commands, 'BuildImageZip') |
| 170 | artifacts.BundleImageZip(self.target_request, self.response, |
| 171 | self.mock_call_config) |
| 172 | patch.assert_not_called() |
| 173 | self.assertEqual(len(self.response.artifacts), 1) |
| 174 | self.assertEqual(self.response.artifacts[0].path, |
| 175 | os.path.join(self.output_dir, 'image.zip')) |
| 176 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 177 | def testBundleImageZip(self): |
| 178 | """BundleImageZip calls cbuildbot/commands with correct args.""" |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 179 | bundle_image_zip = self.PatchObject( |
| 180 | artifacts_svc, 'BundleImageZip', return_value='image.zip') |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 181 | self.PatchObject(os.path, 'exists', return_value=True) |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 182 | artifacts.BundleImageZip(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 183 | self.api_config) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 184 | self.assertEqual( |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 185 | [artifact.path for artifact in self.response.artifacts], |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 186 | [os.path.join(self.output_dir, 'image.zip')]) |
| 187 | |
| 188 | latest = os.path.join(self.source_root, 'src/build/images/target/latest') |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 189 | self.assertEqual( |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 190 | bundle_image_zip.call_args_list, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 191 | [mock.call(self.output_dir, latest)]) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 192 | |
| 193 | def testBundleImageZipNoImageDir(self): |
| 194 | """BundleImageZip dies when image dir does not exist.""" |
| 195 | self.PatchObject(os.path, 'exists', return_value=False) |
| 196 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 197 | artifacts.BundleImageZip(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 198 | self.api_config) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 199 | |
| 200 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 201 | class BundleAutotestFilesTest(BundleTestCase): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 202 | """Unittests for BundleAutotestFiles.""" |
| 203 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 204 | def testValidateOnly(self): |
| 205 | """Sanity check that a validate only call does not execute any logic.""" |
| 206 | patch = self.PatchObject(artifacts_svc, 'BundleAutotestFiles') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 207 | artifacts.BundleAutotestFiles(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 208 | self.validate_only_config) |
| 209 | patch.assert_not_called() |
| 210 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 211 | def testMockCall(self): |
| 212 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 213 | patch = self.PatchObject(artifacts_svc, 'BundleAutotestFiles') |
| 214 | artifacts.BundleAutotestFiles(self.target_request, self.response, |
| 215 | self.mock_call_config) |
| 216 | patch.assert_not_called() |
| 217 | self.assertEqual(len(self.response.artifacts), 1) |
| 218 | self.assertEqual(self.response.artifacts[0].path, |
| 219 | os.path.join(self.output_dir, 'autotest-a.tar.gz')) |
| 220 | |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 221 | def testBundleAutotestFilesLegacy(self): |
| 222 | """BundleAutotestFiles calls service correctly with legacy args.""" |
| 223 | files = { |
| 224 | artifacts_svc.ARCHIVE_CONTROL_FILES: '/tmp/artifacts/autotest-a.tar.gz', |
| 225 | artifacts_svc.ARCHIVE_PACKAGES: '/tmp/artifacts/autotest-b.tar.gz', |
| 226 | } |
| 227 | patch = self.PatchObject(artifacts_svc, 'BundleAutotestFiles', |
| 228 | return_value=files) |
| 229 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 230 | artifacts.BundleAutotestFiles(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 231 | self.api_config) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 232 | |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 233 | # Verify the arguments are being passed through. |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 234 | patch.assert_called_with(mock.ANY, self.sysroot, self.output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 235 | |
| 236 | # Verify the output proto is being populated correctly. |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 237 | self.assertTrue(self.response.artifacts) |
| 238 | paths = [artifact.path for artifact in self.response.artifacts] |
Mike Frysinger | 1f4478c | 2019-10-20 18:33:17 -0400 | [diff] [blame] | 239 | self.assertCountEqual(list(files.values()), paths) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 240 | |
| 241 | def testBundleAutotestFiles(self): |
| 242 | """BundleAutotestFiles calls service correctly.""" |
| 243 | files = { |
| 244 | artifacts_svc.ARCHIVE_CONTROL_FILES: '/tmp/artifacts/autotest-a.tar.gz', |
| 245 | artifacts_svc.ARCHIVE_PACKAGES: '/tmp/artifacts/autotest-b.tar.gz', |
| 246 | } |
| 247 | patch = self.PatchObject(artifacts_svc, 'BundleAutotestFiles', |
| 248 | return_value=files) |
| 249 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 250 | artifacts.BundleAutotestFiles(self.sysroot_request, self.response, |
| 251 | self.api_config) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 252 | |
| 253 | # Verify the arguments are being passed through. |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 254 | patch.assert_called_with(mock.ANY, self.sysroot, self.output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 255 | |
| 256 | # Verify the output proto is being populated correctly. |
| 257 | self.assertTrue(self.response.artifacts) |
| 258 | paths = [artifact.path for artifact in self.response.artifacts] |
Mike Frysinger | 1f4478c | 2019-10-20 18:33:17 -0400 | [diff] [blame] | 259 | self.assertCountEqual(list(files.values()), paths) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 260 | |
| 261 | def testInvalidOutputDir(self): |
| 262 | """Test invalid output directory argument.""" |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 263 | request = self.SysrootRequest(chroot=self.chroot_path, |
| 264 | sysroot=self.sysroot_path) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 265 | |
| 266 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 267 | artifacts.BundleAutotestFiles(request, self.response, self.api_config) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 268 | |
| 269 | def testInvalidSysroot(self): |
| 270 | """Test no sysroot directory.""" |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 271 | request = self.SysrootRequest(chroot=self.chroot_path, |
| 272 | output_dir=self.output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 273 | |
| 274 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 275 | artifacts.BundleAutotestFiles(request, self.response, self.api_config) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 276 | |
| 277 | def testSysrootDoesNotExist(self): |
| 278 | """Test dies when no sysroot does not exist.""" |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 279 | request = self.SysrootRequest(chroot=self.chroot_path, |
| 280 | sysroot='/does/not/exist', |
| 281 | output_dir=self.output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 282 | |
| 283 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 284 | artifacts.BundleAutotestFiles(request, self.response, self.api_config) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 285 | |
| 286 | |
| 287 | class BundleTastFilesTest(BundleTestCase): |
| 288 | """Unittests for BundleTastFiles.""" |
| 289 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 290 | def testValidateOnly(self): |
| 291 | """Sanity check that a validate only call does not execute any logic.""" |
| 292 | patch = self.PatchObject(artifacts_svc, 'BundleTastFiles') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 293 | artifacts.BundleTastFiles(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 294 | self.validate_only_config) |
| 295 | patch.assert_not_called() |
| 296 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 297 | def testMockCall(self): |
| 298 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 299 | patch = self.PatchObject(artifacts_svc, 'BundleTastFiles') |
| 300 | artifacts.BundleTastFiles(self.target_request, self.response, |
| 301 | self.mock_call_config) |
| 302 | patch.assert_not_called() |
| 303 | self.assertEqual(len(self.response.artifacts), 1) |
| 304 | self.assertEqual(self.response.artifacts[0].path, |
| 305 | os.path.join(self.output_dir, 'tast_bundles.tar.gz')) |
| 306 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 307 | def testBundleTastFilesNoLogs(self): |
| 308 | """BundleTasteFiles dies when no tast files found.""" |
| 309 | self.PatchObject(commands, 'BuildTastBundleTarball', |
| 310 | return_value=None) |
| 311 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 312 | artifacts.BundleTastFiles(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 313 | self.api_config) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 314 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 315 | def testBundleTastFilesLegacy(self): |
| 316 | """BundleTastFiles handles legacy args correctly.""" |
| 317 | buildroot = self.tempdir |
| 318 | chroot_dir = os.path.join(buildroot, 'chroot') |
| 319 | sysroot_path = os.path.join(chroot_dir, 'build', 'board') |
| 320 | output_dir = os.path.join(self.tempdir, 'results') |
| 321 | osutils.SafeMakedirs(sysroot_path) |
| 322 | osutils.SafeMakedirs(output_dir) |
| 323 | |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 324 | chroot = chroot_lib.Chroot(chroot_dir) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 325 | sysroot = sysroot_lib.Sysroot('/build/board') |
| 326 | |
| 327 | expected_archive = os.path.join(output_dir, artifacts_svc.TAST_BUNDLE_NAME) |
| 328 | # Patch the service being called. |
| 329 | bundle_patch = self.PatchObject(artifacts_svc, 'BundleTastFiles', |
| 330 | return_value=expected_archive) |
| 331 | self.PatchObject(constants, 'SOURCE_ROOT', new=buildroot) |
| 332 | |
| 333 | request = artifacts_pb2.BundleRequest(build_target={'name': 'board'}, |
| 334 | output_dir=output_dir) |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 335 | artifacts.BundleTastFiles(request, self.response, self.api_config) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 336 | self.assertEqual( |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 337 | [artifact.path for artifact in self.response.artifacts], |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 338 | [expected_archive]) |
| 339 | bundle_patch.assert_called_once_with(chroot, sysroot, output_dir) |
| 340 | |
| 341 | def testBundleTastFiles(self): |
| 342 | """BundleTastFiles calls service correctly.""" |
Alex Klein | b49be8a | 2019-12-20 10:23:03 -0700 | [diff] [blame] | 343 | chroot = chroot_lib.Chroot(self.chroot_path) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 344 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 345 | expected_archive = os.path.join(self.output_dir, |
| 346 | artifacts_svc.TAST_BUNDLE_NAME) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 347 | # Patch the service being called. |
| 348 | bundle_patch = self.PatchObject(artifacts_svc, 'BundleTastFiles', |
| 349 | return_value=expected_archive) |
| 350 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 351 | artifacts.BundleTastFiles(self.sysroot_request, self.response, |
| 352 | self.api_config) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 353 | |
| 354 | # Make sure the artifact got recorded successfully. |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 355 | self.assertTrue(self.response.artifacts) |
| 356 | self.assertEqual(expected_archive, self.response.artifacts[0].path) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 357 | # Make sure the service got called correctly. |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 358 | bundle_patch.assert_called_once_with(chroot, self.sysroot, self.output_dir) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 359 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 360 | |
| 361 | class BundlePinnedGuestImagesTest(BundleTestCase): |
| 362 | """Unittests for BundlePinnedGuestImages.""" |
| 363 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 364 | def testValidateOnly(self): |
| 365 | """Sanity check that a validate only call does not execute any logic.""" |
| 366 | patch = self.PatchObject(commands, 'BuildPinnedGuestImagesTarball') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 367 | artifacts.BundlePinnedGuestImages(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 368 | self.validate_only_config) |
| 369 | patch.assert_not_called() |
| 370 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 371 | def testMockCall(self): |
| 372 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 373 | patch = self.PatchObject(commands, 'BuildPinnedGuestImagesTarball') |
| 374 | artifacts.BundlePinnedGuestImages(self.target_request, self.response, |
| 375 | self.mock_call_config) |
| 376 | patch.assert_not_called() |
| 377 | self.assertEqual(len(self.response.artifacts), 1) |
| 378 | self.assertEqual(self.response.artifacts[0].path, |
| 379 | os.path.join(self.output_dir, |
| 380 | 'pinned-guest-images.tar.gz')) |
| 381 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 382 | def testBundlePinnedGuestImages(self): |
| 383 | """BundlePinnedGuestImages calls cbuildbot/commands with correct args.""" |
| 384 | build_pinned_guest_images_tarball = self.PatchObject( |
| 385 | commands, |
| 386 | 'BuildPinnedGuestImagesTarball', |
| 387 | return_value='pinned-guest-images.tar.gz') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 388 | artifacts.BundlePinnedGuestImages(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 389 | self.api_config) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 390 | self.assertEqual( |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 391 | [artifact.path for artifact in self.response.artifacts], |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 392 | [os.path.join(self.output_dir, 'pinned-guest-images.tar.gz')]) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 393 | self.assertEqual(build_pinned_guest_images_tarball.call_args_list, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 394 | [mock.call(self.source_root, 'target', self.output_dir)]) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 395 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 396 | def testBundlePinnedGuestImagesNoLogs(self): |
Evan Hernandez | de44598 | 2019-04-22 13:42:34 -0600 | [diff] [blame] | 397 | """BundlePinnedGuestImages does not die when no pinned images found.""" |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 398 | self.PatchObject(commands, 'BuildPinnedGuestImagesTarball', |
| 399 | return_value=None) |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 400 | artifacts.BundlePinnedGuestImages(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 401 | self.api_config) |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 402 | self.assertFalse(self.response.artifacts) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 403 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 404 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 405 | class FetchPinnedGuestImagesTest(cros_test_lib.MockTempDirTestCase, |
| 406 | api_config.ApiConfigMixin, BundleRequestMixin): |
| 407 | """Unittests for FetchPinnedGuestImages.""" |
| 408 | |
| 409 | def setUp(self): |
| 410 | self.build_target = 'board' |
| 411 | self.chroot_dir = os.path.join(self.tempdir, 'chroot_dir') |
| 412 | self.sysroot_path = '/sysroot' |
| 413 | self.sysroot_dir = os.path.join(self.chroot_dir, 'sysroot') |
| 414 | osutils.SafeMakedirs(self.sysroot_dir) |
| 415 | |
| 416 | self.input_request = artifacts_pb2.PinnedGuestImageUriRequest( |
| 417 | sysroot={'path': self.sysroot_path, |
| 418 | 'build_target': {'name': self.build_target}}, |
| 419 | chroot={'path': self.chroot_dir}) |
| 420 | |
| 421 | self.response = artifacts_pb2.PinnedGuestImageUriResponse() |
| 422 | |
| 423 | def testValidateOnly(self): |
| 424 | """Sanity check that a validate only call does not execute any logic.""" |
| 425 | patch = self.PatchObject(artifacts_svc, 'FetchPinnedGuestImages') |
| 426 | artifacts.FetchPinnedGuestImages(self.input_request, self.response, |
| 427 | self.validate_only_config) |
| 428 | patch.assert_not_called() |
| 429 | |
| 430 | def testMockCall(self): |
| 431 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 432 | patch = self.PatchObject(artifacts_svc, 'FetchPinnedGuestImages') |
| 433 | artifacts.FetchPinnedGuestImages(self.input_request, self.response, |
| 434 | self.mock_call_config) |
| 435 | patch.assert_not_called() |
| 436 | self.assertEqual(len(self.response.pinned_images), 1) |
| 437 | self.assertEqual(self.response.pinned_images[0].filename, |
| 438 | 'pinned_file.tar.gz') |
| 439 | self.assertEqual(self.response.pinned_images[0].uri, |
| 440 | 'https://testuri.com') |
| 441 | |
| 442 | def testFetchPinnedGuestImages(self): |
| 443 | """FetchPinnedGuestImages calls service with correct args.""" |
| 444 | pins = [] |
| 445 | pins.append(PinnedGuestImage( |
| 446 | filename='my_pinned_file.tar.gz', uri='https://the_testuri.com')) |
| 447 | self.PatchObject(artifacts_svc, 'FetchPinnedGuestImages', |
| 448 | return_value=pins) |
| 449 | artifacts.FetchPinnedGuestImages(self.input_request, self.response, |
| 450 | self.api_config) |
| 451 | self.assertEqual(len(self.response.pinned_images), 1) |
| 452 | self.assertEqual(self.response.pinned_images[0].filename, |
| 453 | 'my_pinned_file.tar.gz') |
| 454 | self.assertEqual(self.response.pinned_images[0].uri, |
| 455 | 'https://the_testuri.com') |
| 456 | |
| 457 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 458 | class BundleFirmwareTest(BundleTestCase): |
| 459 | """Unittests for BundleFirmware.""" |
| 460 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 461 | def testValidateOnly(self): |
| 462 | """Sanity check that a validate only call does not execute any logic.""" |
| 463 | patch = self.PatchObject(artifacts_svc, 'BundleTastFiles') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 464 | artifacts.BundleFirmware(self.sysroot_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 465 | self.validate_only_config) |
| 466 | patch.assert_not_called() |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 467 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 468 | def testMockCall(self): |
| 469 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 470 | patch = self.PatchObject(artifacts_svc, 'BundleTastFiles') |
| 471 | artifacts.BundleFirmware(self.sysroot_request, self.response, |
| 472 | self.mock_call_config) |
| 473 | patch.assert_not_called() |
| 474 | self.assertEqual(len(self.response.artifacts), 1) |
| 475 | self.assertEqual(self.response.artifacts[0].path, |
| 476 | os.path.join(self.output_dir, 'firmware.tar.gz')) |
| 477 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 478 | def testBundleFirmware(self): |
| 479 | """BundleFirmware calls cbuildbot/commands with correct args.""" |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 480 | self.PatchObject( |
| 481 | artifacts_svc, |
| 482 | 'BuildFirmwareArchive', |
| 483 | return_value=os.path.join(self.output_dir, 'firmware.tar.gz')) |
| 484 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 485 | artifacts.BundleFirmware(self.sysroot_request, self.response, |
| 486 | self.api_config) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 487 | self.assertEqual( |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 488 | [artifact.path for artifact in self.response.artifacts], |
| 489 | [os.path.join(self.output_dir, 'firmware.tar.gz')]) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 490 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 491 | def testBundleFirmwareNoLogs(self): |
| 492 | """BundleFirmware dies when no firmware found.""" |
| 493 | self.PatchObject(commands, 'BuildFirmwareArchive', return_value=None) |
| 494 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 495 | artifacts.BundleFirmware(self.sysroot_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 496 | self.api_config) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 497 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 498 | |
| 499 | class BundleEbuildLogsTest(BundleTestCase): |
| 500 | """Unittests for BundleEbuildLogs.""" |
| 501 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 502 | def testValidateOnly(self): |
| 503 | """Sanity check that a validate only call does not execute any logic.""" |
| 504 | patch = self.PatchObject(commands, 'BuildEbuildLogsTarball') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 505 | artifacts.BundleEbuildLogs(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 506 | self.validate_only_config) |
| 507 | patch.assert_not_called() |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 508 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 509 | def testMockCall(self): |
| 510 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 511 | patch = self.PatchObject(commands, 'BuildEbuildLogsTarball') |
| 512 | artifacts.BundleEbuildLogs(self.target_request, self.response, |
| 513 | self.mock_call_config) |
| 514 | patch.assert_not_called() |
| 515 | self.assertEqual(len(self.response.artifacts), 1) |
| 516 | self.assertEqual(self.response.artifacts[0].path, |
| 517 | os.path.join(self.output_dir, 'ebuild-logs.tar.gz')) |
| 518 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 519 | def testBundleEbuildLogs(self): |
| 520 | """BundleEbuildLogs calls cbuildbot/commands with correct args.""" |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 521 | bundle_ebuild_logs_tarball = self.PatchObject( |
| 522 | artifacts_svc, 'BundleEBuildLogsTarball', |
| 523 | return_value='ebuild-logs.tar.gz') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 524 | artifacts.BundleEbuildLogs(self.sysroot_request, self.response, |
| 525 | self.api_config) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 526 | self.assertEqual( |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 527 | [artifact.path for artifact in self.response.artifacts], |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 528 | [os.path.join(self.output_dir, 'ebuild-logs.tar.gz')]) |
Evan Hernandez | a478d80 | 2019-04-08 15:08:24 -0600 | [diff] [blame] | 529 | self.assertEqual( |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 530 | bundle_ebuild_logs_tarball.call_args_list, |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 531 | [mock.call(mock.ANY, self.sysroot, self.output_dir)]) |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 532 | |
| 533 | def testBundleEBuildLogsOldProto(self): |
| 534 | bundle_ebuild_logs_tarball = self.PatchObject( |
| 535 | artifacts_svc, 'BundleEBuildLogsTarball', |
| 536 | return_value='ebuild-logs.tar.gz') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 537 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 538 | artifacts.BundleEbuildLogs(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 539 | self.api_config) |
| 540 | |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 541 | self.assertEqual( |
| 542 | bundle_ebuild_logs_tarball.call_args_list, |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 543 | [mock.call(mock.ANY, self.sysroot, self.output_dir)]) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 544 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 545 | def testBundleEbuildLogsNoLogs(self): |
| 546 | """BundleEbuildLogs dies when no logs found.""" |
| 547 | self.PatchObject(commands, 'BuildEbuildLogsTarball', return_value=None) |
| 548 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 549 | artifacts.BundleEbuildLogs(self.sysroot_request, self.response, |
| 550 | self.api_config) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 551 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 552 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 553 | class BundleChromeOSConfigTest(BundleTestCase): |
| 554 | """Unittests for BundleChromeOSConfig""" |
| 555 | |
| 556 | def testValidateOnly(self): |
| 557 | """Sanity check that a validate only call does not execute any logic.""" |
| 558 | patch = self.PatchObject(artifacts_svc, 'BundleChromeOSConfig') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 559 | artifacts.BundleChromeOSConfig(self.target_request, self.response, |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 560 | self.validate_only_config) |
| 561 | patch.assert_not_called() |
| 562 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 563 | def testMockCall(self): |
| 564 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 565 | patch = self.PatchObject(artifacts_svc, 'BundleChromeOSConfig') |
| 566 | artifacts.BundleChromeOSConfig(self.target_request, self.response, |
| 567 | self.mock_call_config) |
| 568 | patch.assert_not_called() |
| 569 | self.assertEqual(len(self.response.artifacts), 1) |
| 570 | self.assertEqual(self.response.artifacts[0].path, |
| 571 | os.path.join(self.output_dir, 'config.yaml')) |
| 572 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 573 | def testBundleChromeOSConfigCallWithSysroot(self): |
| 574 | """Call with a request that sets sysroot.""" |
| 575 | bundle_chromeos_config = self.PatchObject( |
| 576 | artifacts_svc, 'BundleChromeOSConfig', return_value='config.yaml') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 577 | artifacts.BundleChromeOSConfig(self.sysroot_request, self.response, |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 578 | self.api_config) |
| 579 | self.assertEqual( |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 580 | [artifact.path for artifact in self.response.artifacts], |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 581 | [os.path.join(self.output_dir, 'config.yaml')]) |
| 582 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 583 | self.assertEqual(bundle_chromeos_config.call_args_list, |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 584 | [mock.call(mock.ANY, self.sysroot, self.output_dir)]) |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 585 | |
| 586 | def testBundleChromeOSConfigCallWithBuildTarget(self): |
| 587 | """Call with a request that sets build_target.""" |
| 588 | bundle_chromeos_config = self.PatchObject( |
| 589 | artifacts_svc, 'BundleChromeOSConfig', return_value='config.yaml') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 590 | artifacts.BundleChromeOSConfig(self.target_request, self.response, |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 591 | self.api_config) |
| 592 | |
| 593 | self.assertEqual( |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 594 | [artifact.path for artifact in self.response.artifacts], |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 595 | [os.path.join(self.output_dir, 'config.yaml')]) |
| 596 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 597 | self.assertEqual(bundle_chromeos_config.call_args_list, |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 598 | [mock.call(mock.ANY, self.sysroot, self.output_dir)]) |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 599 | |
| 600 | def testBundleChromeOSConfigNoConfigFound(self): |
| 601 | """An error is raised if the config payload isn't found.""" |
| 602 | self.PatchObject(artifacts_svc, 'BundleChromeOSConfig', return_value=None) |
| 603 | |
| 604 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 605 | artifacts.BundleChromeOSConfig(self.sysroot_request, self.response, |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 606 | self.api_config) |
| 607 | |
| 608 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 609 | class BundleTestUpdatePayloadsTest(cros_test_lib.MockTempDirTestCase, |
| 610 | api_config.ApiConfigMixin): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 611 | """Unittests for BundleTestUpdatePayloads.""" |
| 612 | |
| 613 | def setUp(self): |
| 614 | self.source_root = os.path.join(self.tempdir, 'cros') |
| 615 | osutils.SafeMakedirs(self.source_root) |
| 616 | |
| 617 | self.archive_root = os.path.join(self.tempdir, 'output') |
| 618 | osutils.SafeMakedirs(self.archive_root) |
| 619 | |
| 620 | self.target = 'target' |
Evan Hernandez | 59690b7 | 2019-04-08 16:24:45 -0600 | [diff] [blame] | 621 | self.image_root = os.path.join(self.source_root, |
| 622 | 'src/build/images/target/latest') |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 623 | |
| 624 | self.input_proto = artifacts_pb2.BundleRequest() |
| 625 | self.input_proto.build_target.name = self.target |
| 626 | self.input_proto.output_dir = self.archive_root |
| 627 | self.output_proto = artifacts_pb2.BundleResponse() |
| 628 | |
| 629 | self.PatchObject(constants, 'SOURCE_ROOT', new=self.source_root) |
| 630 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 631 | def MockPayloads(image_path, archive_dir): |
| 632 | osutils.WriteFile(os.path.join(archive_dir, 'payload1.bin'), image_path) |
| 633 | osutils.WriteFile(os.path.join(archive_dir, 'payload2.bin'), image_path) |
| 634 | return [os.path.join(archive_dir, 'payload1.bin'), |
| 635 | os.path.join(archive_dir, 'payload2.bin')] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 636 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 637 | self.bundle_patch = self.PatchObject( |
| 638 | artifacts_svc, 'BundleTestUpdatePayloads', side_effect=MockPayloads) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 639 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 640 | def testValidateOnly(self): |
| 641 | """Sanity check that a validate only call does not execute any logic.""" |
| 642 | patch = self.PatchObject(artifacts_svc, 'BundleTestUpdatePayloads') |
| 643 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 644 | self.validate_only_config) |
| 645 | patch.assert_not_called() |
| 646 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 647 | def testMockCall(self): |
| 648 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 649 | patch = self.PatchObject(artifacts_svc, 'BundleTestUpdatePayloads') |
| 650 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 651 | self.mock_call_config) |
| 652 | patch.assert_not_called() |
| 653 | self.assertEqual(len(self.output_proto.artifacts), 1) |
| 654 | self.assertEqual(self.output_proto.artifacts[0].path, |
| 655 | os.path.join(self.archive_root, 'payload1.bin')) |
| 656 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 657 | def testBundleTestUpdatePayloads(self): |
| 658 | """BundleTestUpdatePayloads calls cbuildbot/commands with correct args.""" |
| 659 | image_path = os.path.join(self.image_root, constants.BASE_IMAGE_BIN) |
| 660 | osutils.WriteFile(image_path, 'image!', makedirs=True) |
| 661 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 662 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 663 | self.api_config) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 664 | |
| 665 | actual = [ |
| 666 | os.path.relpath(artifact.path, self.archive_root) |
| 667 | for artifact in self.output_proto.artifacts |
| 668 | ] |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 669 | expected = ['payload1.bin', 'payload2.bin'] |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 670 | self.assertCountEqual(actual, expected) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 671 | |
| 672 | actual = [ |
| 673 | os.path.relpath(path, self.archive_root) |
| 674 | for path in osutils.DirectoryIterator(self.archive_root) |
| 675 | ] |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 676 | self.assertCountEqual(actual, expected) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 677 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 678 | def testBundleTestUpdatePayloadsNoImageDir(self): |
| 679 | """BundleTestUpdatePayloads dies if no image dir is found.""" |
| 680 | # Intentionally do not write image directory. |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 681 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 682 | self.api_config) |
| 683 | self.assertFalse(self.output_proto.artifacts) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 684 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 685 | def testBundleTestUpdatePayloadsNoImage(self): |
| 686 | """BundleTestUpdatePayloads dies if no usable image is found for target.""" |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 687 | # Intentionally do not write image, but create the directory. |
| 688 | osutils.SafeMakedirs(self.image_root) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 689 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 690 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 691 | self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 692 | |
| 693 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 694 | class BundleSimpleChromeArtifactsTest(cros_test_lib.MockTempDirTestCase, |
| 695 | api_config.ApiConfigMixin): |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 696 | """BundleSimpleChromeArtifacts tests.""" |
| 697 | |
| 698 | def setUp(self): |
| 699 | self.chroot_dir = os.path.join(self.tempdir, 'chroot_dir') |
| 700 | self.sysroot_path = '/sysroot' |
| 701 | self.sysroot_dir = os.path.join(self.chroot_dir, 'sysroot') |
| 702 | osutils.SafeMakedirs(self.sysroot_dir) |
| 703 | self.output_dir = os.path.join(self.tempdir, 'output_dir') |
| 704 | osutils.SafeMakedirs(self.output_dir) |
| 705 | |
| 706 | self.does_not_exist = os.path.join(self.tempdir, 'does_not_exist') |
| 707 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 708 | self.response = artifacts_pb2.BundleResponse() |
| 709 | |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 710 | def _GetRequest(self, chroot=None, sysroot=None, build_target=None, |
| 711 | output_dir=None): |
| 712 | """Helper to create a request message instance. |
| 713 | |
| 714 | Args: |
| 715 | chroot (str): The chroot path. |
| 716 | sysroot (str): The sysroot path. |
| 717 | build_target (str): The build target name. |
| 718 | output_dir (str): The output directory. |
| 719 | """ |
| 720 | return artifacts_pb2.BundleRequest( |
| 721 | sysroot={'path': sysroot, 'build_target': {'name': build_target}}, |
| 722 | chroot={'path': chroot}, output_dir=output_dir) |
| 723 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 724 | def testValidateOnly(self): |
| 725 | """Sanity check that a validate only call does not execute any logic.""" |
| 726 | patch = self.PatchObject(artifacts_svc, 'BundleSimpleChromeArtifacts') |
| 727 | request = self._GetRequest(chroot=self.chroot_dir, |
| 728 | sysroot=self.sysroot_path, |
| 729 | build_target='board', output_dir=self.output_dir) |
| 730 | artifacts.BundleSimpleChromeArtifacts(request, self.response, |
| 731 | self.validate_only_config) |
| 732 | patch.assert_not_called() |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 733 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 734 | def testMockCall(self): |
| 735 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 736 | patch = self.PatchObject(artifacts_svc, 'BundleSimpleChromeArtifacts') |
| 737 | request = self._GetRequest(chroot=self.chroot_dir, |
| 738 | sysroot=self.sysroot_path, |
| 739 | build_target='board', output_dir=self.output_dir) |
| 740 | artifacts.BundleSimpleChromeArtifacts(request, self.response, |
| 741 | self.mock_call_config) |
| 742 | patch.assert_not_called() |
| 743 | self.assertEqual(len(self.response.artifacts), 1) |
| 744 | self.assertEqual(self.response.artifacts[0].path, |
| 745 | os.path.join(self.output_dir, 'simple_chrome.txt')) |
| 746 | |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 747 | def testNoBuildTarget(self): |
| 748 | """Test no build target fails.""" |
| 749 | request = self._GetRequest(chroot=self.chroot_dir, |
| 750 | sysroot=self.sysroot_path, |
| 751 | output_dir=self.output_dir) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 752 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 753 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 754 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 755 | |
| 756 | def testNoSysroot(self): |
| 757 | """Test no sysroot fails.""" |
| 758 | request = self._GetRequest(build_target='board', output_dir=self.output_dir) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 759 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 760 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 761 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 762 | |
| 763 | def testSysrootDoesNotExist(self): |
| 764 | """Test no sysroot fails.""" |
| 765 | request = self._GetRequest(build_target='board', output_dir=self.output_dir, |
| 766 | sysroot=self.does_not_exist) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 767 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 768 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 769 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 770 | |
| 771 | def testNoOutputDir(self): |
| 772 | """Test no output dir fails.""" |
| 773 | request = self._GetRequest(chroot=self.chroot_dir, |
| 774 | sysroot=self.sysroot_path, |
| 775 | build_target='board') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 776 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 777 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 778 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 779 | |
| 780 | def testOutputDirDoesNotExist(self): |
| 781 | """Test no output dir fails.""" |
| 782 | request = self._GetRequest(chroot=self.chroot_dir, |
| 783 | sysroot=self.sysroot_path, |
| 784 | build_target='board', |
| 785 | output_dir=self.does_not_exist) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 786 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 787 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 788 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 789 | |
| 790 | def testOutputHandling(self): |
| 791 | """Test response output.""" |
| 792 | files = ['file1', 'file2', 'file3'] |
| 793 | expected_files = [os.path.join(self.output_dir, f) for f in files] |
| 794 | self.PatchObject(artifacts_svc, 'BundleSimpleChromeArtifacts', |
| 795 | return_value=expected_files) |
| 796 | request = self._GetRequest(chroot=self.chroot_dir, |
| 797 | sysroot=self.sysroot_path, |
| 798 | build_target='board', output_dir=self.output_dir) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 799 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 800 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 801 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 802 | |
| 803 | self.assertTrue(response.artifacts) |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 804 | self.assertCountEqual(expected_files, [a.path for a in response.artifacts]) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 805 | |
| 806 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 807 | class BundleVmFilesTest(cros_test_lib.MockTempDirTestCase, |
| 808 | api_config.ApiConfigMixin): |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 809 | """BuildVmFiles tests.""" |
| 810 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 811 | def setUp(self): |
| 812 | self.output_dir = os.path.join(self.tempdir, 'output') |
| 813 | osutils.SafeMakedirs(self.output_dir) |
| 814 | |
| 815 | self.response = artifacts_pb2.BundleResponse() |
| 816 | |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 817 | def _GetInput(self, chroot=None, sysroot=None, test_results_dir=None, |
| 818 | output_dir=None): |
| 819 | """Helper to build out an input message instance. |
| 820 | |
| 821 | Args: |
| 822 | chroot (str|None): The chroot path. |
| 823 | sysroot (str|None): The sysroot path relative to the chroot. |
| 824 | test_results_dir (str|None): The test results directory relative to the |
| 825 | sysroot. |
| 826 | output_dir (str|None): The directory where the results tarball should be |
| 827 | saved. |
| 828 | """ |
| 829 | return artifacts_pb2.BundleVmFilesRequest( |
| 830 | chroot={'path': chroot}, sysroot={'path': sysroot}, |
| 831 | test_results_dir=test_results_dir, output_dir=output_dir, |
| 832 | ) |
| 833 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 834 | def testValidateOnly(self): |
| 835 | """Sanity check that a validate only call does not execute any logic.""" |
| 836 | patch = self.PatchObject(artifacts_svc, 'BundleVmFiles') |
| 837 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 838 | test_results_dir='/test/results', |
| 839 | output_dir=self.output_dir) |
| 840 | artifacts.BundleVmFiles(in_proto, self.response, self.validate_only_config) |
| 841 | patch.assert_not_called() |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 842 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 843 | def testMockCall(self): |
| 844 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 845 | patch = self.PatchObject(artifacts_svc, 'BundleVmFiles') |
| 846 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 847 | test_results_dir='/test/results', |
| 848 | output_dir=self.output_dir) |
| 849 | artifacts.BundleVmFiles(in_proto, self.response, self.mock_call_config) |
| 850 | patch.assert_not_called() |
| 851 | self.assertEqual(len(self.response.artifacts), 1) |
| 852 | self.assertEqual(self.response.artifacts[0].path, |
| 853 | os.path.join(self.output_dir, 'f1.tar')) |
| 854 | |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 855 | def testChrootMissing(self): |
| 856 | """Test error handling for missing chroot.""" |
| 857 | in_proto = self._GetInput(sysroot='/build/board', |
| 858 | test_results_dir='/test/results', |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 859 | output_dir=self.output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 860 | |
| 861 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 862 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 863 | |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 864 | def testTestResultsDirMissing(self): |
| 865 | """Test error handling for missing test results directory.""" |
| 866 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 867 | output_dir=self.output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 868 | |
| 869 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 870 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 871 | |
| 872 | def testOutputDirMissing(self): |
| 873 | """Test error handling for missing output directory.""" |
| 874 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 875 | test_results_dir='/test/results') |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 876 | |
| 877 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 878 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
| 879 | |
| 880 | def testOutputDirDoesNotExist(self): |
| 881 | """Test error handling for output directory that does not exist.""" |
| 882 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 883 | output_dir=os.path.join(self.tempdir, 'dne'), |
| 884 | test_results_dir='/test/results') |
| 885 | |
| 886 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 887 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 888 | |
| 889 | def testValidCall(self): |
| 890 | """Test image dir building.""" |
| 891 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 892 | test_results_dir='/test/results', |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 893 | output_dir=self.output_dir) |
| 894 | |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 895 | expected_files = ['/tmp/output/f1.tar', '/tmp/output/f2.tar'] |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 896 | patch = self.PatchObject(artifacts_svc, 'BundleVmFiles', |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 897 | return_value=expected_files) |
| 898 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 899 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 900 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 901 | patch.assert_called_with(mock.ANY, '/test/results', self.output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 902 | |
| 903 | # Make sure we have artifacts, and that every artifact is an expected file. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 904 | self.assertTrue(self.response.artifacts) |
| 905 | for artifact in self.response.artifacts: |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 906 | self.assertIn(artifact.path, expected_files) |
| 907 | expected_files.remove(artifact.path) |
| 908 | |
| 909 | # Make sure we've seen all of the expected files. |
| 910 | self.assertFalse(expected_files) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 911 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 912 | |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 913 | |
| 914 | class BundleAFDOGenerationArtifactsTestCase( |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 915 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin): |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 916 | """Unittests for BundleAFDOGenerationArtifacts.""" |
| 917 | |
| 918 | @staticmethod |
| 919 | def mock_die(message, *args): |
| 920 | raise cros_build_lib.DieSystemExit(message % args) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 921 | |
| 922 | def setUp(self): |
| 923 | self.chroot_dir = os.path.join(self.tempdir, 'chroot_dir') |
| 924 | osutils.SafeMakedirs(self.chroot_dir) |
| 925 | temp_dir = os.path.join(self.chroot_dir, 'tmp') |
| 926 | osutils.SafeMakedirs(temp_dir) |
| 927 | self.output_dir = os.path.join(self.tempdir, 'output_dir') |
| 928 | osutils.SafeMakedirs(self.output_dir) |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 929 | self.chrome_root = os.path.join(self.tempdir, 'chrome_root') |
| 930 | osutils.SafeMakedirs(self.chrome_root) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 931 | self.build_target = 'board' |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 932 | self.valid_artifact_type = toolchain_pb2.ORDERFILE |
| 933 | self.invalid_artifact_type = toolchain_pb2.NONE_TYPE |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 934 | self.does_not_exist = os.path.join(self.tempdir, 'does_not_exist') |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 935 | self.PatchObject(cros_build_lib, 'Die', new=self.mock_die) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 936 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 937 | self.response = artifacts_pb2.BundleResponse() |
| 938 | |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 939 | def _GetRequest(self, chroot=None, build_target=None, chrome_root=None, |
| 940 | output_dir=None, artifact_type=None): |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 941 | """Helper to create a request message instance. |
| 942 | |
| 943 | Args: |
| 944 | chroot (str): The chroot path. |
| 945 | build_target (str): The build target name. |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 946 | chrome_root (str): The path to Chrome root. |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 947 | output_dir (str): The output directory. |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 948 | artifact_type (artifacts_pb2.AFDOArtifactType): |
| 949 | The type of the artifact. |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 950 | """ |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 951 | return artifacts_pb2.BundleChromeAFDORequest( |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 952 | chroot={'path': chroot, 'chrome_dir': chrome_root}, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 953 | build_target={'name': build_target}, |
| 954 | output_dir=output_dir, |
| 955 | artifact_type=artifact_type, |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 956 | ) |
| 957 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 958 | def testValidateOnly(self): |
| 959 | """Sanity check that a validate only call does not execute any logic.""" |
| 960 | patch = self.PatchObject(artifacts_svc, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 961 | 'BundleAFDOGenerationArtifacts') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 962 | request = self._GetRequest(chroot=self.chroot_dir, |
| 963 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 964 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 965 | output_dir=self.output_dir, |
| 966 | artifact_type=self.valid_artifact_type) |
| 967 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 968 | self.validate_only_config) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 969 | patch.assert_not_called() |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 970 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 971 | def testMockCall(self): |
| 972 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 973 | patch = self.PatchObject(artifacts_svc, |
| 974 | 'BundleAFDOGenerationArtifacts') |
| 975 | request = self._GetRequest(chroot=self.chroot_dir, |
| 976 | build_target=self.build_target, |
| 977 | chrome_root=self.chrome_root, |
| 978 | output_dir=self.output_dir, |
| 979 | artifact_type=self.valid_artifact_type) |
| 980 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 981 | self.mock_call_config) |
| 982 | patch.assert_not_called() |
| 983 | self.assertEqual(len(self.response.artifacts), 1) |
| 984 | self.assertEqual(self.response.artifacts[0].path, |
| 985 | os.path.join(self.output_dir, 'artifact1')) |
| 986 | |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 987 | def testNoBuildTarget(self): |
| 988 | """Test no build target fails.""" |
| 989 | request = self._GetRequest(chroot=self.chroot_dir, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 990 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 991 | output_dir=self.output_dir, |
| 992 | artifact_type=self.valid_artifact_type) |
| 993 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 994 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 995 | self.api_config) |
| 996 | self.assertEqual('build_target.name is required.', |
| 997 | str(context.exception)) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 998 | |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 999 | def testNoChromeRoot(self): |
| 1000 | """Test no chrome root fails.""" |
| 1001 | request = self._GetRequest(chroot=self.chroot_dir, |
| 1002 | build_target=self.build_target, |
| 1003 | output_dir=self.output_dir, |
| 1004 | artifact_type=self.valid_artifact_type) |
| 1005 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 1006 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 1007 | self.api_config) |
| 1008 | self.assertEqual('chroot.chrome_dir path does not exist: ', |
| 1009 | str(context.exception)) |
| 1010 | |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1011 | def testNoOutputDir(self): |
| 1012 | """Test no output dir fails.""" |
| 1013 | request = self._GetRequest(chroot=self.chroot_dir, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1014 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 1015 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1016 | artifact_type=self.valid_artifact_type) |
| 1017 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 1018 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 1019 | self.api_config) |
| 1020 | self.assertEqual('output_dir is required.', |
| 1021 | str(context.exception)) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1022 | |
| 1023 | def testOutputDirDoesNotExist(self): |
| 1024 | """Test output directory not existing fails.""" |
| 1025 | request = self._GetRequest(chroot=self.chroot_dir, |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1026 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 1027 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1028 | output_dir=self.does_not_exist, |
| 1029 | artifact_type=self.valid_artifact_type) |
| 1030 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 1031 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 1032 | self.api_config) |
| 1033 | self.assertEqual( |
| 1034 | 'output_dir path does not exist: %s' % self.does_not_exist, |
| 1035 | str(context.exception)) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1036 | |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1037 | def testNoArtifactType(self): |
| 1038 | """Test no artifact type.""" |
| 1039 | request = self._GetRequest(chroot=self.chroot_dir, |
| 1040 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 1041 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1042 | output_dir=self.output_dir) |
| 1043 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 1044 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 1045 | self.api_config) |
| 1046 | self.assertIn('artifact_type (0) must be in', |
| 1047 | str(context.exception)) |
| 1048 | |
| 1049 | def testWrongArtifactType(self): |
| 1050 | """Test passing wrong artifact type.""" |
| 1051 | request = self._GetRequest(chroot=self.chroot_dir, |
| 1052 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 1053 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1054 | output_dir=self.output_dir, |
| 1055 | artifact_type=self.invalid_artifact_type) |
| 1056 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 1057 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 1058 | self.api_config) |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 1059 | self.assertIn('artifact_type (%d) must be in' % self.invalid_artifact_type, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1060 | str(context.exception)) |
| 1061 | |
| 1062 | def testOutputHandlingOnOrderfile(self, |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 1063 | artifact_type=toolchain_pb2.ORDERFILE): |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1064 | """Test response output for orderfile.""" |
| 1065 | files = ['artifact1', 'artifact2', 'artifact3'] |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1066 | expected_files = [os.path.join(self.output_dir, f) for f in files] |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1067 | self.PatchObject(artifacts_svc, 'BundleAFDOGenerationArtifacts', |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1068 | return_value=expected_files) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 1069 | |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1070 | request = self._GetRequest(chroot=self.chroot_dir, |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1071 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 1072 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1073 | output_dir=self.output_dir, |
| 1074 | artifact_type=artifact_type) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1075 | |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1076 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 1077 | self.api_config) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1078 | |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1079 | self.assertTrue(self.response.artifacts) |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 1080 | self.assertCountEqual(expected_files, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1081 | [a.path for a in self.response.artifacts]) |
| 1082 | |
| 1083 | def testOutputHandlingOnAFDO(self): |
| 1084 | """Test response output for AFDO.""" |
| 1085 | self.testOutputHandlingOnOrderfile( |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 1086 | artifact_type=toolchain_pb2.BENCHMARK_AFDO) |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 1087 | |
| 1088 | |
| 1089 | class ExportCpeReportTest(cros_test_lib.MockTempDirTestCase, |
| 1090 | api_config.ApiConfigMixin): |
| 1091 | """ExportCpeReport tests.""" |
| 1092 | |
| 1093 | def setUp(self): |
| 1094 | self.response = artifacts_pb2.BundleResponse() |
| 1095 | |
| 1096 | def testValidateOnly(self): |
| 1097 | """Sanity check validate only calls don't execute.""" |
| 1098 | patch = self.PatchObject(artifacts_svc, 'GenerateCpeReport') |
| 1099 | |
| 1100 | request = artifacts_pb2.BundleRequest() |
| 1101 | request.build_target.name = 'board' |
| 1102 | request.output_dir = self.tempdir |
| 1103 | |
| 1104 | artifacts.ExportCpeReport(request, self.response, self.validate_only_config) |
| 1105 | |
| 1106 | patch.assert_not_called() |
| 1107 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 1108 | def testMockCall(self): |
| 1109 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 1110 | patch = self.PatchObject(artifacts_svc, 'GenerateCpeReport') |
| 1111 | |
| 1112 | request = artifacts_pb2.BundleRequest() |
| 1113 | request.build_target.name = 'board' |
| 1114 | request.output_dir = self.tempdir |
| 1115 | |
| 1116 | artifacts.ExportCpeReport(request, self.response, self.mock_call_config) |
| 1117 | |
| 1118 | patch.assert_not_called() |
| 1119 | self.assertEqual(len(self.response.artifacts), 2) |
| 1120 | self.assertEqual(self.response.artifacts[0].path, |
| 1121 | os.path.join(self.tempdir, 'cpe_report.txt')) |
| 1122 | self.assertEqual(self.response.artifacts[1].path, |
| 1123 | os.path.join(self.tempdir, 'cpe_warnings.txt')) |
| 1124 | |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 1125 | def testNoBuildTarget(self): |
| 1126 | request = artifacts_pb2.BundleRequest() |
| 1127 | request.output_dir = self.tempdir |
| 1128 | |
| 1129 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 1130 | artifacts.ExportCpeReport(request, self.response, self.api_config) |
| 1131 | |
| 1132 | def testSuccess(self): |
| 1133 | """Test success case.""" |
| 1134 | expected = artifacts_svc.CpeResult( |
| 1135 | report='/output/report.json', warnings='/output/warnings.json') |
| 1136 | self.PatchObject(artifacts_svc, 'GenerateCpeReport', return_value=expected) |
| 1137 | |
| 1138 | request = artifacts_pb2.BundleRequest() |
| 1139 | request.build_target.name = 'board' |
| 1140 | request.output_dir = self.tempdir |
| 1141 | |
| 1142 | artifacts.ExportCpeReport(request, self.response, self.api_config) |
| 1143 | |
| 1144 | for artifact in self.response.artifacts: |
| 1145 | self.assertIn(artifact.path, [expected.report, expected.warnings]) |