Remove hard-coded LAVA token

We want to push run_lava_job.sh to OpenCI repo.
Therefore this patch removes the hard-coded token in the script.
Instead username and token for LAVA server are passed as arguments
from tf jobs script (tf-worker.yaml). There is a corresponding
patch in the tf jobs repo.

Change-Id: I82e17a98042077d4b9572865d34437e6fd06aaa3
Signed-off-by: Zelalem <zelalem.aweke@arm.com>
diff --git a/job/tf-worker/run_lava.py b/job/tf-worker/run_lava.py
index 93d522c..ddf6304 100644
--- a/job/tf-worker/run_lava.py
+++ b/job/tf-worker/run_lava.py
@@ -86,6 +86,16 @@
         help="directory to store the job_output.log",
     )
     parser.add_argument(
+        "--username",
+        required=True,
+        help="the user name for lava server",
+    )
+    parser.add_argument(
+        "--token",
+        required=True,
+        help="the token for lava server",
+    )
+    parser.add_argument(
         "-v", action="count", default=0, help="Increase printing of debug ouptut"
     )
     args = parser.parse_args()
@@ -95,7 +105,8 @@
         logging.getLogger().setLevel(logging.INFO)
     logging.debug(args)
     try:
-        if not retry_job([args.script, args.job, args.save], args.retries):
+        if not retry_job([args.script, args.job, args.save, args.username, args.token],\
+                args.retries):
             logging.critical("All jobs failed with infra errors; retries exhausted")
             sys.exit(-1)
         else:
diff --git a/job/tf-worker/run_lava_job.sh b/job/tf-worker/run_lava_job.sh
new file mode 100755
index 0000000..c3adcb3
--- /dev/null
+++ b/job/tf-worker/run_lava_job.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Submit jobs to LAVA and wait until the job is complete. This script replace
+# the "managed script" previously used and provide the same behavior.
+#
+# Required arguments:
+# 1: yaml job file
+# 2: a location to store output
+#
+# output:
+# ./job_results.yaml
+# ${SAVE_OUTPUT}/job_output.log
+
+set -e
+
+source "$CI_ROOT/utils.sh"
+
+JOB_FILE="$1"
+SAVE_OUTPUT="$2"
+
+LAVA_HOST="${LAVA_HOST:-lava.oss.arm.com}"
+LAVA_USER="$3"
+LAVA_TOKEN="$4"
+LAVA_URL="https://${LAVA_HOST}"
+
+if [ ! -f "${JOB_FILE}" ]; then
+	echo "error: LAVA job file does not exist: ${JOB_FILE}"
+	exit 1
+fi
+
+# Install lavacli with fixes
+virtualenv -p $(which python3) venv
+source venv/bin/activate
+pip install -q lavacli
+
+# Configure lavacli
+lavacli identities add \
+--username $LAVA_USER \
+--token $LAVA_TOKEN \
+--uri ${LAVA_URL}/RPC2 \
+default
+
+# Submit a job using lavacli
+JOB_ID=$(lavacli jobs submit ${JOB_FILE})
+if [ -z "$JOB_ID" ] ; then
+	echo "Couldn't submit. Stopping."
+	exit 1
+fi
+
+echo "Job url: https://lava.oss.arm.com/scheduler/job/$JOB_ID"
+
+# Wait for the job to finish
+lavacli jobs wait $JOB_ID
+
+# Output to the specified directory before uploading artefacts
+mkdir -p "${SAVE_OUTPUT}"
+lavacli jobs logs $JOB_ID > "${SAVE_OUTPUT}/job_output.log"
+cp ${SAVE_OUTPUT}/job_output.log $workspace/artefacts
+
+# Send file(s) to artefacts receiver
+if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "${SAVE_OUTPUT}" ]; then
+    source "$CI_ROOT/script/send_artefacts.sh" "${SAVE_OUTPUT}"
+fi
+
+# Get results
+lavacli results $JOB_ID --yaml > "job_results.yaml"
+
+# Exit virtualenv
+deactivate