summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorentin LABBE <clabbe@baylibre.com>2021-03-08 10:08:54 +0000
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2021-03-16 16:02:56 +0000
commitd29d852f562fbe7f129c465a5ece7d6953b5fc33 (patch)
tree88d7eed0dd0ed6b7fbc6d78345ebc36a4776c073
parent45393b7e90e2376231dfe7ef8585ab98cecb71fa (diff)
SPEC-3414: Add an helper to push and upload build meta to kernelci
This patch adds an helper to push and upload bmeta.json to kernelci. Change-Id: I129fce4583569542f03a9c9617b9d70b50c725e3 Bug-AGL: SPEC-3414 Signed-off-by: Corentin LABBE <clabbe@baylibre.com> (cherry picked from commit e77bec194555ab2f73bf5370d38d7565bc868b52)
-rwxr-xr-xutils/agl-publish.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/utils/agl-publish.py b/utils/agl-publish.py
new file mode 100755
index 0000000..a6b540b
--- /dev/null
+++ b/utils/agl-publish.py
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+
+import argparse
+import requests
+from urllib.parse import urljoin
+import os
+import json
+import urllib
+
+ptoken=os.environ["KCI_PUSH_TOKEN"]
+utoken=os.environ["KCI_UPLOAD_TOKEN"]
+
+parser = argparse.ArgumentParser(description="AGL create bmeta", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+parser.add_argument('--arch', action='store', help="arch of the build", required=True)
+parser.add_argument('--branch', action='store', help="branch of the build", required=True)
+parser.add_argument('--commit', action='store', help="commit of the build", required=True)
+parser.add_argument('--build_version', action='store', help="build_version of the build", required=True)
+parser.add_argument('--machine', action='store', help="machine of the build", required=True)
+parser.add_argument('--api', action='store', help="URL to kernelci backend API", required=True)
+args = parser.parse_args()
+
+bmeta = {}
+bmeta["arch"] = args.arch
+bmeta["build_log"] = "build.log"
+bmeta["build_environment"] = "AGL-yocto"
+bmeta["defconfig"] = "defconfig"
+bmeta["defconfig_full"] = "defconfig+CONFIG_AGL=y"
+
+bmeta["git_branch"] = args.branch
+bmeta["git_commit"] = args.commit
+bmeta["git_describe"] = args.branch
+bmeta["job"] = "AGL-yocto"
+
+fsr = "AGL-yocto/%s/%s/%s/" % (args.branch, args.build_version, args.machine)
+bmeta["file_server_resource"] = fsr
+
+print(bmeta)
+
+DIR_META="agl-build-meta"
+# create directory with artifacts to be uploaded (bmeta.json)
+if not os.path.exists(DIR_META):
+ os.mkdir(DIR_META)
+
+# write bmeta in it
+with open(os.path.join(DIR_META, 'bmeta.json'), 'w') as json_file:
+ json.dump(bmeta, json_file, indent=4, sort_keys=True)
+
+def upload():
+ path = bmeta["file_server_resource"]
+
+ headers = {
+ 'Authorization': utoken,
+ }
+ data = {
+ 'path': path,
+ }
+ artifacts = {}
+ for root, _, files in os.walk(DIR_META):
+ for f in files:
+ px = os.path.relpath(root, DIR_META)
+ artifacts[os.path.join(px, f)] = open(os.path.join(root, f), "rb")
+
+ files = {
+ 'file{}'.format(i): (name, fobj)
+ for i, (name, fobj) in enumerate(artifacts.items())
+ }
+ url = urljoin(args.api, 'upload')
+ print("DATA====================")
+ print(data)
+ return 0
+ resp = requests.post(url, headers=headers, data=data, files=files)
+ resp.raise_for_status()
+ print(resp.reason)
+ print(resp.text)
+
+
+def publish_kernel():
+ data = {k: bmeta[v] for k, v in {
+ 'file_server_resource': 'file_server_resource',
+ 'job': 'job',
+ 'git_branch': 'git_branch',
+ 'arch': 'arch',
+ 'kernel': 'git_describe',
+ 'build_environment': 'build_environment',
+ 'defconfig': 'defconfig',
+ 'defconfig_full': 'defconfig_full',
+ }.items()}
+ print("DATA====================")
+ print(data)
+ return 0
+ headers = {
+ 'Authorization': ptoken,
+ 'Content-Type': 'application/json',
+ }
+ url = urllib.parse.urljoin(args.api, '/build')
+ data_json = json.dumps(data)
+ resp = requests.post(url, headers=headers, data=data_json)
+ resp.raise_for_status()
+ print(resp.reason)
+ print(resp.text)
+
+print("============== UPLOAD")
+upload()
+print("============== PUBLISH")
+publish_kernel()
+