blob: 3dc2271318c3d012e16cf674ec788ca94a8f9b0a [file] [log] [blame]
Evan Hernandezf388cbf2019-04-01 11:15:23 -06001# -*- 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
8from __future__ import print_function
9
Michael Mortensen2d6a2402019-11-26 13:40:40 -070010import collections
Evan Hernandezf388cbf2019-04-01 11:15:23 -060011import os
12
Mike Frysinger6db648e2018-07-24 19:57:58 -040013import mock
14
Alex Klein231d2da2019-07-22 16:44:45 -060015from chromite.api import api_config
Evan Hernandezf388cbf2019-04-01 11:15:23 -060016from chromite.api.controller import artifacts
17from chromite.api.gen.chromite.api import artifacts_pb2
Tiancong Wang24a3df72019-08-20 15:48:51 -070018from chromite.api.gen.chromite.api import toolchain_pb2
Evan Hernandezf388cbf2019-04-01 11:15:23 -060019from chromite.cbuildbot import commands
Alex Kleinb9d810b2019-07-01 12:38:02 -060020from chromite.lib import chroot_lib
Evan Hernandezf388cbf2019-04-01 11:15:23 -060021from chromite.lib import constants
22from chromite.lib import cros_build_lib
23from chromite.lib import cros_test_lib
24from chromite.lib import osutils
Alex Klein238d8862019-05-07 11:32:46 -060025from chromite.lib import sysroot_lib
Alex Klein2275d692019-04-23 16:04:12 -060026from chromite.service import artifacts as artifacts_svc
Evan Hernandezf388cbf2019-04-01 11:15:23 -060027
28
Michael Mortensen2d6a2402019-11-26 13:40:40 -070029PinnedGuestImage = collections.namedtuple('PinnedGuestImage',
30 ['filename', 'uri'])
31
32
Alex Kleind91e95a2019-09-17 10:39:02 -060033class 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 Klein231d2da2019-07-22 16:44:45 -060070class BundleTestCase(cros_test_lib.MockTempDirTestCase,
Alex Kleind91e95a2019-09-17 10:39:02 -060071 api_config.ApiConfigMixin, BundleRequestMixin):
Evan Hernandezf388cbf2019-04-01 11:15:23 -060072 """Basic setup for all artifacts unittests."""
73
74 def setUp(self):
Alex Klein231d2da2019-07-22 16:44:45 -060075 self.output_dir = os.path.join(self.tempdir, 'artifacts')
76 osutils.SafeMakedirs(self.output_dir)
77 self.sysroot_path = '/build/target'
Alex Klein68c8fdf2019-09-25 15:09:11 -060078 self.sysroot = sysroot_lib.Sysroot(self.sysroot_path)
Alex Klein231d2da2019-07-22 16:44:45 -060079 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 Klein68c8fdf2019-09-25 15:09:11 -060084 # All requests use same response type.
Alex Klein231d2da2019-07-22 16:44:45 -060085 self.response = artifacts_pb2.BundleResponse()
86
Alex Klein68c8fdf2019-09-25 15:09:11 -060087 # 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 Klein231d2da2019-07-22 16:44:45 -0600100 self.source_root = self.tempdir
101 self.PatchObject(constants, 'SOURCE_ROOT', new=self.tempdir)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600102
103
Alex Kleind91e95a2019-09-17 10:39:02 -0600104class 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 Klein68c8fdf2019-09-25 15:09:11 -0600110 artifacts.BundleImageArchives(self.target_request, self.response,
Alex Kleind91e95a2019-09-17 10:39:02 -0600111 self.validate_only_config)
112 patch.assert_not_called()
113
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700114 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 Kleind91e95a2019-09-17 10:39:02 -0600126 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 Klein68c8fdf2019-09-25 15:09:11 -0600130 artifacts.BundleImageArchives(request, self.response, self.api_config)
Alex Kleind91e95a2019-09-17 10:39:02 -0600131
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 Klein68c8fdf2019-09-25 15:09:11 -0600136 artifacts.BundleImageArchives(request, self.response, self.api_config)
Alex Kleind91e95a2019-09-17 10:39:02 -0600137
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 Klein68c8fdf2019-09-25 15:09:11 -0600143 artifacts.BundleImageArchives(request, self.response, self.api_config)
Alex Kleind91e95a2019-09-17 10:39:02 -0600144
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 Klein68c8fdf2019-09-25 15:09:11 -0600151 artifacts.BundleImageArchives(self.target_request, self.response,
Alex Kleind91e95a2019-09-17 10:39:02 -0600152 self.api_config)
153
Mike Frysinger678735c2019-09-28 18:23:28 -0400154 self.assertCountEqual(expected, [a.path for a in self.response.artifacts])
Alex Kleind91e95a2019-09-17 10:39:02 -0600155
156
Evan Hernandez9f125ac2019-04-08 17:18:47 -0600157class BundleImageZipTest(BundleTestCase):
158 """Unittests for BundleImageZip."""
159
Alex Klein231d2da2019-07-22 16:44:45 -0600160 def testValidateOnly(self):
161 """Sanity check that a validate only call does not execute any logic."""
162 patch = self.PatchObject(commands, 'BuildImageZip')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600163 artifacts.BundleImageZip(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600164 self.validate_only_config)
165 patch.assert_not_called()
166
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700167 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 Hernandez9f125ac2019-04-08 17:18:47 -0600177 def testBundleImageZip(self):
178 """BundleImageZip calls cbuildbot/commands with correct args."""
Michael Mortensen01910922019-07-24 14:48:10 -0600179 bundle_image_zip = self.PatchObject(
180 artifacts_svc, 'BundleImageZip', return_value='image.zip')
Evan Hernandez9f125ac2019-04-08 17:18:47 -0600181 self.PatchObject(os.path, 'exists', return_value=True)
Alex Klein68c8fdf2019-09-25 15:09:11 -0600182 artifacts.BundleImageZip(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600183 self.api_config)
Evan Hernandez9f125ac2019-04-08 17:18:47 -0600184 self.assertEqual(
Alex Klein68c8fdf2019-09-25 15:09:11 -0600185 [artifact.path for artifact in self.response.artifacts],
Alex Klein231d2da2019-07-22 16:44:45 -0600186 [os.path.join(self.output_dir, 'image.zip')])
187
188 latest = os.path.join(self.source_root, 'src/build/images/target/latest')
Evan Hernandez9f125ac2019-04-08 17:18:47 -0600189 self.assertEqual(
Michael Mortensen01910922019-07-24 14:48:10 -0600190 bundle_image_zip.call_args_list,
Alex Klein231d2da2019-07-22 16:44:45 -0600191 [mock.call(self.output_dir, latest)])
Evan Hernandez9f125ac2019-04-08 17:18:47 -0600192
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 Klein68c8fdf2019-09-25 15:09:11 -0600197 artifacts.BundleImageZip(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600198 self.api_config)
Evan Hernandez9f125ac2019-04-08 17:18:47 -0600199
200
Alex Klein68c8fdf2019-09-25 15:09:11 -0600201class BundleAutotestFilesTest(BundleTestCase):
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600202 """Unittests for BundleAutotestFiles."""
203
Alex Klein231d2da2019-07-22 16:44:45 -0600204 def testValidateOnly(self):
205 """Sanity check that a validate only call does not execute any logic."""
206 patch = self.PatchObject(artifacts_svc, 'BundleAutotestFiles')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600207 artifacts.BundleAutotestFiles(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600208 self.validate_only_config)
209 patch.assert_not_called()
210
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700211 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 Klein238d8862019-05-07 11:32:46 -0600221 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 Klein68c8fdf2019-09-25 15:09:11 -0600230 artifacts.BundleAutotestFiles(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600231 self.api_config)
Alex Klein238d8862019-05-07 11:32:46 -0600232
Alex Klein238d8862019-05-07 11:32:46 -0600233 # Verify the arguments are being passed through.
Alex Kleine21a0952019-08-23 16:08:16 -0600234 patch.assert_called_with(mock.ANY, self.sysroot, self.output_dir)
Alex Klein238d8862019-05-07 11:32:46 -0600235
236 # Verify the output proto is being populated correctly.
Alex Klein68c8fdf2019-09-25 15:09:11 -0600237 self.assertTrue(self.response.artifacts)
238 paths = [artifact.path for artifact in self.response.artifacts]
Mike Frysinger1f4478c2019-10-20 18:33:17 -0400239 self.assertCountEqual(list(files.values()), paths)
Alex Klein238d8862019-05-07 11:32:46 -0600240
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 Klein68c8fdf2019-09-25 15:09:11 -0600250 artifacts.BundleAutotestFiles(self.sysroot_request, self.response,
251 self.api_config)
Alex Klein238d8862019-05-07 11:32:46 -0600252
253 # Verify the arguments are being passed through.
Alex Kleine21a0952019-08-23 16:08:16 -0600254 patch.assert_called_with(mock.ANY, self.sysroot, self.output_dir)
Alex Klein238d8862019-05-07 11:32:46 -0600255
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 Frysinger1f4478c2019-10-20 18:33:17 -0400259 self.assertCountEqual(list(files.values()), paths)
Alex Klein238d8862019-05-07 11:32:46 -0600260
261 def testInvalidOutputDir(self):
262 """Test invalid output directory argument."""
Alex Klein68c8fdf2019-09-25 15:09:11 -0600263 request = self.SysrootRequest(chroot=self.chroot_path,
264 sysroot=self.sysroot_path)
Alex Klein238d8862019-05-07 11:32:46 -0600265
266 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600267 artifacts.BundleAutotestFiles(request, self.response, self.api_config)
Alex Klein238d8862019-05-07 11:32:46 -0600268
269 def testInvalidSysroot(self):
270 """Test no sysroot directory."""
Alex Klein68c8fdf2019-09-25 15:09:11 -0600271 request = self.SysrootRequest(chroot=self.chroot_path,
272 output_dir=self.output_dir)
Alex Klein238d8862019-05-07 11:32:46 -0600273
274 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600275 artifacts.BundleAutotestFiles(request, self.response, self.api_config)
Alex Klein238d8862019-05-07 11:32:46 -0600276
277 def testSysrootDoesNotExist(self):
278 """Test dies when no sysroot does not exist."""
Alex Klein68c8fdf2019-09-25 15:09:11 -0600279 request = self.SysrootRequest(chroot=self.chroot_path,
280 sysroot='/does/not/exist',
281 output_dir=self.output_dir)
Alex Klein238d8862019-05-07 11:32:46 -0600282
283 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600284 artifacts.BundleAutotestFiles(request, self.response, self.api_config)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600285
286
287class BundleTastFilesTest(BundleTestCase):
288 """Unittests for BundleTastFiles."""
289
Alex Klein231d2da2019-07-22 16:44:45 -0600290 def testValidateOnly(self):
291 """Sanity check that a validate only call does not execute any logic."""
292 patch = self.PatchObject(artifacts_svc, 'BundleTastFiles')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600293 artifacts.BundleTastFiles(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600294 self.validate_only_config)
295 patch.assert_not_called()
296
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700297 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 Hernandez9a5d3122019-04-09 10:51:23 -0600307 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 Klein68c8fdf2019-09-25 15:09:11 -0600312 artifacts.BundleTastFiles(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600313 self.api_config)
Evan Hernandez9a5d3122019-04-09 10:51:23 -0600314
Alex Kleinb9d810b2019-07-01 12:38:02 -0600315 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 Klein171da612019-08-06 14:00:42 -0600324 chroot = chroot_lib.Chroot(chroot_dir)
Alex Kleinb9d810b2019-07-01 12:38:02 -0600325 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 Klein68c8fdf2019-09-25 15:09:11 -0600335 artifacts.BundleTastFiles(request, self.response, self.api_config)
Alex Kleinb9d810b2019-07-01 12:38:02 -0600336 self.assertEqual(
Alex Klein68c8fdf2019-09-25 15:09:11 -0600337 [artifact.path for artifact in self.response.artifacts],
Alex Kleinb9d810b2019-07-01 12:38:02 -0600338 [expected_archive])
339 bundle_patch.assert_called_once_with(chroot, sysroot, output_dir)
340
341 def testBundleTastFiles(self):
342 """BundleTastFiles calls service correctly."""
Alex Klein68c8fdf2019-09-25 15:09:11 -0600343 chroot = chroot_lib.Chroot(self.chroot_path,
344 env={'FEATURES': 'separatedebug'})
Alex Kleinb9d810b2019-07-01 12:38:02 -0600345
Alex Klein68c8fdf2019-09-25 15:09:11 -0600346 expected_archive = os.path.join(self.output_dir,
347 artifacts_svc.TAST_BUNDLE_NAME)
Alex Kleinb9d810b2019-07-01 12:38:02 -0600348 # Patch the service being called.
349 bundle_patch = self.PatchObject(artifacts_svc, 'BundleTastFiles',
350 return_value=expected_archive)
351
Alex Klein68c8fdf2019-09-25 15:09:11 -0600352 artifacts.BundleTastFiles(self.sysroot_request, self.response,
353 self.api_config)
Alex Kleinb9d810b2019-07-01 12:38:02 -0600354
355 # Make sure the artifact got recorded successfully.
Alex Klein68c8fdf2019-09-25 15:09:11 -0600356 self.assertTrue(self.response.artifacts)
357 self.assertEqual(expected_archive, self.response.artifacts[0].path)
Alex Kleinb9d810b2019-07-01 12:38:02 -0600358 # Make sure the service got called correctly.
Alex Klein68c8fdf2019-09-25 15:09:11 -0600359 bundle_patch.assert_called_once_with(chroot, self.sysroot, self.output_dir)
Alex Kleinb9d810b2019-07-01 12:38:02 -0600360
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600361
362class BundlePinnedGuestImagesTest(BundleTestCase):
363 """Unittests for BundlePinnedGuestImages."""
364
Alex Klein231d2da2019-07-22 16:44:45 -0600365 def testValidateOnly(self):
366 """Sanity check that a validate only call does not execute any logic."""
367 patch = self.PatchObject(commands, 'BuildPinnedGuestImagesTarball')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600368 artifacts.BundlePinnedGuestImages(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600369 self.validate_only_config)
370 patch.assert_not_called()
371
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700372 def testMockCall(self):
373 """Test that a mock call does not execute logic, returns mocked value."""
374 patch = self.PatchObject(commands, 'BuildPinnedGuestImagesTarball')
375 artifacts.BundlePinnedGuestImages(self.target_request, self.response,
376 self.mock_call_config)
377 patch.assert_not_called()
378 self.assertEqual(len(self.response.artifacts), 1)
379 self.assertEqual(self.response.artifacts[0].path,
380 os.path.join(self.output_dir,
381 'pinned-guest-images.tar.gz'))
382
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600383 def testBundlePinnedGuestImages(self):
384 """BundlePinnedGuestImages calls cbuildbot/commands with correct args."""
385 build_pinned_guest_images_tarball = self.PatchObject(
386 commands,
387 'BuildPinnedGuestImagesTarball',
388 return_value='pinned-guest-images.tar.gz')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600389 artifacts.BundlePinnedGuestImages(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600390 self.api_config)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600391 self.assertEqual(
Alex Klein68c8fdf2019-09-25 15:09:11 -0600392 [artifact.path for artifact in self.response.artifacts],
Alex Klein231d2da2019-07-22 16:44:45 -0600393 [os.path.join(self.output_dir, 'pinned-guest-images.tar.gz')])
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600394 self.assertEqual(build_pinned_guest_images_tarball.call_args_list,
Alex Klein231d2da2019-07-22 16:44:45 -0600395 [mock.call(self.source_root, 'target', self.output_dir)])
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600396
Evan Hernandez9a5d3122019-04-09 10:51:23 -0600397 def testBundlePinnedGuestImagesNoLogs(self):
Evan Hernandezde445982019-04-22 13:42:34 -0600398 """BundlePinnedGuestImages does not die when no pinned images found."""
Evan Hernandez9a5d3122019-04-09 10:51:23 -0600399 self.PatchObject(commands, 'BuildPinnedGuestImagesTarball',
400 return_value=None)
Alex Klein68c8fdf2019-09-25 15:09:11 -0600401 artifacts.BundlePinnedGuestImages(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600402 self.api_config)
Alex Klein68c8fdf2019-09-25 15:09:11 -0600403 self.assertFalse(self.response.artifacts)
Evan Hernandez9a5d3122019-04-09 10:51:23 -0600404
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600405
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700406class FetchPinnedGuestImagesTest(cros_test_lib.MockTempDirTestCase,
407 api_config.ApiConfigMixin, BundleRequestMixin):
408 """Unittests for FetchPinnedGuestImages."""
409
410 def setUp(self):
411 self.build_target = 'board'
412 self.chroot_dir = os.path.join(self.tempdir, 'chroot_dir')
413 self.sysroot_path = '/sysroot'
414 self.sysroot_dir = os.path.join(self.chroot_dir, 'sysroot')
415 osutils.SafeMakedirs(self.sysroot_dir)
416
417 self.input_request = artifacts_pb2.PinnedGuestImageUriRequest(
418 sysroot={'path': self.sysroot_path,
419 'build_target': {'name': self.build_target}},
420 chroot={'path': self.chroot_dir})
421
422 self.response = artifacts_pb2.PinnedGuestImageUriResponse()
423
424 def testValidateOnly(self):
425 """Sanity check that a validate only call does not execute any logic."""
426 patch = self.PatchObject(artifacts_svc, 'FetchPinnedGuestImages')
427 artifacts.FetchPinnedGuestImages(self.input_request, self.response,
428 self.validate_only_config)
429 patch.assert_not_called()
430
431 def testMockCall(self):
432 """Test that a mock call does not execute logic, returns mocked value."""
433 patch = self.PatchObject(artifacts_svc, 'FetchPinnedGuestImages')
434 artifacts.FetchPinnedGuestImages(self.input_request, self.response,
435 self.mock_call_config)
436 patch.assert_not_called()
437 self.assertEqual(len(self.response.pinned_images), 1)
438 self.assertEqual(self.response.pinned_images[0].filename,
439 'pinned_file.tar.gz')
440 self.assertEqual(self.response.pinned_images[0].uri,
441 'https://testuri.com')
442
443 def testFetchPinnedGuestImages(self):
444 """FetchPinnedGuestImages calls service with correct args."""
445 pins = []
446 pins.append(PinnedGuestImage(
447 filename='my_pinned_file.tar.gz', uri='https://the_testuri.com'))
448 self.PatchObject(artifacts_svc, 'FetchPinnedGuestImages',
449 return_value=pins)
450 artifacts.FetchPinnedGuestImages(self.input_request, self.response,
451 self.api_config)
452 self.assertEqual(len(self.response.pinned_images), 1)
453 self.assertEqual(self.response.pinned_images[0].filename,
454 'my_pinned_file.tar.gz')
455 self.assertEqual(self.response.pinned_images[0].uri,
456 'https://the_testuri.com')
457
458
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600459class BundleFirmwareTest(BundleTestCase):
460 """Unittests for BundleFirmware."""
461
Alex Klein231d2da2019-07-22 16:44:45 -0600462 def testValidateOnly(self):
463 """Sanity check that a validate only call does not execute any logic."""
464 patch = self.PatchObject(artifacts_svc, 'BundleTastFiles')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600465 artifacts.BundleFirmware(self.sysroot_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600466 self.validate_only_config)
467 patch.assert_not_called()
Michael Mortensen38675192019-06-28 16:52:55 +0000468
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700469 def testMockCall(self):
470 """Test that a mock call does not execute logic, returns mocked value."""
471 patch = self.PatchObject(artifacts_svc, 'BundleTastFiles')
472 artifacts.BundleFirmware(self.sysroot_request, self.response,
473 self.mock_call_config)
474 patch.assert_not_called()
475 self.assertEqual(len(self.response.artifacts), 1)
476 self.assertEqual(self.response.artifacts[0].path,
477 os.path.join(self.output_dir, 'firmware.tar.gz'))
478
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600479 def testBundleFirmware(self):
480 """BundleFirmware calls cbuildbot/commands with correct args."""
Alex Klein231d2da2019-07-22 16:44:45 -0600481 self.PatchObject(
482 artifacts_svc,
483 'BuildFirmwareArchive',
484 return_value=os.path.join(self.output_dir, 'firmware.tar.gz'))
485
Alex Klein68c8fdf2019-09-25 15:09:11 -0600486 artifacts.BundleFirmware(self.sysroot_request, self.response,
487 self.api_config)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600488 self.assertEqual(
Alex Klein231d2da2019-07-22 16:44:45 -0600489 [artifact.path for artifact in self.response.artifacts],
490 [os.path.join(self.output_dir, 'firmware.tar.gz')])
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600491
Evan Hernandez9a5d3122019-04-09 10:51:23 -0600492 def testBundleFirmwareNoLogs(self):
493 """BundleFirmware dies when no firmware found."""
494 self.PatchObject(commands, 'BuildFirmwareArchive', return_value=None)
495 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein68c8fdf2019-09-25 15:09:11 -0600496 artifacts.BundleFirmware(self.sysroot_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600497 self.api_config)
Evan Hernandez9a5d3122019-04-09 10:51:23 -0600498
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600499
500class BundleEbuildLogsTest(BundleTestCase):
501 """Unittests for BundleEbuildLogs."""
502
Alex Klein231d2da2019-07-22 16:44:45 -0600503 def testValidateOnly(self):
504 """Sanity check that a validate only call does not execute any logic."""
505 patch = self.PatchObject(commands, 'BuildEbuildLogsTarball')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600506 artifacts.BundleEbuildLogs(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600507 self.validate_only_config)
508 patch.assert_not_called()
Michael Mortensen3f382cb2019-07-29 13:21:49 -0600509
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700510 def testMockCall(self):
511 """Test that a mock call does not execute logic, returns mocked value."""
512 patch = self.PatchObject(commands, 'BuildEbuildLogsTarball')
513 artifacts.BundleEbuildLogs(self.target_request, self.response,
514 self.mock_call_config)
515 patch.assert_not_called()
516 self.assertEqual(len(self.response.artifacts), 1)
517 self.assertEqual(self.response.artifacts[0].path,
518 os.path.join(self.output_dir, 'ebuild-logs.tar.gz'))
519
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600520 def testBundleEbuildLogs(self):
521 """BundleEbuildLogs calls cbuildbot/commands with correct args."""
Michael Mortensen3f382cb2019-07-29 13:21:49 -0600522 bundle_ebuild_logs_tarball = self.PatchObject(
523 artifacts_svc, 'BundleEBuildLogsTarball',
524 return_value='ebuild-logs.tar.gz')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600525 artifacts.BundleEbuildLogs(self.sysroot_request, self.response,
526 self.api_config)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600527 self.assertEqual(
Michael Mortensen3f382cb2019-07-29 13:21:49 -0600528 [artifact.path for artifact in self.response.artifacts],
Alex Klein68c8fdf2019-09-25 15:09:11 -0600529 [os.path.join(self.output_dir, 'ebuild-logs.tar.gz')])
Evan Hernandeza478d802019-04-08 15:08:24 -0600530 self.assertEqual(
Michael Mortensen3f382cb2019-07-29 13:21:49 -0600531 bundle_ebuild_logs_tarball.call_args_list,
Alex Klein68c8fdf2019-09-25 15:09:11 -0600532 [mock.call(mock.ANY, self.sysroot, self.output_dir)])
Michael Mortensen3f382cb2019-07-29 13:21:49 -0600533
534 def testBundleEBuildLogsOldProto(self):
535 bundle_ebuild_logs_tarball = self.PatchObject(
536 artifacts_svc, 'BundleEBuildLogsTarball',
537 return_value='ebuild-logs.tar.gz')
Alex Klein231d2da2019-07-22 16:44:45 -0600538
Alex Klein68c8fdf2019-09-25 15:09:11 -0600539 artifacts.BundleEbuildLogs(self.target_request, self.response,
Alex Klein231d2da2019-07-22 16:44:45 -0600540 self.api_config)
541
Michael Mortensen3f382cb2019-07-29 13:21:49 -0600542 self.assertEqual(
543 bundle_ebuild_logs_tarball.call_args_list,
Alex Klein68c8fdf2019-09-25 15:09:11 -0600544 [mock.call(mock.ANY, self.sysroot, self.output_dir)])
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600545
Evan Hernandez9a5d3122019-04-09 10:51:23 -0600546 def testBundleEbuildLogsNoLogs(self):
547 """BundleEbuildLogs dies when no logs found."""
548 self.PatchObject(commands, 'BuildEbuildLogsTarball', return_value=None)
549 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein68c8fdf2019-09-25 15:09:11 -0600550 artifacts.BundleEbuildLogs(self.sysroot_request, self.response,
551 self.api_config)
Evan Hernandez9a5d3122019-04-09 10:51:23 -0600552
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600553
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600554class BundleChromeOSConfigTest(BundleTestCase):
555 """Unittests for BundleChromeOSConfig"""
556
557 def testValidateOnly(self):
558 """Sanity check that a validate only call does not execute any logic."""
559 patch = self.PatchObject(artifacts_svc, 'BundleChromeOSConfig')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600560 artifacts.BundleChromeOSConfig(self.target_request, self.response,
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600561 self.validate_only_config)
562 patch.assert_not_called()
563
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700564 def testMockCall(self):
565 """Test that a mock call does not execute logic, returns mocked value."""
566 patch = self.PatchObject(artifacts_svc, 'BundleChromeOSConfig')
567 artifacts.BundleChromeOSConfig(self.target_request, self.response,
568 self.mock_call_config)
569 patch.assert_not_called()
570 self.assertEqual(len(self.response.artifacts), 1)
571 self.assertEqual(self.response.artifacts[0].path,
572 os.path.join(self.output_dir, 'config.yaml'))
573
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600574 def testBundleChromeOSConfigCallWithSysroot(self):
575 """Call with a request that sets sysroot."""
576 bundle_chromeos_config = self.PatchObject(
577 artifacts_svc, 'BundleChromeOSConfig', return_value='config.yaml')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600578 artifacts.BundleChromeOSConfig(self.sysroot_request, self.response,
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600579 self.api_config)
580 self.assertEqual(
Alex Klein68c8fdf2019-09-25 15:09:11 -0600581 [artifact.path for artifact in self.response.artifacts],
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600582 [os.path.join(self.output_dir, 'config.yaml')])
583
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600584 self.assertEqual(bundle_chromeos_config.call_args_list,
Alex Klein68c8fdf2019-09-25 15:09:11 -0600585 [mock.call(mock.ANY, self.sysroot, self.output_dir)])
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600586
587 def testBundleChromeOSConfigCallWithBuildTarget(self):
588 """Call with a request that sets build_target."""
589 bundle_chromeos_config = self.PatchObject(
590 artifacts_svc, 'BundleChromeOSConfig', return_value='config.yaml')
Alex Klein68c8fdf2019-09-25 15:09:11 -0600591 artifacts.BundleChromeOSConfig(self.target_request, self.response,
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600592 self.api_config)
593
594 self.assertEqual(
Alex Klein68c8fdf2019-09-25 15:09:11 -0600595 [artifact.path for artifact in self.response.artifacts],
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600596 [os.path.join(self.output_dir, 'config.yaml')])
597
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600598 self.assertEqual(bundle_chromeos_config.call_args_list,
Alex Klein68c8fdf2019-09-25 15:09:11 -0600599 [mock.call(mock.ANY, self.sysroot, self.output_dir)])
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600600
601 def testBundleChromeOSConfigNoConfigFound(self):
602 """An error is raised if the config payload isn't found."""
603 self.PatchObject(artifacts_svc, 'BundleChromeOSConfig', return_value=None)
604
605 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein68c8fdf2019-09-25 15:09:11 -0600606 artifacts.BundleChromeOSConfig(self.sysroot_request, self.response,
Andrew Lamb67bd68f2019-08-15 09:09:15 -0600607 self.api_config)
608
609
Alex Klein231d2da2019-07-22 16:44:45 -0600610class BundleTestUpdatePayloadsTest(cros_test_lib.MockTempDirTestCase,
611 api_config.ApiConfigMixin):
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600612 """Unittests for BundleTestUpdatePayloads."""
613
614 def setUp(self):
615 self.source_root = os.path.join(self.tempdir, 'cros')
616 osutils.SafeMakedirs(self.source_root)
617
618 self.archive_root = os.path.join(self.tempdir, 'output')
619 osutils.SafeMakedirs(self.archive_root)
620
621 self.target = 'target'
Evan Hernandez59690b72019-04-08 16:24:45 -0600622 self.image_root = os.path.join(self.source_root,
623 'src/build/images/target/latest')
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600624
625 self.input_proto = artifacts_pb2.BundleRequest()
626 self.input_proto.build_target.name = self.target
627 self.input_proto.output_dir = self.archive_root
628 self.output_proto = artifacts_pb2.BundleResponse()
629
630 self.PatchObject(constants, 'SOURCE_ROOT', new=self.source_root)
631
Alex Kleincb541e82019-06-26 15:06:11 -0600632 def MockPayloads(image_path, archive_dir):
633 osutils.WriteFile(os.path.join(archive_dir, 'payload1.bin'), image_path)
634 osutils.WriteFile(os.path.join(archive_dir, 'payload2.bin'), image_path)
635 return [os.path.join(archive_dir, 'payload1.bin'),
636 os.path.join(archive_dir, 'payload2.bin')]
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600637
Alex Kleincb541e82019-06-26 15:06:11 -0600638 self.bundle_patch = self.PatchObject(
639 artifacts_svc, 'BundleTestUpdatePayloads', side_effect=MockPayloads)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600640
Alex Klein231d2da2019-07-22 16:44:45 -0600641 def testValidateOnly(self):
642 """Sanity check that a validate only call does not execute any logic."""
643 patch = self.PatchObject(artifacts_svc, 'BundleTestUpdatePayloads')
644 artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto,
645 self.validate_only_config)
646 patch.assert_not_called()
647
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700648 def testMockCall(self):
649 """Test that a mock call does not execute logic, returns mocked value."""
650 patch = self.PatchObject(artifacts_svc, 'BundleTestUpdatePayloads')
651 artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto,
652 self.mock_call_config)
653 patch.assert_not_called()
654 self.assertEqual(len(self.output_proto.artifacts), 1)
655 self.assertEqual(self.output_proto.artifacts[0].path,
656 os.path.join(self.archive_root, 'payload1.bin'))
657
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600658 def testBundleTestUpdatePayloads(self):
659 """BundleTestUpdatePayloads calls cbuildbot/commands with correct args."""
660 image_path = os.path.join(self.image_root, constants.BASE_IMAGE_BIN)
661 osutils.WriteFile(image_path, 'image!', makedirs=True)
662
Alex Klein231d2da2019-07-22 16:44:45 -0600663 artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto,
664 self.api_config)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600665
666 actual = [
667 os.path.relpath(artifact.path, self.archive_root)
668 for artifact in self.output_proto.artifacts
669 ]
Alex Kleincb541e82019-06-26 15:06:11 -0600670 expected = ['payload1.bin', 'payload2.bin']
Mike Frysinger678735c2019-09-28 18:23:28 -0400671 self.assertCountEqual(actual, expected)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600672
673 actual = [
674 os.path.relpath(path, self.archive_root)
675 for path in osutils.DirectoryIterator(self.archive_root)
676 ]
Mike Frysinger678735c2019-09-28 18:23:28 -0400677 self.assertCountEqual(actual, expected)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600678
Evan Hernandez9f125ac2019-04-08 17:18:47 -0600679 def testBundleTestUpdatePayloadsNoImageDir(self):
680 """BundleTestUpdatePayloads dies if no image dir is found."""
681 # Intentionally do not write image directory.
Alex Kleind2bf1462019-10-24 16:37:04 -0600682 artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto,
683 self.api_config)
684 self.assertFalse(self.output_proto.artifacts)
Evan Hernandez9f125ac2019-04-08 17:18:47 -0600685
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600686 def testBundleTestUpdatePayloadsNoImage(self):
687 """BundleTestUpdatePayloads dies if no usable image is found for target."""
Evan Hernandez9f125ac2019-04-08 17:18:47 -0600688 # Intentionally do not write image, but create the directory.
689 osutils.SafeMakedirs(self.image_root)
Evan Hernandezf388cbf2019-04-01 11:15:23 -0600690 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600691 artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto,
692 self.api_config)
Alex Klein6504eca2019-04-18 15:37:56 -0600693
694
Alex Klein231d2da2019-07-22 16:44:45 -0600695class BundleSimpleChromeArtifactsTest(cros_test_lib.MockTempDirTestCase,
696 api_config.ApiConfigMixin):
Alex Klein2275d692019-04-23 16:04:12 -0600697 """BundleSimpleChromeArtifacts tests."""
698
699 def setUp(self):
700 self.chroot_dir = os.path.join(self.tempdir, 'chroot_dir')
701 self.sysroot_path = '/sysroot'
702 self.sysroot_dir = os.path.join(self.chroot_dir, 'sysroot')
703 osutils.SafeMakedirs(self.sysroot_dir)
704 self.output_dir = os.path.join(self.tempdir, 'output_dir')
705 osutils.SafeMakedirs(self.output_dir)
706
707 self.does_not_exist = os.path.join(self.tempdir, 'does_not_exist')
708
Alex Klein231d2da2019-07-22 16:44:45 -0600709 self.response = artifacts_pb2.BundleResponse()
710
Alex Klein2275d692019-04-23 16:04:12 -0600711 def _GetRequest(self, chroot=None, sysroot=None, build_target=None,
712 output_dir=None):
713 """Helper to create a request message instance.
714
715 Args:
716 chroot (str): The chroot path.
717 sysroot (str): The sysroot path.
718 build_target (str): The build target name.
719 output_dir (str): The output directory.
720 """
721 return artifacts_pb2.BundleRequest(
722 sysroot={'path': sysroot, 'build_target': {'name': build_target}},
723 chroot={'path': chroot}, output_dir=output_dir)
724
Alex Klein231d2da2019-07-22 16:44:45 -0600725 def testValidateOnly(self):
726 """Sanity check that a validate only call does not execute any logic."""
727 patch = self.PatchObject(artifacts_svc, 'BundleSimpleChromeArtifacts')
728 request = self._GetRequest(chroot=self.chroot_dir,
729 sysroot=self.sysroot_path,
730 build_target='board', output_dir=self.output_dir)
731 artifacts.BundleSimpleChromeArtifacts(request, self.response,
732 self.validate_only_config)
733 patch.assert_not_called()
Alex Klein2275d692019-04-23 16:04:12 -0600734
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700735 def testMockCall(self):
736 """Test that a mock call does not execute logic, returns mocked value."""
737 patch = self.PatchObject(artifacts_svc, 'BundleSimpleChromeArtifacts')
738 request = self._GetRequest(chroot=self.chroot_dir,
739 sysroot=self.sysroot_path,
740 build_target='board', output_dir=self.output_dir)
741 artifacts.BundleSimpleChromeArtifacts(request, self.response,
742 self.mock_call_config)
743 patch.assert_not_called()
744 self.assertEqual(len(self.response.artifacts), 1)
745 self.assertEqual(self.response.artifacts[0].path,
746 os.path.join(self.output_dir, 'simple_chrome.txt'))
747
Alex Klein2275d692019-04-23 16:04:12 -0600748 def testNoBuildTarget(self):
749 """Test no build target fails."""
750 request = self._GetRequest(chroot=self.chroot_dir,
751 sysroot=self.sysroot_path,
752 output_dir=self.output_dir)
Alex Klein231d2da2019-07-22 16:44:45 -0600753 response = self.response
Alex Klein2275d692019-04-23 16:04:12 -0600754 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600755 artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config)
Alex Klein2275d692019-04-23 16:04:12 -0600756
757 def testNoSysroot(self):
758 """Test no sysroot fails."""
759 request = self._GetRequest(build_target='board', output_dir=self.output_dir)
Alex Klein231d2da2019-07-22 16:44:45 -0600760 response = self.response
Alex Klein2275d692019-04-23 16:04:12 -0600761 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600762 artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config)
Alex Klein2275d692019-04-23 16:04:12 -0600763
764 def testSysrootDoesNotExist(self):
765 """Test no sysroot fails."""
766 request = self._GetRequest(build_target='board', output_dir=self.output_dir,
767 sysroot=self.does_not_exist)
Alex Klein231d2da2019-07-22 16:44:45 -0600768 response = self.response
Alex Klein2275d692019-04-23 16:04:12 -0600769 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600770 artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config)
Alex Klein2275d692019-04-23 16:04:12 -0600771
772 def testNoOutputDir(self):
773 """Test no output dir fails."""
774 request = self._GetRequest(chroot=self.chroot_dir,
775 sysroot=self.sysroot_path,
776 build_target='board')
Alex Klein231d2da2019-07-22 16:44:45 -0600777 response = self.response
Alex Klein2275d692019-04-23 16:04:12 -0600778 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600779 artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config)
Alex Klein2275d692019-04-23 16:04:12 -0600780
781 def testOutputDirDoesNotExist(self):
782 """Test no output dir fails."""
783 request = self._GetRequest(chroot=self.chroot_dir,
784 sysroot=self.sysroot_path,
785 build_target='board',
786 output_dir=self.does_not_exist)
Alex Klein231d2da2019-07-22 16:44:45 -0600787 response = self.response
Alex Klein2275d692019-04-23 16:04:12 -0600788 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600789 artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config)
Alex Klein2275d692019-04-23 16:04:12 -0600790
791 def testOutputHandling(self):
792 """Test response output."""
793 files = ['file1', 'file2', 'file3']
794 expected_files = [os.path.join(self.output_dir, f) for f in files]
795 self.PatchObject(artifacts_svc, 'BundleSimpleChromeArtifacts',
796 return_value=expected_files)
797 request = self._GetRequest(chroot=self.chroot_dir,
798 sysroot=self.sysroot_path,
799 build_target='board', output_dir=self.output_dir)
Alex Klein231d2da2019-07-22 16:44:45 -0600800 response = self.response
Alex Klein2275d692019-04-23 16:04:12 -0600801
Alex Klein231d2da2019-07-22 16:44:45 -0600802 artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config)
Alex Klein2275d692019-04-23 16:04:12 -0600803
804 self.assertTrue(response.artifacts)
Mike Frysinger678735c2019-09-28 18:23:28 -0400805 self.assertCountEqual(expected_files, [a.path for a in response.artifacts])
Alex Klein2275d692019-04-23 16:04:12 -0600806
807
Alex Klein231d2da2019-07-22 16:44:45 -0600808class BundleVmFilesTest(cros_test_lib.MockTempDirTestCase,
809 api_config.ApiConfigMixin):
Alex Klein6504eca2019-04-18 15:37:56 -0600810 """BuildVmFiles tests."""
811
Alex Klein231d2da2019-07-22 16:44:45 -0600812 def setUp(self):
813 self.output_dir = os.path.join(self.tempdir, 'output')
814 osutils.SafeMakedirs(self.output_dir)
815
816 self.response = artifacts_pb2.BundleResponse()
817
Alex Klein6504eca2019-04-18 15:37:56 -0600818 def _GetInput(self, chroot=None, sysroot=None, test_results_dir=None,
819 output_dir=None):
820 """Helper to build out an input message instance.
821
822 Args:
823 chroot (str|None): The chroot path.
824 sysroot (str|None): The sysroot path relative to the chroot.
825 test_results_dir (str|None): The test results directory relative to the
826 sysroot.
827 output_dir (str|None): The directory where the results tarball should be
828 saved.
829 """
830 return artifacts_pb2.BundleVmFilesRequest(
831 chroot={'path': chroot}, sysroot={'path': sysroot},
832 test_results_dir=test_results_dir, output_dir=output_dir,
833 )
834
Alex Klein231d2da2019-07-22 16:44:45 -0600835 def testValidateOnly(self):
836 """Sanity check that a validate only call does not execute any logic."""
837 patch = self.PatchObject(artifacts_svc, 'BundleVmFiles')
838 in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board',
839 test_results_dir='/test/results',
840 output_dir=self.output_dir)
841 artifacts.BundleVmFiles(in_proto, self.response, self.validate_only_config)
842 patch.assert_not_called()
Alex Klein6504eca2019-04-18 15:37:56 -0600843
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700844 def testMockCall(self):
845 """Test that a mock call does not execute logic, returns mocked value."""
846 patch = self.PatchObject(artifacts_svc, 'BundleVmFiles')
847 in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board',
848 test_results_dir='/test/results',
849 output_dir=self.output_dir)
850 artifacts.BundleVmFiles(in_proto, self.response, self.mock_call_config)
851 patch.assert_not_called()
852 self.assertEqual(len(self.response.artifacts), 1)
853 self.assertEqual(self.response.artifacts[0].path,
854 os.path.join(self.output_dir, 'f1.tar'))
855
Alex Klein6504eca2019-04-18 15:37:56 -0600856 def testChrootMissing(self):
857 """Test error handling for missing chroot."""
858 in_proto = self._GetInput(sysroot='/build/board',
859 test_results_dir='/test/results',
Alex Klein231d2da2019-07-22 16:44:45 -0600860 output_dir=self.output_dir)
Alex Klein6504eca2019-04-18 15:37:56 -0600861
862 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600863 artifacts.BundleVmFiles(in_proto, self.response, self.api_config)
Alex Klein6504eca2019-04-18 15:37:56 -0600864
Alex Klein6504eca2019-04-18 15:37:56 -0600865 def testTestResultsDirMissing(self):
866 """Test error handling for missing test results directory."""
867 in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board',
Alex Klein231d2da2019-07-22 16:44:45 -0600868 output_dir=self.output_dir)
Alex Klein6504eca2019-04-18 15:37:56 -0600869
870 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600871 artifacts.BundleVmFiles(in_proto, self.response, self.api_config)
Alex Klein6504eca2019-04-18 15:37:56 -0600872
873 def testOutputDirMissing(self):
874 """Test error handling for missing output directory."""
875 in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board',
876 test_results_dir='/test/results')
Alex Klein6504eca2019-04-18 15:37:56 -0600877
878 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600879 artifacts.BundleVmFiles(in_proto, self.response, self.api_config)
880
881 def testOutputDirDoesNotExist(self):
882 """Test error handling for output directory that does not exist."""
883 in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board',
884 output_dir=os.path.join(self.tempdir, 'dne'),
885 test_results_dir='/test/results')
886
887 with self.assertRaises(cros_build_lib.DieSystemExit):
888 artifacts.BundleVmFiles(in_proto, self.response, self.api_config)
Alex Klein6504eca2019-04-18 15:37:56 -0600889
890 def testValidCall(self):
891 """Test image dir building."""
892 in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board',
893 test_results_dir='/test/results',
Alex Klein231d2da2019-07-22 16:44:45 -0600894 output_dir=self.output_dir)
895
Alex Klein6504eca2019-04-18 15:37:56 -0600896 expected_files = ['/tmp/output/f1.tar', '/tmp/output/f2.tar']
Michael Mortensen51f06722019-07-18 09:55:50 -0600897 patch = self.PatchObject(artifacts_svc, 'BundleVmFiles',
Alex Klein6504eca2019-04-18 15:37:56 -0600898 return_value=expected_files)
899
Alex Klein231d2da2019-07-22 16:44:45 -0600900 artifacts.BundleVmFiles(in_proto, self.response, self.api_config)
Alex Klein6504eca2019-04-18 15:37:56 -0600901
Alex Klein231d2da2019-07-22 16:44:45 -0600902 patch.assert_called_with(mock.ANY, '/test/results', self.output_dir)
Alex Klein6504eca2019-04-18 15:37:56 -0600903
904 # Make sure we have artifacts, and that every artifact is an expected file.
Alex Klein231d2da2019-07-22 16:44:45 -0600905 self.assertTrue(self.response.artifacts)
906 for artifact in self.response.artifacts:
Alex Klein6504eca2019-04-18 15:37:56 -0600907 self.assertIn(artifact.path, expected_files)
908 expected_files.remove(artifact.path)
909
910 # Make sure we've seen all of the expected files.
911 self.assertFalse(expected_files)
Tiancong Wangc4805b72019-06-11 12:12:03 -0700912
Alex Kleinb9d810b2019-07-01 12:38:02 -0600913
Tiancong Wang50b80a92019-08-01 14:46:15 -0700914
915class BundleAFDOGenerationArtifactsTestCase(
Alex Klein231d2da2019-07-22 16:44:45 -0600916 cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin):
Tiancong Wang50b80a92019-08-01 14:46:15 -0700917 """Unittests for BundleAFDOGenerationArtifacts."""
918
919 @staticmethod
920 def mock_die(message, *args):
921 raise cros_build_lib.DieSystemExit(message % args)
Tiancong Wangc4805b72019-06-11 12:12:03 -0700922
923 def setUp(self):
924 self.chroot_dir = os.path.join(self.tempdir, 'chroot_dir')
925 osutils.SafeMakedirs(self.chroot_dir)
926 temp_dir = os.path.join(self.chroot_dir, 'tmp')
927 osutils.SafeMakedirs(temp_dir)
928 self.output_dir = os.path.join(self.tempdir, 'output_dir')
929 osutils.SafeMakedirs(self.output_dir)
Tiancong Wang2ade7932019-09-27 14:15:40 -0700930 self.chrome_root = os.path.join(self.tempdir, 'chrome_root')
931 osutils.SafeMakedirs(self.chrome_root)
Tiancong Wangc4805b72019-06-11 12:12:03 -0700932 self.build_target = 'board'
Tiancong Wang24a3df72019-08-20 15:48:51 -0700933 self.valid_artifact_type = toolchain_pb2.ORDERFILE
934 self.invalid_artifact_type = toolchain_pb2.NONE_TYPE
Tiancong Wangc4805b72019-06-11 12:12:03 -0700935 self.does_not_exist = os.path.join(self.tempdir, 'does_not_exist')
Tiancong Wang50b80a92019-08-01 14:46:15 -0700936 self.PatchObject(cros_build_lib, 'Die', new=self.mock_die)
Tiancong Wangc4805b72019-06-11 12:12:03 -0700937
Alex Klein231d2da2019-07-22 16:44:45 -0600938 self.response = artifacts_pb2.BundleResponse()
939
Tiancong Wang2ade7932019-09-27 14:15:40 -0700940 def _GetRequest(self, chroot=None, build_target=None, chrome_root=None,
941 output_dir=None, artifact_type=None):
Tiancong Wangc4805b72019-06-11 12:12:03 -0700942 """Helper to create a request message instance.
943
944 Args:
945 chroot (str): The chroot path.
946 build_target (str): The build target name.
Tiancong Wang2ade7932019-09-27 14:15:40 -0700947 chrome_root (str): The path to Chrome root.
Tiancong Wangc4805b72019-06-11 12:12:03 -0700948 output_dir (str): The output directory.
Tiancong Wang50b80a92019-08-01 14:46:15 -0700949 artifact_type (artifacts_pb2.AFDOArtifactType):
950 The type of the artifact.
Tiancong Wangc4805b72019-06-11 12:12:03 -0700951 """
Tiancong Wang50b80a92019-08-01 14:46:15 -0700952 return artifacts_pb2.BundleChromeAFDORequest(
Tiancong Wang2ade7932019-09-27 14:15:40 -0700953 chroot={'path': chroot, 'chrome_dir': chrome_root},
Tiancong Wang50b80a92019-08-01 14:46:15 -0700954 build_target={'name': build_target},
955 output_dir=output_dir,
956 artifact_type=artifact_type,
Tiancong Wangc4805b72019-06-11 12:12:03 -0700957 )
958
Alex Klein231d2da2019-07-22 16:44:45 -0600959 def testValidateOnly(self):
960 """Sanity check that a validate only call does not execute any logic."""
961 patch = self.PatchObject(artifacts_svc,
Tiancong Wang50b80a92019-08-01 14:46:15 -0700962 'BundleAFDOGenerationArtifacts')
Alex Klein231d2da2019-07-22 16:44:45 -0600963 request = self._GetRequest(chroot=self.chroot_dir,
964 build_target=self.build_target,
Tiancong Wang2ade7932019-09-27 14:15:40 -0700965 chrome_root=self.chrome_root,
Tiancong Wang50b80a92019-08-01 14:46:15 -0700966 output_dir=self.output_dir,
967 artifact_type=self.valid_artifact_type)
968 artifacts.BundleAFDOGenerationArtifacts(request, self.response,
969 self.validate_only_config)
Alex Klein231d2da2019-07-22 16:44:45 -0600970 patch.assert_not_called()
Tiancong Wangc4805b72019-06-11 12:12:03 -0700971
Michael Mortensen2d6a2402019-11-26 13:40:40 -0700972 def testMockCall(self):
973 """Test that a mock call does not execute logic, returns mocked value."""
974 patch = self.PatchObject(artifacts_svc,
975 'BundleAFDOGenerationArtifacts')
976 request = self._GetRequest(chroot=self.chroot_dir,
977 build_target=self.build_target,
978 chrome_root=self.chrome_root,
979 output_dir=self.output_dir,
980 artifact_type=self.valid_artifact_type)
981 artifacts.BundleAFDOGenerationArtifacts(request, self.response,
982 self.mock_call_config)
983 patch.assert_not_called()
984 self.assertEqual(len(self.response.artifacts), 1)
985 self.assertEqual(self.response.artifacts[0].path,
986 os.path.join(self.output_dir, 'artifact1'))
987
Tiancong Wangc4805b72019-06-11 12:12:03 -0700988 def testNoBuildTarget(self):
989 """Test no build target fails."""
990 request = self._GetRequest(chroot=self.chroot_dir,
Tiancong Wang2ade7932019-09-27 14:15:40 -0700991 chrome_root=self.chrome_root,
Tiancong Wang50b80a92019-08-01 14:46:15 -0700992 output_dir=self.output_dir,
993 artifact_type=self.valid_artifact_type)
994 with self.assertRaises(cros_build_lib.DieSystemExit) as context:
995 artifacts.BundleAFDOGenerationArtifacts(request, self.response,
996 self.api_config)
997 self.assertEqual('build_target.name is required.',
998 str(context.exception))
Tiancong Wangc4805b72019-06-11 12:12:03 -0700999
Tiancong Wang2ade7932019-09-27 14:15:40 -07001000 def testNoChromeRoot(self):
1001 """Test no chrome root fails."""
1002 request = self._GetRequest(chroot=self.chroot_dir,
1003 build_target=self.build_target,
1004 output_dir=self.output_dir,
1005 artifact_type=self.valid_artifact_type)
1006 with self.assertRaises(cros_build_lib.DieSystemExit) as context:
1007 artifacts.BundleAFDOGenerationArtifacts(request, self.response,
1008 self.api_config)
1009 self.assertEqual('chroot.chrome_dir path does not exist: ',
1010 str(context.exception))
1011
Tiancong Wangc4805b72019-06-11 12:12:03 -07001012 def testNoOutputDir(self):
1013 """Test no output dir fails."""
1014 request = self._GetRequest(chroot=self.chroot_dir,
Tiancong Wang50b80a92019-08-01 14:46:15 -07001015 build_target=self.build_target,
Tiancong Wang2ade7932019-09-27 14:15:40 -07001016 chrome_root=self.chrome_root,
Tiancong Wang50b80a92019-08-01 14:46:15 -07001017 artifact_type=self.valid_artifact_type)
1018 with self.assertRaises(cros_build_lib.DieSystemExit) as context:
1019 artifacts.BundleAFDOGenerationArtifacts(request, self.response,
1020 self.api_config)
1021 self.assertEqual('output_dir is required.',
1022 str(context.exception))
Tiancong Wangc4805b72019-06-11 12:12:03 -07001023
1024 def testOutputDirDoesNotExist(self):
1025 """Test output directory not existing fails."""
1026 request = self._GetRequest(chroot=self.chroot_dir,
Tiancong Wangc4805b72019-06-11 12:12:03 -07001027 build_target=self.build_target,
Tiancong Wang2ade7932019-09-27 14:15:40 -07001028 chrome_root=self.chrome_root,
Tiancong Wang50b80a92019-08-01 14:46:15 -07001029 output_dir=self.does_not_exist,
1030 artifact_type=self.valid_artifact_type)
1031 with self.assertRaises(cros_build_lib.DieSystemExit) as context:
1032 artifacts.BundleAFDOGenerationArtifacts(request, self.response,
1033 self.api_config)
1034 self.assertEqual(
1035 'output_dir path does not exist: %s' % self.does_not_exist,
1036 str(context.exception))
Tiancong Wangc4805b72019-06-11 12:12:03 -07001037
Tiancong Wang50b80a92019-08-01 14:46:15 -07001038 def testNoArtifactType(self):
1039 """Test no artifact type."""
1040 request = self._GetRequest(chroot=self.chroot_dir,
1041 build_target=self.build_target,
Tiancong Wang2ade7932019-09-27 14:15:40 -07001042 chrome_root=self.chrome_root,
Tiancong Wang50b80a92019-08-01 14:46:15 -07001043 output_dir=self.output_dir)
1044 with self.assertRaises(cros_build_lib.DieSystemExit) as context:
1045 artifacts.BundleAFDOGenerationArtifacts(request, self.response,
1046 self.api_config)
1047 self.assertIn('artifact_type (0) must be in',
1048 str(context.exception))
1049
1050 def testWrongArtifactType(self):
1051 """Test passing wrong artifact type."""
1052 request = self._GetRequest(chroot=self.chroot_dir,
1053 build_target=self.build_target,
Tiancong Wang2ade7932019-09-27 14:15:40 -07001054 chrome_root=self.chrome_root,
Tiancong Wang50b80a92019-08-01 14:46:15 -07001055 output_dir=self.output_dir,
1056 artifact_type=self.invalid_artifact_type)
1057 with self.assertRaises(cros_build_lib.DieSystemExit) as context:
1058 artifacts.BundleAFDOGenerationArtifacts(request, self.response,
1059 self.api_config)
Tiancong Wang24a3df72019-08-20 15:48:51 -07001060 self.assertIn('artifact_type (%d) must be in' % self.invalid_artifact_type,
Tiancong Wang50b80a92019-08-01 14:46:15 -07001061 str(context.exception))
1062
1063 def testOutputHandlingOnOrderfile(self,
Tiancong Wang24a3df72019-08-20 15:48:51 -07001064 artifact_type=toolchain_pb2.ORDERFILE):
Tiancong Wang50b80a92019-08-01 14:46:15 -07001065 """Test response output for orderfile."""
1066 files = ['artifact1', 'artifact2', 'artifact3']
Tiancong Wangc4805b72019-06-11 12:12:03 -07001067 expected_files = [os.path.join(self.output_dir, f) for f in files]
Tiancong Wang50b80a92019-08-01 14:46:15 -07001068 self.PatchObject(artifacts_svc, 'BundleAFDOGenerationArtifacts',
Tiancong Wangc4805b72019-06-11 12:12:03 -07001069 return_value=expected_files)
Alex Klein231d2da2019-07-22 16:44:45 -06001070
Tiancong Wangc4805b72019-06-11 12:12:03 -07001071 request = self._GetRequest(chroot=self.chroot_dir,
Tiancong Wangc4805b72019-06-11 12:12:03 -07001072 build_target=self.build_target,
Tiancong Wang2ade7932019-09-27 14:15:40 -07001073 chrome_root=self.chrome_root,
Tiancong Wang50b80a92019-08-01 14:46:15 -07001074 output_dir=self.output_dir,
1075 artifact_type=artifact_type)
Tiancong Wangc4805b72019-06-11 12:12:03 -07001076
Tiancong Wang50b80a92019-08-01 14:46:15 -07001077 artifacts.BundleAFDOGenerationArtifacts(request, self.response,
1078 self.api_config)
Tiancong Wangc4805b72019-06-11 12:12:03 -07001079
Tiancong Wang50b80a92019-08-01 14:46:15 -07001080 self.assertTrue(self.response.artifacts)
Mike Frysinger678735c2019-09-28 18:23:28 -04001081 self.assertCountEqual(expected_files,
Tiancong Wang50b80a92019-08-01 14:46:15 -07001082 [a.path for a in self.response.artifacts])
1083
1084 def testOutputHandlingOnAFDO(self):
1085 """Test response output for AFDO."""
1086 self.testOutputHandlingOnOrderfile(
Tiancong Wang24a3df72019-08-20 15:48:51 -07001087 artifact_type=toolchain_pb2.BENCHMARK_AFDO)
Alex Klein0b1cbfc2019-08-14 10:09:58 -06001088
1089
1090class ExportCpeReportTest(cros_test_lib.MockTempDirTestCase,
1091 api_config.ApiConfigMixin):
1092 """ExportCpeReport tests."""
1093
1094 def setUp(self):
1095 self.response = artifacts_pb2.BundleResponse()
1096
1097 def testValidateOnly(self):
1098 """Sanity check validate only calls don't execute."""
1099 patch = self.PatchObject(artifacts_svc, 'GenerateCpeReport')
1100
1101 request = artifacts_pb2.BundleRequest()
1102 request.build_target.name = 'board'
1103 request.output_dir = self.tempdir
1104
1105 artifacts.ExportCpeReport(request, self.response, self.validate_only_config)
1106
1107 patch.assert_not_called()
1108
Michael Mortensen2d6a2402019-11-26 13:40:40 -07001109 def testMockCall(self):
1110 """Test that a mock call does not execute logic, returns mocked value."""
1111 patch = self.PatchObject(artifacts_svc, 'GenerateCpeReport')
1112
1113 request = artifacts_pb2.BundleRequest()
1114 request.build_target.name = 'board'
1115 request.output_dir = self.tempdir
1116
1117 artifacts.ExportCpeReport(request, self.response, self.mock_call_config)
1118
1119 patch.assert_not_called()
1120 self.assertEqual(len(self.response.artifacts), 2)
1121 self.assertEqual(self.response.artifacts[0].path,
1122 os.path.join(self.tempdir, 'cpe_report.txt'))
1123 self.assertEqual(self.response.artifacts[1].path,
1124 os.path.join(self.tempdir, 'cpe_warnings.txt'))
1125
Alex Klein0b1cbfc2019-08-14 10:09:58 -06001126 def testNoBuildTarget(self):
1127 request = artifacts_pb2.BundleRequest()
1128 request.output_dir = self.tempdir
1129
1130 with self.assertRaises(cros_build_lib.DieSystemExit):
1131 artifacts.ExportCpeReport(request, self.response, self.api_config)
1132
1133 def testSuccess(self):
1134 """Test success case."""
1135 expected = artifacts_svc.CpeResult(
1136 report='/output/report.json', warnings='/output/warnings.json')
1137 self.PatchObject(artifacts_svc, 'GenerateCpeReport', return_value=expected)
1138
1139 request = artifacts_pb2.BundleRequest()
1140 request.build_target.name = 'board'
1141 request.output_dir = self.tempdir
1142
1143 artifacts.ExportCpeReport(request, self.response, self.api_config)
1144
1145 for artifact in self.response.artifacts:
1146 self.assertIn(artifact.path, [expected.report, expected.warnings])