Skip to content

Commit e979b04

Browse files
committed
Explain on the bug, rather than failing, when try is closed. Fixes #325
hg.mozilla.org's push hook refuses pushes while try is closed, and also when it can't reach treestatus to check. Updatebot retried that ten times and then reported a generic failure. Recognise the hook's message instead: don't retry, tell the library owner why there's no try run and the ./mach try command to push it themselves, and still submit the update to Phabricator.
1 parent 06fddba commit e979b04

5 files changed

Lines changed: 135 additions & 4 deletions

File tree

‎apis/taskcluster.py‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# License, v. 2.0. If a copy of the MPL was not distributed with this
55
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
66

7+
import re
8+
import shlex
79
from enum import unique, IntEnum
810
import jsone
911
import platform
@@ -15,6 +17,22 @@
1517
from components.logging import logEntryExit, logEntryExitNoArgs, LogLevel
1618
from components.providerbase import BaseProvider, INeedsCommandProvider, INeedsLoggingProvider
1719

20+
# hg.mozilla.org's push hook refuses pushes to a closed tree, and also when it
21+
# can't reach treestatus to find out (see version-control-tools'
22+
# hghooks/mozhghooks/treeclosure.py).
23+
TREE_CLOSED = re.compile(r"\S+ is CLOSED! Reason: (.*)")
24+
TREE_STATUS_UNAVAILABLE = "Unable to check if the tree is open - treating as if CLOSED."
25+
26+
27+
class TryTreeClosedError(Exception):
28+
"""Try refused the push because it's closed (or treestatus couldn't be reached).
29+
Retrying won't help until the tree reopens."""
30+
def __init__(self, reason, try_command):
31+
super().__init__("Try is closed: " + reason)
32+
self.reason = reason
33+
self.try_command = try_command
34+
35+
1836
# We want to run tests a total of four times
1937
TRIGGER_TOTAL = 4
2038

@@ -148,7 +166,7 @@ def _vcs_setup(self):
148166
self._vcs_setup_initialized = True
149167

150168
@logEntryExit
151-
@retry
169+
@retry(giveup=(TryTreeClosedError,))
152170
def submit_to_try(self, library, recursed=0):
153171
self._vcs_setup()
154172

@@ -165,8 +183,16 @@ def submit_to_try(self, library, recursed=0):
165183
else:
166184
try_arguments = ["./mach", "try", "auto", "--push-to-vcs"]
167185

168-
ret = self.run(try_arguments, clean_return=True)
186+
ret = self.run(try_arguments, clean_return=False)
169187
output = ret.stdout.decode()
188+
if ret.returncode:
189+
stderr = ret.stderr.decode() if getattr(ret, "stderr", None) else ""
190+
closed = TREE_CLOSED.search(output + stderr)
191+
if closed:
192+
raise TryTreeClosedError(closed.group(1).strip(), shlex.join(try_arguments))
193+
if TREE_STATUS_UNAVAILABLE in output + stderr:
194+
raise TryTreeClosedError("its tree status couldn't be checked, so the push was refused as if it were closed", shlex.join(try_arguments))
195+
ret.check_returncode()
170196

171197
isNext = False
172198
try_link = None

‎components/bugzilla.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ def COULD_NOT_VENDOR(library, errormessage):
157157
s += "> " + line + "\n"
158158
return s
159159

160+
@staticmethod
161+
def TRY_CLOSED(reason, try_command):
162+
return """
163+
I couldn't push a try run for this update because try is closed (%s).
164+
165+
I'm still submitting it to Phabricator, but I won't push a try run for it
166+
myself. Once try reopens, you can apply the patch from Phabricator and push
167+
the try run I would have, with:
168+
169+
%s
170+
""" % (reason, try_command)
171+
160172
@staticmethod
161173
def COULD_NOT_SUBMIT_DIFF_TOO_LARGE(library, errormessage):
162174
return """

‎tasktypes/vendoring.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from tasktypes.base import BaseTaskRunner
1212
from apis.phabricator import DiffTooLargeError
13-
from apis.taskcluster import Classification
13+
from apis.taskcluster import Classification, TryTreeClosedError
1414
from components.bugzilla import CommentTemplates
1515
from components.mach_vendor import VendorResult
1616
from components.dbmodels import JOBSTATUS, JOBOUTCOME, JOBTYPE
@@ -279,6 +279,11 @@ def _process_new_job(self, library, task, new_version, timestamp, most_recent_jo
279279
self.dbProvider.add_try_run(created_job, try_revision, 'all platforms')
280280
self.dbProvider.update_job_status(created_job, newstatus=JOBSTATUS.AWAITING_SECOND_PLATFORMS_TRY_RESULTS)
281281
self.bugzillaProvider.comment_on_bug(created_job.bugzilla_id, CommentTemplates.TRY_RUN_SUBMITTED(try_revision))
282+
except TryTreeClosedError as e:
283+
# Not an Updatebot failure: explain on the bug and carry on to Phabricator without a try run.
284+
self.logger.log(str(e), level=LogLevel.Warning)
285+
self.dbProvider.update_job_status(created_job, JOBSTATUS.DONE, JOBOUTCOME.COULD_NOT_SUBMIT_TO_TRY)
286+
self.bugzillaProvider.comment_on_bug(created_job.bugzilla_id, CommentTemplates.TRY_CLOSED(e.reason, e.try_command), needinfo=library.maintainer_bz)
282287
except Exception as e:
283288
self.dbProvider.update_job_status(created_job, JOBSTATUS.DONE, JOBOUTCOME.COULD_NOT_SUBMIT_TO_TRY)
284289
self.bugzillaProvider.comment_on_bug(created_job.bugzilla_id, CommentTemplates.COULD_NOT_GENERAL_ERROR("submit to try."), needinfo=library.maintainer_bz)

‎tests/functionality_all_platforms.py‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from apis.taskcluster import TaskclusterProvider
3333
from apis.phabricator import PhabricatorProvider
3434

35-
from tests.functionality_utilities import SHARED_COMMAND_MAPPINGS, TRY_OUTPUT, TRY_LOCKED_OUTPUT, ARC_OUTPUT, CONDUIT_EDIT_OUTPUT, MockedBugzillaProvider, treeherder_response
35+
from tests.functionality_utilities import SHARED_COMMAND_MAPPINGS, TRY_OUTPUT, TRY_LOCKED_OUTPUT, TRY_CLOSED_OUTPUT, TRY_TREESTATUS_UNAVAILABLE_OUTPUT, ARC_OUTPUT, CONDUIT_EDIT_OUTPUT, MockedBugzillaProvider, treeherder_response
3636
from tests.mock_commandprovider import TestCommandProvider
3737
from tests.mock_aiprovider import MockAIProvider
3838
from tests.mock_libraryprovider import MockLibraryProvider
@@ -736,6 +736,58 @@ def testFailsDuringTrySubmitLockedForever(self):
736736
finally:
737737
self._cleanup(u, expected_values)
738738

739+
def _run_with_try_closed(self, try_output):
740+
library_filter = 'dav1d'
741+
try_calls = [0]
742+
743+
def try_submit():
744+
try_calls[0] += 1
745+
return (1, try_output)
746+
747+
(u, expected_values, _check_jobs) = self._setup(
748+
library_filter,
749+
lambda b: ["try_rev|2021-02-09 15:30:04 -0500|2021-02-12 17:40:01 +0000"],
750+
lambda: 50, # get_filed_bug_id_func,
751+
lambda b: {}, # filed_bug_ids_func
752+
AssertFalse, # treeherder_response
753+
command_callbacks={'try_submit': try_submit}
754+
)
755+
comments = []
756+
original_comment_on_bug = u.bugzillaProvider.comment_on_bug
757+
u.bugzillaProvider.comment_on_bug = lambda bug_id, comment, *args, **kwargs: (comments.append(comment), original_comment_on_bug(bug_id, comment, *args, **kwargs))
758+
exceptions = []
759+
original_log_exception = u.logger.log_exception
760+
u.logger.log_exception = lambda e: (exceptions.append(e), original_log_exception(e))
761+
try:
762+
u.run(library_filter=library_filter)
763+
764+
self.assertEqual(try_calls[0], 1, "Retried pushing to a closed try")
765+
self.assertEqual(exceptions, [], "A closed try shouldn't be reported as an Updatebot error")
766+
lib = [lib for lib in u.libraryProvider.get_libraries(u.config_dictionary['General']['gecko-path']) if library_filter in lib.name][0]
767+
j = u.dbProvider.get_job(lib, expected_values.library_new_version_id())
768+
self.assertEqual(JOBSTATUS.DONE, j.status, "Expected status JOBSTATUS.DONE, got status %s" % (j.status.name))
769+
self.assertEqual(JOBOUTCOME.COULD_NOT_SUBMIT_TO_TRY, j.outcome, "Expected outcome JOBOUTCOME.COULD_NOT_SUBMIT_TO_TRY, got outcome %s" % (j.outcome.name))
770+
self.assertEqual(len(j.phab_revisions), 1, "Should still have submitted to Phabricator")
771+
closed_comments = [c for c in comments if "because try is closed" in c]
772+
self.assertEqual(len(closed_comments), 1)
773+
self.assertIn("./mach try", closed_comments[0])
774+
return closed_comments[0]
775+
finally:
776+
u.logger.log_exception = original_log_exception
777+
self._cleanup(u, expected_values)
778+
779+
# Create -> ./mach vendor -> commit -> try is closed -> comment, and still submit to Phabricator
780+
@logEntryExitHeaderLine
781+
def testTryClosed(self):
782+
comment = self._run_with_try_closed(TRY_CLOSED_OUTPUT)
783+
self.assertIn("(infra: worker pools are down)", comment)
784+
785+
# Create -> ./mach vendor -> commit -> treestatus is down, so the push hook treats try as closed
786+
@logEntryExitHeaderLine
787+
def testTryTreestatusUnavailable(self):
788+
comment = self._run_with_try_closed(TRY_TREESTATUS_UNAVAILABLE_OUTPUT)
789+
self.assertIn("tree status couldn't be checked", comment)
790+
739791
# Create -> ./mach vendor -> commit -> Fails during try submit
740792
@logEntryExitHeaderLine
741793
def testTryLockedOutput(self):

‎tests/functionality_utilities.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,42 @@ def TRY_OUTPUT(revision, include_auto_line=True):
138138
return s
139139

140140

141+
# What hg.mozilla.org's push hook prints when try is closed, and when it can't reach treestatus
142+
TRY_CLOSED_OUTPUT = """
143+
Creating temporary commit for remote...
144+
pushing to ssh://hg.mozilla.org/try
145+
remote: adding changesets
146+
remote: adding manifests
147+
remote: adding file changes
148+
remote:
149+
remote:
150+
remote: ************************** ERROR ****************************
151+
remote: try is CLOSED! Reason: infra: worker pools are down
152+
remote: To push despite the closed tree, include "CLOSED TREE" in your push comment
153+
remote: *************************************************************
154+
remote:
155+
remote:
156+
remote: transaction abort!
157+
remote: rollback completed
158+
temporary commit removed, repository restored
159+
Error running mach:
160+
"""
161+
162+
TRY_TREESTATUS_UNAVAILABLE_OUTPUT = """
163+
Creating temporary commit for remote...
164+
pushing to ssh://hg.mozilla.org/try
165+
remote: ************************** ERROR ****************************
166+
remote: Error accessing https://treestatus.prod.lando.prod.cloudops.mozgcp.net/trees/try :
167+
remote: HTTP Error 502: Bad Gateway
168+
remote: Unable to check if the tree is open - treating as if CLOSED.
169+
remote: To push regardless, include "CLOSED TREE" in your push comment.
170+
remote: *************************************************************
171+
remote: transaction abort!
172+
remote: rollback completed
173+
temporary commit removed, repository restored
174+
Error running mach:
175+
"""
176+
141177
TRY_LOCKED_OUTPUT = """
142178
Creating temporary commit for remote...
143179
A try_task_config.json

0 commit comments

Comments
 (0)