aboutsummaryrefslogtreecommitdiff
path: root/monitor
diff options
context:
space:
mode:
authorDavid Spickett <david.spickett@linaro.org>2021-03-22 12:25:13 +0000
committerDavid Spickett <david.spickett@linaro.org>2021-03-22 15:22:57 +0000
commite88fe59dfe2680dab66b8a02336a2bc69414da5a (patch)
treecdbe8e20871fd476a39468b451da50eeedda1544 /monitor
parent7f18f4d7f4d708e449c32b3174d5889b419839eb (diff)
bot-status.py: Catch wget exceptions outside of wrapper
This means we aren't returning True as in yes, there was an error. Which makes sense when you look at wget() but elsehwere it seems backwards. By catching the exception where we call wget, the failure handling can be clearer. Change-Id: If7c74431dab31503c15681ba39225a576e3da407
Diffstat (limited to 'monitor')
-rwxr-xr-xmonitor/bot-status.py42
1 files changed, 22 insertions, 20 deletions
diff --git a/monitor/bot-status.py b/monitor/bot-status.py
index 38d9f5f..25ca4fe 100755
--- a/monitor/bot-status.py
+++ b/monitor/bot-status.py
@@ -29,26 +29,25 @@ def not_ignored(s):
return not ignored(s)
-# Returns the parsed json URL or and error string.
+# Returns the parsed json URL or raises an exception
def wget(session, url):
- try:
- req = session.get(url)
- except requests.exceptions.RequestException as e:
- return str(e), True
- return req.json(), False
+ return session.get(url).json()
# Returns a string with the GIT revision usesd on build BUILDID and
# PREV_BUILDID in the form '<id_buildid>-<id_prev_buildid>'.
def get_bot_failure_changes(session, base_url, buildid, prev_buildid):
def wget_build_rev(bid):
- contents, err = wget(session,
- "{}/api/v2/builds/{}/changes"
- .format(base_url, bid))
- changes = contents['changes']
- if err or not changes:
+ try:
+ contents = wget(session,
+ "{}/api/v2/builds/{}/changes"
+ .format(base_url, bid))
+ except requests.exceptions.RequestException:
return None
- return changes[0]['revision']
+ changes = contents['changes']
+ if changes:
+ return changes[0]['revision']
+ return None
revision = wget_build_rev(buildid)[:GIT_SHORT_LEN]
prev_revision = None
@@ -73,10 +72,12 @@ RESULT_COLORS = {
}
def get_bot_failing_steps(session, base_url, buildid):
- contents, err = wget(session, "{}/api/v2/builds/{}/steps"
- .format(base_url, buildid))
- if err:
+ try:
+ contents = wget(session, "{}/api/v2/builds/{}/steps"
+ .format(base_url, buildid))
+ except requests.exceptions.RequestException:
return ""
+
for step in contents["steps"]:
if step["results"] in RESULT_COLORS:
yield (step["name"], step["results"])
@@ -85,11 +86,12 @@ def get_bot_failing_steps(session, base_url, buildid):
# Get the status of a individual bot BOT. Returns a dict with the
# information.
def get_bot_status(session, bot, base_url, builder_url, build_url):
- (builds, err) = wget(session,
- "{}/api/v2/{}/{}/{}"
- .format(base_url, builder_url, bot, build_url))
- if err:
- return { 'fail' : err }
+ try:
+ builds = wget(session,
+ "{}/api/v2/{}/{}/{}"
+ .format(base_url, builder_url, bot, build_url))
+ except requests.exceptions.RequestException as e:
+ return {'fail': True}
reversed_builds = iter(sorted(builds['builds'], key=lambda b: -b["number"]))
for build in reversed_builds: