Skip to content

Commit

Permalink
Check upstream openstack opensuse devstack failure
Browse files Browse the repository at this point in the history
  • Loading branch information
JanZerebecki committed Dec 7, 2020
1 parent 1937f93 commit 254f0c9
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
106 changes: 106 additions & 0 deletions jenkins/ci.suse.de/cloud-check-upstream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/python3

from functools import lru_cache
import re
import requests
import pprint
import inspect


def get_jobs(tenant="openstack", api_prefix="https://zuul.opendev.org"):
r = requests.get(
"{prefix}/api/tenant/{tenant}/jobs".format(
tenant=tenant, prefix=api_prefix
)
)
r.raise_for_status()
return r.json()


@lru_cache(maxsize=3)
def get_job_details(
job_name, tenant="openstack", api_prefix="https://zuul.opendev.org"
):
r = requests.get(
"{prefix}/api/tenant/{tenant}/job/{job_name}".format(
job_name=job_name, tenant=tenant, prefix=api_prefix
)
)
r.raise_for_status()
return r.json()


def get_builds(
job_name=None,
limit=50,
skip=0,
branch=None,
uuid=None,
newrev=None,
ref=None,
patchset=None,
change=None,
pipeline=None,
project=None,
tenant="openstack",
api_prefix="https://zuul.opendev.org",
):
arginfo = inspect.getargvalues(inspect.currentframe())
params = {}
for a in arginfo.args:
if a not in ["api_prefix"] and arginfo.locals[a] is not None:
params[a] = arginfo.locals[a]
r = requests.get(
"{prefix}/api/tenant/{tenant}/builds".format(
tenant=tenant, prefix=api_prefix
),
params,
)
r.raise_for_status()
return r.json()


def filter_jobs(substring):
for j in get_jobs():
if re.search(r"(?i)suse", j["name"]):
yield j


def list_all_suse():
jobs = filter_jobs("suse")
pprint.pprint(list(jobs))


def job_status(job_name):
builds = get_builds(
job_name, branch="master", pipeline="periodic-weekly", limit=1
)
last = builds[0]
print("Last job run:")
pprint.pprint(last)
print(
"\nList these jobs at: https://zuul.opendev.org/t/openstack/builds?job_name=devstack-platform-opensuse-15&branch=master&pipeline=periodic-weekly"
)
print("\n\n")
if last["result"] == "SUCCESS":
print("Last job was a success.")
return True
else:
print("ERROR: Last job was a {}. ".format(last["result"]))
return False


def main_without_exit():
result = job_status("devstack-platform-opensuse-15")
if result is True:
return 0
return 1


def main():
result = main_without_exit()
exit(result)


if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions jenkins/ci.suse.de/cloud-check-upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- project:
name: cloud-check-upstream
jobs:
- 'cloud-check-upstream'

- builder:
name: builder-cloud-check-upstream
builders:
- shell: !include-raw: cloud-check-upstream.py

- job:
name: 'cloud-check-upstream'
node: cloud-trackupstream
description: |
Job to check if OpenSUSE failed in the OpenStack upstream CI.
triggers:
- timed: '4 4 * * 1'

builders:
- builder-cloud-check-upstream

wrappers:
- timestamps
- timeout:
fail: true
write-description: "ERROR: this should not time out."
timeout: 180

0 comments on commit 254f0c9

Please sign in to comment.