Skip to content

Commit d84217f

Browse files
Merge pull request #115 from alokgoswami-ag/feature/job-failure-lists
added feature to get failed job info
2 parents b7449ec + b8114b8 commit d84217f

File tree

4 files changed

+71
-40
lines changed

4 files changed

+71
-40
lines changed

CI_DailyBuildUpdates.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,37 @@ def main():
1414
parser.add_argument('--info_type', default='brief', choices=['brief','detailed'], help='specify the job info type (brief or detailed)')
1515
parser.add_argument('--zone', help='specify the lease/zone', type= lambda arg:arg.split(','))
1616
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')
17+
parser.add_argument('--job_install_status',default='All',choices=['failure','success'],help='Specify the desired job install status to filter the jobs accordingly')
18+
1719
args = parser.parse_args()
1820
if args.job_type == 'p':
1921
config_file = 'p_periodic.json'
2022
elif args.job_type == 'z':
2123
config_file = 'z_periodic.json'
2224
elif args.job_type == 'pa':
2325
config_file = 'p_auxillary.json'
26+
27+
if args.job_install_status == 'failure':
28+
job_install_status = 'failure'
29+
elif args.job_install_status == 'success':
30+
job_install_status ='success'
31+
else:
32+
job_install_status='All'
2433

2534
monitor.PROW_URL = monitor.set_prow_url(args.job_type)
2635
config_data = monitor.load_config(config_file)
2736
if args.info_type == "brief":
2837
summary_list = []
2938
for ci_name,ci_link in config_data.items():
3039
build_list = monitor.get_jobs(ci_link)
31-
summary_list.extend(monitor.get_brief_job_info(build_list,ci_name,zone=args.zone))
40+
summary_list.extend(monitor.get_brief_job_info(build_list,ci_name,zone=args.zone,job_filter=job_install_status))
3241
if len(summary_list)==0:
3342
print("******************* No builds found ******************************")
3443
print(tabulate(summary_list, headers='keys', tablefmt="pipe", stralign='left'))
3544
elif args.info_type == "detailed":
3645
for ci_name,ci_link in config_data.items():
3746
build_list = monitor.get_jobs(ci_link)
38-
monitor.get_detailed_job_info(build_list,ci_name,zone=args.zone)
47+
monitor.get_detailed_job_info(build_list,ci_name,zone=args.zone,job_filter=job_install_status)
3948

4049
if __name__ == "__main__":
4150
main()

CI_JobHistory.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def main():
316316
parser.add_argument('--zone', help='specify the lease/zone', type= lambda arg:arg.split(','))
317317
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')
318318
parser.add_argument('--filter',default='All',type= lambda arg:arg.split(','), help='Specify the filter string to fetch jobs (Example heavy build / libvirt / powervs / upgrade / 4.14 / 4.15 / 4.16 / 4.17/ 4.18 )')
319+
parser.add_argument('--job_install_status',default='All',choices=['failure','success'],help='Specify the desired job install status to filter the jobs accordingly')
319320
args = parser.parse_args()
320321
filter=args.filter
321322

@@ -325,6 +326,13 @@ def main():
325326
config_file = 'z_periodic.json'
326327
elif args.job_type == 'pa':
327328
config_file = 'p_auxillary.json'
329+
330+
if args.job_install_status == 'failure':
331+
job_install_status = 'failure'
332+
elif args.job_install_status == 'success':
333+
job_install_status ='success'
334+
else:
335+
job_install_status='All'
328336

329337
monitor.PROW_URL = monitor.set_prow_url(args.job_type)
330338
config_data = monitor.load_config(config_file)
@@ -356,14 +364,14 @@ def main():
356364
summary_list = []
357365
for ci_name,ci_link in ci_list.items():
358366
spy_links = monitor.get_jobs_with_date(ci_link,start_date,end_date)
359-
summary_list.extend(monitor.get_brief_job_info(spy_links,ci_name,zone=args.zone))
367+
summary_list.extend(monitor.get_brief_job_info(spy_links,ci_name,zone=args.zone,job_filter=job_install_status))
360368
monitor.final_job_list = []
361369
print(tabulate(summary_list, headers='keys', tablefmt="pipe", stralign='left'))
362370

363371
if option == '3':
364372
for ci_name,ci_link in ci_list.items():
365373
spy_links = monitor.get_jobs_with_date(ci_link,start_date,end_date)
366-
monitor.get_detailed_job_info(spy_links,ci_name,zone=args.zone)
374+
monitor.get_detailed_job_info(spy_links,ci_name,zone=args.zone,job_filter=job_install_status)
367375
monitor.final_job_list = []
368376

369377
if option == '4':

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,16 @@ Create a virtualenv if required and install required packages using "pip install
8888
query_option: Query code to fetch information from builds.
8989
• Check Node Crash: Detects if a node crashed during execution.
9090
• Brief Job Information: Provides a summary of job execution.
91-
• Detailed Job Information: Provides in-depth details of jobs.
91+
• Detailed Job Information: Provides in-depth details of jobs based on job_filter.
92+
job_filter: 'all' (default), 'success', or 'failure'
93+
- 'success' → show only cluster installs that succeeded
94+
- 'failure' → show only cluster installs that failed or errored
9295
• Failed Test Cases: Provides a list of test cases that are failed in the CI run.
9396
• Get Builds with Test Case Failures: Identifies builds where given test cases failed.
9497
• Test Case Failure Frequency: Analyzes how often test cases fail.
9598
• Get Build Based on Release: Retrieves builds corresponding to a specific release
9699
release: release that needs to be checked
97-
next release: next release or latest
98-
100+
next release: next release or latest
99101
before_date: End date.
100102
after_date: Start date.
101103
tc_name: Testcase name which will be used in quering the failure frequency.

monitor.py

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def get_lease(build_log_response,job_platform):
530530
'''
531531

532532
lease = ""
533-
zone_log_re = re.compile('(Acquired 1 lease\(s\) for {}-quota-slice: \[)([^]]+)(\])'.format(job_platform), re.MULTILINE|re.DOTALL)
533+
zone_log_re = re.compile(r'(Acquired 1 lease\(s\) for {}-quota-slice: \[)([^]]+)(\])'.format(job_platform), re.MULTILINE|re.DOTALL)
534534
zone_log_match = zone_log_re.search(build_log_response.text)
535535
if zone_log_match is None:
536536
lease = "Failed to fetch lease information"
@@ -698,7 +698,7 @@ def get_failed_monitor_testcases(spy_link,job_type):
698698
response = requests.get(test_log_junit_dir_url, verify=False, timeout=15)
699699

700700
if response.status_code == 200:
701-
monitor_test_failure_summary_filename_re = re.compile('(test-failures-summary_monitor_2[^.]*\.json)')
701+
monitor_test_failure_summary_filename_re = re.compile(r'(test-failures-summary_monitor_2[^.]*\.json)')
702702
monitor_test_failure_summary_filename_match = monitor_test_failure_summary_filename_re.search(response.text, re.MULTILINE|re.DOTALL)
703703

704704
if monitor_test_failure_summary_filename_match is not None:
@@ -748,7 +748,7 @@ def get_failed_monitor_testcases_from_xml(spy_link,job_type):
748748
response = requests.get(test_log_junit_dir_url, verify=False, timeout=15)
749749

750750
if response.status_code == 200:
751-
test_failure_summary_filename_re = re.compile('(e2e-monitor-tests__2[^.]*\.xml)')
751+
test_failure_summary_filename_re = re.compile(r'(e2e-monitor-tests__2[^.]*\.xml)')
752752
test_failure_summary_filename_match = test_failure_summary_filename_re.search(response.text, re.MULTILINE|re.DOTALL)
753753

754754
if test_failure_summary_filename_match is not None:
@@ -841,7 +841,7 @@ def get_failed_e2e_testcases(spy_link,job_type):
841841
response = requests.get(test_log_junit_dir_url, verify=False, timeout=15)
842842

843843
if response.status_code == 200:
844-
test_failure_summary_filename_re = re.compile('(test-failures-summary_2[^.]*\.json)')
844+
test_failure_summary_filename_re = re.compile(r'(test-failures-summary_2[^.]*\.json)')
845845
test_failure_summary_filename_match = test_failure_summary_filename_re.search(response.text, re.MULTILINE|re.DOTALL)
846846

847847
if test_failure_summary_filename_match is not None:
@@ -1222,7 +1222,7 @@ def get_next_page_first_build_date(ci_next_page_spylink,end_date):
12221222
print("Failed to extract the spy-links from spylink please check the UI!")
12231223
return "ERROR"
12241224

1225-
def get_brief_job_info(build_list,prow_ci_name,zone=None):
1225+
def get_brief_job_info(build_list,prow_ci_name,zone=None,job_filter='All'):
12261226

12271227
"""
12281228
Gets brief information of all the jobs
@@ -1247,6 +1247,11 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
12471247
for build in build_list:
12481248
match = re.search(pattern_build_id, build)
12491249
build_id = match.group(1)
1250+
cluster_status = cluster_deploy_status(build)
1251+
if job_filter == "success" and (cluster_status == "FAILURE" or cluster_status =="ERROR"):
1252+
continue
1253+
elif job_filter == "failure" and cluster_status =='SUCCESS':
1254+
continue
12501255
try:
12511256
url = constants.PROW_VIEW_URL + build[8:] + '/prowjob.json'
12521257
time=fetch_build_time(url)
@@ -1291,93 +1296,100 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
12911296
summary_list.append(job_dict)
12921297
return summary_list
12931298

1294-
def get_detailed_job_info(build_list,prow_ci_name,zone=None):
1295-
1299+
def get_detailed_job_info(build_list, prow_ci_name, zone=None, job_filter="all"):
12961300
"""
12971301
Prints detailed information of all the jobs.
12981302
12991303
Args:
13001304
build_list: list of builds
13011305
prow_ci_name: CI name
1302-
zone(string, optional): Cluster deployment zone
1306+
zone (string, optional): Cluster deployment zone
1307+
install_status_filter (string, optional): 'all' (default), 'success', or 'failure'
1308+
- 'failure' → show only cluster installs that failed or error
1309+
- 'success' → show only cluster installs that
1310+
- 'all' → show all builds
1311+
13031312
"""
13041313

1305-
if isinstance(build_list,str):
1314+
if isinstance(build_list, str):
13061315
print(build_list)
13071316
return 1
1308-
1309-
if len(build_list) > 0:
1310-
print("--------------------------------------------------------------------------------------------------")
1311-
print(prow_ci_name)
13121317

13131318
deploy_count = 0
13141319
e2e_count = 0
1315-
i=0
1320+
i = 0
13161321

13171322
builds_to_deleted = []
13181323
for build in build_list:
13191324
lease, nightly = get_quota_and_nightly(build)
1325+
cluster_status = cluster_deploy_status(build)
1326+
if job_filter == "success" and (cluster_status == "FAILURE" or cluster_status =="ERROR"):
1327+
continue
1328+
elif job_filter == "failure" and cluster_status =='SUCCESS':
1329+
continue
1330+
print("--------------------------------------------------------------------------------------------------")
1331+
print(prow_ci_name)
13201332
if zone is not None and lease not in zone:
13211333
builds_to_deleted.append(build)
13221334
continue
1323-
i=i+1
1324-
print(i,"Job link:"+constants.JOB_LINK_URL+build)
1335+
i += 1
1336+
print(i, "Job link:" + constants.JOB_LINK_URL + build)
13251337
try:
13261338
url = constants.PROW_VIEW_URL + build[8:] + '/prowjob.json'
1327-
time=fetch_build_time(url)
1339+
time = fetch_build_time(url)
13281340
print("Build start time:", time)
13291341
except (requests.exceptions.RequestException, KeyError, ValueError) as e:
13301342
print("Error fetching build time:", e)
1343+
13311344
build_status = check_job_status(build)
1332-
sensitive_info_expose_status=check_if_sensitive_info_exposed(build)
1345+
sensitive_info_expose_status = check_if_sensitive_info_exposed(build)
13331346

1334-
if sensitive_info_expose_status == True:
1347+
if sensitive_info_expose_status:
13351348
print("*********************************")
13361349
print("Build log removed")
13371350
print("*********************************")
13381351

13391352
print("Nightly info-", nightly)
1340-
13411353
if build_status == 'SUCCESS':
1354+
13421355
deploy_count += 1
1343-
e2e_count=e2e_count+1
1356+
e2e_count += 1
13441357
if "sno" not in build:
13451358
print("Lease Quota-", lease)
13461359
check_node_crash(build)
13471360
print("Build Passed")
1361+
13481362
elif build_status == 'FAILURE':
1349-
cluster_status=cluster_deploy_status(build)
13501363
if "sno" not in build:
13511364
print("Lease Quota-", lease)
13521365
node_status = get_node_status(build)
13531366
print(node_status)
13541367
hypervisor_error_status = check_hypervisor_error(build)
13551368
if hypervisor_error_status:
1356-
print("Cluster Creation Failed."+constants.HYPERVISOR_CONNECTION_ERROR)
1357-
else :
1369+
print("Cluster Creation Failed." + constants.HYPERVISOR_CONNECTION_ERROR)
1370+
else:
13581371
check_node_crash(build)
13591372

13601373
if cluster_status == 'SUCCESS':
13611374
deploy_count += 1
13621375
if "sno" not in prow_ci_name:
1363-
job_type,_ = job_classifier(build)
1364-
tc_exe_status=print_all_failed_tc(build,job_type)
1365-
if tc_exe_status=="SUCCESS":
1366-
e2e_count=e2e_count+1
1376+
job_type, _ = job_classifier(build)
1377+
tc_exe_status = print_all_failed_tc(build, job_type)
1378+
if tc_exe_status == "SUCCESS":
1379+
e2e_count += 1
13671380

13681381
elif cluster_status == 'FAILURE':
13691382
print("Cluster Creation Failed")
1370-
13711383

1372-
elif cluster_status == 'ERROR' and not hypervisor_error_status :
1384+
elif cluster_status == 'ERROR' and not hypervisor_error_status:
13731385
print('Unable to get cluster status please check prowCI UI ')
13741386
else:
13751387
print(build_status)
13761388

13771389
print("\n")
1378-
1390+
13791391
build_list = list(set(build_list) - set(builds_to_deleted))
1380-
if len(build_list) != 0:
1392+
if len(build_list) != 0 and i!=0:
13811393
print ("\n{}/{} deploys succeeded".format(deploy_count, len(build_list)))
13821394
print ("{}/{} e2e tests succeeded".format(e2e_count, len(build_list)))
1383-
print("--------------------------------------------------------------------------------------------------")
1395+
print("--------------------------------------------------------------------------------------------------")

0 commit comments

Comments
 (0)