def testSendNotificationForCulprit(self, mock_post, _): repo_name = 'chromium' revision = 'rev1' revert_status = None culprit = WfSuspectedCL.Create(repo_name, revision, 123) culprit.put() culprit_link = culprit.GetCulpritLink() false_positive_bug_link = gerrit.CreateFinditWrongBugLink( gerrit.FINDIT_BUILD_FAILURE_COMPONENT, culprit_link, revision) parameters = SendNotificationForCulpritParameters( cl_key=culprit.key.urlsafe(), force_notify=False, revert_status=revert_status, failure_type=failure_type.COMPILE) self.assertTrue( gerrit.SendNotificationForCulprit(parameters, self.codereview_info)) message = textwrap.dedent(""" Findit (https://goo.gl/kROfz5) %s this CL at revision %s as the culprit for failures in the build cycles as shown on: https://analysis.chromium.org/waterfall/culprit?key=%s If it is a false positive, please report it at %s.""") % ( 'identified', self.culprit_commit_position, culprit.key.urlsafe(), false_positive_bug_link) mock_post.assert_called_once_with(self.review_change_id, message, True)
def testSubmitRevertSucceed(self, mock_fn, mock_commit, mock_add, *_): repo_name = 'chromium' revision = 'rev1' commit_position = 123 cl_info = ClInfo(self.review_server_host, self.review_change_id) cl_info.commits.append( Commit('20001', 'rev1', [], datetime(2017, 2, 1, 0, 0, 0))) mock_fn.return_value = cl_info mock_commit.return_value = True culprit = WfSuspectedCL.Create(repo_name, revision, commit_position) revert_for_culprit = RevertCL() revert_change_id = '54321' revert_for_culprit.revert_cl_url = 'https://%s/q/%s' % ( self.review_server_host, revert_change_id) culprit.revert_cl = revert_for_culprit culprit.revert_status = status.COMPLETED culprit.put() revert_status = services_constants.CREATED_BY_FINDIT commit_status = gerrit.CommitRevert( SubmitRevertCLParameters(cl_key=culprit.key.urlsafe(), revert_status=revert_status), self.codereview_info) self.assertEqual(services_constants.COMMITTED, commit_status) mock_commit.assert_called_once_with(revert_change_id) culprit_link = ( 'https://analysis.chromium.org/waterfall/culprit?key=%s' % (culprit.key.urlsafe())) false_positive_bug_link = gerrit.CreateFinditWrongBugLink( gerrit.FINDIT_BUILD_FAILURE_COMPONENT, culprit_link, revision) message = textwrap.dedent(""" Sheriffs, CL owner or CL reviewers: Please confirm this revert if it is correct. If it is a false positive, please reland the original CL and report this false positive at %s. For more information about Findit auto-revert: %s. Sheriffs, it'll be much appreciated if you could take a couple minutes to fill out this survey: %s.""") % ( false_positive_bug_link, gerrit._MANUAL_LINK, gerrit._SURVEY_LINK) mock_add.assert_called_once_with(revert_change_id, ['*****@*****.**'], message)
def _GenerateMessageText(culprit, bug_id): """Generates the body to notify a culprit with. Args: culprit (FlakeCulprit): The culprit to extract display information from and eventually notify. bug_id (int): An optional bug to include in the notification text. Can be None if not to be included. Returns: message (str): The body of the notification to send. """ false_positive_bug_link = gerrit.CreateFinditWrongBugLink( gerrit.FINDIT_FLAKE_COMPONENT, culprit.GetCulpritLink(), culprit.revision) return _NOTIFICATION_MESSAGE_TEMPLATE.format( culprit_revision=culprit.commit_position or culprit.revision, culprit_link=culprit.GetCulpritLink(), flake_bug_link=_BUG_TEMPLATE.format(bug_id) if bug_id else '', findit_wrong_bug_link=false_positive_bug_link)
def testRevertCLSucceed(self, mock_fn, mock_gerrit, mock_add, *_): repo_name = 'chromium' revision = 'rev1' commit_position = 123 sample_failed_step = 'compile' cl_info = ClInfo(self.review_server_host, self.review_change_id) cl_info.commits.append( Commit('20001', 'rev1', [], datetime(2017, 2, 1, 0, 0, 0))) cl_info.owner_email = '*****@*****.**' mock_fn.return_value = cl_info mock_gerrit.return_value = '54321' culprit = WfSuspectedCL.Create(repo_name, revision, commit_position) culprit.builds = { 'm/b/2': { 'status': None }, 'm/b/1': { 'status': None }, 'm/b/3': { 'status': None }, 'm1/b/0': { 'status': None }, } culprit.put() revert_status, _, _ = gerrit.RevertCulprit(culprit.key.urlsafe(), 'm/b/1', failure_type.COMPILE, sample_failed_step, self.codereview_info) self.assertEquals(revert_status, services_constants.CREATED_BY_FINDIT) reason = textwrap.dedent(""" Findit (https://goo.gl/kROfz5) identified CL at revision %s as the culprit for failures in the build cycles as shown on: https://analysis.chromium.org/waterfall/culprit?key=%s\n Sample Failed Build: %s\n Sample Failed Step: %s""") % (commit_position, culprit.key.urlsafe(), buildbot.CreateBuildUrl( 'm', 'b', '1'), sample_failed_step) mock_gerrit.assert_called_once_with(reason, self.review_change_id, '20001', bug_id=None) culprit_link = ( 'https://analysis.chromium.org/waterfall/culprit?key=%s' % (culprit.key.urlsafe())) false_positive_bug_link = gerrit.CreateFinditWrongBugLink( gerrit.FINDIT_BUILD_FAILURE_COMPONENT, culprit_link, revision) auto_revert_bug_query = urllib.urlencode({ 'status': 'Available', 'components': 'Tools>Test>FindIt>Autorevert', 'summary': 'Auto Revert failed on %s' % revision, 'comment': 'Detail is %s' % culprit_link }) auto_revert_bug_link = ( 'https://bugs.chromium.org/p/chromium/issues/entry?%s') % ( auto_revert_bug_query) message = textwrap.dedent(""" Sheriffs, CL owner or CL reviewers: Please submit this revert if it is correct. If it is a false positive, please abandon and report it at %s. If failed to submit the revert, please abandon it and report the failure at %s. For more information about Findit auto-revert: %s. Sheriffs, it'll be much appreciated if you could take a couple minutes to fill out this survey: %s.""") % ( false_positive_bug_link, auto_revert_bug_link, gerrit._MANUAL_LINK, gerrit._SURVEY_LINK) mock_add.assert_called_once_with('54321', ['*****@*****.**'], message)
def testSubmitRevertFailed(self, mock_fn, mock_commit, mock_add, *_): repo_name = 'chromium' revision = 'rev1' commit_position = 123 cl_info = ClInfo(self.review_server_host, self.review_change_id) cl_info.commits.append( Commit('20001', 'rev1', [], datetime(2017, 2, 1, 0, 0, 0))) mock_fn.return_value = cl_info mock_commit.return_value = False culprit = WfSuspectedCL.Create(repo_name, revision, commit_position) revert_for_culprit = RevertCL() revert_change_id = '54321' revert_for_culprit.revert_cl_url = 'https://%s/q/%s' % ( self.review_server_host, revert_change_id) culprit.revert_cl = revert_for_culprit culprit.revert_status = status.COMPLETED culprit.put() revert_status = services_constants.CREATED_BY_FINDIT commit_status = gerrit.CommitRevert( SubmitRevertCLParameters(cl_key=culprit.key.urlsafe(), revert_status=revert_status), self.codereview_info) self.assertEqual(services_constants.ERROR, commit_status) mock_commit.assert_called_once_with(revert_change_id) culprit_link = ( 'https://analysis.chromium.org/waterfall/culprit?key=%s' % culprit.key.urlsafe()) false_positive_bug_link = gerrit.CreateFinditWrongBugLink( gerrit.FINDIT_BUILD_FAILURE_COMPONENT, culprit_link, revision) auto_revert_bug_query = urllib.urlencode({ 'status': 'Available', 'components': 'Tools>Test>FindIt>Autorevert', 'summary': 'Auto Revert failed on %s' % revision, 'comment': 'Detail is %s' % culprit_link }) auto_revert_bug_link = ( 'https://bugs.chromium.org/p/chromium/issues/entry?%s') % ( auto_revert_bug_query) message = textwrap.dedent(""" Sheriffs, CL owner or CL reviewers: Please submit this revert if it is correct. If it is a false positive, please abandon and report it at %s. If failed to submit the revert, please abandon it and report the failure at %s. For more information about Findit auto-revert: %s. Sheriffs, it'll be much appreciated if you could take a couple minutes to fill out this survey: %s.""") % ( false_positive_bug_link, auto_revert_bug_link, gerrit._MANUAL_LINK, gerrit._SURVEY_LINK) mock_add.assert_called_once_with('54321', ['*****@*****.**'], message)