|
| 1 | +from tabulate import tabulate |
| 2 | +import re |
| 3 | +from datetime import datetime |
| 4 | +import monitor |
| 5 | +import configparser |
| 6 | +import argparse |
| 7 | + |
| 8 | +config_vars = configparser.ConfigParser() |
| 9 | +config_vars.read('config.ini') |
| 10 | + |
| 11 | +JENKINS = config_vars.get('Settings', 'JENKINS') |
| 12 | + |
| 13 | +def get_nightly_name(): |
| 14 | + if JENKINS == "False": |
| 15 | + nightly = input("Enter the name of nightly image: ") |
| 16 | + return nightly |
| 17 | + elif JENKINS == "True": |
| 18 | + nightly = config_vars.get('Settings', 'nightly') |
| 19 | + return nightly |
| 20 | + |
| 21 | +def get_job_name(): |
| 22 | + |
| 23 | + ''' |
| 24 | + Gets selected CI input. |
| 25 | +
|
| 26 | + Returns: |
| 27 | + dict: Dictionary of selected job name and job link |
| 28 | + ''' |
| 29 | + |
| 30 | + parser = argparse.ArgumentParser(description='Get the job history') |
| 31 | + parser.add_argument('--job_type', default='p', choices=['p','z','pa'], help= 'Specify the CI job type (Power(p) or s390x(z) or Power Auxillary(pa)), default is p') |
| 32 | + |
| 33 | + args = parser.parse_args() |
| 34 | + |
| 35 | + if args.job_type == 'p': |
| 36 | + config_file = 'p_periodic.json' |
| 37 | + elif args.job_type == 'z': |
| 38 | + config_file = 'z_periodic.json' |
| 39 | + elif args.job_type == 'pa': |
| 40 | + config_file = 'p_auxillary.json' |
| 41 | + |
| 42 | + monitor.PROW_URL = monitor.set_prow_url(args.job_type) |
| 43 | + config_data = monitor.load_config(config_file) |
| 44 | + |
| 45 | + j=0 |
| 46 | + ci_name_list = [] |
| 47 | + options_int_list = [] |
| 48 | + selected_config_data = {} |
| 49 | + |
| 50 | + if JENKINS == "False": |
| 51 | + for ci_name in config_data.keys(): |
| 52 | + j=j+1 |
| 53 | + ci_name_list.append(ci_name) |
| 54 | + print(j,'',ci_name) |
| 55 | + option = input("Select the required ci's serial number with a space ") |
| 56 | + selected_options = option.split() |
| 57 | + for ci in selected_options: |
| 58 | + try: |
| 59 | + ci_to_int = int(ci) |
| 60 | + if 0 < ci_to_int <= len(config_data): |
| 61 | + options_int_list.append(ci_to_int) |
| 62 | + else: |
| 63 | + return_value = "Enter the options in range of 1 to " + str(len(config_data)+1) |
| 64 | + print(return_value) |
| 65 | + return "ERROR" |
| 66 | + except ValueError: |
| 67 | + return "Enter valid options" |
| 68 | + elif JENKINS == "True": |
| 69 | + for ci_name in config_data.keys(): |
| 70 | + j=j+1 |
| 71 | + ci_name_list.append(ci_name) |
| 72 | + |
| 73 | + selected_ci = config_vars.get('Settings', 'selected_ci') |
| 74 | + options_int_list = [int(value) for value in selected_ci.split(',')] |
| 75 | + |
| 76 | + for i in options_int_list: |
| 77 | + config_temp_data = {ci_name_list[i-1]: config_data[ci_name_list[i-1]]} |
| 78 | + selected_config_data.update(config_temp_data) |
| 79 | + config_temp_data = {} |
| 80 | + |
| 81 | + return selected_config_data |
| 82 | + |
| 83 | + |
| 84 | +def get_builds_with_same_nightly(job_name,nightly_image): |
| 85 | + builds=[] |
| 86 | + agg_builds = [] |
| 87 | + pattern = r'\d{4}-\d{2}-\d{2}' |
| 88 | + match = re.search(pattern,nightly_image) |
| 89 | + |
| 90 | + if match != None: |
| 91 | + date_str = match.group() |
| 92 | + nightly_date = datetime.strptime(date_str,"%Y-%m-%d").date() |
| 93 | + current_date = datetime.now().date() |
| 94 | + builds=monitor.get_jobs_with_date(job_name,current_date,nightly_date) |
| 95 | + for spylink in reversed(builds): |
| 96 | + ng = "" |
| 97 | + _, ng = monitor.get_quota_and_nightly(spylink) |
| 98 | + pattern_1 = r'\d{4}-\d{2}-\d{2}' |
| 99 | + match_1 = re.search(pattern_1,ng) |
| 100 | + if match_1 != None: |
| 101 | + date_str_1 = match_1.group() |
| 102 | + ng_date = datetime.strptime(date_str_1,"%Y-%m-%d").date() |
| 103 | + if ng_date > nightly_date: |
| 104 | + break |
| 105 | + else: |
| 106 | + if nightly_image in ng: |
| 107 | + agg_builds.append(spylink) |
| 108 | + else: |
| 109 | + continue |
| 110 | + return agg_builds |
| 111 | + |
| 112 | +def main(): |
| 113 | + nightly_image = get_nightly_name() |
| 114 | + selected_jobs = get_job_name() |
| 115 | + print("****************************************") |
| 116 | + print("Payload: ",nightly_image) |
| 117 | + print("****************************************") |
| 118 | + for job_name,job_link in selected_jobs.items(): |
| 119 | + build_list = [] |
| 120 | + build_list = get_builds_with_same_nightly(job_link,nightly_image) |
| 121 | + monitor.get_detailed_job_info(build_list,job_name) |
| 122 | + |
| 123 | +if __name__ == "__main__": |
| 124 | + main() |
0 commit comments