diff options
author | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2016-06-08 19:02:35 +0100 |
---|---|---|
committer | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2016-06-08 19:02:35 +0100 |
commit | b7450215c570f42c5b9f0388f6e1f358cd3aee32 (patch) | |
tree | 8cb6dcdeebeb384cb7366aa0f69e2d83cdafa6ec |
Initial commit
Signed-off-by: Milosz Wasilewski <milosz.wasilewski@linaro.org>
-rw-r--r-- | post-build-report.py | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/post-build-report.py b/post-build-report.py new file mode 100644 index 0000000..868e737 --- /dev/null +++ b/post-build-report.py @@ -0,0 +1,116 @@ +#!/usr/bin/python +import os +import sys +import json +import httplib +import logging + +from urlparse import urljoin, urlsplit + + +logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) +logger = logging.getLogger(__name__) +httplib.HTTPConnection.debuglevel = 1 + + +RESULT_ENDPOINT = "/api/result/" + + +def _push_object(auth_pw, backend_url, endpoint, params): + usplit = urlsplit(backend_url) + url = urljoin(backend_url, endpoint) + + logger.info("Submitting to URL: %s" % url) + + headers = { + "Content-type": "application/json", + "Accept": "application/json", + "Authorization": "Token %s" % auth_pw + } + + conn = None + if usplit.scheme.lower() == "http": + conn = httplib.HTTPConnection(usplit.netloc) + if usplit.scheme.lower() == "https": + conn = httplib.HTTPSConnection(usplit.netloc) + + if conn is None: + print "Unknown scheme: %s" % usplit.scheme + sys.exit(1) + + conn.request("POST", endpoint, json.dumps(params), headers) + + response = conn.getresponse() + if response.status < 300: + return response.read() + else: + logger.warn(response.status) + logger.warn(response.reason) + logger.warn(response.read()) + return [] + + +def _get_manifest(workspace_path): + manifest_path = os.path.join(workspace_path, "pinned-manifest.xml") + print "Searching for: %s" % manifest_path + if os.path.exists(manifest_path): + with open(manifest_path, "r") as manifest_file: + return manifest_file.read() + print "Manifest not found" + return None + + + +if __name__ == '__main__': + jenkins_project_name = os.environ.get("SOURCE_PROJECT_NAME") + + jenkins_build_number = os.environ.get("SOURCE_BUILD_NUMBER") + jenkins_build_id = os.environ.get("SOURCE_BUILD_ID") + jenkins_build_url = os.environ.get("SOURCE_BUILD_URL") + + branch_name = os.environ.get("SOURCE_BRANCH_NAME", "") + + art_url = os.environ.get("ART_URL", "http://localhost:8000/") + art_token = os.environ.get("ART_TOKEN") + + manifest = _get_manifest(os.environ.get("WORKSPACE")) + test_jobs = os.environ.get("LAVA_JOB_IDS", "") + + if jenkins_build_number is None: + print "Build number not set. Exiting!" + sys.exit(1) + if jenkins_project_name is None: + print "Project name not set. Exiting!" + sys.exit(1) + if jenkins_build_url is None: + print "Build URL not set. Exiting!" + sys.exit(1) + if art_token is None: + print "ART token not set. Exiting!" + sys.exit(1) + if not manifest: + print "Manifest missing. Exiting!" + sys.exit(1) + + print "Registered test jobs: %s" % test_jobs + + params = { + 'name': jenkins_project_name, + + 'build_id': jenkins_build_id, + 'build_url': jenkins_build_url, + 'build_number': jenkins_build_number, + + 'test_jobs': test_jobs, + 'manifest': manifest, + 'branch_name': branch_name, + + "gerrit_change_number": os.environ.get("SOURCE_GERRIT_CHANGE_NUMBER"), + "gerrit_patchset_number":os.environ.get("SOURCE_GERRIT_PATCHSET_NUMBER"), + "gerrit_change_url": os.environ.get("SOURCE_GERRIT_CHANGE_URL"), + "gerrit_change_id": os.environ.get("SOURCE_GERRIT_CHANGE_ID", "") + } + + print params + + _push_object(art_token, art_url, RESULT_ENDPOINT, params) |