def testLatestBuildSucceeded(self, mock_fn, *_): repo_name = 'chromium' revision = 'rev1' cl_info = ClInfo(self.review_server_host, self.review_change_id) cl_info.owner_email = '*****@*****.**' cl_info.commits.append( Commit('20001', 'rev1', datetime(2017, 2, 1, 0, 0, 0))) revert_cl = ClInfo('revert_review_host', '123V3127') revert_cl.url = 'https://codereview.chromium.org/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.put() pipeline = CreateRevertCLPipeline('m', 'b', 123, repo_name, revision) revert_status = pipeline.run('m', 'b', 123, repo_name, revision) self.assertEquals(revert_status, create_revert_cl_pipeline.SKIPPED) culprit = WfSuspectedCL.Get(repo_name, revision) self.assertEqual(culprit.revert_status, status.SKIPPED) self.assertIsNotNone(culprit.revert_cl) self.assertEqual(culprit.skip_revert_reason, create_revert_cl_pipeline.NEWEST_BUILD_GREEN)
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 testRevertCLNotSaved(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', '123V3127') revert_cl.url = 'https://codereview.chromium.org/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 WfSuspectedCL.Create(repo_name, revision, 123).put() pipeline = CreateRevertCLPipeline('m', 'b', 123, repo_name, revision) revert_status = pipeline.run('m', 'b', 123, repo_name, revision) self.assertEquals(revert_status, create_revert_cl_pipeline.CREATED_BY_FINDIT) culprit = WfSuspectedCL.Get(repo_name, revision) self.assertEqual(culprit.revert_status, status.COMPLETED) self.assertIsNotNone(culprit.revert_cl)
def testRevertCLSucceed(self, mock_fn, mock_revert, *_): repo_name = 'chromium' revision = 'rev1' commit_position = 123 build_key = 'm/b/123' cl_info = ClInfo(self.review_server_host, self.review_change_id) cl_info.commits.append( Commit('20001', 'rev1', ['rev0'], datetime(2017, 2, 1, 0, 0, 0))) cl_info.owner_email = '*****@*****.**' mock_fn.return_value = cl_info mock_revert.return_value = '54321' culprit = WfSuspectedCL.Create(repo_name, revision, commit_position) culprit.builds = { build_key: { 'status': None, 'failures': { 'step': ['test1'] } } } culprit.put() pipeline_input = CreateRevertCLParameters( cl_key=culprit.key.urlsafe(), build_key=build_key, failure_type=failure_type.COMPILE) pipeline = CreateRevertCLPipeline(pipeline_input) revert_status = pipeline.run(pipeline_input) self.assertEquals(revert_status, constants.CREATED_BY_FINDIT) culprit = WfSuspectedCL.Get(repo_name, revision) self.assertEqual(culprit.revert_status, status.COMPLETED) self.assertIsNotNone(culprit.revert_cl) 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', '123'), 'step') mock_revert.assert_called_with(reason, self.review_change_id, '20001', bug_id=None)
def testRevertCLSucceed(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 = '*****@*****.**' mock_fn.return_value = cl_info WfSuspectedCL.Create(repo_name, revision, 123).put() pipeline = CreateRevertCLPipeline('m', 'b', 123, repo_name, revision) revert_status = pipeline.run('m', 'b', 123, repo_name, revision) self.assertEquals(revert_status, create_revert_cl_pipeline.CREATED_BY_FINDIT) culprit = WfSuspectedCL.Get(repo_name, revision) self.assertEqual(culprit.revert_status, status.COMPLETED) self.assertIsNotNone(culprit.revert_cl)
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 testCulpritCreatedByFindit(self, mock_fn, _): repo_name = 'chromium' revision = 'rev1' cl_info = ClInfo(self.review_server_host, self.review_change_id) cl_info.owner_email = constants.DEFAULT_SERVICE_ACCOUNT 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() pipeline = CreateRevertCLPipeline('m', 'b', 123, repo_name, revision) revert_status = pipeline.run('m', 'b', 123, repo_name, revision) self.assertEquals(revert_status, create_revert_cl_pipeline.SKIPPED) culprit = WfSuspectedCL.Get(repo_name, revision) self.assertEqual(culprit.revert_status, status.SKIPPED) self.assertIsNone(culprit.revert_cl) self.assertEqual(culprit.skip_revert_reason, create_revert_cl_pipeline.CULPRIT_OWNED_BY_FINDIT)
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)