diff options
author | Vishal Bhoj <vishal.bhoj@linaro.org> | 2018-08-09 16:39:54 +0530 |
---|---|---|
committer | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2018-09-04 08:15:57 +0000 |
commit | fb1c1b0ede682582d0e3f4c920137542130deea2 (patch) | |
tree | 76cca445730c2ea3bb545bcf963da99991dce91a | |
parent | 56f7ff9ecdd3a57a70a9bfbb8774217f4e11d202 (diff) |
automated: linux: initial ota update test
Change-Id: Ia5cd0303437bd28f2992b1f8f26fe77a265b697e
Signed-off-by: Vishal Bhoj <vishal.bhoj@linaro.org>
-rw-r--r-- | automated/linux/ota-update/ota-update.py | 56 | ||||
-rwxr-xr-x | automated/linux/ota-update/ota-update.sh | 24 | ||||
-rw-r--r-- | automated/linux/ota-update/ota-update.yaml | 30 |
3 files changed, 110 insertions, 0 deletions
diff --git a/automated/linux/ota-update/ota-update.py b/automated/linux/ota-update/ota-update.py new file mode 100644 index 0000000..9668f92 --- /dev/null +++ b/automated/linux/ota-update/ota-update.py @@ -0,0 +1,56 @@ +import requests +import json +import yaml +import time +import sys +import os +from argparse import ArgumentParser + +sys.path.insert(0, '../../lib/') +import py_test_lib # nopep8 + +OUTPUT = '%s/output' % os.getcwd() +RESULT_FILE = '%s/result.txt' % OUTPUT + +parser = ArgumentParser() +parser.add_argument("-d", "--device", dest="devicename", default="hikey-r2-01", + help="Device Name to be updated") +parser.add_argument("-is", "--installed-sha", dest="installed_sha", default="", + help="OTA update sha") +parser.add_argument("-us", "--update-sha", dest="update_sha", default="", + help="OTA update sha") +args = parser.parse_args() +url = "http://api.ota-prototype.linaro.org/devices/%s/" % args.devicename +headers = { + "OTA-TOKEN": "BadT0ken5", + "Content-type": "application/json" +} +data = json.dumps({"image": {"hash": args.update_sha}}) + + +def match_sha_on_server(sha): + loop = 0 + while loop < 20: + r = requests.get(url, headers=headers) + resp = yaml.load(r.text) + currentsha_on_server = resp.get("deviceImage").get("image").get("hash").get("sha256") + if currentsha_on_server == sha: + return 0 + loop = loop + 1 + time.sleep(30) + if loop == 10: + print "FAIL: Installed sha on device did not match" + return -1 + +if match_sha_on_server(args.installed_sha) == 0: + py_test_lib.add_result(RESULT_FILE, "installed-device-sha-match-server pass") + r = requests.put(url, data=data, headers=headers) + if match_sha_on_server(args.update_sha) == 0: + py_test_lib.add_result(RESULT_FILE, "ota-update-to-%s pass" % args.update_sha) + print "PASS: %s updated to %s successfully" % (args.devicename, args.update_sha) + else: + py_test_lib.add_result(RESULT_FILE, "ota-update-to-%s fail" % args.update_sha) + print "FAIL: %s update to %s failed" % (args.devicename, args.update_sha) +else: + py_test_lib.add_result(RESULT_FILE, "installed-device-sha-match-server fail") + print "FAIL: Insalled device sha to %s mismatched on the server" % args.devicename diff --git a/automated/linux/ota-update/ota-update.sh b/automated/linux/ota-update/ota-update.sh new file mode 100755 index 0000000..c7c7448 --- /dev/null +++ b/automated/linux/ota-update/ota-update.sh @@ -0,0 +1,24 @@ +#!/bin/bash +RESULT_FILE="$(pwd)/output/result.txt" +export RESULT_FILE +mkdir output + +DUT_IPADDRESS=$(lava-target-ip) +DUT=$(case "${DUT_IPADDRESS}" in + ("10.7.0.68") echo "hikey-r2-01";; + ("10.7.0.69") echo "hikey-r2-02";; + ("10.7.0.66") echo "hikey-r2-03";; + ("10.7.0.73") echo "hikey-r2-04";; + (*) echo "invalid";; + esac) + +wget http://testdata.linaro.org/apks/osf/"${DUT}"-sota.tar -O sota.tar +sshpass -p 'osf' scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no sota.tar osf@"${DUT_IPADDRESS}":~/ +sshpass -p 'osf' ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no osf@"${DUT_IPADDRESS}" "echo osf | sudo -S tar -xvf sota.tar -C /var/" +sshpass -p 'osf' ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no osf@"${DUT_IPADDRESS}" "echo osf | sudo -S systemctl restart aktualizr" + +python ota-update.py -d "${DUT}" -is "${BASELINE_SHA}" -us "${UPDATE_SHA}" + +# Restore device image back to baseline for future testing. The server information +# about images on device should match the actual image on the device. +python ota-update.py -d "${DUT}" -us "${BASELINE_SHA}" -is "${UPDATE_SHA}" diff --git a/automated/linux/ota-update/ota-update.yaml b/automated/linux/ota-update/ota-update.yaml new file mode 100644 index 0000000..d5b8b22 --- /dev/null +++ b/automated/linux/ota-update/ota-update.yaml @@ -0,0 +1,30 @@ +metadata: + name: ota-update + format: "Lava-Test-Shell Test Definition 1.0" + description: "Tests OTA update on device" + maintainer: + - vishal.bhoj@linaro.org + os: + - ubuntu + - debian + - centos + - fedora + - openembedded + devices: + - hi6220-hikey + + scope: + - functional + - performance + +params: + # TODO: Need ostree package info to be trigger deployment + SKIP_INSTALL: "false" + UPDATE_SHA: "" + BASELINE_SHA: "" + +run: + steps: + - cd automated/linux/ota-update + - . ./ota-update.sh + - ../../utils/send-to-lava.sh ./output/result.txt |