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