-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRETRY_LIMIT
executable file
·72 lines (60 loc) · 2.56 KB
/
RETRY_LIMIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
from pprint import pprint
import re
import requests
import yaml
import dateutil.parser
from datetime import datetime
from datetime import timezone
MAX_HOURS = 12
def last_task_failure(log_url):
r = requests.get(log_url + "job-output.json")
for playbook in r.json():
failures = sum([int(h["failures"]) for h in playbook["stats"].values()])
if not failures:
continue
playbook_path = playbook["playbook"]
for play in playbook["plays"]:
for task in play["tasks"]:
has_failed = any([r.get("failed") for r in task["hosts"].values()])
if has_failed:
for host, result in task["hosts"].items():
if not result.get("failed"):
continue
print("{host}: {name}, playbook={playbook_path}".format(host=host, name=task["task"]["name"], playbook_path=playbook_path))
return
def get_inventory(log_url):
r = requests.get(log_url + "zuul-info/inventory.yaml")
return yaml.safe_load(r.text)
def iter_builds():
jobs = [
"ansible-test-cloud-integration-vcenter_1esxi_without_nested-python36_1_of_2",
"ansible-test-cloud-integration-vcenter_1esxi_without_nested-python36_2_of_2",
"ansible-test-cloud-integration-vcenter_1esxi_with_nested-python36",
"ansible-test-cloud-integration-vcenter_2esxi_without_nested-python36",
]
for job in jobs:
url_template = "https://dashboard.zuul.ansible.com/api/tenant/ansible/builds?job_name={job}&limit=30"
r = requests.get(url_template.format(job=job))
builds = r.json()
for build in builds:
yield build
for build in iter_builds():
delta = datetime.now(timezone.utc) - dateutil.parser.parse(build["end_time"] + 'Z')
age = int(delta.total_seconds() / 3600)
if age > MAX_HOURS:
continue
if build["result"] != "RETRY_LIMIT":
continue
print("Log URL: {}".format(build["log_url"]))
last_task_failure(build["log_url"])
inventory = get_inventory(build["log_url"])
change_url = inventory["all"]["vars"]["zuul"]["change_url"]
cloud = inventory["all"]["hosts"]["esxi1"]["nodepool"]["cloud"]
region = inventory["all"]["hosts"]["esxi1"]["nodepool"]["az"]
host_id = inventory["all"]["hosts"]["esxi1"]["nodepool"]["host_id"]
print("host: {cloud}-{region}-{host_id}".format(
cloud=cloud, region=region, host_id=host_id
))
print("Change: {change_url}".format(change_url=change_url))
print("")