Support build type pending.
For build created by trybot runs of Launch Control, the build type is pending,
rather than submitted. The change use the leading character P in build id to
determine if the build type is pending.
BUG=b:28826171
TEST=moblab run
Change-Id: Ie466d000cbf2b6b24305370fe1ff325f078785b7
Reviewed-on: https://chromium-review.googlesource.com/345683
Commit-Ready: Dan Shi <dshi@google.com>
Tested-by: Dan Shi <dshi@google.com>
Reviewed-by: Simran Basi <sbasi@chromium.org>
diff --git a/android_build.py b/android_build.py
index dd1a931..555f4c6 100644
--- a/android_build.py
+++ b/android_build.py
@@ -51,6 +51,19 @@
http_auth = credentials.authorize(httplib2.Http())
return discovery.build(DEFAULT_BUILDER, 'v1', http=http_auth)
+ @staticmethod
+ def _GetBuildType(build_id):
+ """Get the build type based on the given build id.
+
+ Args:
+ build_id: Build id of the Android build, e.g., 2155602.
+
+ Returns:
+ The build type, e.g., submitted, pending.
+ """
+ if build_id and build_id.lower().startswith('p'):
+ return 'pending'
+ return 'submitted'
@classmethod
def _VerifyBranch(cls, service_obj, branch, build_id, target):
@@ -66,8 +79,9 @@
AndroidBuildFetchError: If the given build id and target are not for the
specified branch.
"""
+ build_type = cls._GetBuildType(build_id)
builds = service_obj.build().list(
- buildType='submitted', branch=branch, buildId=build_id, target=target,
+ buildType=build_type, branch=branch, buildId=build_id, target=target,
maxResults=0).execute(num_retries=MAX_ATTEMPTS)
if not builds:
raise AndroidBuildFetchError(
@@ -99,10 +113,11 @@
"""
service_obj = cls._GetServiceObject()
cls._VerifyBranch(service_obj, branch, build_id, target)
+ build_type = cls._GetBuildType(build_id)
# Get all artifacts for the given build_id and target.
artifacts = service_obj.buildartifact().list(
- buildType='submitted', buildId=build_id, target=target,
+ buildType=build_type, buildId=build_id, target=target,
attemptId='latest', maxResults=0).execute(num_retries=MAX_ATTEMPTS)
return artifacts['artifacts']
@@ -124,9 +139,10 @@
# Delete partially downloaded file if exists.
subprocess.call(['rm', '-rf', dest_file])
+ build_type = cls._GetBuildType(build_id)
# TODO(dshi): Add retry logic here to avoid API flakes.
download_req = service_obj.buildartifact().get_media(
- buildType='submitted', buildId=build_id, target=target,
+ buildType=build_type, buildId=build_id, target=target,
attemptId='latest', resourceId=resource_id)
with io.FileIO(dest_file, mode='wb') as fh:
downloader = apiclient.http.MediaIoBaseDownload(