summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Díaz <daniel.diaz@linaro.org>2015-09-22 16:18:44 -0700
committerFathi Boudra <fathi.boudra@linaro.org>2015-10-08 10:03:15 +0300
commit8d42d9ef617695547627e801f6cff599c77e0cb7 (patch)
tree29032c6ed1c50a5f0ce00478ff176b984e2beb49
parentf40e681f8c89132f8898682e32fc9e284045665b (diff)
downloadpost-build-lava-8d42d9ef617695547627e801f6cff599c77e0cb7.tar.gz
Add support for submitting Android jobs
With these changes, it should be possible to use post-build-lava to submit Android jobs as well. A functional change has been introuced: * Add FRONTEND_JOB_NAME env variable, which is used in the download URL. If not defined, it will use the job name as it did previously. Change-Id: I8136ef6f82b3785058dd47e0245f9d1739c58c84 Signed-off-by: Daniel Díaz <daniel.diaz@linaro.org>
-rwxr-xr-xpost-build-lava.py186
1 files changed, 186 insertions, 0 deletions
diff --git a/post-build-lava.py b/post-build-lava.py
index 694000a..bb82110 100755
--- a/post-build-lava.py
+++ b/post-build-lava.py
@@ -2,6 +2,7 @@
import base64
import collections
+import fileinput
import os
import sys
import json
@@ -50,6 +51,60 @@ ci_base_url = 'https://ci.linaro.org/jenkins/job/'
# Snapshots base URL
snapshots_url = 'http://snapshots.linaro.org'
+# Map a TARGET_PRODUCT to LAVA parameters.
+product_map = {
+ "vexpress": {
+ "test_device_type": "vexpress-a9",
+ },
+ "vexpress_rtsm": {
+ "test_device_type": "rtsm_ve-a15x4-a7x4",
+ },
+ "juno": {
+ "test_device_type": "wg",
+ "test_stream": "/private/team/wg/wg-private/",
+ },
+ "fvp": {
+ "test_device_type": "rtsm_fvp_base-aemv8a",
+ },
+ "full_jacinto6evm": {
+ "test_device_type": "vayu",
+ },
+ "fujitsu": {
+ "test_device_type": "aa9",
+ "test_stream": "/private/team/fujitsu/ci-LT-Fujitsu-working-tree/"
+ },
+ "aosp_manta": {
+ "test_device_type": "nexus10",
+ },
+ "aosp_flounder": {
+ "test_device_type": "nexus9",
+ },
+ "apm": {
+ "test_device_type": "mustang",
+ },
+}
+
+
+class LAVADeviceBase(object):
+ """
+ Base class for definition of the device type and target in lava job.
+ """
+
+ def __init__(self, name=None):
+ self.name = name
+
+
+class LAVADeviceType(LAVADeviceBase):
+ """
+ Representation the definition of the device type in lava job.
+ """
+
+
+class LAVADeviceTarget(LAVADeviceBase):
+ """
+ Representation the definition of the device target in lava job.
+ """
+
def obfuscate_credentials(s):
return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)
@@ -189,10 +244,138 @@ def lava_submit(config, lava_server):
sys.exit()
+def get_job_list():
+ job_list = ['CUSTOM_JSON_URL']
+ sec_job_prefix = 'CUSTOM_JSON_URL_'
+
+ for var in os.environ.keys():
+ if var.startswith(sec_job_prefix):
+ job_list.append(var)
+ job_list.sort()
+
+ return job_list
+
+
+def replace(fp, pattern, subst):
+ print pattern
+ print subst
+ for line in fileinput.input(fp, inplace=1):
+ if pattern in line:
+ line = line.replace(pattern, subst)
+ sys.stdout.write(line)
+ fileinput.close()
+
+
+def get_lava_device_type_or_target():
+ '''
+ Here we support the specification by both,
+ LAVA_DEVICE or LAVA_DEVICE_TYPE, and we can specify
+ both of them at the same time.
+ '''
+ devices = []
+
+ # allow to submit to a specific device
+ test_device = os.environ.get('LAVA_DEVICE')
+ if test_device:
+ targets = test_device.split(',')
+ for dev_target in targets:
+ dev_target = dev_target.strip()
+ if dev_target:
+ devices.append(LAVADeviceTarget(name=dev_target))
+
+ # allow overload lava device_type by build config
+ test_device_type = os.environ.get('LAVA_DEVICE_TYPE')
+
+ target_product = os.environ.get('TARGET_PRODUCT')
+ # only use the default device type when neither of
+ # LAVA_DEVICE or LAVA_DEVICE_TYPE is specified.
+ # or say we will not use the value when any of
+ # LAVA_DEVICE or LAVA_DEVICE_TYPE is specified.
+ if (not test_device_type) and (not test_device):
+ test_device_type = product_map[target_product]["test_device_type"]
+ if test_device_type:
+ types = test_device_type.split(',')
+ for dev_type in types:
+ dev_type = dev_type.strip()
+ if dev_type:
+ devices.append(LAVADeviceType(name=dev_type))
+
+ return devices
+
+
+def submit_job_from_url():
+ """This routine updates a predefined job with the parameters specific
+ to this particular build"""
+ job_list = get_job_list()
+ for job in job_list:
+ lava_job_url = os.environ.get(job)
+ if lava_job_url is None:
+ print "Error: No CUSTOM_JSON_URL provided"
+ return
+ jobresource = urllib2.urlopen(lava_job_url)
+ jobjson = open('job.json','wb')
+ jobjson.write(jobresource.read())
+ jobjson.close()
+ # Job name, defined by android-build, e.g. linaro-android_leb-panda
+ job_name = os.environ.get("JOB_NAME")
+ default_frontend_job_name = "~" + job_name.replace("_", "/", 1)
+ frontend_job_name = os.environ.get("FRONTEND_JOB_NAME", default_frontend_job_name)
+
+ # Build number, defined by android-build, e.g. 61
+ build_number = os.environ.get("BUILD_NUMBER")
+
+ # download base URL, this may differ from job URL if we don't host
+ # downloads in Jenkins any more
+ download_url = "%s/%s/%s/" % ('%s/android/' % snapshots_url,
+ frontend_job_name,
+ build_number)
+ # Set the file extension based on the type of artifacts
+ artifact_type = os.environ.get("MAKE_TARGETS", "tarball")
+ if artifact_type == "droidcore":
+ file_extension = "img"
+ else:
+ file_extension = "tar.bz2"
+
+ boot_subst = "%s%s%s" % (download_url, "/boot.", file_extension)
+ system_subst = "%s%s%s" % (download_url, "/system.", file_extension)
+ userdata_subst = "%s%s%s" % (download_url, "/userdata.", file_extension)
+
+ replace("job.json", "%%ANDROID_BOOT%%", boot_subst)
+ replace("job.json", "%%ANDROID_SYSTEM%%", system_subst)
+ replace("job.json", "%%ANDROID_DATA%%", userdata_subst)
+ replace("job.json", "%%ANDROID_META_NAME%%", job_name)
+ replace("job.json", "%%JOB_NAME%%", job_name)
+ replace("job.json", "%%ANDROID_META_BUILD%%", build_number)
+ replace("job.json", "%%ANDROID_META_URL%%", os.environ.get("BUILD_URL"))
+ replace("job.json", "%%BUNDLE_STREAM%%", os.environ.get('LAVA_STREAM', '/private/team/linaro/android-daily/'))
+ replace("job.json", "%%WA2_JOB_NAME%%", build_number)
+ replace("job.json", "%%DOWNLOAD_URL%%", download_url)
+
+ devices = get_lava_device_type_or_target()
+
+ # LAVA server URL
+ lava_server = os.environ.get('LAVA_SERVER',
+ 'validation.linaro.org/RPC2/')
+
+ device = None
+ if len(devices) > 0:
+ device = devices[0];
+
+ replace("job.json", "%%DUT_TYPE%%", device.name)
+ with open("job.json", 'r') as fin:
+ print fin.read()
+ with open("job.json") as fd:
+ config = fd.read().strip()
+ lava_submit(config=config, lava_server=lava_server)
+
+ sys.exit()
+
+
def main():
'''Script entry point: return some JSON based on calling args.
We should be called from Jenkins and expect the following to be defined:
$HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
+ or, alternatively, $TARGET_PRODUCT $JOB_NAME $BUILD_NUMBER $BUILD_URL
'''
# LAVA server URL
@@ -208,6 +391,9 @@ def main():
else:
auth = None
+ if os.environ.get('TARGET_PRODUCT') is not None:
+ submit_job_from_url()
+
# Allow to override completely the generated json
# using file provided by the user
custom_json_url = os.environ.get('CUSTOM_JSON_URL')