blob: 655417d3863ec4d66874f221bbfd7196abf4b80a [file] [log] [blame]
Dean Bircha6ede7e2020-03-13 14:00:33 +00001#!/usr/bin/env python3
2
3from __future__ import print_function
4
5"""
6Script for submitting multiple LAVA definitions
7"""
8
9__copyright__ = """
10/*
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080011 * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
Dean Bircha6ede7e2020-03-13 14:00:33 +000012 *
13 * SPDX-License-Identifier: BSD-3-Clause
14 *
15 */
16 """
17
Dean Bircha6ede7e2020-03-13 14:00:33 +000018import glob
Dean Bircha6ede7e2020-03-13 14:00:33 +000019import argparse
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080020from lava_helper import test_lava_dispatch_credentials
Dean Bircha6ede7e2020-03-13 14:00:33 +000021from lava_helper_configs import *
22
Dean Bircha6ede7e2020-03-13 14:00:33 +000023
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080024def list_files_from_dir(user_args, job_dir=""):
25 if job_dir == "":
26 job_dir = user_args.job_dir
Dean Bircha6ede7e2020-03-13 14:00:33 +000027 file_list = []
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080028 for filename in glob.iglob(job_dir + '**/*.yaml', recursive=True):
Dean Bircha6ede7e2020-03-13 14:00:33 +000029 file_list.append(filename)
30 print("Found job {}".format(filename))
31 return file_list
32
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080033
34def submit_lava_jobs(user_args, job_dir=""):
Dean Bircha6ede7e2020-03-13 14:00:33 +000035 """ Submit a job to LAVA backend, block untill it is completed, and
36 fetch the results files if successful. If not, calls sys exit with 1
37 return code """
38
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080039 if job_dir == "":
40 job_dir = user_args.job_dir
41
Dean Bircha6ede7e2020-03-13 14:00:33 +000042 lava = test_lava_dispatch_credentials(user_args)
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080043 file_list = list_files_from_dir(user_args, job_dir)
Dean Bircha6ede7e2020-03-13 14:00:33 +000044 job_id_list = []
45 for job_file in file_list:
46 job_id, job_url = lava.submit_job(job_file)
47
48 # The reason of failure will be reported to user by LAVA_RPC_connector
49 if job_id is None and job_url is None:
50 print("Job failed")
51 else:
52 print("Job submitted at: " + job_url)
53 job_id_list.append(job_id)
54
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080055 return job_id_list
Dean Bircha6ede7e2020-03-13 14:00:33 +000056
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080057
Dean Bircha6ede7e2020-03-13 14:00:33 +000058def main(user_args):
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080059 job_id_list = submit_lava_jobs(user_args)
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080060 print("JOBS: {}".format(",".join(str(x) for x in job_id_list)))
Dean Bircha6ede7e2020-03-13 14:00:33 +000061
62
63def get_cmd_args():
64 """ Parse command line arguments """
65
66 # Parse command line arguments to override config
67 parser = argparse.ArgumentParser(description="Lava Create Jobs")
68 cmdargs = parser.add_argument_group("Create LAVA Jobs")
69
70 # Configuration control
71 cmdargs.add_argument(
72 "--lava-url", dest="lava_url", action="store", help="LAVA lab URL (without RPC2)"
73 )
74 cmdargs.add_argument(
75 "--job-dir", dest="job_dir", action="store", help="LAVA jobs directory"
76 )
77 cmdargs.add_argument(
78 "--lava-token", dest="lava_token", action="store", help="LAVA auth token"
79 )
80 cmdargs.add_argument(
81 "--lava-user", dest="lava_user", action="store", help="LAVA username"
82 )
83 cmdargs.add_argument(
84 "--use-env", dest="token_from_env", action="store_true", default=False, help="LAVA username"
85 )
86 cmdargs.add_argument(
87 "--lava-timeout", dest="dispatch_timeout", action="store", default=3600, help="LAVA username"
88 )
89 return parser.parse_args()
90
91
92if __name__ == "__main__":
93 main(get_cmd_args())