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