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