Bug 1666809 - [taskgraph] Consider pushes a backstop if the last backstop had a broken decision task, r=taskgraph-reviewers,aki

Depends on D91330

Differential Revision: https://phabricator.services.mozilla.com/D91331
This commit is contained in:
Andrew Halberstadt 2020-09-24 19:54:21 +00:00
parent 6ea38b96d9
commit 0c36e740a0
2 changed files with 40 additions and 12 deletions

View File

@ -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"):

View File

@ -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