Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -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 | |
Alex Klein | e0fa642 | 2019-06-21 12:01:39 -0600 | [diff] [blame] | 5 | """Router class for the Build API. |
| 6 | |
| 7 | Handles routing requests to the appropriate controller and handles service |
| 8 | registration. |
| 9 | """ |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 10 | |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 11 | import collections |
Mike Frysinger | c2e72b4 | 2023-03-03 22:34:04 -0500 | [diff] [blame] | 12 | import contextlib |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 13 | import importlib |
Chris McDonald | 1672ddb | 2021-07-21 11:48:23 -0600 | [diff] [blame] | 14 | import logging |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 15 | import os |
Tomasz Tylenda | b429230 | 2021-08-08 18:59:36 +0900 | [diff] [blame] | 16 | from types import ModuleType |
| 17 | from typing import Callable, List, TYPE_CHECKING |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 18 | |
Mike Frysinger | 2c02406 | 2021-05-22 15:43:22 -0400 | [diff] [blame] | 19 | from chromite.third_party.google.protobuf import symbol_database |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 20 | |
| 21 | from chromite.api import controller |
| 22 | from chromite.api import field_handler |
Alex Klein | 4de25e8 | 2019-08-05 15:58:39 -0600 | [diff] [blame] | 23 | from chromite.api.gen.chromite.api import android_pb2 |
Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 24 | from chromite.api.gen.chromite.api import api_pb2 |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 25 | from chromite.api.gen.chromite.api import artifacts_pb2 |
| 26 | from chromite.api.gen.chromite.api import binhost_pb2 |
| 27 | from chromite.api.gen.chromite.api import build_api_pb2 |
Tristan Honscheid | 52ba4d2 | 2023-02-09 11:59:29 -0700 | [diff] [blame] | 28 | from chromite.api.gen.chromite.api import copybot_pb2 |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 29 | from chromite.api.gen.chromite.api import depgraph_pb2 |
Benjamin Shai | 80317fc | 2023-08-22 19:33:41 +0000 | [diff] [blame] | 30 | from chromite.api.gen.chromite.api import dlc_pb2 |
Jett Rink | 17ed0f5 | 2020-09-25 17:14:31 -0600 | [diff] [blame] | 31 | from chromite.api.gen.chromite.api import firmware_pb2 |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 32 | from chromite.api.gen.chromite.api import image_pb2 |
Alex Klein | d4d9caa | 2021-11-10 15:44:52 -0700 | [diff] [blame] | 33 | from chromite.api.gen.chromite.api import metadata_pb2 |
Lizzy Presland | e723c01 | 2022-06-10 05:05:37 +0000 | [diff] [blame] | 34 | from chromite.api.gen.chromite.api import observability_pb2 |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 35 | from chromite.api.gen.chromite.api import packages_pb2 |
George Engelbrecht | fe63c8c | 2019-08-31 22:51:29 -0600 | [diff] [blame] | 36 | from chromite.api.gen.chromite.api import payload_pb2 |
Alexander Liu | 008389c | 2022-06-27 18:30:11 +0000 | [diff] [blame] | 37 | from chromite.api.gen.chromite.api import portage_explorer_pb2 |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 38 | from chromite.api.gen.chromite.api import sdk_pb2 |
| 39 | from chromite.api.gen.chromite.api import sysroot_pb2 |
| 40 | from chromite.api.gen.chromite.api import test_pb2 |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 41 | from chromite.api.gen.chromite.api import toolchain_pb2 |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 42 | from chromite.lib import constants |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 43 | from chromite.lib import cros_build_lib |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 44 | from chromite.lib import osutils |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 45 | from chromite.utils import memoize |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 46 | |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 47 | |
Tomasz Tylenda | b429230 | 2021-08-08 18:59:36 +0900 | [diff] [blame] | 48 | if TYPE_CHECKING: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 49 | from chromite.third_party import google |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 50 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 51 | from chromite.api import api_config |
| 52 | from chromite.api import message_util |
Mike Frysinger | 88770ef | 2021-05-21 11:04:00 -0400 | [diff] [blame] | 53 | |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 54 | MethodData = collections.namedtuple( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 55 | "MethodData", ("service_descriptor", "module_name", "method_descriptor") |
| 56 | ) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 57 | |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame] | 58 | |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 59 | class Error(Exception): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 60 | """Base error class for the module.""" |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 61 | |
| 62 | |
Alex Klein | d3394c2 | 2020-06-16 14:05:06 -0600 | [diff] [blame] | 63 | class InvalidSdkError(Error): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 64 | """Raised when the SDK is invalid or does not exist.""" |
Alex Klein | d3394c2 | 2020-06-16 14:05:06 -0600 | [diff] [blame] | 65 | |
| 66 | |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 67 | class CrosSdkNotRunError(Error): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 68 | """Raised when the cros_sdk command could not be run to enter the chroot.""" |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 69 | |
| 70 | |
| 71 | # API Service Errors. |
| 72 | class UnknownServiceError(Error): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 73 | """Error raised when the requested service has not been registered.""" |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 74 | |
| 75 | |
| 76 | class ControllerModuleNotDefinedError(Error): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 77 | """Error class for when no controller has been defined for a service.""" |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 78 | |
| 79 | |
| 80 | class ServiceControllerNotFoundError(Error): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 81 | """Error raised when the service's controller cannot be imported.""" |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 82 | |
| 83 | |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 84 | class TotSdkError(Error): |
| 85 | """When attempting to run a ToT endpoint inside the SDK.""" |
| 86 | |
| 87 | |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 88 | # API Method Errors. |
| 89 | class UnknownMethodError(Error): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 90 | """The service has been defined in the proto, but the method has not.""" |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 91 | |
| 92 | |
| 93 | class MethodNotFoundError(Error): |
Alex Klein | 54c891a | 2023-01-24 10:45:41 -0700 | [diff] [blame] | 94 | """The method's implementation cannot be found in the controller.""" |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 95 | |
| 96 | |
Alex Klein | 074f94f | 2023-06-22 10:32:06 -0600 | [diff] [blame] | 97 | class Router: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 98 | """Encapsulates the request dispatching logic.""" |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 99 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 100 | REEXEC_INPUT_FILE = "input_proto" |
| 101 | REEXEC_OUTPUT_FILE = "output_proto" |
| 102 | REEXEC_CONFIG_FILE = "config_proto" |
Alex Klein | bd6edf8 | 2019-07-18 10:30:49 -0600 | [diff] [blame] | 103 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 104 | def __init__(self): |
| 105 | self._services = {} |
| 106 | self._aliases = {} |
| 107 | # All imported generated messages get added to this symbol db. |
| 108 | self._sym_db = symbol_database.Default() |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 109 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 110 | # Save the service and method extension info for looking up |
| 111 | # configured extension data. |
| 112 | extensions = build_api_pb2.DESCRIPTOR.extensions_by_name |
| 113 | self._svc_options_ext = extensions["service_options"] |
| 114 | self._method_options_ext = extensions["method_options"] |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 115 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 116 | @memoize.Memoize |
| 117 | def _get_method_data(self, service_name, method_name): |
| 118 | """Get the descriptors and module name for the given Service/Method.""" |
| 119 | try: |
| 120 | svc, module_name = self._services[service_name] |
| 121 | except KeyError: |
| 122 | raise UnknownServiceError( |
| 123 | "The %s service has not been registered." % service_name |
| 124 | ) |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 125 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 126 | try: |
| 127 | method_desc = svc.methods_by_name[method_name] |
| 128 | except KeyError: |
| 129 | raise UnknownMethodError( |
| 130 | "The %s method has not been defined in the %s " |
| 131 | "service." % (method_name, service_name) |
| 132 | ) |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 133 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 134 | return MethodData( |
| 135 | service_descriptor=svc, |
| 136 | module_name=module_name, |
| 137 | method_descriptor=method_desc, |
| 138 | ) |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 139 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 140 | def get_input_message_instance(self, service_name, method_name): |
| 141 | """Get an empty input message instance for the specified method.""" |
| 142 | method_data = self._get_method_data(service_name, method_name) |
| 143 | return self._sym_db.GetPrototype( |
| 144 | method_data.method_descriptor.input_type |
| 145 | )() |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 146 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 147 | def _get_output_message_instance(self, service_name, method_name): |
| 148 | """Get an empty output message instance for the specified method.""" |
| 149 | method_data = self._get_method_data(service_name, method_name) |
| 150 | return self._sym_db.GetPrototype( |
| 151 | method_data.method_descriptor.output_type |
| 152 | )() |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 153 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 154 | def _get_module_name(self, service_name, method_name): |
| 155 | """Get the name of the module containing the endpoint implementation.""" |
| 156 | return self._get_method_data(service_name, method_name).module_name |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 157 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 158 | def _get_service_options(self, service_name, method_name): |
| 159 | """Get the configured service options for the endpoint.""" |
| 160 | method_data = self._get_method_data(service_name, method_name) |
| 161 | svc_extensions = method_data.service_descriptor.GetOptions().Extensions |
| 162 | return svc_extensions[self._svc_options_ext] |
Alex Klein | 92341cd | 2020-02-27 14:11:04 -0700 | [diff] [blame] | 163 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 164 | def _get_method_options(self, service_name, method_name): |
| 165 | """Get the configured method options for the endpoint.""" |
| 166 | method_data = self._get_method_data(service_name, method_name) |
| 167 | method_extensions = ( |
| 168 | method_data.method_descriptor.GetOptions().Extensions |
| 169 | ) |
| 170 | return method_extensions[self._method_options_ext] |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 171 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 172 | def Register(self, proto_module: ModuleType): |
| 173 | """Register the services from a generated proto module. |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 174 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 175 | Args: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 176 | proto_module: The generated proto module to register. |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 177 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 178 | Raises: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 179 | ServiceModuleNotDefinedError when the service cannot be found in the |
| 180 | provided module. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 181 | """ |
| 182 | services = proto_module.DESCRIPTOR.services_by_name |
| 183 | for service_name, svc in services.items(): |
| 184 | module_name = ( |
| 185 | svc.GetOptions().Extensions[self._svc_options_ext].module |
| 186 | ) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 187 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 188 | if not module_name: |
| 189 | raise ControllerModuleNotDefinedError( |
Alex Klein | 54c891a | 2023-01-24 10:45:41 -0700 | [diff] [blame] | 190 | "The module must be defined in the service definition: " |
| 191 | f"{proto_module}.{service_name}" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 192 | ) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 193 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 194 | self._services[svc.full_name] = (svc, module_name) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 195 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 196 | def ListMethods(self): |
| 197 | """List all methods registered with the router.""" |
| 198 | services = [] |
| 199 | for service_name, (svc, _module) in self._services.items(): |
| 200 | svc_visibility = getattr( |
| 201 | svc.GetOptions().Extensions[self._svc_options_ext], |
| 202 | "service_visibility", |
| 203 | build_api_pb2.LV_VISIBLE, |
| 204 | ) |
| 205 | if svc_visibility == build_api_pb2.LV_HIDDEN: |
| 206 | continue |
Alex Klein | 6cce6f6 | 2021-03-02 14:24:05 -0700 | [diff] [blame] | 207 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 208 | for method_name in svc.methods_by_name.keys(): |
| 209 | method_options = self._get_method_options( |
| 210 | service_name, method_name |
| 211 | ) |
| 212 | method_visibility = getattr( |
| 213 | method_options, |
| 214 | "method_visibility", |
| 215 | build_api_pb2.LV_VISIBLE, |
| 216 | ) |
| 217 | if method_visibility == build_api_pb2.LV_HIDDEN: |
| 218 | continue |
| 219 | |
| 220 | services.append("%s/%s" % (service_name, method_name)) |
| 221 | |
| 222 | return sorted(services) |
| 223 | |
| 224 | def Route( |
| 225 | self, |
| 226 | service_name: str, |
| 227 | method_name: str, |
| 228 | config: "api_config.ApiConfig", |
| 229 | input_handler: "message_util.MessageHandler", |
| 230 | output_handlers: List["message_util.MessageHandler"], |
| 231 | config_handler: "message_util.MessageHandler", |
| 232 | ) -> int: |
| 233 | """Dispatch the request. |
| 234 | |
| 235 | Args: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 236 | service_name: The fully qualified service name. |
| 237 | method_name: The name of the method being called. |
| 238 | config: The call configs. |
| 239 | input_handler: The request message handler. |
| 240 | output_handlers: The response message handlers. |
| 241 | config_handler: The config message handler. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 242 | |
| 243 | Returns: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 244 | The return code. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 245 | |
| 246 | Raises: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 247 | InvalidInputFileError when the input file cannot be read. |
| 248 | InvalidOutputFileError when the output file cannot be written. |
| 249 | ServiceModuleNotFoundError when the service module cannot be |
| 250 | imported. |
| 251 | MethodNotFoundError when the method cannot be retrieved from the |
| 252 | module. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 253 | """ |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 254 | # Fetch the method options for chroot and method name overrides. |
| 255 | method_options = self._get_method_options(service_name, method_name) |
| 256 | |
| 257 | # Check the chroot settings before running. |
| 258 | service_options = self._get_service_options(service_name, method_name) |
| 259 | |
| 260 | if self._needs_branch_reexecution( |
| 261 | service_options, method_options, config |
| 262 | ): |
| 263 | logging.info("Re-executing the endpoint on the branched BAPI.") |
| 264 | return self._reexecute_branched( |
| 265 | input_handler, |
| 266 | output_handlers, |
| 267 | config_handler, |
| 268 | service_name, |
| 269 | method_name, |
| 270 | ) |
| 271 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 272 | input_msg = self.get_input_message_instance(service_name, method_name) |
| 273 | input_handler.read_into(input_msg) |
| 274 | |
| 275 | # Get an empty output message instance. |
| 276 | output_msg = self._get_output_message_instance( |
| 277 | service_name, method_name |
| 278 | ) |
| 279 | |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 280 | chroot_reexec = self._needs_chroot_reexecution( |
| 281 | service_options, method_options, config |
| 282 | ) |
Alex Klein | 6cce6f6 | 2021-03-02 14:24:05 -0700 | [diff] [blame] | 283 | |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 284 | if chroot_reexec and not constants.IS_BRANCHED_CHROMITE: |
| 285 | # Can't run inside the SDK with ToT chromite. |
| 286 | raise TotSdkError( |
| 287 | f"Cannot run ToT {service_name}/{method_name} inside the SDK." |
| 288 | ) |
| 289 | elif chroot_reexec: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 290 | logging.info("Re-executing the endpoint inside the chroot.") |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 291 | return self._reexecute_inside( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 292 | input_msg, |
| 293 | output_msg, |
| 294 | config, |
| 295 | input_handler, |
| 296 | output_handlers, |
| 297 | config_handler, |
| 298 | service_name, |
| 299 | method_name, |
| 300 | ) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 301 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 302 | # Allow proto-based method name override. |
| 303 | if method_options.HasField("implementation_name"): |
| 304 | implementation_name = method_options.implementation_name |
| 305 | else: |
| 306 | implementation_name = method_name |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 307 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 308 | # Import the module and get the method. |
| 309 | module_name = self._get_module_name(service_name, method_name) |
| 310 | method_impl = self._GetMethod(module_name, implementation_name) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 311 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 312 | # Successfully located; call and return. |
| 313 | return_code = method_impl(input_msg, output_msg, config) |
| 314 | if return_code is None: |
| 315 | return_code = controller.RETURN_CODE_SUCCESS |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 316 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 317 | for h in output_handlers: |
| 318 | h.write_from(output_msg) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 319 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 320 | return return_code |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 321 | |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 322 | def _needs_branch_reexecution( |
| 323 | self, |
| 324 | service_options: "google.protobuf.Message", |
| 325 | method_options: "google.protobuf.Message", |
| 326 | config: "api_config.ApiConfig", |
| 327 | ) -> bool: |
| 328 | """Check if the call needs to be re-executed on the branched BAPI.""" |
| 329 | if not config.run_endpoint: |
| 330 | # Do not re-exec for validate only and mock calls. |
| 331 | return False |
| 332 | |
| 333 | if method_options.HasField("method_branched_execution"): |
| 334 | # Prefer the method option when set. |
| 335 | branched_exec = method_options.method_branched_execution |
| 336 | elif service_options.HasField("service_branched_execution"): |
| 337 | # Fall back to the service option. |
| 338 | branched_exec = service_options.service_branched_execution |
| 339 | else: |
| 340 | branched_exec = build_api_pb2.EXECUTE_BRANCHED |
| 341 | |
| 342 | if branched_exec in ( |
| 343 | build_api_pb2.EXECUTE_NOT_SPECIFIED, |
| 344 | build_api_pb2.EXECUTE_BRANCHED, |
| 345 | ): |
| 346 | return not constants.IS_BRANCHED_CHROMITE |
| 347 | |
| 348 | return False |
| 349 | |
| 350 | def _needs_chroot_reexecution( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 351 | self, |
| 352 | service_options: "google.protobuf.Message", |
| 353 | method_options: "google.protobuf.Message", |
| 354 | config: "api_config.ApiConfig", |
| 355 | ) -> bool: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 356 | """Check the chroot options; execute assertion or note reexec as needed. |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 357 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 358 | Args: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 359 | service_options: The service options. |
| 360 | method_options: The method options. |
| 361 | config: The Build API call config instance. |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 362 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 363 | Returns: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 364 | True iff it needs to be reexeced inside the chroot. |
Alex Klein | bd6edf8 | 2019-07-18 10:30:49 -0600 | [diff] [blame] | 365 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 366 | Raises: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 367 | cros_build_lib.DieSystemExit when the chroot setting cannot be |
| 368 | satisfied. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 369 | """ |
| 370 | if not config.run_endpoint: |
| 371 | # Do not enter the chroot for validate only and mock calls. |
| 372 | return False |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 373 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 374 | chroot_assert = build_api_pb2.NO_ASSERTION |
| 375 | if method_options.HasField("method_chroot_assert"): |
| 376 | # Prefer the method option when set. |
| 377 | chroot_assert = method_options.method_chroot_assert |
| 378 | elif service_options.HasField("service_chroot_assert"): |
| 379 | # Fall back to the service option. |
| 380 | chroot_assert = service_options.service_chroot_assert |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 381 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 382 | if chroot_assert == build_api_pb2.INSIDE: |
| 383 | return not cros_build_lib.IsInsideChroot() |
| 384 | elif chroot_assert == build_api_pb2.OUTSIDE: |
| 385 | # If it must be run outside we have to already be outside. |
| 386 | cros_build_lib.AssertOutsideChroot() |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 387 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 388 | return False |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 389 | |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 390 | def _reexecute_branched( |
| 391 | self, |
| 392 | input_handler: "message_util.MessageHandler", |
| 393 | output_handlers: List["message_util.MessageHandler"], |
| 394 | config_handler: "message_util.MessageHandler", |
| 395 | service_name: str, |
| 396 | method_name: str, |
| 397 | ): |
| 398 | """Re-execute the call on the branched BAPI. |
| 399 | |
| 400 | Args: |
| 401 | input_handler: Input message handler. |
| 402 | output_handlers: Output message handlers. |
| 403 | config_handler: Config message handler. |
| 404 | service_name: The name of the service to run. |
| 405 | method_name: The name of the method to run. |
| 406 | """ |
| 407 | cmd = [ |
| 408 | constants.BRANCHED_CHROMITE_DIR / "bin" / "build_api", |
| 409 | f"{service_name}/{method_name}", |
| 410 | input_handler.input_arg, |
| 411 | input_handler.path, |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 412 | "--debug", |
| 413 | ] |
Alex Klein | db79a3c | 2023-05-11 09:45:20 -0600 | [diff] [blame] | 414 | |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 415 | for output_handler in output_handlers: |
| 416 | cmd += [ |
| 417 | output_handler.output_arg, |
| 418 | output_handler.path, |
| 419 | ] |
| 420 | |
Alex Klein | db79a3c | 2023-05-11 09:45:20 -0600 | [diff] [blame] | 421 | # Config is optional, check it was actually used before adding. |
| 422 | if config_handler.path: |
| 423 | cmd += [ |
| 424 | config_handler.config_arg, |
| 425 | config_handler.path, |
| 426 | ] |
| 427 | |
Alex Klein | 12fc7ca | 2023-04-26 18:23:18 -0600 | [diff] [blame] | 428 | try: |
| 429 | result = cros_build_lib.run( |
| 430 | cmd, |
| 431 | check=False, |
| 432 | ) |
| 433 | except cros_build_lib.RunCommandError: |
| 434 | # A non-zero return code will not result in an error, but one |
| 435 | # is still thrown when the command cannot be run in the first |
| 436 | # place. This is known to happen at least when the PATH does |
| 437 | # not include the chromite bin dir. |
| 438 | raise CrosSdkNotRunError("Unable to execute the branched BAPI.") |
| 439 | |
| 440 | logging.info( |
| 441 | "Endpoint execution completed, return code: %d", |
| 442 | result.returncode, |
| 443 | ) |
| 444 | |
| 445 | return result.returncode |
| 446 | |
| 447 | def _reexecute_inside( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 448 | self, |
| 449 | input_msg: "google.protobuf.Message", |
| 450 | output_msg: "google.protobuf.Message", |
| 451 | config: "api_config.ApiConfig", |
| 452 | input_handler: "message_util.MessageHandler", |
| 453 | output_handlers: List["message_util.MessageHandler"], |
| 454 | config_handler: "message_util.MessageHandler", |
| 455 | service_name: str, |
| 456 | method_name: str, |
| 457 | ): |
| 458 | """Re-execute the service inside the chroot. |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 459 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 460 | Args: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 461 | input_msg: The parsed input message. |
| 462 | output_msg: The empty output message instance. |
| 463 | config: The call configs. |
| 464 | input_handler: Input message handler. |
| 465 | output_handlers: Output message handlers. |
| 466 | config_handler: Config message handler. |
| 467 | service_name: The name of the service to run. |
| 468 | method_name: The name of the method to run. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 469 | """ |
| 470 | # Parse the chroot and clear the chroot field in the input message. |
| 471 | chroot = field_handler.handle_chroot(input_msg) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 472 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 473 | if not chroot.exists(): |
| 474 | raise InvalidSdkError("Chroot does not exist.") |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 475 | |
Brian Norris | 2d53f9f | 2023-05-30 12:57:48 -0700 | [diff] [blame] | 476 | # This may be redundant with other SDK setup flows, but we need this |
| 477 | # tmp directory to exist (including across chromite updates, where the |
| 478 | # path may move) before we can write our proto messages (e.g., for |
| 479 | # SdkService/Update) to it below. |
| 480 | osutils.SafeMakedirsNonRoot(chroot.tmp, mode=0o777) |
| 481 | |
Mike Frysinger | c2e72b4 | 2023-03-03 22:34:04 -0500 | [diff] [blame] | 482 | # Use a ExitStack to avoid the deep nesting this many context managers |
| 483 | # introduces. |
| 484 | with contextlib.ExitStack() as stack: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 485 | # TempDirs setup. |
Mike Frysinger | c2e72b4 | 2023-03-03 22:34:04 -0500 | [diff] [blame] | 486 | tempdir = stack.enter_context(chroot.tempdir()) |
| 487 | sync_tempdir = stack.enter_context(chroot.tempdir()) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 488 | # The copy-paths-in context manager to handle Path messages. |
Mike Frysinger | c2e72b4 | 2023-03-03 22:34:04 -0500 | [diff] [blame] | 489 | stack.enter_context( |
| 490 | field_handler.copy_paths_in( |
| 491 | input_msg, |
| 492 | chroot.tmp, |
Brian Norris | 5c637c4 | 2023-05-04 18:07:48 -0700 | [diff] [blame] | 493 | chroot=chroot, |
Mike Frysinger | c2e72b4 | 2023-03-03 22:34:04 -0500 | [diff] [blame] | 494 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 495 | ) |
| 496 | # The sync-directories context manager to handle SyncedDir messages. |
Mike Frysinger | c2e72b4 | 2023-03-03 22:34:04 -0500 | [diff] [blame] | 497 | stack.enter_context( |
| 498 | field_handler.sync_dirs( |
| 499 | input_msg, |
| 500 | sync_tempdir, |
Brian Norris | 5c637c4 | 2023-05-04 18:07:48 -0700 | [diff] [blame] | 501 | chroot=chroot, |
Mike Frysinger | c2e72b4 | 2023-03-03 22:34:04 -0500 | [diff] [blame] | 502 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 503 | ) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 504 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 505 | # Parse goma. |
Brian Norris | d0dfeae | 2023-03-09 13:06:47 -0800 | [diff] [blame] | 506 | chroot.goma = field_handler.handle_goma( |
| 507 | input_msg, chroot.path, chroot.out_path |
| 508 | ) |
Alex Klein | d1e9e5c | 2020-12-14 12:32:32 -0700 | [diff] [blame] | 509 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 510 | # Parse remoteexec. |
| 511 | chroot.remoteexec = field_handler.handle_remoteexec(input_msg) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 512 | |
Alex Klein | 54c891a | 2023-01-24 10:45:41 -0700 | [diff] [blame] | 513 | # Build inside-chroot paths for the input, output, and config |
| 514 | # messages. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 515 | new_input = os.path.join(tempdir, self.REEXEC_INPUT_FILE) |
Brian Norris | 8faf47b | 2023-03-03 16:19:08 -0800 | [diff] [blame] | 516 | chroot_input = chroot.chroot_path(new_input) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 517 | new_output = os.path.join(tempdir, self.REEXEC_OUTPUT_FILE) |
Brian Norris | 8faf47b | 2023-03-03 16:19:08 -0800 | [diff] [blame] | 518 | chroot_output = chroot.chroot_path(new_output) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 519 | new_config = os.path.join(tempdir, self.REEXEC_CONFIG_FILE) |
Brian Norris | 8faf47b | 2023-03-03 16:19:08 -0800 | [diff] [blame] | 520 | chroot_config = chroot.chroot_path(new_config) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 521 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 522 | # Setup the inside-chroot message files. |
| 523 | logging.info("Writing input message to: %s", new_input) |
| 524 | input_handler.write_from(input_msg, path=new_input) |
| 525 | osutils.Touch(new_output) |
| 526 | logging.info("Writing config message to: %s", new_config) |
| 527 | config_handler.write_from(config.get_proto(), path=new_config) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 528 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 529 | # We can use a single output to write the rest of them. Use the |
| 530 | # first one as the reexec output and just translate its output in |
| 531 | # the rest of the handlers after. |
| 532 | output_handler = output_handlers[0] |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 533 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 534 | cmd = [ |
| 535 | "build_api", |
| 536 | "%s/%s" % (service_name, method_name), |
| 537 | input_handler.input_arg, |
| 538 | chroot_input, |
| 539 | output_handler.output_arg, |
| 540 | chroot_output, |
| 541 | config_handler.config_arg, |
| 542 | chroot_config, |
| 543 | "--debug", |
| 544 | ] |
Alex Klein | 915cce9 | 2019-12-17 14:19:50 -0700 | [diff] [blame] | 545 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 546 | try: |
Brian Norris | 3a585d2 | 2023-07-19 16:26:11 -0700 | [diff] [blame] | 547 | result = chroot.run( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 548 | cmd, |
Alex Klein | 9057b1a | 2023-05-23 15:44:18 -0600 | [diff] [blame] | 549 | cwd=constants.SOURCE_ROOT, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 550 | check=False, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 551 | ) |
| 552 | except cros_build_lib.RunCommandError: |
| 553 | # A non-zero return code will not result in an error, but one |
| 554 | # is still thrown when the command cannot be run in the first |
| 555 | # place. This is known to happen at least when the PATH does |
| 556 | # not include the chromite bin dir. |
| 557 | raise CrosSdkNotRunError("Unable to enter the chroot.") |
Alex Klein | d3394c2 | 2020-06-16 14:05:06 -0600 | [diff] [blame] | 558 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 559 | logging.info( |
| 560 | "Endpoint execution completed, return code: %d", |
| 561 | result.returncode, |
| 562 | ) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 563 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 564 | # Transfer result files out of the chroot. |
| 565 | output_handler.read_into(output_msg, path=new_output) |
| 566 | field_handler.extract_results(input_msg, output_msg, chroot) |
Alex Klein | 9b7331e | 2019-12-30 14:37:21 -0700 | [diff] [blame] | 567 | |
Alex Klein | 54c891a | 2023-01-24 10:45:41 -0700 | [diff] [blame] | 568 | # Write out all the response formats. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 569 | for handler in output_handlers: |
| 570 | handler.write_from(output_msg) |
Joanna Wang | 92cad81 | 2021-11-03 14:52:08 -0700 | [diff] [blame] | 571 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 572 | return result.returncode |
Alex Klein | 9b7331e | 2019-12-30 14:37:21 -0700 | [diff] [blame] | 573 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 574 | def _GetMethod(self, module_name: str, method_name: str) -> Callable: |
| 575 | """Get the implementation of the method for the service module. |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 576 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 577 | Args: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 578 | module_name: The name of the service module. |
| 579 | method_name: The name of the method. |
Alex Klein | e191ed6 | 2020-02-27 15:59:55 -0700 | [diff] [blame] | 580 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 581 | Returns: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 582 | The method. |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 583 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 584 | Raises: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 585 | MethodNotFoundError when the method cannot be found in the module. |
| 586 | ServiceModuleNotFoundError when the service module cannot be |
| 587 | imported. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 588 | """ |
| 589 | try: |
| 590 | module = importlib.import_module( |
| 591 | controller.IMPORT_PATTERN % module_name |
| 592 | ) |
| 593 | except ImportError as e: |
| 594 | raise ServiceControllerNotFoundError(str(e)) |
| 595 | try: |
| 596 | return getattr(module, method_name) |
| 597 | except AttributeError as e: |
| 598 | raise MethodNotFoundError(str(e)) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 599 | |
| 600 | |
Tomasz Tylenda | b429230 | 2021-08-08 18:59:36 +0900 | [diff] [blame] | 601 | def RegisterServices(router: Router): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 602 | """Register all the services. |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 603 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 604 | Args: |
Alex Klein | a044268 | 2022-10-10 13:47:38 -0600 | [diff] [blame] | 605 | router: The router. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 606 | """ |
| 607 | router.Register(android_pb2) |
| 608 | router.Register(api_pb2) |
| 609 | router.Register(artifacts_pb2) |
| 610 | router.Register(binhost_pb2) |
Tristan Honscheid | 52ba4d2 | 2023-02-09 11:59:29 -0700 | [diff] [blame] | 611 | router.Register(copybot_pb2) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 612 | router.Register(depgraph_pb2) |
Benjamin Shai | 80317fc | 2023-08-22 19:33:41 +0000 | [diff] [blame] | 613 | router.Register(dlc_pb2) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 614 | router.Register(firmware_pb2) |
| 615 | router.Register(image_pb2) |
| 616 | router.Register(metadata_pb2) |
Lizzy Presland | e723c01 | 2022-06-10 05:05:37 +0000 | [diff] [blame] | 617 | router.Register(observability_pb2) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 618 | router.Register(packages_pb2) |
| 619 | router.Register(payload_pb2) |
| 620 | router.Register(portage_explorer_pb2) |
| 621 | router.Register(sdk_pb2) |
| 622 | router.Register(sysroot_pb2) |
| 623 | router.Register(test_pb2) |
| 624 | router.Register(toolchain_pb2) |
| 625 | logging.debug("Services registered successfully.") |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 626 | |
| 627 | |
| 628 | def GetRouter(): |
Alex Klein | 54c891a | 2023-01-24 10:45:41 -0700 | [diff] [blame] | 629 | """Get a router that has had all the services registered.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 630 | router = Router() |
| 631 | RegisterServices(router) |
Alex Klein | 146d477 | 2019-06-20 13:48:25 -0600 | [diff] [blame] | 632 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 633 | return router |