diff options
author | Riku Voipio <riku.voipio@linaro.org> | 2013-11-15 15:52:32 +0200 |
---|---|---|
committer | Riku Voipio <riku.voipio@linaro.org> | 2013-11-15 15:52:32 +0200 |
commit | 94fb39b20729e3acc42944d455df6eaa840ded2c (patch) | |
tree | 59d975558ff2ae27f35112bbbe7597b23065c73c | |
parent | 1e7fe1a0c07fd27eddcc90b359a705c46c4375a6 (diff) |
Add easy json job submit
-rwxr-xr-x | jenkins-arndale-commands.sh | 1 | ||||
-rwxr-xr-x | submit-json.py | 89 |
2 files changed, 90 insertions, 0 deletions
diff --git a/jenkins-arndale-commands.sh b/jenkins-arndale-commands.sh index e762d16..b6c613f 100755 --- a/jenkins-arndale-commands.sh +++ b/jenkins-arndale-commands.sh @@ -44,6 +44,7 @@ sed -e "s,%%KERNEL_URL%%,https://snapshots.linaro.org/kernel-hwpack/linux-arndal kvm-ci/job_template.json > job_arndale_kvm.json cat job_arndale_kvm.json +./kvm-ci/submit_json job_arndale_kvm.json cat << EOF > BUILD-INFO.txt Format-Version: 0.1 diff --git a/submit-json.py b/submit-json.py new file mode 100755 index 0000000..095c149 --- /dev/null +++ b/submit-json.py @@ -0,0 +1,89 @@ +#!/usr/bin/python + +import os +import sys +import json +import xmlrpclib +import urllib2 +import re + +def obfuscate_credentials(s): + return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s) + +def lava_submit(config): + # LAVA user + lava_user = os.environ.get('LAVA_USER') + if lava_user is None: + f = open('/var/run/lava/lava-user') + lava_user = f.read().strip() + f.close() + + # LAVA token + lava_token = os.environ.get('LAVA_TOKEN') + if lava_token is None: + f = open('/var/run/lava/lava-token') + lava_token = f.read().strip() + f.close() + + # LAVA server URL + lava_server = os.environ.get('LAVA_SERVER', + 'validation.linaro.org/lava-server/RPC2/') + + # LAVA server base URL + lava_server_root = lava_server.rstrip('/') + if lava_server_root.endswith('/RPC2'): + lava_server_root = lava_server_root[:-len('/RPC2')] + + try: + server_url = \ + 'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}' + server = \ + xmlrpclib.ServerProxy(server_url.format( + lava_user=lava_user, + lava_token=lava_token, + lava_server=lava_server), verbose=False) + print server + lava_job_id = server.scheduler.submit_job(config) + except xmlrpclib.ProtocolError, e: + print 'Error making a LAVA request:', obfuscate_credentials(str(e)) + sys.exit(1) + except xmlrpclib.Fault as err: + print "A fault occurred" + print "Fault code: %d" % err.faultCode + print "Fault string: %s" % err.faultString + sys.exit(1) + + print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \ + (lava_job_id, lava_server_root, lava_job_id) + json.dump({'lava_url': 'http://' + lava_server_root, + 'job_id': lava_job_id}, open('lava-job-info', 'w')) + + +def main(): + '''Script entry point. + We should be called from Jenkins and expect the following to be defined: + pass json file as first parameter or in stdin + ''' + + if len(sys.argv) <= 1: + # no command line parameter, read stdin + config=sys.stdin.read() + else: + try: + json_fp = open(sys.argv[1]) + config = json_fp.read() + json_fp.close() + except IOError as e: + print "I/O error({0}): {1}".format(e.errno, e.strerror) + + print config + + skip_lava = os.environ.get('SKIP_LAVA') + if skip_lava is None: + lava_submit(config) + else: + print 'LAVA job submission skipped.' + + +if __name__ == '__main__': + main() |