diff --git a/taskcluster/taskgraph/test/test_util_backstop.py b/taskcluster/taskgraph/test/test_util_backstop.py index 4993ff645e27..ba941d0638d7 100644 --- a/taskcluster/taskgraph/test/test_util_backstop.py +++ b/taskcluster/taskgraph/test/test_util_backstop.py @@ -18,18 +18,28 @@ from taskgraph.util.backstop import ( BACKSTOP_TIME_INTERVAL, ) from taskgraph.util.taskcluster import ( + get_artifact_url, get_index_url, + get_task_url, ) LAST_BACKSTOP_ID = 0 LAST_BACKSTOP_PUSHDATE = mktime(datetime.now().timetuple()) DEFAULT_RESPONSES = { + "index": { + "status": 200, + "json": {"taskId": LAST_BACKSTOP_ID}, + }, "artifact": { "status": 200, "body": dedent(""" pushdate: {} """.format(LAST_BACKSTOP_PUSHDATE)) }, + "status": { + "status": 200, + "json": {"status": {"state": "complete"}}, + }, } @@ -50,7 +60,7 @@ def params(): ( pytest.param( { - "artifact": {"status": 404}, + "index": {"status": 404}, }, {"pushlog_id": 1}, True, @@ -98,12 +108,25 @@ def params(): True, id="release branches always a backstop", ), + pytest.param( + { + "index": DEFAULT_RESPONSES["index"], + "status": { + "status": 200, + "json": {"status": {"state": "failed"}}, + }, + }, + {}, + True, + id="last backstop failed", + ), ), ) def test_is_backstop(responses, params, response_args, extra_params, expected): - index = BACKSTOP_INDEX.format(project=params["project"]) urls = { - "artifact": get_index_url(index) + "/artifacts/public/parameters.yml", + "index": get_index_url(BACKSTOP_INDEX.format(project=params["project"])), + "artifact": get_artifact_url(LAST_BACKSTOP_ID, "public/parameters.yml"), + "status": get_task_url(LAST_BACKSTOP_ID) + "/status", } for key in ("index", "status", "artifact"): diff --git a/taskcluster/taskgraph/util/backstop.py b/taskcluster/taskgraph/util/backstop.py index 17eaa5bf86ad..731b70501e85 100644 --- a/taskcluster/taskgraph/util/backstop.py +++ b/taskcluster/taskgraph/util/backstop.py @@ -4,9 +4,11 @@ from __future__ import absolute_import, print_function, unicode_literals -from requests import HTTPError - -from taskgraph.util.taskcluster import get_artifact_from_index +from taskgraph.util.taskcluster import ( + find_task_id, + get_artifact, + status_task, +) BACKSTOP_PUSH_INTERVAL = 20 @@ -50,13 +52,16 @@ def is_backstop( index = BACKSTOP_INDEX.format(project=project) try: - last_pushdate = get_artifact_from_index(index, 'public/parameters.yml')["pushdate"] - except HTTPError as e: - if e.response.status_code == 404: - # There hasn't been a backstop push yet. - return True - raise + last_backstop_id = find_task_id(index) + except KeyError: + # Index wasn't found, implying there hasn't been a backstop push yet. + return True + if status_task(last_backstop_id) in ("failed", "exception"): + # If the last backstop failed its decision task, make this a backstop. + return True + + last_pushdate = get_artifact(last_backstop_id, 'public/parameters.yml')["pushdate"] if (pushdate - last_pushdate) / 60 >= time_interval: return True return False