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