api: artifacts: Cleanup legacy code paths
Cleanup some legacy input handling code paths that haven't been
relevant since at least April 2020.
BUG=b:223433932
TEST=CQ
Change-Id: Ib8de7880e2fbc06234671a90c3432376eb28a10a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3684159
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: Lizzy Presland <zland@google.com>
Commit-Queue: Lizzy Presland <zland@google.com>
Auto-Submit: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/artifacts.py b/api/controller/artifacts.py
index 28db938..372f3f5 100644
--- a/api/controller/artifacts.py
+++ b/api/controller/artifacts.py
@@ -282,40 +282,20 @@
@faux.success(_BundleAutotestFilesResponse)
@faux.empty_error
-@validate.require('output_dir')
+@validate.require('sysroot.path')
@validate.exists('output_dir')
-def BundleAutotestFiles(
- input_proto: artifacts_pb2.BundleRequest,
- output_proto: artifacts_pb2.BundleResponse,
- config: 'api_config.ApiConfig'):
- """Tar the autotest files for a build target.
-
- Args:
- input_proto: The input proto.
- output_proto: The output proto.
- config: The API call config.
- """
+@validate.validation_complete
+def BundleAutotestFiles(input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig') -> None:
+ """Tar the autotest files for a build target."""
output_dir = input_proto.output_dir
- target = input_proto.build_target.name
chroot = controller_util.ParseChroot(input_proto.chroot)
-
- if target:
- sysroot_path = os.path.join('/build', target)
- else:
- # New style call, use chroot and sysroot.
- sysroot_path = input_proto.sysroot.path
- if not sysroot_path:
- cros_build_lib.Die('sysroot.path is required.')
-
- sysroot = sysroot_lib.Sysroot(sysroot_path)
-
- # TODO(saklein): Switch to the validate_only decorator when legacy handling
- # is removed.
- if config.validate_only:
- return controller.RETURN_CODE_VALID_INPUT
+ sysroot = controller_util.ParseSysroot(input_proto.sysroot)
if not sysroot.Exists(chroot=chroot):
- cros_build_lib.Die('Sysroot path must exist: %s', sysroot.path)
+ logging.warning('Sysroot does not exist: %s', sysroot.path)
+ return
try:
# Note that this returns the full path to *multiple* tarballs.
@@ -336,52 +316,28 @@
@faux.success(_BundleTastFilesResponse)
@faux.empty_error
-@validate.require('output_dir')
+@validate.require('sysroot.path')
@validate.exists('output_dir')
-def BundleTastFiles(
- input_proto: artifacts_pb2.BundleRequest,
- output_proto: artifacts_pb2.BundleResponse,
- config: 'api_config.ApiConfig'):
- """Tar the tast files for a build target.
-
- Args:
- input_proto: The input proto.
- output_proto: The output proto.
- config: The API call config.
- """
- target = input_proto.build_target.name
+@validate.validation_complete
+def BundleTastFiles(input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig') -> None:
+ """Tar the tast files for a build target."""
output_dir = input_proto.output_dir
- build_root = constants.SOURCE_ROOT
-
chroot = controller_util.ParseChroot(input_proto.chroot)
- sysroot_path = input_proto.sysroot.path
+ sysroot = controller_util.ParseSysroot(input_proto.sysroot)
- # TODO(saklein) Cleanup legacy handling after it has been switched over.
- if target:
- # Legacy handling.
- chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot'))
- sysroot_path = os.path.join('/build', target)
-
- # New handling - chroot & sysroot based.
- # TODO(saklein) Switch this to the require decorator when legacy is removed.
- if not sysroot_path:
- cros_build_lib.Die('sysroot.path is required.')
-
- # TODO(saklein): Switch to the validation_complete decorator when legacy
- # handling is removed.
- if config.validate_only:
- return controller.RETURN_CODE_VALID_INPUT
-
- sysroot = sysroot_lib.Sysroot(sysroot_path)
if not sysroot.Exists(chroot=chroot):
- cros_build_lib.Die('Sysroot must exist.')
+ logging.warning('Sysroot does not exist: %s', sysroot.path)
+ return
archive = artifacts.BundleTastFiles(chroot, sysroot, output_dir)
- if archive:
- output_proto.artifacts.add().path = archive
- else:
- logging.warning('Found no tast files for %s.', target)
+ if not archive:
+ logging.warning('Found no tast files for %s.', sysroot.path)
+ return
+
+ output_proto.artifacts.add().path = archive
def BundlePinnedGuestImages(_input_proto, _output_proto, _config):
@@ -522,41 +478,29 @@
@faux.success(_BundleEbuildLogsResponse)
@faux.empty_error
+@validate.require('sysroot.path')
@validate.exists('output_dir')
-def BundleEbuildLogs(
- input_proto: artifacts_pb2.BundleRequest,
- output_proto: artifacts_pb2.BundleResponse,
- config: 'api_config.ApiConfig'):
- """Tar the ebuild logs for a build target.
-
- Args:
- input_proto: The input proto.
- output_proto: The output proto.
- config: The API call config.
- """
+@validate.validation_complete
+def BundleEbuildLogs(input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig') -> None:
+ """Tar the ebuild logs for a build target."""
output_dir = input_proto.output_dir
- sysroot_path = input_proto.sysroot.path
chroot = controller_util.ParseChroot(input_proto.chroot)
+ sysroot = controller_util.ParseSysroot(input_proto.sysroot)
- # TODO(mmortensen) Cleanup legacy handling after it has been switched over.
- target = input_proto.build_target.name
- if target:
- # Legacy handling.
- build_root = constants.SOURCE_ROOT
- chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot'))
- sysroot_path = os.path.join('/build', target)
+ if not sysroot.Exists(chroot=chroot):
+ logging.warning('Sysroot does not exist: %s', sysroot.path)
+ return
- # TODO(saklein): Switch to validation_complete decorator after legacy
- # handling has been cleaned up.
- if config.validate_only:
- return controller.RETURN_CODE_VALID_INPUT
-
- sysroot = sysroot_lib.Sysroot(sysroot_path)
archive = artifacts.BundleEBuildLogsTarball(chroot, sysroot, output_dir)
- if archive is None:
- cros_build_lib.Die(
+
+ if not archive:
+ logging.warning(
'Could not create ebuild logs archive. No logs found for %s.',
sysroot.path)
+ return
+
output_proto.artifacts.add().path = os.path.join(output_dir, archive)
@@ -681,34 +625,20 @@
@faux.success(_ExportCpeReportResponse)
@faux.empty_error
+@validate.require('sysroot.path')
@validate.exists('output_dir')
-def ExportCpeReport(
- input_proto: artifacts_pb2.BundleRequest,
- output_proto: artifacts_pb2.BundleResponse,
- config: 'api_config.ApiConfig'):
- """Export a CPE report.
-
- Args:
- input_proto: The input proto.
- output_proto: The output proto.
- config: The API call config.
- """
+@validate.validation_complete
+def ExportCpeReport(input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig') -> None:
+ """Export a CPE report."""
chroot = controller_util.ParseChroot(input_proto.chroot)
+ sysroot = controller_util.ParseSysroot(input_proto.sysroot)
output_dir = input_proto.output_dir
- if input_proto.build_target.name:
- # Legacy handling - use the default sysroot path for the build target.
- build_target = controller_util.ParseBuildTarget(input_proto.build_target)
- sysroot = sysroot_lib.Sysroot(build_target.root)
- elif input_proto.sysroot.path:
- sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path)
- else:
- # TODO(saklein): Switch to validate decorators once legacy handling can be
- # cleaned up.
- cros_build_lib.Die('sysroot.path is required.')
-
- if config.validate_only:
- return controller.RETURN_CODE_VALID_INPUT
+ if not sysroot.Exists(chroot=chroot):
+ logging.warning('Sysroot does not exist: %s', sysroot.path)
+ return
cpe_result = artifacts.GenerateCpeReport(chroot, sysroot, output_dir)