Zelalem | 8afa092 | 2020-08-28 10:40:44 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Leonardo Sandoval | 579c737 | 2020-10-23 15:23:32 -0500 | [diff] [blame] | 3 | # Copyright (c) 2019-2020 Arm Limited. All rights reserved. |
Zelalem | 8afa092 | 2020-08-28 10:40:44 -0500 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # Submit jobs to LAVA and wait until the job is complete. This script replace |
| 9 | # the "managed script" previously used and provide the same behavior. |
| 10 | # |
| 11 | # Required arguments: |
| 12 | # 1: yaml job file |
| 13 | # 2: a location to store output |
| 14 | # |
| 15 | # output: |
| 16 | # ./job_results.yaml |
| 17 | # ${SAVE_OUTPUT}/job_output.log |
| 18 | |
| 19 | set -e |
| 20 | |
| 21 | source "$CI_ROOT/utils.sh" |
| 22 | |
Manish V Badarkhe | 20097fc | 2020-11-17 09:43:23 +0000 | [diff] [blame] | 23 | export XDG_CONFIG_HOME="${WORKSPACE}" |
| 24 | |
Zelalem | 8afa092 | 2020-08-28 10:40:44 -0500 | [diff] [blame] | 25 | JOB_FILE="$1" |
| 26 | SAVE_OUTPUT="$2" |
| 27 | |
| 28 | LAVA_HOST="${LAVA_HOST:-lava.oss.arm.com}" |
| 29 | LAVA_USER="$3" |
| 30 | LAVA_TOKEN="$4" |
| 31 | LAVA_URL="https://${LAVA_HOST}" |
| 32 | |
| 33 | if [ ! -f "${JOB_FILE}" ]; then |
| 34 | echo "error: LAVA job file does not exist: ${JOB_FILE}" |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | # Install lavacli with fixes |
| 39 | virtualenv -p $(which python3) venv |
| 40 | source venv/bin/activate |
Maksims Svecovs | 8cf07df | 2022-05-13 14:58:23 +0100 | [diff] [blame] | 41 | pip install -q lavacli ruamel.yaml dataclasses |
Zelalem | 8afa092 | 2020-08-28 10:40:44 -0500 | [diff] [blame] | 42 | |
Zelalem | 8afa092 | 2020-08-28 10:40:44 -0500 | [diff] [blame] | 43 | # Configure lavacli |
| 44 | lavacli identities add \ |
| 45 | --username $LAVA_USER \ |
| 46 | --token $LAVA_TOKEN \ |
| 47 | --uri ${LAVA_URL}/RPC2 \ |
| 48 | default |
| 49 | |
| 50 | # Submit a job using lavacli |
| 51 | JOB_ID=$(lavacli jobs submit ${JOB_FILE}) |
| 52 | if [ -z "$JOB_ID" ] ; then |
| 53 | echo "Couldn't submit. Stopping." |
| 54 | exit 1 |
| 55 | fi |
| 56 | |
| 57 | echo "Job url: https://lava.oss.arm.com/scheduler/job/$JOB_ID" |
| 58 | |
| 59 | # Wait for the job to finish |
| 60 | lavacli jobs wait $JOB_ID |
| 61 | |
| 62 | # Output to the specified directory before uploading artefacts |
| 63 | mkdir -p "${SAVE_OUTPUT}" |
Manish V Badarkhe | d9a9502 | 2021-07-26 06:02:59 +0100 | [diff] [blame] | 64 | curl https://lava.oss.arm.com/scheduler/job/$JOB_ID/log_file/plain > "${SAVE_OUTPUT}/job_output.log" |
Zelalem | 8afa092 | 2020-08-28 10:40:44 -0500 | [diff] [blame] | 65 | cp ${SAVE_OUTPUT}/job_output.log $workspace/artefacts |
| 66 | |
| 67 | # Send file(s) to artefacts receiver |
| 68 | if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "${SAVE_OUTPUT}" ]; then |
| 69 | source "$CI_ROOT/script/send_artefacts.sh" "${SAVE_OUTPUT}" |
| 70 | fi |
| 71 | |
| 72 | # Get results |
| 73 | lavacli results $JOB_ID --yaml > "job_results.yaml" |
| 74 | |
| 75 | # Exit virtualenv |
| 76 | deactivate |