blob: 7f36f26fb9dcab2f384b72391e989dfebd39aaad [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 +000021
Dean Bircha6ede7e2020-03-13 14:00:33 +000022
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080023def list_files_from_dir(user_args, job_dir=""):
24 if job_dir == "":
25 job_dir = user_args.job_dir
Dean Bircha6ede7e2020-03-13 14:00:33 +000026 file_list = []
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080027 for filename in glob.iglob(job_dir + '**/*.yaml', recursive=True):
Dean Bircha6ede7e2020-03-13 14:00:33 +000028 file_list.append(filename)
29 print("Found job {}".format(filename))
30 return file_list
31
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080032
33def submit_lava_jobs(user_args, job_dir=""):
Dean Bircha6ede7e2020-03-13 14:00:33 +000034 """ Submit a job to LAVA backend, block untill it is completed, and
35 fetch the results files if successful. If not, calls sys exit with 1
36 return code """
37
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080038 if job_dir == "":
39 job_dir = user_args.job_dir
40
Dean Bircha6ede7e2020-03-13 14:00:33 +000041 lava = test_lava_dispatch_credentials(user_args)
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080042 file_list = list_files_from_dir(user_args, job_dir)
Dean Bircha6ede7e2020-03-13 14:00:33 +000043 job_id_list = []
44 for job_file in file_list:
45 job_id, job_url = lava.submit_job(job_file)
46
47 # The reason of failure will be reported to user by LAVA_RPC_connector
48 if job_id is None and job_url is None:
49 print("Job failed")
50 else:
51 print("Job submitted at: " + job_url)
52 job_id_list.append(job_id)
53
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080054 return job_id_list
Dean Bircha6ede7e2020-03-13 14:00:33 +000055
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080056
Dean Bircha6ede7e2020-03-13 14:00:33 +000057def main(user_args):
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080058 job_id_list = submit_lava_jobs(user_args)
Xinyu Zhangf2b7cbf2021-05-18 20:17:34 +080059 print("JOBS: {}".format(",".join(str(x) for x in job_id_list)))
Dean Bircha6ede7e2020-03-13 14:00:33 +000060
61
62def get_cmd_args():
63 """ Parse command line arguments """
64
65 # Parse command line arguments to override config
66 parser = argparse.ArgumentParser(description="Lava Create Jobs")
67 cmdargs = parser.add_argument_group("Create LAVA Jobs")
68
69 # Configuration control
70 cmdargs.add_argument(
71 "--lava-url", dest="lava_url", action="store", help="LAVA lab URL (without RPC2)"
72 )
73 cmdargs.add_argument(
74 "--job-dir", dest="job_dir", action="store", help="LAVA jobs directory"
75 )
76 cmdargs.add_argument(
77 "--lava-token", dest="lava_token", action="store", help="LAVA auth token"
78 )
79 cmdargs.add_argument(
80 "--lava-user", dest="lava_user", action="store", help="LAVA username"
81 )
82 cmdargs.add_argument(
83 "--use-env", dest="token_from_env", action="store_true", default=False, help="LAVA username"
84 )
85 cmdargs.add_argument(
86 "--lava-timeout", dest="dispatch_timeout", action="store", default=3600, help="LAVA username"
87 )
88 return parser.parse_args()
89
90
91if __name__ == "__main__":
92 main(get_cmd_args())