Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions apis/taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import re
import shlex
from enum import unique, IntEnum
import jsone
import platform
Expand All @@ -15,6 +17,22 @@
from components.logging import logEntryExit, logEntryExitNoArgs, LogLevel
from components.providerbase import BaseProvider, INeedsCommandProvider, INeedsLoggingProvider

# hg.mozilla.org's push hook refuses pushes to a closed tree, and also when it
# can't reach treestatus to find out (see version-control-tools'
# hghooks/mozhghooks/treeclosure.py).
TREE_CLOSED = re.compile(r"\S+ is CLOSED! Reason: (.*)")
TREE_STATUS_UNAVAILABLE = "Unable to check if the tree is open - treating as if CLOSED."


class TryTreeClosedError(Exception):
"""Try refused the push because it's closed (or treestatus couldn't be reached).
Retrying won't help until the tree reopens."""
def __init__(self, reason, try_command):
super().__init__("Try is closed: " + reason)
self.reason = reason
self.try_command = try_command


# We want to run tests a total of four times
TRIGGER_TOTAL = 4

Expand Down Expand Up @@ -148,7 +166,7 @@ def _vcs_setup(self):
self._vcs_setup_initialized = True

@logEntryExit
@retry
@retry(giveup=(TryTreeClosedError,))
def submit_to_try(self, library, recursed=0):
self._vcs_setup()

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

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

isNext = False
try_link = None
Expand Down
12 changes: 12 additions & 0 deletions components/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ def COULD_NOT_VENDOR(library, errormessage):
s += "> " + line + "\n"
return s

@staticmethod
def TRY_CLOSED(reason, try_command):
return """
I couldn't push a try run for this update because try is closed (%s).

I'm still submitting it to Phabricator, but I won't push a try run for it
myself. Once try reopens, you can apply the patch from Phabricator and push
the try run I would have, with:

%s
""" % (reason, try_command)

@staticmethod
def COULD_NOT_SUBMIT_DIFF_TOO_LARGE(library, errormessage):
return """
Expand Down
7 changes: 6 additions & 1 deletion tasktypes/vendoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from tasktypes.base import BaseTaskRunner
from apis.phabricator import DiffTooLargeError
from apis.taskcluster import Classification
from apis.taskcluster import Classification, TryTreeClosedError
from components.bugzilla import CommentTemplates
from components.mach_vendor import VendorResult
from components.dbmodels import JOBSTATUS, JOBOUTCOME, JOBTYPE
Expand Down Expand Up @@ -279,6 +279,11 @@ def _process_new_job(self, library, task, new_version, timestamp, most_recent_jo
self.dbProvider.add_try_run(created_job, try_revision, 'all platforms')
self.dbProvider.update_job_status(created_job, newstatus=JOBSTATUS.AWAITING_SECOND_PLATFORMS_TRY_RESULTS)
self.bugzillaProvider.comment_on_bug(created_job.bugzilla_id, CommentTemplates.TRY_RUN_SUBMITTED(try_revision))
except TryTreeClosedError as e:
# Not an Updatebot failure: explain on the bug and carry on to Phabricator without a try run.
self.logger.log(str(e), level=LogLevel.Warning)
self.dbProvider.update_job_status(created_job, JOBSTATUS.DONE, JOBOUTCOME.COULD_NOT_SUBMIT_TO_TRY)
self.bugzillaProvider.comment_on_bug(created_job.bugzilla_id, CommentTemplates.TRY_CLOSED(e.reason, e.try_command), needinfo=library.maintainer_bz)
except Exception as e:
self.dbProvider.update_job_status(created_job, JOBSTATUS.DONE, JOBOUTCOME.COULD_NOT_SUBMIT_TO_TRY)
self.bugzillaProvider.comment_on_bug(created_job.bugzilla_id, CommentTemplates.COULD_NOT_GENERAL_ERROR("submit to try."), needinfo=library.maintainer_bz)
Expand Down
54 changes: 53 additions & 1 deletion tests/functionality_all_platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from apis.taskcluster import TaskclusterProvider
from apis.phabricator import PhabricatorProvider

from tests.functionality_utilities import SHARED_COMMAND_MAPPINGS, TRY_OUTPUT, TRY_LOCKED_OUTPUT, ARC_OUTPUT, CONDUIT_EDIT_OUTPUT, MockedBugzillaProvider, treeherder_response
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
from tests.mock_commandprovider import TestCommandProvider
from tests.mock_aiprovider import MockAIProvider
from tests.mock_libraryprovider import MockLibraryProvider
Expand Down Expand Up @@ -736,6 +736,58 @@ def testFailsDuringTrySubmitLockedForever(self):
finally:
self._cleanup(u, expected_values)

def _run_with_try_closed(self, try_output):
library_filter = 'dav1d'
try_calls = [0]

def try_submit():
try_calls[0] += 1
return (1, try_output)

(u, expected_values, _check_jobs) = self._setup(
library_filter,
lambda b: ["try_rev|2021-02-09 15:30:04 -0500|2021-02-12 17:40:01 +0000"],
lambda: 50, # get_filed_bug_id_func,
lambda b: {}, # filed_bug_ids_func
AssertFalse, # treeherder_response
command_callbacks={'try_submit': try_submit}
)
comments = []
original_comment_on_bug = u.bugzillaProvider.comment_on_bug
u.bugzillaProvider.comment_on_bug = lambda bug_id, comment, *args, **kwargs: (comments.append(comment), original_comment_on_bug(bug_id, comment, *args, **kwargs))
exceptions = []
original_log_exception = u.logger.log_exception
u.logger.log_exception = lambda e: (exceptions.append(e), original_log_exception(e))
try:
u.run(library_filter=library_filter)

self.assertEqual(try_calls[0], 1, "Retried pushing to a closed try")
self.assertEqual(exceptions, [], "A closed try shouldn't be reported as an Updatebot error")
lib = [lib for lib in u.libraryProvider.get_libraries(u.config_dictionary['General']['gecko-path']) if library_filter in lib.name][0]
j = u.dbProvider.get_job(lib, expected_values.library_new_version_id())
self.assertEqual(JOBSTATUS.DONE, j.status, "Expected status JOBSTATUS.DONE, got status %s" % (j.status.name))
self.assertEqual(JOBOUTCOME.COULD_NOT_SUBMIT_TO_TRY, j.outcome, "Expected outcome JOBOUTCOME.COULD_NOT_SUBMIT_TO_TRY, got outcome %s" % (j.outcome.name))
self.assertEqual(len(j.phab_revisions), 1, "Should still have submitted to Phabricator")
closed_comments = [c for c in comments if "because try is closed" in c]
self.assertEqual(len(closed_comments), 1)
self.assertIn("./mach try", closed_comments[0])
return closed_comments[0]
finally:
u.logger.log_exception = original_log_exception
self._cleanup(u, expected_values)

# Create -> ./mach vendor -> commit -> try is closed -> comment, and still submit to Phabricator
@logEntryExitHeaderLine
def testTryClosed(self):
comment = self._run_with_try_closed(TRY_CLOSED_OUTPUT)
self.assertIn("(infra: worker pools are down)", comment)

# Create -> ./mach vendor -> commit -> treestatus is down, so the push hook treats try as closed
@logEntryExitHeaderLine
def testTryTreestatusUnavailable(self):
comment = self._run_with_try_closed(TRY_TREESTATUS_UNAVAILABLE_OUTPUT)
self.assertIn("tree status couldn't be checked", comment)

# Create -> ./mach vendor -> commit -> Fails during try submit
@logEntryExitHeaderLine
def testTryLockedOutput(self):
Expand Down
36 changes: 36 additions & 0 deletions tests/functionality_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,42 @@ def TRY_OUTPUT(revision, include_auto_line=True):
return s


# What hg.mozilla.org's push hook prints when try is closed, and when it can't reach treestatus
TRY_CLOSED_OUTPUT = """
Creating temporary commit for remote...
pushing to ssh://hg.mozilla.org/try
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote:
remote:
remote: ************************** ERROR ****************************
remote: try is CLOSED! Reason: infra: worker pools are down
remote: To push despite the closed tree, include "CLOSED TREE" in your push comment
remote: *************************************************************
remote:
remote:
remote: transaction abort!
remote: rollback completed
temporary commit removed, repository restored
Error running mach:
"""

TRY_TREESTATUS_UNAVAILABLE_OUTPUT = """
Creating temporary commit for remote...
pushing to ssh://hg.mozilla.org/try
remote: ************************** ERROR ****************************
remote: Error accessing https://treestatus.prod.lando.prod.cloudops.mozgcp.net/trees/try :
remote: HTTP Error 502: Bad Gateway
remote: Unable to check if the tree is open - treating as if CLOSED.
remote: To push regardless, include "CLOSED TREE" in your push comment.
remote: *************************************************************
remote: transaction abort!
remote: rollback completed
temporary commit removed, repository restored
Error running mach:
"""

TRY_LOCKED_OUTPUT = """
Creating temporary commit for remote...
A try_task_config.json
Expand Down
Loading