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.""" |
| 190 | output_proto.artifacts.add().path = os.path.join( |
| 191 | input_proto.output_dir, "path0.tar.xz" |
| 192 | ) |
| 193 | output_proto.artifacts.add().path = os.path.join( |
| 194 | input_proto.output_dir, "path1.tar.xz" |
| 195 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 196 | |
| 197 | |
| 198 | @faux.success(_BundleImageArchivesResponse) |
| 199 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 200 | @validate.require("build_target.name") |
| 201 | @validate.exists("output_dir") |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 202 | @validate.validation_complete |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 203 | def BundleImageArchives( |
| 204 | input_proto: artifacts_pb2.BundleRequest, |
| 205 | output_proto: artifacts_pb2.BundleResponse, |
| 206 | _config: "api_config.ApiConfig", |
| 207 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 208 | """Create a .tar.xz archive for each image that has been created.""" |
| 209 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 210 | output_dir = input_proto.output_dir |
| 211 | image_dir = _GetImageDir(constants.SOURCE_ROOT, build_target.name) |
| 212 | if image_dir is None: |
| 213 | return |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 214 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 215 | archives = artifacts.ArchiveImages(image_dir, output_dir) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 216 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 217 | for archive in archives: |
| 218 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 219 | |
| 220 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 221 | def _BundleImageZipResponse(input_proto, output_proto, _config) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 222 | """Add artifact zip files to a successful response.""" |
| 223 | output_proto.artifacts.add().path = os.path.join( |
| 224 | input_proto.output_dir, "image.zip" |
| 225 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 226 | |
| 227 | |
| 228 | @faux.success(_BundleImageZipResponse) |
| 229 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 230 | @validate.require("build_target.name", "output_dir") |
| 231 | @validate.exists("output_dir") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 232 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 233 | def BundleImageZip( |
| 234 | input_proto: artifacts_pb2.BundleRequest, |
| 235 | output_proto: artifacts_pb2.BundleResponse, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 236 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 237 | ) -> Optional[int]: |
| 238 | """Bundle image.zip.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 239 | target = input_proto.build_target.name |
| 240 | output_dir = input_proto.output_dir |
| 241 | image_dir = _GetImageDir(constants.SOURCE_ROOT, target) |
| 242 | if image_dir is None: |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 243 | logging.warning("Image build directory not found.") |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 244 | return None |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 245 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 246 | archive = artifacts.BundleImageZip(output_dir, image_dir) |
| 247 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 248 | |
| 249 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 250 | def _BundleTestUpdatePayloadsResponse( |
| 251 | input_proto, output_proto, _config |
| 252 | ) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 253 | """Add test payload files to a successful response.""" |
| 254 | output_proto.artifacts.add().path = os.path.join( |
| 255 | input_proto.output_dir, "payload1.bin" |
| 256 | ) |
| 257 | output_proto.artifacts.add().path = os.path.join( |
| 258 | input_proto.output_dir, "payload1.json" |
| 259 | ) |
| 260 | output_proto.artifacts.add().path = os.path.join( |
| 261 | input_proto.output_dir, "payload1.log" |
| 262 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 263 | |
| 264 | |
| 265 | @faux.success(_BundleTestUpdatePayloadsResponse) |
| 266 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 267 | @validate.require("build_target.name", "output_dir") |
| 268 | @validate.exists("output_dir") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 269 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 270 | def BundleTestUpdatePayloads( |
| 271 | input_proto: artifacts_pb2.BundleRequest, |
| 272 | output_proto: artifacts_pb2.BundleResponse, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 273 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 274 | ) -> Optional[int]: |
| 275 | """Generate minimal update payloads for the build target for testing.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 276 | target = input_proto.build_target.name |
| 277 | output_dir = input_proto.output_dir |
| 278 | build_root = constants.SOURCE_ROOT |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 279 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 280 | # Use the first available image to create the update payload. |
| 281 | img_dir = _GetImageDir(build_root, target) |
| 282 | if img_dir is None: |
| 283 | return None |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 284 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 285 | img_types = [ |
| 286 | constants.IMAGE_TYPE_TEST, |
| 287 | constants.IMAGE_TYPE_DEV, |
| 288 | constants.IMAGE_TYPE_BASE, |
| 289 | ] |
| 290 | img_names = [constants.IMAGE_TYPE_TO_NAME[t] for t in img_types] |
| 291 | img_paths = [os.path.join(img_dir, x) for x in img_names] |
| 292 | 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] | 293 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 294 | if not valid_images: |
| 295 | cros_build_lib.Die( |
| 296 | 'Expected to find an image of type among %r for target "%s" ' |
| 297 | "at path %s.", |
| 298 | img_types, |
| 299 | target, |
| 300 | img_dir, |
| 301 | ) |
| 302 | image = valid_images[0] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 303 | |
Greg Edelston | e041939 | 2023-06-22 22:13:43 +0000 | [diff] [blame] | 304 | payloads = artifacts.BundleTestUpdatePayloads(image, output_dir) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 305 | for payload in payloads: |
| 306 | output_proto.artifacts.add().path = payload |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 307 | |
| 308 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 309 | def _BundleAutotestFilesResponse(input_proto, output_proto, _config) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 310 | """Add test autotest files to a successful response.""" |
| 311 | output_proto.artifacts.add().path = os.path.join( |
| 312 | input_proto.output_dir, "autotest-a.tar.gz" |
| 313 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 314 | |
| 315 | |
| 316 | @faux.success(_BundleAutotestFilesResponse) |
| 317 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 318 | @validate.require("sysroot.path") |
| 319 | @validate.exists("output_dir") |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 320 | @validate.validation_complete |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 321 | def BundleAutotestFiles( |
| 322 | input_proto: artifacts_pb2.BundleRequest, |
| 323 | output_proto: artifacts_pb2.BundleResponse, |
| 324 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 325 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 326 | """Tar the autotest files for a build target.""" |
| 327 | output_dir = input_proto.output_dir |
| 328 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 329 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 330 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 331 | if not sysroot.Exists(chroot=chroot): |
| 332 | logging.warning("Sysroot does not exist: %s", sysroot.path) |
| 333 | return |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 334 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 335 | try: |
| 336 | # Note that this returns the full path to *multiple* tarballs. |
| 337 | archives = artifacts.BundleAutotestFiles(chroot, sysroot, output_dir) |
| 338 | except artifacts.Error as e: |
| 339 | logging.warning(e) |
| 340 | return |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 341 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 342 | for archive in archives.values(): |
| 343 | output_proto.artifacts.add().path = archive |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 344 | |
| 345 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 346 | def _BundleTastFilesResponse(input_proto, output_proto, _config) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 347 | """Add test tast files to a successful response.""" |
| 348 | output_proto.artifacts.add().path = os.path.join( |
| 349 | input_proto.output_dir, "tast_bundles.tar.gz" |
| 350 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 351 | |
| 352 | |
| 353 | @faux.success(_BundleTastFilesResponse) |
| 354 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 355 | @validate.require("sysroot.path") |
| 356 | @validate.exists("output_dir") |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 357 | @validate.validation_complete |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 358 | def BundleTastFiles( |
| 359 | input_proto: artifacts_pb2.BundleRequest, |
| 360 | output_proto: artifacts_pb2.BundleResponse, |
| 361 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 362 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 363 | """Tar the tast files for a build target.""" |
| 364 | output_dir = input_proto.output_dir |
| 365 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 366 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 367 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 368 | if not sysroot.Exists(chroot=chroot): |
| 369 | logging.warning("Sysroot does not exist: %s", sysroot.path) |
| 370 | return |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 371 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 372 | archive = artifacts.BundleTastFiles(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 373 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 374 | if not archive: |
| 375 | logging.warning("Found no tast files for %s.", sysroot.path) |
| 376 | return |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 377 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 378 | output_proto.artifacts.add().path = archive |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 379 | |
| 380 | |
Fergus Dall | 34d74e1 | 2020-09-29 15:52:32 +1000 | [diff] [blame] | 381 | def BundlePinnedGuestImages(_input_proto, _output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 382 | # TODO(crbug/1034529): Remove this endpoint |
| 383 | pass |
| 384 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 385 | |
Fergus Dall | 34d74e1 | 2020-09-29 15:52:32 +1000 | [diff] [blame] | 386 | def FetchPinnedGuestImageUris(_input_proto, _output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 387 | # TODO(crbug/1034529): Remove this endpoint |
| 388 | pass |
Alex Klein | 7bf0ecb | 2019-06-25 10:04:15 -0600 | [diff] [blame] | 389 | |
| 390 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 391 | def _FetchMetadataResponse( |
| 392 | _input_proto, output_proto, _config |
| 393 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 394 | """Populate the output_proto with sample data.""" |
| 395 | for fp in ("/metadata/foo.txt", "/metadata/bar.jsonproto"): |
| 396 | output_proto.filepaths.add( |
| 397 | path=common_pb2.Path(path=fp, location=common_pb2.Path.OUTSIDE) |
| 398 | ) |
| 399 | return controller.RETURN_CODE_SUCCESS |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 400 | |
| 401 | |
| 402 | @faux.success(_FetchMetadataResponse) |
| 403 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 404 | @validate.exists("chroot.path") |
| 405 | @validate.require("sysroot.path") |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 406 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 407 | def FetchMetadata( |
| 408 | input_proto: artifacts_pb2.FetchMetadataRequest, |
| 409 | output_proto: artifacts_pb2.FetchMetadataResponse, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 410 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 411 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 412 | """FetchMetadata returns the paths to all build/test metadata files. |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 413 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 414 | This implements ArtifactsService.FetchMetadata. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 415 | """ |
| 416 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 417 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
| 418 | for path in test.FindAllMetadataFiles(chroot, sysroot): |
| 419 | output_proto.filepaths.add( |
| 420 | path=common_pb2.Path(path=path, location=common_pb2.Path.OUTSIDE) |
| 421 | ) |
| 422 | return controller.RETURN_CODE_SUCCESS |
Greg Edelston | dc94107 | 2021-08-11 12:32:30 -0600 | [diff] [blame] | 423 | |
| 424 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 425 | def _BundleFirmwareResponse(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 426 | """Add test firmware image files to a successful response.""" |
| 427 | output_proto.artifacts.add().path = os.path.join( |
| 428 | input_proto.output_dir, "firmware.tar.gz" |
| 429 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 430 | |
| 431 | |
| 432 | @faux.success(_BundleFirmwareResponse) |
| 433 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 434 | @validate.require("sysroot.path") |
| 435 | @validate.exists("output_dir") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 436 | @validate.validation_complete |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 437 | def BundleFirmware( |
| 438 | input_proto: artifacts_pb2.BundleRequest, |
| 439 | output_proto: artifacts_pb2.BundleResponse, |
| 440 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 441 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 442 | """Tar the firmware images for a build target.""" |
| 443 | output_dir = input_proto.output_dir |
| 444 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 445 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 446 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 447 | if not chroot.exists(): |
| 448 | logging.warning("Chroot does not exist: %s", chroot.path) |
| 449 | return |
| 450 | elif not sysroot.Exists(chroot=chroot): |
| 451 | logging.warning("Sysroot does not exist: %s", sysroot.path) |
| 452 | return |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 453 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 454 | archive = artifacts.BuildFirmwareArchive(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 455 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 456 | if not archive: |
| 457 | logging.warning( |
| 458 | "Could not create firmware archive. No firmware found for %s.", |
| 459 | sysroot.path, |
| 460 | ) |
| 461 | return |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 462 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 463 | output_proto.artifacts.add().path = archive |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 464 | |
| 465 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 466 | def _BundleFpmcuUnittestsResponse(input_proto, output_proto, _config) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 467 | """Add fingerprint MCU unittest binaries to a successful response.""" |
| 468 | output_proto.artifacts.add().path = os.path.join( |
| 469 | input_proto.output_dir, "fpmcu_unittests.tar.gz" |
| 470 | ) |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 471 | |
| 472 | |
| 473 | @faux.success(_BundleFpmcuUnittestsResponse) |
| 474 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 475 | @validate.require("sysroot.path") |
| 476 | @validate.exists("output_dir") |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 477 | @validate.validation_complete |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 478 | def BundleFpmcuUnittests( |
| 479 | input_proto: artifacts_pb2.BundleRequest, |
| 480 | output_proto: artifacts_pb2.BundleResponse, |
| 481 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 482 | ) -> Optional[int]: |
| 483 | """Tar the fingerprint MCU unittest binaries for a build target.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 484 | output_dir = input_proto.output_dir |
| 485 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 486 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 487 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 488 | if not chroot.exists(): |
| 489 | logging.warning("Chroot does not exist: %s", chroot.path) |
| 490 | return |
| 491 | elif not sysroot.Exists(chroot=chroot): |
| 492 | logging.warning("Sysroot does not exist: %s", sysroot.path) |
| 493 | return |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 494 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 495 | archive = artifacts.BundleFpmcuUnittests(chroot, sysroot, output_dir) |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 496 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 497 | if not archive: |
| 498 | logging.warning("No fpmcu unittests found for %s.", sysroot.path) |
| 499 | return |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 500 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 501 | output_proto.artifacts.add().path = archive |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 502 | |
| 503 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 504 | def _BundleEbuildLogsResponse(input_proto, output_proto, _config) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 505 | """Add test log files to a successful response.""" |
| 506 | output_proto.artifacts.add().path = os.path.join( |
| 507 | input_proto.output_dir, "ebuild-logs.tar.gz" |
| 508 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 509 | |
| 510 | |
| 511 | @faux.success(_BundleEbuildLogsResponse) |
| 512 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 513 | @validate.require("sysroot.path") |
| 514 | @validate.exists("output_dir") |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 515 | @validate.validation_complete |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 516 | def BundleEbuildLogs( |
| 517 | input_proto: artifacts_pb2.BundleRequest, |
| 518 | output_proto: artifacts_pb2.BundleResponse, |
| 519 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 520 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 521 | """Tar the ebuild logs for a build target.""" |
| 522 | output_dir = input_proto.output_dir |
| 523 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 524 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Evan Hernandez | a478d80 | 2019-04-08 15:08:24 -0600 | [diff] [blame] | 525 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 526 | if not sysroot.Exists(chroot=chroot): |
| 527 | logging.warning("Sysroot does not exist: %s", sysroot.path) |
| 528 | return |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 529 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 530 | archive = artifacts.BundleEBuildLogsTarball(chroot, sysroot, output_dir) |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 531 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 532 | if not archive: |
| 533 | logging.warning( |
| 534 | "Could not create ebuild logs archive. No logs found for %s.", |
| 535 | sysroot.path, |
| 536 | ) |
| 537 | return |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 538 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 539 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 540 | |
| 541 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 542 | def _BundleChromeOSConfigResponse(input_proto, output_proto, _config) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 543 | """Add test config files to a successful response.""" |
| 544 | output_proto.artifacts.add().path = os.path.join( |
| 545 | input_proto.output_dir, "config.yaml" |
| 546 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 547 | |
| 548 | |
| 549 | @faux.success(_BundleChromeOSConfigResponse) |
| 550 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 551 | @validate.require("sysroot.path") |
| 552 | @validate.exists("output_dir") |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 553 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 554 | def BundleChromeOSConfig( |
| 555 | input_proto: artifacts_pb2.BundleRequest, |
| 556 | output_proto: artifacts_pb2.BundleResponse, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 557 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 558 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 559 | """Output the ChromeOS Config payload for a build target.""" |
| 560 | output_dir = input_proto.output_dir |
| 561 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 562 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 563 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 564 | chromeos_config = artifacts.BundleChromeOSConfig( |
| 565 | chroot, sysroot, output_dir |
| 566 | ) |
Alex Klein | 2d8333c | 2022-06-01 13:29:01 -0600 | [diff] [blame] | 567 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 568 | if not chromeos_config: |
| 569 | logging.warning( |
| 570 | "Could not create ChromeOS Config for %s.", sysroot.path |
| 571 | ) |
| 572 | return |
Alex Klein | 383a7a3 | 2021-12-07 16:01:19 -0700 | [diff] [blame] | 573 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 574 | output_proto.artifacts.add().path = os.path.join( |
| 575 | output_dir, chromeos_config |
| 576 | ) |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 577 | |
| 578 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 579 | def _BundleSimpleChromeArtifactsResponse( |
| 580 | input_proto, output_proto, _config |
| 581 | ) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 582 | """Add test simple chrome files to a successful response.""" |
| 583 | output_proto.artifacts.add().path = os.path.join( |
| 584 | input_proto.output_dir, "simple_chrome.txt" |
| 585 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 586 | |
| 587 | |
| 588 | @faux.success(_BundleSimpleChromeArtifactsResponse) |
| 589 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 590 | @validate.require("output_dir", "sysroot.build_target.name", "sysroot.path") |
| 591 | @validate.exists("output_dir") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 592 | @validate.validation_complete |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 593 | def BundleSimpleChromeArtifacts( |
| 594 | input_proto, output_proto, _config |
| 595 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 596 | """Create the simple chrome artifacts.""" |
| 597 | sysroot_path = input_proto.sysroot.path |
| 598 | output_dir = input_proto.output_dir |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 599 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 600 | # Build out the argument instances. |
| 601 | build_target = controller_util.ParseBuildTarget( |
| 602 | input_proto.sysroot.build_target |
| 603 | ) |
| 604 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 605 | # Sysroot.path needs to be the fully qualified path, including the chroot. |
| 606 | full_sysroot_path = os.path.join(chroot.path, sysroot_path.lstrip(os.sep)) |
| 607 | sysroot = sysroot_lib.Sysroot(full_sysroot_path) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 608 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 609 | # Check that the sysroot exists before we go on. |
| 610 | if not sysroot.Exists(): |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 611 | logging.warning("The sysroot does not exist.") |
| 612 | return |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 613 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 614 | try: |
| 615 | results = artifacts.BundleSimpleChromeArtifacts( |
| 616 | chroot, sysroot, build_target, output_dir |
| 617 | ) |
| 618 | except artifacts.Error as e: |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 619 | logging.warning( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 620 | "Error %s raised in BundleSimpleChromeArtifacts: %s", type(e), e |
| 621 | ) |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 622 | return |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 623 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 624 | for file_name in results: |
| 625 | output_proto.artifacts.add().path = file_name |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 626 | |
| 627 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 628 | def _BundleVmFilesResponse(input_proto, output_proto, _config) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 629 | """Add test vm files to a successful response.""" |
| 630 | output_proto.artifacts.add().path = os.path.join( |
| 631 | input_proto.output_dir, "f1.tar" |
| 632 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 633 | |
| 634 | |
| 635 | @faux.success(_BundleVmFilesResponse) |
| 636 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 637 | @validate.require("chroot.path", "test_results_dir", "output_dir") |
| 638 | @validate.exists("output_dir") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 639 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 640 | def BundleVmFiles( |
| 641 | input_proto: artifacts_pb2.BundleVmFilesRequest, |
| 642 | output_proto: artifacts_pb2.BundleResponse, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 643 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 644 | ) -> None: |
| 645 | """Tar VM disk and memory files.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 646 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 647 | test_results_dir = input_proto.test_results_dir |
| 648 | output_dir = input_proto.output_dir |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 649 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 650 | archives = artifacts.BundleVmFiles(chroot, test_results_dir, output_dir) |
| 651 | for archive in archives: |
| 652 | output_proto.artifacts.add().path = archive |
| 653 | |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 654 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 655 | def _ExportCpeReportResponse(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 656 | """Add test cpe results to a successful response.""" |
| 657 | output_proto.artifacts.add().path = os.path.join( |
| 658 | input_proto.output_dir, "cpe_report.txt" |
| 659 | ) |
| 660 | output_proto.artifacts.add().path = os.path.join( |
| 661 | input_proto.output_dir, "cpe_warnings.txt" |
| 662 | ) |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 663 | |
| 664 | |
| 665 | @faux.success(_ExportCpeReportResponse) |
| 666 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 667 | @validate.require("sysroot.path") |
| 668 | @validate.exists("output_dir") |
Alex Klein | 036833d | 2022-06-01 13:05:01 -0600 | [diff] [blame] | 669 | @validate.validation_complete |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 670 | def ExportCpeReport( |
| 671 | input_proto: artifacts_pb2.BundleRequest, |
| 672 | output_proto: artifacts_pb2.BundleResponse, |
| 673 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 674 | ) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 675 | """Export a CPE report.""" |
| 676 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 677 | sysroot = controller_util.ParseSysroot(input_proto.sysroot) |
| 678 | output_dir = input_proto.output_dir |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 679 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 680 | if not sysroot.Exists(chroot=chroot): |
| 681 | logging.warning("Sysroot does not exist: %s", sysroot.path) |
| 682 | return |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 683 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 684 | cpe_result = artifacts.GenerateCpeReport(chroot, sysroot, output_dir) |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 685 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 686 | output_proto.artifacts.add().path = cpe_result.report |
| 687 | output_proto.artifacts.add().path = cpe_result.warnings |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 688 | |
| 689 | |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 690 | def _BundleGceTarballResponse(input_proto, output_proto, _config) -> None: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 691 | """Add artifact tarball to a successful response.""" |
| 692 | output_proto.artifacts.add().path = os.path.join( |
| 693 | input_proto.output_dir, constants.TEST_IMAGE_GCE_TAR |
| 694 | ) |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 695 | |
| 696 | |
| 697 | @faux.success(_BundleGceTarballResponse) |
| 698 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 699 | @validate.require("build_target.name", "output_dir") |
| 700 | @validate.exists("output_dir") |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 701 | @validate.validation_complete |
Varun Somani | 04dccd7 | 2021-10-09 01:06:11 +0000 | [diff] [blame] | 702 | def BundleGceTarball( |
| 703 | input_proto: artifacts_pb2.BundleRequest, |
| 704 | output_proto: artifacts_pb2.BundleResponse, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 705 | _config: "api_config.ApiConfig", |
Alex Klein | b6847e2 | 2022-11-07 10:44:48 -0700 | [diff] [blame] | 706 | ) -> Optional[int]: |
| 707 | """Bundle the test image into a tarball suitable for importing into GCE.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 708 | target = input_proto.build_target.name |
| 709 | output_dir = input_proto.output_dir |
| 710 | image_dir = _GetImageDir(constants.SOURCE_ROOT, target) |
| 711 | if image_dir is None: |
| 712 | return None |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 713 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 714 | tarball = artifacts.BundleGceTarball(output_dir, image_dir) |
| 715 | output_proto.artifacts.add().path = tarball |