Skip to content

Commit 447533d

Browse files
authored
Modified get_quota_and_nightly (#48)
Signed-off-by: KeerthanaAP <[email protected]>
1 parent e272118 commit 447533d

File tree

1 file changed

+88
-101
lines changed

1 file changed

+88
-101
lines changed

monitor.py

Lines changed: 88 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,68 @@ def check_node_crash(spy_link):
352352
except requests.RequestException:
353353
return "Error while sending request to url"
354354

355+
def get_lease(build_log_response,job_platform):
356+
357+
'''
358+
Gets lease/region where cluster is deployed.
359+
parameter:
360+
build_log_response: build log response.
361+
job_platform(string):The infrastructure where the cluster is deployed.
362+
Returns:
363+
lease(string): Acquired lease/region
364+
'''
365+
366+
lease = ""
367+
zone_log_re = re.compile('(Acquired 1 lease\(s\) for {}-quota-slice: \[)([^]]+)(\])'.format(job_platform), re.MULTILINE|re.DOTALL)
368+
zone_log_match = zone_log_re.search(build_log_response.text)
369+
if zone_log_match is None:
370+
lease = "Failed to fetch lease information"
371+
else:
372+
lease = zone_log_match.group(2)
373+
return lease
374+
375+
def get_nightly(build_log_url,build_log_response, job_platform):
376+
377+
'''
378+
Gets nightly image used.
379+
parameter:
380+
build_log_url(string): link to access the logs of the job.
381+
build_log_response: build log response.
382+
job_platform(string): Architecture (ppc64le or s390x or multi).
383+
Returns:
384+
nightly(string): Nighlty image used.
385+
'''
386+
387+
if "upgrade" not in build_log_url:
388+
nightly_log_re = re.compile('(Resolved release {}-latest to (\S+))'.format(job_platform), re.MULTILINE|re.DOTALL)
389+
nightly_log_match = nightly_log_re.search(build_log_response.text)
390+
if nightly_log_match is None:
391+
if job_platform == 'multi':
392+
nightly = "Failed to fetch nightly image"
393+
else:
394+
rc_nightly_log_re = re.compile('(Using explicitly provided pull-spec for release {}-latest \((\S+)\))'.format(job_platform), re.MULTILINE|re.DOTALL)
395+
rc_nightly_log_match = rc_nightly_log_re.search(build_log_response.text)
396+
if rc_nightly_log_match is None:
397+
nightly = "Unable to fetch nightly information- No match found"
398+
else:
399+
nightly = rc_nightly_log_match.group(2)
400+
else:
401+
nightly = job_platform+"-latest-"+ nightly_log_match.group(2)
402+
else:
403+
nightly_initial_log_re = re.compile('(Resolved release {}-initial to (\S+))'.format(job_platform), re.MULTILINE|re.DOTALL)
404+
nightly_initial_log_match = nightly_initial_log_re.search(build_log_response.text)
405+
if nightly_initial_log_match is None:
406+
nightly = "Unable to fetch nightly {}-initial information- No match found".format(job_platform)
407+
else:
408+
nightly = job_platform+"-initial-"+ nightly_initial_log_match.group(2)
409+
nightly_latest_log_re = re.compile('(Resolved release {}-latest to (\S+))'.format(job_platform), re.MULTILINE|re.DOTALL)
410+
nightly_latest_log_match = nightly_latest_log_re.search(build_log_response.text)
411+
if nightly_latest_log_match is None:
412+
nightly = nightly + " Unable to fetch nightly {}-latest information- No match found".format(job_platform)
413+
else:
414+
nightly = nightly +" "+job_platform+"-latest-"+ nightly_latest_log_match.group(2)
415+
return nightly
416+
355417
def get_quota_and_nightly(spy_link):
356418

357419
'''
@@ -367,109 +429,34 @@ def get_quota_and_nightly(spy_link):
367429

368430
_,job_platform = job_classifier(spy_link)
369431
lease = ""
370-
371-
if 'ppc64le' in spy_link:
372-
build_log_url = PROW_VIEW_URL + spy_link[8:] + "/build-log.txt"
373-
if job_platform == "libvirt":
374-
job_platform+="-ppc64le"
375-
elif job_platform == "powervs":
376-
job_platform+="-[1-9]"
377-
378-
zone_log_re = re.compile('(Acquired 1 lease\(s\) for {}-quota-slice: \[)([^]]+)(\])'.format(job_platform), re.MULTILINE|re.DOTALL)
379-
try:
380-
build_log_response = requests.get(build_log_url, verify=False, timeout=15)
381-
zone_log_match = zone_log_re.search(build_log_response.text)
382-
if zone_log_match is None:
383-
lease = "Failed to fetch lease information"
384-
else:
385-
lease = zone_log_match.group(2)
386-
# Fetch the nightly information for non-upgrade jobs
387-
if "upgrade" not in build_log_url:
388-
nightly_log_re = re.compile('(Resolved release ppc64le-latest to (\S+))', re.MULTILINE|re.DOTALL)
389-
nightly_log_match = nightly_log_re.search(build_log_response.text)
390-
if nightly_log_match is None:
391-
rc_nightly_log_re = re.compile('(Using explicitly provided pull-spec for release ppc64le-latest \((\S+)\))', re.MULTILINE|re.DOTALL)
392-
rc_nightly_log_match = rc_nightly_log_re.search(build_log_response.text)
393-
if rc_nightly_log_match is None:
394-
nightly = "Unable to fetch nightly information- No match found"
395-
else:
396-
nightly = rc_nightly_log_match.group(2)
397-
else:
398-
nightly = "ppc64le-latest-"+ nightly_log_match.group(2)
399-
# Fetch nightly information for upgrade jobs- fetch both ppc64le-initial and ppc64le-latest
400-
else:
401-
nightly_initial_log_re = re.compile('(Resolved release ppc64le-initial to (\S+))', re.MULTILINE|re.DOTALL)
402-
nightly_initial_log_match = nightly_initial_log_re.search(build_log_response.text)
403-
if nightly_initial_log_match is None:
404-
nightly = "Unable to fetch nightly ppc64le-initial information- No match found"
405-
else:
406-
nightly = "ppc64le-initial-"+ nightly_initial_log_match.group(2)
407-
nightly_latest_log_re = re.compile('(Resolved release ppc64le-latest to (\S+))', re.MULTILINE|re.DOTALL)
408-
nightly_latest_log_match = nightly_latest_log_re.search(build_log_response.text)
409-
if nightly_latest_log_match is None:
410-
nightly = nightly + " Unable to fetch nightly ppc64le-latest information- No match found"
411-
else:
412-
nightly = nightly + " ppc64le-latest-"+ nightly_latest_log_match.group(2)
413-
return lease, nightly
414-
except requests.Timeout:
415-
return "Request timed out"
416-
except requests.RequestException:
417-
return "Error while sending request to url"
418-
419-
elif 's390x' in spy_link:
420-
build_log_url = PROW_VIEW_URL + spy_link[8:] + "/build-log.txt"
421-
if job_platform == "libvirt":
432+
build_log_url = PROW_VIEW_URL + spy_link[8:] + "/build-log.txt"
433+
try:
434+
build_log_response = requests.get(build_log_url, verify=False, timeout=15)
435+
if 'ppc64le' in spy_link:
436+
if job_platform == "libvirt":
437+
job_platform+="-ppc64le"
438+
elif job_platform == "powervs":
439+
job_platform+="-[1-9]"
440+
lease = get_lease(build_log_response,job_platform)
441+
nightly = get_nightly(build_log_url,build_log_response, 'ppc64le')
442+
443+
elif 's390x' in spy_link:
422444
job_platform+="-s390x"
445+
lease = get_lease(build_log_response,job_platform )
446+
nightly = get_nightly(build_log_url,build_log_response, 's390x')
423447

424-
zone_log_re = re.compile('(Acquired 1 lease\(s\) for {}-quota-slice: \[)([^]]+)(\])'.format(job_platform), re.MULTILINE|re.DOTALL)
425-
try:
426-
build_log_response = requests.get(build_log_url, verify=False, timeout=15)
427-
zone_log_match = zone_log_re.search(build_log_response.text)
428-
if zone_log_match is None:
429-
lease = "Failed to fetch lease information"
430-
else:
431-
lease = zone_log_match.group(2)
432-
nightly_log_re = re.compile('(Resolved release s390x-latest to (\S+))', re.MULTILINE|re.DOTALL)
433-
nightly_log_match = nightly_log_re.search(build_log_response.text)
434-
if nightly_log_match is None:
435-
rc_nightly_log_re = re.compile('(Using explicitly provided pull-spec for release s390x-latest \((\S+)\))', re.MULTILINE|re.DOTALL)
436-
rc_nightly_log_match = rc_nightly_log_re.search(build_log_response.text)
437-
if rc_nightly_log_match is None:
438-
nightly = "Unable to fetch nightly information- No match found"
439-
else:
440-
nightly = rc_nightly_log_match.group(2)
441-
else:
442-
nightly = "s390x-latest-"+ nightly_log_match.group(2)
443-
return lease, nightly
444-
except requests.Timeout:
445-
return "Request timed out"
446-
except requests.RequestException:
447-
return "Error while sending request to url"
448-
else:
449-
build_log_url = PROW_VIEW_URL + spy_link[8:] + "/build-log.txt"
450-
try:
451-
build_log_response = requests.get(build_log_url, verify=False, timeout=15)
452-
# lease is not applicable for SNO hence checking only for MCE
453-
if "mce" in spy_link:
454-
job_platform = "aws" #currently it contains only aws hence hardcoding
455-
zone_log_re = re.compile('(Acquired 1 lease\(s\) for {}-quota-slice: \[)([^]]+)(\])'.format(job_platform), re.MULTILINE|re.DOTALL)
456-
zone_log_match = zone_log_re.search(build_log_response.text)
457-
if zone_log_match is None:
458-
lease = "Failed to fetch lease information"
459-
else:
460-
lease = zone_log_match.group(2)
461-
nightly_log_re = re.compile('(Resolved release multi-latest to (\S+))', re.MULTILINE|re.DOTALL)
462-
nightly_log_match = nightly_log_re.search(build_log_response.text)
463-
if nightly_log_match is None:
464-
nightly = "Failed to fetch nightly image"
465-
else:
466-
nightly = "multi-latest-"+ nightly_log_match.group(2)
467-
return lease, nightly
468-
except requests.Timeout:
469-
return "Request timed out"
470-
except requests.RequestException:
471-
return "Error while sending request to url"
472-
448+
elif "mce" in spy_link:
449+
job_platform = "aws"
450+
lease = get_lease(build_log_response,job_platform )
451+
nightly = get_nightly(build_log_url,build_log_response, "multi")
452+
else:
453+
# lease is not applicable for SNO
454+
nightly = get_nightly(build_log_url,build_log_response, "multi")
455+
return lease, nightly
456+
except requests.Timeout:
457+
return "Request timed out"
458+
except requests.RequestException:
459+
return "Error while sending request to url"
473460

474461
def job_classifier(spy_link):
475462

0 commit comments

Comments
 (0)