Build API: Prevent entering the chroot for mock/validate calls.

The interface for mock/validate calls should allow them to all be
executed without setting up the chroot. In practice, this currently
breaks at least the dependency service, but since nothing is relying
on it, that's fine for now.

I am planning on exploring adding builders that use the mock and validate
functionality, this will be a prereq for that.

BUG=None
TEST=run_pytest

Change-Id: I21aa38a2bbc2ff2793fc7d7ba0ab8ae0236dbcb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2589369
Tested-by: Alex Klein <saklein@chromium.org>
Auto-Submit: Alex Klein <saklein@chromium.org>
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Commit-Queue: Michael Mortensen <mmortensen@google.com>
diff --git a/api/router.py b/api/router.py
index 0fd85be..f556552 100644
--- a/api/router.py
+++ b/api/router.py
@@ -208,7 +208,7 @@
 
     # Check the chroot settings before running.
     service_options = self._get_service_options(service_name, method_name)
-    if self._ChrootCheck(service_options, method_options):
+    if self._ChrootCheck(service_options, method_options, config):
       # Run inside the chroot instead.
       logging.info('Re-executing the endpoint inside the chroot.')
       return self._ReexecuteInside(input_msg, output_msg, config, input_handler,
@@ -235,12 +235,14 @@
 
     return return_code
 
-  def _ChrootCheck(self, service_options, method_options):
+  def _ChrootCheck(self, service_options, method_options,
+                   config: 'api_config.ApiConfig'):
     """Check the chroot options, and execute assertion or note reexec as needed.
 
     Args:
       service_options (google.protobuf.Message): The service options.
       method_options (google.protobuf.Message): The method options.
+      config: The Build API call config instance.
 
     Returns:
       bool - True iff it needs to be reexeced inside the chroot.
@@ -248,6 +250,10 @@
     Raises:
       cros_build_lib.DieSystemExit when the chroot setting cannot be satisfied.
     """
+    if not config.run_endpoint:
+      # Do not enter the chroot for validate only and mock calls.
+      return False
+
     chroot_assert = build_api_pb2.NO_ASSERTION
     if method_options.HasField('method_chroot_assert'):
       # Prefer the method option when set.