def testAddedReviewerFailedBefore(self, mock_fn, mock_send, *_): repo_name = 'chromium' revision = 'rev1' 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 = '*****@*****.**' revert_cl = ClInfo('revert_review_host', '123V3127') revert_cl.url = 'https://chromium-review.googlesource.com/54321' cl_info.reverts.append( Revert('20001', revert_cl, constants.DEFAULT_SERVICE_ACCOUNT, datetime(2017, 2, 1, 1, 0, 0))) mock_fn.return_value = cl_info culprit = WfSuspectedCL.Create(repo_name, revision, 123) culprit.revert_cl = RevertCL() culprit.revert_status = status.RUNNING culprit.cr_notification_status = status.COMPLETED culprit.put() revert_status, _, _ = gerrit.RevertCulprit(culprit.key.urlsafe(), 'm/b/1', failure_type.COMPILE, 'compile', self.codereview_info) self.assertEquals(revert_status, services_constants.CREATED_BY_FINDIT)
def testAutoRevertOff(self, mock_fn, _): repo_name = 'chromium' revision = 'rev1' cl_info = ClInfo(self.review_server_host, self.review_change_id) cl_info.auto_revert_off = True cl_info.commits.append( Commit('20001', 'rev1', [], datetime(2017, 2, 1, 0, 0, 0))) mock_fn.return_value = cl_info culprit = WfSuspectedCL.Create(repo_name, revision, 123) culprit.put() revert_status, revert, reason = gerrit.RevertCulprit( culprit.key.urlsafe(), 'm/b/1', failure_type.COMPILE, 'compile', self.codereview_info) self.assertEquals(services_constants.SKIPPED, revert_status) self.assertEquals(services_constants.AUTO_REVERT_OFF, reason) self.assertIsNone(revert)
def RevertCulprit(parameters, analysis_id): culprit = entity_util.GetEntityFromUrlsafeKey(parameters.cl_key) assert culprit repo_name = culprit.repo_name revision = culprit.revision build_key = parameters.build_key if _CanCreateRevertForCulprit(parameters, analysis_id): codereview_info = GetCodeReviewDataForACulprit(parameters.cl_key) revert_status, revert_cl, skip_reason = gerrit.RevertCulprit( parameters.cl_key, build_key, parameters.failure_type, GetSampleFailedStepName(repo_name, revision, build_key), codereview_info) _UpdateCulprit(parameters.cl_key, revert_status=constants. AUTO_REVERT_STATUS_TO_ANALYSIS_STATUS[revert_status], revert_cl=revert_cl, skip_revert_reason=skip_reason) return revert_status return constants.SKIPPED
def testSheriffRevertedIt(self, mock_fn, _): repo_name = 'chromium' revision = 'rev1' 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 = '*****@*****.**' revert_cl = ClInfo('revert_review_host', '123V3137') cl_info.reverts.append( Revert('20001', revert_cl, 'a@b', datetime(2017, 2, 1, 1, 0, 0))) mock_fn.return_value = cl_info suspect_cl = WfSuspectedCL.Create(repo_name, revision, 123) suspect_cl.put() revert_status, revert, reason = gerrit.RevertCulprit( suspect_cl.key.urlsafe(), 'm/b/1', failure_type.COMPILE, 'compile', self.codereview_info) self.assertIsNone(revert) self.assertEqual(services_constants.REVERTED_BY_SHERIFF, reason) self.assertEquals(revert_status, services_constants.CREATED_BY_SHERIFF)
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)