Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 1 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Implements ArtifactService.""" |
| 6 | |
Chris McDonald | 1672ddb | 2021-07-21 11:48:23 -0600 | [diff] [blame] | 7 | import logging |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 8 | import os |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 9 | from typing import Any, NamedTuple, Optional, TYPE_CHECKING |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 10 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 11 | from chromite.api import controller |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 12 | from chromite.api import faux |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 13 | from chromite.api import validate |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 14 | from chromite.api.controller import controller_util |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 15 | from chromite.api.controller import image as image_controller |
| 16 | from chromite.api.controller import sysroot as sysroot_controller |
David Welling | c1433c2 | 2021-06-25 16:29:48 +0000 | [diff] [blame] | 17 | from chromite.api.controller import test as test_controller |
LaMont Jones | 58362a4 | 2021-02-04 17:40:08 -0700 | [diff] [blame] | 18 | from chromite.api.gen.chromite.api import artifacts_pb2 |
Jaques Clapauch | f616bcd | 2021-04-09 20:14:40 +0000 | [diff] [blame] | 19 | from chromite.api.gen.chromiumos import common_pb2 |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 20 | from chromite.lib import constants |
| 21 | from chromite.lib import cros_build_lib |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 22 | from chromite.lib import sysroot_lib |
| 23 | from chromite.service import artifacts |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 24 | from chromite.service import test |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 25 | |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 26 | |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 27 | if TYPE_CHECKING: |
| 28 | from chromite.api import api_config |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 29 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 30 | class RegisteredGet(NamedTuple): |
| 31 | """An registered function for calling Get on an artifact type.""" |
| 32 | output_proto: artifacts_pb2.GetResponse |
| 33 | artifact_dict: Any |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 34 | |
| 35 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 36 | def ExampleGetResponse(_input_proto, _output_proto, _config): |
| 37 | """Give an example GetResponse with a minimal coverage set.""" |
| 38 | _output_proto = artifacts_pb2.GetResponse( |
| 39 | artifacts=common_pb2.UploadedArtifactsByService( |
| 40 | image=image_controller.ExampleGetResponse(), |
| 41 | sysroot=sysroot_controller.ExampleGetResponse(), |
| 42 | )) |
| 43 | return controller.RETURN_CODE_SUCCESS |
| 44 | |
| 45 | |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 46 | @faux.empty_error |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 47 | @faux.success(ExampleGetResponse) |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 48 | @validate.exists('result_path.path.path') |
| 49 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 50 | def Get( |
| 51 | input_proto: artifacts_pb2.GetRequest, |
| 52 | output_proto: artifacts_pb2.GetResponse, |
| 53 | _config: 'api_config.ApiConfig'): |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 54 | """Get all artifacts. |
| 55 | |
| 56 | Get all artifacts for the build. |
| 57 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 58 | Note: As the individual artifact_type bundlers are added here, they *must* |
| 59 | stop uploading it via the individual bundler function. |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 60 | |
| 61 | Args: |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 62 | input_proto: The input proto. |
| 63 | output_proto: The output proto. |
| 64 | _config: The API call config. |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 65 | """ |
Jaques Clapauch | f616bcd | 2021-04-09 20:14:40 +0000 | [diff] [blame] | 66 | output_dir = input_proto.result_path.path.path |
| 67 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 68 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
LaMont Jones | 8b88e9d | 2021-06-28 16:37:34 -0600 | [diff] [blame] | 69 | # This endpoint does not currently support any artifacts that are built |
| 70 | # without a sysroot being present. |
| 71 | if not sysroot.path: |
| 72 | return controller.RETURN_CODE_SUCCESS |
| 73 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 74 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 75 | build_target = controller_util.ParseBuildTarget( |
| 76 | input_proto.sysroot.build_target) |
Jaques Clapauch | f616bcd | 2021-04-09 20:14:40 +0000 | [diff] [blame] | 77 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 78 | # A list of RegisteredGet tuples (input proto, output proto, get results). |
| 79 | get_res_list = [ |
| 80 | RegisteredGet( |
| 81 | output_proto.artifacts.image, |
| 82 | image_controller.GetArtifacts( |
| 83 | input_proto.artifact_info.image, chroot, sysroot, build_target, |
| 84 | output_dir)), |
| 85 | RegisteredGet( |
| 86 | output_proto.artifacts.sysroot, |
| 87 | sysroot_controller.GetArtifacts( |
| 88 | input_proto.artifact_info.sysroot, chroot, sysroot, build_target, |
David Welling | c1433c2 | 2021-06-25 16:29:48 +0000 | [diff] [blame] | 89 | output_dir)), |
| 90 | RegisteredGet( |
| 91 | output_proto.artifacts.test, |
| 92 | test_controller.GetArtifacts( |
Jack Neus | c9707c3 | 2021-07-23 21:48:54 +0000 | [diff] [blame] | 93 | input_proto.artifact_info.test, chroot, sysroot, build_target, |
| 94 | output_dir)), |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 95 | ] |
Jaques Clapauch | f616bcd | 2021-04-09 20:14:40 +0000 | [diff] [blame] | 96 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 97 | for get_res in get_res_list: |
| 98 | for artifact_dict in get_res.artifact_dict: |
| 99 | get_res.output_proto.artifacts.add( |
| 100 | artifact_type=artifact_dict['type'], |
| 101 | paths=[ |
| 102 | common_pb2.Path( |
| 103 | path=x, location=common_pb2.Path.Location.OUTSIDE) |
| 104 | for x in artifact_dict['paths'] |
| 105 | ]) |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 106 | return controller.RETURN_CODE_SUCCESS |
| 107 | |
| 108 | |
LaMont Jones | 58362a4 | 2021-02-04 17:40:08 -0700 | [diff] [blame] | 109 | def _BuildSetupResponse(_input_proto, output_proto, _config): |
| 110 | """Just return POINTLESS for now.""" |
| 111 | # All of the artifact types we support claim that the build is POINTLESS. |
| 112 | output_proto.build_relevance = artifacts_pb2.BuildSetupResponse.POINTLESS |
| 113 | |
| 114 | |
| 115 | @faux.success(_BuildSetupResponse) |
| 116 | @faux.empty_error |
| 117 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 118 | def BuildSetup( |
| 119 | _input_proto: artifacts_pb2.GetRequest, |
| 120 | output_proto: artifacts_pb2.GetResponse, |
| 121 | _config: 'api_config.ApiConfig'): |
| 122 | |
LaMont Jones | 58362a4 | 2021-02-04 17:40:08 -0700 | [diff] [blame] | 123 | """Setup anything needed for building artifacts |
| 124 | |
| 125 | If any artifact types require steps prior to building the package, they go |
| 126 | here. For example, see ToolchainService/PrepareForBuild. |
| 127 | |
| 128 | Note: crbug/1034529 introduces this method as a noop. As the individual |
| 129 | artifact_type bundlers are added here, they *must* stop uploading it via the |
| 130 | individual bundler function. |
| 131 | |
| 132 | Args: |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 133 | _input_proto: The input proto. |
| 134 | output_proto: The output proto. |
| 135 | _config: The API call config. |
LaMont Jones | 58362a4 | 2021-02-04 17:40:08 -0700 | [diff] [blame] | 136 | """ |
| 137 | # If any artifact_type says "NEEDED", the return is NEEDED. |
| 138 | # Otherwise, if any artifact_type says "UNKNOWN", the return is UNKNOWN. |
| 139 | # Otherwise, the return is POINTLESS. |
| 140 | output_proto.build_relevance = artifacts_pb2.BuildSetupResponse.POINTLESS |
| 141 | return controller.RETURN_CODE_SUCCESS |
| 142 | |
| 143 | |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 144 | def _GetImageDir(build_root: str, target: str) -> Optional[str]: |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 145 | """Return path containing images for the given build target. |
| 146 | |
Alex Klein | e2612a0 | 2019-04-18 13:51:06 -0600 | [diff] [blame] | 147 | TODO(saklein) Expand image_lib.GetLatestImageLink to support this use case. |
| 148 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 149 | Args: |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 150 | build_root: Path to checkout where build occurs. |
| 151 | target: Name of the build target. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 152 | |
| 153 | Returns: |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 154 | Path to the latest directory containing target images or None. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 155 | """ |
| 156 | image_dir = os.path.join(build_root, 'src/build/images', target, 'latest') |
| 157 | if not os.path.exists(image_dir): |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 158 | logging.warning('Expected to find image output for target %s at %s, but ' |
| 159 | 'path does not exist', target, image_dir) |
| 160 | return None |
| 161 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 162 | return image_dir |
| 163 | |
| 164 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 165 | def _BundleImageArchivesResponse(input_proto, output_proto, _config): |
| 166 | """Add artifact paths to a successful response.""" |
| 167 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 168 | 'path0.tar.xz') |
| 169 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 170 | 'path1.tar.xz') |
| 171 | |
| 172 | |
| 173 | @faux.success(_BundleImageArchivesResponse) |
| 174 | @faux.empty_error |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 175 | @validate.require('build_target.name') |
| 176 | @validate.exists('output_dir') |
| 177 | @validate.validation_complete |
| 178 | def BundleImageArchives(input_proto, output_proto, _config): |
| 179 | """Create a .tar.xz archive for each image that has been created.""" |
| 180 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 181 | output_dir = input_proto.output_dir |
| 182 | image_dir = _GetImageDir(constants.SOURCE_ROOT, build_target.name) |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 183 | if image_dir is None: |
| 184 | return |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 185 | |
| 186 | archives = artifacts.ArchiveImages(image_dir, output_dir) |
| 187 | |
| 188 | for archive in archives: |
| 189 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
| 190 | |
| 191 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 192 | def _BundleImageZipResponse(input_proto, output_proto, _config): |
| 193 | """Add artifact zip files to a successful response.""" |
| 194 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 195 | 'image.zip') |
| 196 | |
| 197 | |
| 198 | @faux.success(_BundleImageZipResponse) |
| 199 | @faux.empty_error |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 200 | @validate.require('build_target.name', 'output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 201 | @validate.exists('output_dir') |
| 202 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 203 | def BundleImageZip( |
| 204 | input_proto: artifacts_pb2.BundleRequest, |
| 205 | output_proto: artifacts_pb2.BundleResponse, |
| 206 | _config: 'api_config.ApiConfig'): |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 207 | """Bundle image.zip. |
| 208 | |
| 209 | Args: |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 210 | input_proto: The input proto. |
| 211 | output_proto: The output proto. |
| 212 | _config: The API call config. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 213 | """ |
| 214 | target = input_proto.build_target.name |
| 215 | output_dir = input_proto.output_dir |
| 216 | image_dir = _GetImageDir(constants.SOURCE_ROOT, target) |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 217 | if image_dir is None: |
| 218 | return None |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 219 | |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 220 | archive = artifacts.BundleImageZip(output_dir, image_dir) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 221 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
| 222 | |
| 223 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 224 | def _BundleTestUpdatePayloadsResponse(input_proto, output_proto, _config): |
| 225 | """Add test payload files to a successful response.""" |
| 226 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 227 | 'payload1.bin') |
George Engelbrecht | f0239d5 | 2022-04-06 13:09:33 -0600 | [diff] [blame] | 228 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 229 | 'payload1.json') |
| 230 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 231 | 'payload1.log') |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 232 | |
| 233 | |
| 234 | @faux.success(_BundleTestUpdatePayloadsResponse) |
| 235 | @faux.empty_error |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 236 | @validate.require('build_target.name', 'output_dir') |
| 237 | @validate.exists('output_dir') |
| 238 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 239 | def BundleTestUpdatePayloads( |
| 240 | input_proto: artifacts_pb2.BundleRequest, |
| 241 | output_proto: artifacts_pb2.BundleResponse, |
| 242 | _config: 'api_config.ApiConfig'): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 243 | """Generate minimal update payloads for the build target for testing. |
| 244 | |
| 245 | Args: |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 246 | input_proto: The input proto. |
| 247 | output_proto: The output proto. |
| 248 | _config: The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 249 | """ |
| 250 | target = input_proto.build_target.name |
| 251 | output_dir = input_proto.output_dir |
| 252 | build_root = constants.SOURCE_ROOT |
| 253 | |
| 254 | # Use the first available image to create the update payload. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 255 | img_dir = _GetImageDir(build_root, target) |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 256 | if img_dir is None: |
| 257 | return None |
| 258 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 259 | img_types = [constants.IMAGE_TYPE_TEST, constants.IMAGE_TYPE_DEV, |
| 260 | constants.IMAGE_TYPE_BASE] |
| 261 | img_names = [constants.IMAGE_TYPE_TO_NAME[t] for t in img_types] |
Mike Frysinger | 66ce413 | 2019-07-17 22:52:52 -0400 | [diff] [blame] | 262 | img_paths = [os.path.join(img_dir, x) for x in img_names] |
Mike Frysinger | a552be4 | 2018-08-17 14:39:32 -0400 | [diff] [blame] | 263 | valid_images = [x for x in img_paths if os.path.exists(x)] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 264 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 265 | if not valid_images: |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 266 | cros_build_lib.Die( |
| 267 | 'Expected to find an image of type among %r for target "%s" ' |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 268 | 'at path %s.', img_types, target, img_dir) |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 269 | image = valid_images[0] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 270 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 271 | payloads = artifacts.BundleTestUpdatePayloads(image, output_dir) |
| 272 | for payload in payloads: |
| 273 | output_proto.artifacts.add().path = payload |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 274 | |
| 275 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 276 | def _BundleAutotestFilesResponse(input_proto, output_proto, _config): |
| 277 | """Add test autotest files to a successful response.""" |
| 278 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 279 | 'autotest-a.tar.gz') |
| 280 | |
| 281 | |
| 282 | @faux.success(_BundleAutotestFilesResponse) |
| 283 | @faux.empty_error |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 284 | @validate.require('sysroot.path') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 285 | @validate.exists('output_dir') |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 286 | @validate.validation_complete |
| 287 | def BundleAutotestFiles(input_proto: artifacts_pb2.BundleRequest, |
| 288 | output_proto: artifacts_pb2.BundleResponse, |
| 289 | _config: 'api_config.ApiConfig') -> None: |
| 290 | """Tar the autotest files for a build target.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 291 | output_dir = input_proto.output_dir |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 292 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 293 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 294 | |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 295 | if not sysroot.Exists(chroot=chroot): |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 296 | logging.warning('Sysroot does not exist: %s', sysroot.path) |
| 297 | return |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 298 | |
| 299 | try: |
| 300 | # Note that this returns the full path to *multiple* tarballs. |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 301 | archives = artifacts.BundleAutotestFiles(chroot, sysroot, output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 302 | except artifacts.Error as e: |
Alex Klein | 0389031 | 2020-06-30 09:59:50 -0600 | [diff] [blame] | 303 | logging.warning(e) |
| 304 | return |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 305 | |
| 306 | for archive in archives.values(): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 307 | output_proto.artifacts.add().path = archive |
| 308 | |
| 309 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 310 | def _BundleTastFilesResponse(input_proto, output_proto, _config): |
| 311 | """Add test tast files to a successful response.""" |
| 312 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 313 | 'tast_bundles.tar.gz') |
| 314 | |
| 315 | |
| 316 | @faux.success(_BundleTastFilesResponse) |
| 317 | @faux.empty_error |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 318 | @validate.require('sysroot.path') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 319 | @validate.exists('output_dir') |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 320 | @validate.validation_complete |
| 321 | def BundleTastFiles(input_proto: artifacts_pb2.BundleRequest, |
| 322 | output_proto: artifacts_pb2.BundleResponse, |
| 323 | _config: 'api_config.ApiConfig') -> None: |
| 324 | """Tar the tast files for a build target.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 325 | output_dir = input_proto.output_dir |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 326 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 327 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 328 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 329 | if not sysroot.Exists(chroot=chroot): |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 330 | logging.warning('Sysroot does not exist: %s', sysroot.path) |
| 331 | return |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 332 | |
| 333 | archive = artifacts.BundleTastFiles(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 334 | |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 335 | if not archive: |
| 336 | logging.warning('Found no tast files for %s.', sysroot.path) |
| 337 | return |
| 338 | |
| 339 | output_proto.artifacts.add().path = archive |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 340 | |
| 341 | |
Fergus Dall | 34d74e1 | 2020-09-29 15:52:32 +1000 | [diff] [blame] | 342 | def BundlePinnedGuestImages(_input_proto, _output_proto, _config): |
| 343 | # TODO(crbug/1034529): Remove this endpoint |
| 344 | pass |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 345 | |
Fergus Dall | 34d74e1 | 2020-09-29 15:52:32 +1000 | [diff] [blame] | 346 | def FetchPinnedGuestImageUris(_input_proto, _output_proto, _config): |
| 347 | # TODO(crbug/1034529): Remove this endpoint |
| 348 | pass |
Alex Klein | 7bf0ecb | 2019-06-25 10:04:15 -0600 | [diff] [blame] | 349 | |
| 350 | |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 351 | def _FetchMetadataResponse(_input_proto, output_proto, _config): |
| 352 | """Populate the output_proto with sample data.""" |
| 353 | for fp in ('/metadata/foo.txt', '/metadata/bar.jsonproto'): |
| 354 | output_proto.filepaths.add(path=common_pb2.Path( |
| 355 | path=fp, location=common_pb2.Path.OUTSIDE)) |
| 356 | return controller.RETURN_CODE_SUCCESS |
| 357 | |
| 358 | |
| 359 | @faux.success(_FetchMetadataResponse) |
| 360 | @faux.empty_error |
| 361 | @validate.exists('chroot.path') |
| 362 | @validate.require('sysroot.path') |
| 363 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 364 | def FetchMetadata( |
| 365 | input_proto: artifacts_pb2.FetchMetadataRequest, |
| 366 | output_proto: artifacts_pb2.FetchMetadataResponse, |
| 367 | _config: 'api_config.ApiConfig'): |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 368 | """FetchMetadata returns the paths to all build/test metadata files. |
| 369 | |
| 370 | This implements ArtifactsService.FetchMetadata. |
| 371 | |
| 372 | Args: |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 373 | input_proto: The input proto. |
| 374 | output_proto: The output proto. |
| 375 | config: The API call config. |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 376 | """ |
| 377 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 378 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
| 379 | for path in test.FindAllMetadataFiles(chroot, sysroot): |
| 380 | output_proto.filepaths.add( |
| 381 | path=common_pb2.Path(path=path, location=common_pb2.Path.OUTSIDE)) |
| 382 | return controller.RETURN_CODE_SUCCESS |
| 383 | |
| 384 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 385 | def _BundleFirmwareResponse(input_proto, output_proto, _config): |
| 386 | """Add test firmware image files to a successful response.""" |
| 387 | output_proto.artifacts.add().path = os.path.join( |
| 388 | input_proto.output_dir, 'firmware.tar.gz') |
| 389 | |
| 390 | |
| 391 | @faux.success(_BundleFirmwareResponse) |
| 392 | @faux.empty_error |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 393 | @validate.require('sysroot.path') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 394 | @validate.exists('output_dir') |
| 395 | @validate.validation_complete |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 396 | def BundleFirmware(input_proto: artifacts_pb2.BundleRequest, |
| 397 | output_proto: artifacts_pb2.BundleResponse, |
| 398 | _config: 'api_config.ApiConfig') -> None: |
| 399 | """Tar the firmware images for a build target.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 400 | output_dir = input_proto.output_dir |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 401 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 402 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 403 | |
| 404 | if not chroot.exists(): |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 405 | logging.warning('Chroot does not exist: %s', chroot.path) |
| 406 | return |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 407 | elif not sysroot.Exists(chroot=chroot): |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 408 | logging.warning('Sysroot does not exist: %s', sysroot.path) |
| 409 | return |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 410 | |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 411 | archive = artifacts.BuildFirmwareArchive(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 412 | |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 413 | if not archive: |
George Engelbrecht | 9e41e17 | 2021-11-18 17:04:22 -0700 | [diff] [blame] | 414 | logging.warning( |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 415 | 'Could not create firmware archive. No firmware found for %s.', |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 416 | sysroot.path) |
George Engelbrecht | 9e41e17 | 2021-11-18 17:04:22 -0700 | [diff] [blame] | 417 | return |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 418 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 419 | output_proto.artifacts.add().path = archive |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 420 | |
| 421 | |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 422 | def _BundleFpmcuUnittestsResponse(input_proto, output_proto, _config): |
| 423 | """Add fingerprint MCU unittest binaries to a successful response.""" |
| 424 | output_proto.artifacts.add().path = os.path.join( |
| 425 | input_proto.output_dir, 'fpmcu_unittests.tar.gz') |
| 426 | |
| 427 | |
| 428 | @faux.success(_BundleFpmcuUnittestsResponse) |
| 429 | @faux.empty_error |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 430 | @validate.require('sysroot.path') |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 431 | @validate.exists('output_dir') |
| 432 | @validate.validation_complete |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 433 | def BundleFpmcuUnittests(input_proto: artifacts_pb2.BundleRequest, |
| 434 | output_proto: artifacts_pb2.BundleResponse, |
| 435 | _config: 'api_config.ApiConfig') -> None: |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 436 | """Tar the fingerprint MCU unittest binaries for a build target. |
| 437 | |
| 438 | Args: |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 439 | input_proto: The input proto. |
| 440 | output_proto: The output proto. |
| 441 | _config: The API call config. |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 442 | """ |
| 443 | output_dir = input_proto.output_dir |
| 444 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 445 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 446 | |
| 447 | if not chroot.exists(): |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 448 | logging.warning('Chroot does not exist: %s', chroot.path) |
| 449 | return |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 450 | elif not sysroot.Exists(chroot=chroot): |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 451 | logging.warning('Sysroot does not exist: %s', sysroot.path) |
| 452 | return |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 453 | |
| 454 | archive = artifacts.BundleFpmcuUnittests(chroot, sysroot, output_dir) |
| 455 | |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 456 | if not archive: |
| 457 | logging.warning('No fpmcu unittests found for %s.', sysroot.path) |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 458 | return |
| 459 | |
| 460 | output_proto.artifacts.add().path = archive |
| 461 | |
| 462 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 463 | def _BundleEbuildLogsResponse(input_proto, output_proto, _config): |
| 464 | """Add test log files to a successful response.""" |
| 465 | output_proto.artifacts.add().path = os.path.join( |
| 466 | input_proto.output_dir, 'ebuild-logs.tar.gz') |
| 467 | |
| 468 | |
| 469 | @faux.success(_BundleEbuildLogsResponse) |
| 470 | @faux.empty_error |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 471 | @validate.require('sysroot.path') |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 472 | @validate.exists('output_dir') |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 473 | @validate.validation_complete |
| 474 | def BundleEbuildLogs(input_proto: artifacts_pb2.BundleRequest, |
| 475 | output_proto: artifacts_pb2.BundleResponse, |
| 476 | _config: 'api_config.ApiConfig') -> None: |
| 477 | """Tar the ebuild logs for a build target.""" |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 478 | output_dir = input_proto.output_dir |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 479 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 480 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Evan Hernandez | a478d80 | 2019-04-08 15:08:24 -0600 | [diff] [blame] | 481 | |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 482 | if not sysroot.Exists(chroot=chroot): |
| 483 | logging.warning('Sysroot does not exist: %s', sysroot.path) |
| 484 | return |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 485 | |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 486 | archive = artifacts.BundleEBuildLogsTarball(chroot, sysroot, output_dir) |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 487 | |
| 488 | if not archive: |
| 489 | logging.warning( |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 490 | 'Could not create ebuild logs archive. No logs found for %s.', |
| 491 | sysroot.path) |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 492 | return |
| 493 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 494 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 495 | |
| 496 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 497 | def _BundleChromeOSConfigResponse(input_proto, output_proto, _config): |
| 498 | """Add test config files to a successful response.""" |
| 499 | output_proto.artifacts.add().path = os.path.join( |
| 500 | input_proto.output_dir, 'config.yaml') |
| 501 | |
| 502 | |
| 503 | @faux.success(_BundleChromeOSConfigResponse) |
| 504 | @faux.empty_error |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 505 | @validate.require('sysroot.path') |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 506 | @validate.exists('output_dir') |
| 507 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 508 | def BundleChromeOSConfig( |
| 509 | input_proto: artifacts_pb2.BundleRequest, |
| 510 | output_proto: artifacts_pb2.BundleResponse, |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 511 | _config: 'api_config.ApiConfig') -> None: |
| 512 | """Output the ChromeOS Config payload for a build target.""" |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 513 | output_dir = input_proto.output_dir |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 514 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 515 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 516 | |
| 517 | chromeos_config = artifacts.BundleChromeOSConfig(chroot, sysroot, output_dir) |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 518 | |
Alex Klein | 383a7a3 | 2021-12-07 16:01:19 -0700 | [diff] [blame] | 519 | if not chromeos_config: |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame^] | 520 | logging.warning('Could not create ChromeOS Config for %s.', sysroot.path) |
Alex Klein | 383a7a3 | 2021-12-07 16:01:19 -0700 | [diff] [blame] | 521 | return |
| 522 | |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 523 | output_proto.artifacts.add().path = os.path.join(output_dir, chromeos_config) |
| 524 | |
| 525 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 526 | def _BundleSimpleChromeArtifactsResponse(input_proto, output_proto, _config): |
| 527 | """Add test simple chrome files to a successful response.""" |
| 528 | output_proto.artifacts.add().path = os.path.join( |
| 529 | input_proto.output_dir, 'simple_chrome.txt') |
| 530 | |
| 531 | |
| 532 | @faux.success(_BundleSimpleChromeArtifactsResponse) |
| 533 | @faux.empty_error |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 534 | @validate.require('output_dir', 'sysroot.build_target.name', 'sysroot.path') |
| 535 | @validate.exists('output_dir') |
| 536 | @validate.validation_complete |
| 537 | def BundleSimpleChromeArtifacts(input_proto, output_proto, _config): |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 538 | """Create the simple chrome artifacts.""" |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 539 | sysroot_path = input_proto.sysroot.path |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 540 | output_dir = input_proto.output_dir |
| 541 | |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 542 | # Build out the argument instances. |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 543 | build_target = controller_util.ParseBuildTarget( |
| 544 | input_proto.sysroot.build_target) |
| 545 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 546 | # Sysroot.path needs to be the fully qualified path, including the chroot. |
| 547 | full_sysroot_path = os.path.join(chroot.path, sysroot_path.lstrip(os.sep)) |
| 548 | sysroot = sysroot_lib.Sysroot(full_sysroot_path) |
| 549 | |
| 550 | # Quick sanity check that the sysroot exists before we go on. |
| 551 | if not sysroot.Exists(): |
| 552 | cros_build_lib.Die('The sysroot does not exist.') |
| 553 | |
| 554 | try: |
| 555 | results = artifacts.BundleSimpleChromeArtifacts(chroot, sysroot, |
| 556 | build_target, output_dir) |
| 557 | except artifacts.Error as e: |
| 558 | cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', |
| 559 | type(e), e) |
| 560 | |
| 561 | for file_name in results: |
| 562 | output_proto.artifacts.add().path = file_name |
| 563 | |
| 564 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 565 | def _BundleVmFilesResponse(input_proto, output_proto, _config): |
| 566 | """Add test vm files to a successful response.""" |
| 567 | output_proto.artifacts.add().path = os.path.join( |
| 568 | input_proto.output_dir, 'f1.tar') |
| 569 | |
| 570 | |
| 571 | @faux.success(_BundleVmFilesResponse) |
| 572 | @faux.empty_error |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 573 | @validate.require('chroot.path', 'test_results_dir', 'output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 574 | @validate.exists('output_dir') |
| 575 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 576 | def BundleVmFiles( |
| 577 | input_proto: artifacts_pb2.BundleVmFilesRequest, |
| 578 | output_proto: artifacts_pb2.BundleResponse, |
| 579 | _config: 'api_config.ApiConfig'): |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 580 | """Tar VM disk and memory files. |
| 581 | |
| 582 | Args: |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 583 | input_proto: The input proto. |
| 584 | output_proto: The output proto. |
| 585 | _config: The API call config. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 586 | """ |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 587 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 588 | test_results_dir = input_proto.test_results_dir |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 589 | output_dir = input_proto.output_dir |
| 590 | |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 591 | archives = artifacts.BundleVmFiles( |
| 592 | chroot, test_results_dir, output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 593 | for archive in archives: |
| 594 | output_proto.artifacts.add().path = archive |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 595 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 596 | def _ExportCpeReportResponse(input_proto, output_proto, _config): |
| 597 | """Add test cpe results to a successful response.""" |
| 598 | output_proto.artifacts.add().path = os.path.join( |
| 599 | input_proto.output_dir, 'cpe_report.txt') |
| 600 | output_proto.artifacts.add().path = os.path.join( |
| 601 | input_proto.output_dir, 'cpe_warnings.txt') |
| 602 | |
| 603 | |
| 604 | @faux.success(_ExportCpeReportResponse) |
| 605 | @faux.empty_error |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 606 | @validate.require('sysroot.path') |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 607 | @validate.exists('output_dir') |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 608 | @validate.validation_complete |
| 609 | def ExportCpeReport(input_proto: artifacts_pb2.BundleRequest, |
| 610 | output_proto: artifacts_pb2.BundleResponse, |
| 611 | _config: 'api_config.ApiConfig') -> None: |
| 612 | """Export a CPE report.""" |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 613 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 614 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 615 | output_dir = input_proto.output_dir |
| 616 | |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 617 | if not sysroot.Exists(chroot=chroot): |
| 618 | logging.warning('Sysroot does not exist: %s', sysroot.path) |
| 619 | return |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 620 | |
| 621 | cpe_result = artifacts.GenerateCpeReport(chroot, sysroot, output_dir) |
| 622 | |
| 623 | output_proto.artifacts.add().path = cpe_result.report |
| 624 | output_proto.artifacts.add().path = cpe_result.warnings |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 625 | |
| 626 | |
| 627 | def _BundleGceTarballResponse(input_proto, output_proto, _config): |
| 628 | """Add artifact tarball to a successful response.""" |
| 629 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 630 | constants.TEST_IMAGE_GCE_TAR) |
| 631 | |
| 632 | |
| 633 | @faux.success(_BundleGceTarballResponse) |
| 634 | @faux.empty_error |
| 635 | @validate.require('build_target.name', 'output_dir') |
| 636 | @validate.exists('output_dir') |
| 637 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 638 | def BundleGceTarball( |
| 639 | input_proto: artifacts_pb2.BundleRequest, |
| 640 | output_proto: artifacts_pb2.BundleResponse, |
| 641 | _config: 'api_config.ApiConfig'): |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 642 | """Bundle the test image into a tarball suitable for importing into GCE. |
| 643 | |
| 644 | Args: |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 645 | input_proto: The input proto. |
| 646 | output_proto: The output proto. |
| 647 | _config: The API call config. |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 648 | """ |
| 649 | target = input_proto.build_target.name |
| 650 | output_dir = input_proto.output_dir |
| 651 | image_dir = _GetImageDir(constants.SOURCE_ROOT, target) |
| 652 | if image_dir is None: |
| 653 | return None |
| 654 | |
| 655 | tarball = artifacts.BundleGceTarball(output_dir, image_dir) |
| 656 | output_proto.artifacts.add().path = tarball |