Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -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 | """Portage Binhost operations.""" |
| 6 | |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 7 | import os |
| 8 | import shutil |
Kevin Shelton | 703b688 | 2022-01-24 16:31:31 -0800 | [diff] [blame] | 9 | from typing import TYPE_CHECKING |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 10 | import urllib.parse |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 11 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 12 | from chromite.api import controller |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 13 | from chromite.api import faux |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 14 | from chromite.api import validate |
Alex Klein | af0e045 | 2019-06-03 18:10:01 -0600 | [diff] [blame] | 15 | from chromite.api.controller import controller_util |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 16 | from chromite.api.gen.chromite.api import binhost_pb2 |
Greg Edelston | 724c13d | 2023-04-07 16:19:24 -0600 | [diff] [blame] | 17 | from chromite.lib import binpkg |
LaMont Jones | c64ae21 | 2019-04-15 15:41:28 -0600 | [diff] [blame] | 18 | from chromite.lib import constants |
| 19 | from chromite.lib import cros_build_lib |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 20 | from chromite.lib import gs |
Alex Klein | af0e045 | 2019-06-03 18:10:01 -0600 | [diff] [blame] | 21 | from chromite.lib import sysroot_lib |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 22 | from chromite.service import binhost |
| 23 | |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 24 | |
Kevin Shelton | 703b688 | 2022-01-24 16:31:31 -0800 | [diff] [blame] | 25 | if TYPE_CHECKING: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 26 | from chromite.api import api_config |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame] | 27 | |
Alex Klein | af0e045 | 2019-06-03 18:10:01 -0600 | [diff] [blame] | 28 | _OVERLAY_TYPE_TO_NAME = { |
| 29 | binhost_pb2.OVERLAYTYPE_PUBLIC: constants.PUBLIC_OVERLAYS, |
| 30 | binhost_pb2.OVERLAYTYPE_PRIVATE: constants.PRIVATE_OVERLAYS, |
| 31 | binhost_pb2.OVERLAYTYPE_BOTH: constants.BOTH_OVERLAYS, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 32 | binhost_pb2.OVERLAYTYPE_NONE: None, |
Alex Klein | af0e045 | 2019-06-03 18:10:01 -0600 | [diff] [blame] | 33 | } |
| 34 | |
Arif Kasim | 6242cdd | 2022-10-19 17:51:00 +0000 | [diff] [blame] | 35 | # Default maximum number of URIs to be stored in Binhost conf file. |
| 36 | _DEFAULT_BINHOST_MAX_URIS = 1 |
| 37 | |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 38 | |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 39 | def _GetBinhostsResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 40 | """Add fake binhosts to a successful response.""" |
| 41 | new_binhost = output_proto.binhosts.add() |
| 42 | new_binhost.uri = ( |
| 43 | "gs://cr-prebuilt/board/amd64-generic/" |
| 44 | "paladin-R66-17.0.0-rc2/packages/" |
| 45 | ) |
| 46 | new_binhost.package_index = "Packages" |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 47 | |
| 48 | |
| 49 | @faux.success(_GetBinhostsResponse) |
| 50 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 51 | @validate.require("build_target.name") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 52 | @validate.validation_complete |
| 53 | def GetBinhosts(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 54 | """Get a list of binhosts.""" |
| 55 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
Alex Klein | 7e40d25 | 2019-06-10 09:01:32 -0600 | [diff] [blame] | 56 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 57 | binhosts = binhost.GetBinhosts(build_target) |
Alex Klein | 7e40d25 | 2019-06-10 09:01:32 -0600 | [diff] [blame] | 58 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 59 | for current in binhosts: |
| 60 | new_binhost = output_proto.binhosts.add() |
| 61 | new_binhost.uri = current |
| 62 | new_binhost.package_index = "Packages" |
Alex Klein | 7e40d25 | 2019-06-10 09:01:32 -0600 | [diff] [blame] | 63 | |
| 64 | |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 65 | def _GetPrivatePrebuiltAclArgsResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 66 | """Add fake acls to a successful response.""" |
| 67 | new_arg = output_proto.args.add() |
| 68 | new_arg.arg = "-g" |
| 69 | new_arg.value = "group1:READ" |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 70 | |
| 71 | |
| 72 | @faux.success(_GetPrivatePrebuiltAclArgsResponse) |
| 73 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 74 | @validate.require("build_target.name") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 75 | @validate.validation_complete |
| 76 | def GetPrivatePrebuiltAclArgs(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 77 | """Get the ACL args from the files in the private overlays.""" |
| 78 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
Alex Klein | a471f68 | 2019-05-31 11:23:45 -0600 | [diff] [blame] | 79 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 80 | try: |
| 81 | args = binhost.GetPrebuiltAclArgs(build_target) |
| 82 | except binhost.Error as e: |
| 83 | cros_build_lib.Die(e) |
Alex Klein | a471f68 | 2019-05-31 11:23:45 -0600 | [diff] [blame] | 84 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 85 | for arg, value in args: |
| 86 | new_arg = output_proto.args.add() |
| 87 | new_arg.arg = arg |
| 88 | new_arg.value = value |
Alex Klein | a471f68 | 2019-05-31 11:23:45 -0600 | [diff] [blame] | 89 | |
| 90 | |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 91 | def _PrepareBinhostUploadsResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 92 | """Add fake binhost upload targets to a successful response.""" |
| 93 | output_proto.uploads_dir = "/upload/directory" |
| 94 | output_proto.upload_targets.add().path = "upload_target" |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 95 | |
| 96 | |
| 97 | @faux.success(_PrepareBinhostUploadsResponse) |
| 98 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 99 | @validate.require("uri") |
Kevin Shelton | 703b688 | 2022-01-24 16:31:31 -0800 | [diff] [blame] | 100 | def PrepareBinhostUploads( |
| 101 | input_proto: binhost_pb2.PrepareBinhostUploadsRequest, |
| 102 | output_proto: binhost_pb2.PrepareBinhostUploadsResponse, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 103 | config: "api_config.ApiConfig", |
| 104 | ): |
| 105 | """Return a list of files to upload to the binhost. |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 106 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 107 | See BinhostService documentation in api/proto/binhost.proto. |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 108 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 109 | Args: |
Alex Klein | 611dddd | 2022-10-11 17:02:01 -0600 | [diff] [blame] | 110 | input_proto: The input proto. |
| 111 | output_proto: The output proto. |
| 112 | config: The API call config. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 113 | """ |
| 114 | if input_proto.sysroot.build_target.name: |
| 115 | build_target_msg = input_proto.sysroot.build_target |
| 116 | else: |
| 117 | build_target_msg = input_proto.build_target |
| 118 | sysroot_path = input_proto.sysroot.path |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 119 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 120 | if not sysroot_path and not build_target_msg.name: |
| 121 | cros_build_lib.Die("Sysroot.path is required.") |
Alex Klein | af0e045 | 2019-06-03 18:10:01 -0600 | [diff] [blame] | 122 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 123 | build_target = controller_util.ParseBuildTarget(build_target_msg) |
| 124 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | af0e045 | 2019-06-03 18:10:01 -0600 | [diff] [blame] | 125 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 126 | if not sysroot_path: |
| 127 | sysroot_path = build_target.root |
| 128 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
Alex Klein | af0e045 | 2019-06-03 18:10:01 -0600 | [diff] [blame] | 129 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 130 | uri = input_proto.uri |
| 131 | # For now, we enforce that all input URIs are Google Storage buckets. |
| 132 | if not gs.PathIsGs(uri): |
| 133 | raise ValueError("Upload URI %s must be Google Storage." % uri) |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 134 | |
Alex Klein | a0472ed | 2022-11-02 12:07:04 -0600 | [diff] [blame] | 135 | package_index_paths = [f.path.path for f in input_proto.package_index_files] |
| 136 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 137 | if config.validate_only: |
| 138 | return controller.RETURN_CODE_VALID_INPUT |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 139 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 140 | parsed_uri = urllib.parse.urlparse(uri) |
| 141 | upload_uri = gs.GetGsURL(parsed_uri.netloc, for_gsutil=True).rstrip("/") |
| 142 | upload_path = parsed_uri.path.lstrip("/") |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 143 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 144 | # Read all packages and update the index. The index must be uploaded to the |
| 145 | # binhost for Portage to use it, so include it in upload_targets. |
| 146 | uploads_dir = binhost.GetPrebuiltsRoot(chroot, sysroot, build_target) |
| 147 | index_path = binhost.UpdatePackageIndex( |
| 148 | uploads_dir, upload_uri, upload_path, sudo=True |
| 149 | ) |
Alex Klein | a0472ed | 2022-11-02 12:07:04 -0600 | [diff] [blame] | 150 | upload_targets = binhost.GetPrebuiltsFiles( |
| 151 | uploads_dir, package_index_paths=package_index_paths, sudo=True |
| 152 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 153 | assert index_path.startswith( |
| 154 | uploads_dir |
| 155 | ), "expected index_path to start with uploads_dir" |
| 156 | upload_targets.append(index_path[len(uploads_dir) :]) |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 157 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 158 | output_proto.uploads_dir = uploads_dir |
| 159 | for upload_target in upload_targets: |
| 160 | output_proto.upload_targets.add().path = upload_target.strip("/") |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 161 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 162 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 163 | def _PrepareDevInstallBinhostUploadsResponse( |
| 164 | _input_proto, output_proto, _config |
| 165 | ): |
| 166 | """Add fake binhost files to a successful response.""" |
| 167 | output_proto.upload_targets.add().path = "app-arch/zip-3.0-r3.tbz2" |
| 168 | output_proto.upload_targets.add().path = "virtual/python-enum34-1.tbz2" |
| 169 | output_proto.upload_targets.add().path = "Packages" |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 170 | |
| 171 | |
| 172 | @faux.success(_PrepareDevInstallBinhostUploadsResponse) |
| 173 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 174 | @validate.require("uri", "sysroot.path") |
| 175 | @validate.exists("uploads_dir") |
Kevin Shelton | 703b688 | 2022-01-24 16:31:31 -0800 | [diff] [blame] | 176 | def PrepareDevInstallBinhostUploads( |
| 177 | input_proto: binhost_pb2.PrepareDevInstallBinhostUploadsRequest, |
| 178 | output_proto: binhost_pb2.PrepareDevInstallBinhostUploadsResponse, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 179 | config: "api_config.ApiConfig", |
| 180 | ): |
| 181 | """Return a list of files to upload to the binhost" |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 182 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 183 | The files will also be copied to the uploads_dir. |
| 184 | See BinhostService documentation in api/proto/binhost.proto. |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 185 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 186 | Args: |
Alex Klein | 611dddd | 2022-10-11 17:02:01 -0600 | [diff] [blame] | 187 | input_proto: The input proto. |
| 188 | output_proto: The output proto. |
| 189 | config: The API call config. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 190 | """ |
| 191 | sysroot_path = input_proto.sysroot.path |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 192 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 193 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 194 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 195 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 196 | uri = input_proto.uri |
| 197 | # For now, we enforce that all input URIs are Google Storage buckets. |
| 198 | if not gs.PathIsGs(uri): |
| 199 | raise ValueError("Upload URI %s must be Google Storage." % uri) |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 200 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 201 | if config.validate_only: |
| 202 | return controller.RETURN_CODE_VALID_INPUT |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 203 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 204 | parsed_uri = urllib.parse.urlparse(uri) |
| 205 | upload_uri = gs.GetGsURL(parsed_uri.netloc, for_gsutil=True).rstrip("/") |
| 206 | upload_path = parsed_uri.path.lstrip("/") |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 207 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 208 | # Calculate the filename for the to-be-created Packages file, which will |
| 209 | # contain only devinstall packages. |
| 210 | devinstall_package_index_path = os.path.join( |
| 211 | input_proto.uploads_dir, "Packages" |
| 212 | ) |
| 213 | upload_targets_list = binhost.ReadDevInstallFilesToCreatePackageIndex( |
| 214 | chroot, sysroot, devinstall_package_index_path, upload_uri, upload_path |
| 215 | ) |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 216 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 217 | package_dir = chroot.full_path(sysroot.path, "packages") |
| 218 | for upload_target in upload_targets_list: |
| 219 | # Copy each package to target/category/package |
| 220 | upload_target = upload_target.strip("/") |
| 221 | category = upload_target.split(os.sep)[0] |
| 222 | target_dir = os.path.join(input_proto.uploads_dir, category) |
| 223 | if not os.path.exists(target_dir): |
| 224 | os.makedirs(target_dir) |
| 225 | full_src_pkg_path = os.path.join(package_dir, upload_target) |
| 226 | full_target_src_path = os.path.join( |
| 227 | input_proto.uploads_dir, upload_target |
| 228 | ) |
| 229 | shutil.copyfile(full_src_pkg_path, full_target_src_path) |
| 230 | output_proto.upload_targets.add().path = upload_target |
| 231 | output_proto.upload_targets.add().path = "Packages" |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 232 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 233 | |
Greg Edelston | 724c13d | 2023-04-07 16:19:24 -0600 | [diff] [blame] | 234 | def _UpdatePackageIndexResponse(_input_proto, _output_proto, _config): |
| 235 | """Set up a fake successful response.""" |
| 236 | |
| 237 | |
| 238 | @faux.success(_UpdatePackageIndexResponse) |
| 239 | @faux.empty_error |
| 240 | @validate.require("package_index_file") |
| 241 | @validate.require_any("set_upload_location") |
| 242 | @validate.validation_complete |
| 243 | def UpdatePackageIndex( |
| 244 | input_proto: binhost_pb2.UpdatePackageIndexRequest, |
| 245 | _output_proto: binhost_pb2.UpdatePackageIndexResponse, |
| 246 | _config: "api_config.ApiConfig", |
| 247 | ): |
| 248 | """Implementation for the BinhostService/UpdatePackageIndex endpoint.""" |
| 249 | # Load the index file. |
| 250 | index_path = controller_util.pb2_path_to_pathlib_path( |
| 251 | input_proto.package_index_file, |
| 252 | chroot=input_proto.chroot, |
| 253 | ) |
| 254 | pkgindex = binpkg.PackageIndex() |
| 255 | pkgindex.ReadFilePath(index_path) |
| 256 | |
| 257 | # Set the upload location for all packages. |
| 258 | if input_proto.set_upload_location: |
| 259 | if not input_proto.uri: |
| 260 | raise ValueError("set_upload_location is True, but no uri provided") |
| 261 | parsed_uri = urllib.parse.urlparse(input_proto.uri) |
| 262 | pkgindex.SetUploadLocation( |
| 263 | gs.GetGsURL(parsed_uri.netloc, for_gsutil=True).rstrip("/"), |
| 264 | parsed_uri.path.lstrip("/"), |
| 265 | ) |
| 266 | |
| 267 | # Write the updated index file back to its original location. |
| 268 | pkgindex.WriteFile(index_path) |
| 269 | |
| 270 | |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 271 | def _SetBinhostResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 272 | """Add fake binhost file to a successful response.""" |
| 273 | output_proto.output_file = "/path/to/BINHOST.conf" |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 274 | |
| 275 | |
| 276 | @faux.success(_SetBinhostResponse) |
| 277 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 278 | @validate.require("build_target.name", "key", "uri") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 279 | @validate.validation_complete |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 280 | def SetBinhost( |
| 281 | input_proto: binhost_pb2.SetBinhostRequest, |
| 282 | output_proto: binhost_pb2.SetBinhostResponse, |
| 283 | _config: "api_config.ApiConfig", |
| 284 | ): |
| 285 | """Set the URI for a given binhost key and build target. |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 286 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 287 | See BinhostService documentation in api/proto/binhost.proto. |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 288 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 289 | Args: |
Alex Klein | 611dddd | 2022-10-11 17:02:01 -0600 | [diff] [blame] | 290 | input_proto: The input proto. |
| 291 | output_proto: The output proto. |
| 292 | _config: The API call config. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 293 | """ |
| 294 | target = input_proto.build_target.name |
| 295 | key = binhost_pb2.BinhostKey.Name(input_proto.key) |
| 296 | uri = input_proto.uri |
| 297 | private = input_proto.private |
Arif Kasim | 6242cdd | 2022-10-19 17:51:00 +0000 | [diff] [blame] | 298 | max_uris = input_proto.max_uris or _DEFAULT_BINHOST_MAX_URIS |
Alex Klein | 6fb0eb8 | 2019-05-20 16:16:14 -0600 | [diff] [blame] | 299 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 300 | output_proto.output_file = binhost.SetBinhost( |
Arif Kasim | 6242cdd | 2022-10-19 17:51:00 +0000 | [diff] [blame] | 301 | target, key, uri, private=private, max_uris=max_uris |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 302 | ) |
LaMont Jones | c64ae21 | 2019-04-15 15:41:28 -0600 | [diff] [blame] | 303 | |
LaMont Jones | c64ae21 | 2019-04-15 15:41:28 -0600 | [diff] [blame] | 304 | |
Arif Kasim | a046726 | 2022-11-11 17:08:14 +0000 | [diff] [blame] | 305 | def _GetBinhostConfPathResponse(_input_proto, output_proto, _config): |
| 306 | """Add fake binhost file to a successful response.""" |
| 307 | output_proto.conf_path = "/path/to/BINHOST.conf" |
| 308 | |
| 309 | |
| 310 | @faux.success(_GetBinhostConfPathResponse) |
| 311 | @faux.empty_error |
| 312 | @validate.require("build_target.name", "key") |
| 313 | @validate.validation_complete |
| 314 | def GetBinhostConfPath( |
| 315 | input_proto: binhost_pb2.GetBinhostConfPathRequest, |
| 316 | output_proto: binhost_pb2.GetBinhostConfPathResponse, |
| 317 | _config: "api_config.ApiConfig", |
| 318 | ): |
| 319 | target = input_proto.build_target.name |
| 320 | key = binhost_pb2.BinhostKey.Name(input_proto.key) |
| 321 | private = input_proto.private |
| 322 | output_proto.conf_path = str( |
| 323 | binhost.GetBinhostConfPath(target, key, private) |
| 324 | ) |
| 325 | |
| 326 | |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 327 | def _RegenBuildCacheResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 328 | """Add fake binhosts cache path to a successful response.""" |
| 329 | output_proto.modified_overlays.add().path = "/path/to/BuildCache" |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 330 | |
| 331 | |
| 332 | @faux.success(_RegenBuildCacheResponse) |
| 333 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 334 | @validate.require("overlay_type") |
| 335 | @validate.is_in("overlay_type", _OVERLAY_TYPE_TO_NAME) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 336 | @validate.validation_complete |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 337 | def RegenBuildCache( |
| 338 | input_proto: binhost_pb2.RegenBuildCacheRequest, |
| 339 | output_proto: binhost_pb2.RegenBuildCacheResponse, |
| 340 | _config: "api_config.ApiConfig", |
| 341 | ): |
| 342 | """Regenerate the Build Cache for a build target. |
LaMont Jones | c64ae21 | 2019-04-15 15:41:28 -0600 | [diff] [blame] | 343 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 344 | See BinhostService documentation in api/proto/binhost.proto. |
LaMont Jones | c64ae21 | 2019-04-15 15:41:28 -0600 | [diff] [blame] | 345 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 346 | Args: |
Alex Klein | 611dddd | 2022-10-11 17:02:01 -0600 | [diff] [blame] | 347 | input_proto: The input proto. |
| 348 | output_proto: The output proto. |
| 349 | _config: The API call config. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 350 | """ |
| 351 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 352 | overlay_type = input_proto.overlay_type |
| 353 | overlays = binhost.RegenBuildCache( |
| 354 | chroot, _OVERLAY_TYPE_TO_NAME[overlay_type] |
| 355 | ) |
Alex Klein | 82c85d4 | 2019-08-14 15:47:51 -0600 | [diff] [blame] | 356 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 357 | for overlay in overlays: |
| 358 | output_proto.modified_overlays.add().path = overlay |