def testProcessRerunBuildResultBuildPassed(self, mock_compile_failures, mock_analysis): build_id = 8000000000123 build_number = 123 builder = BuilderID(project='chromeos', bucket='postsubmit', builder='findit-variable') build = Build(id=build_id, builder=builder, number=build_number, status=common_pb2.SUCCESS, tags=[{ 'key': 'analyzed_build_id', 'value': str(self.analyzed_build_id) }]) build.input.gitiles_commit.host = 'gitiles.host.com' build.input.gitiles_commit.project = 'project/name' build.input.gitiles_commit.ref = 'ref/heads/master' build.input.gitiles_commit.id = 'git_sha_6543221' build.create_time.FromDatetime(datetime(2019, 4, 9)) step1 = Step(name='s1', status=common_pb2.SUCCESS) step2 = Step(name=self.compile_step_name, status=common_pb2.SUCCESS) build.steps.extend([step1, step2]) CompileRerunBuild.Create(luci_project=self.context.luci_project_name, luci_bucket=build.builder.bucket, luci_builder=build.builder.builder, build_id=build_id, legacy_build_number=build_number, gitiles_host=self.context.gitiles_host, gitiles_project=self.context.gitiles_project, gitiles_ref=self.context.gitiles_ref, gitiles_id='git_sha_6543221', commit_position=6543221, status=build.status, create_time=build.create_time.ToDatetime(), parent_key=self.analysis.key).put() self.assertTrue( compile_analysis.OnCompileRerunBuildCompletion( self.context, build)) self.assertFalse(mock_compile_failures.called) rerun_build = CompileRerunBuild.get_by_id(build_id, parent=self.analysis.key) self.assertEqual({}, rerun_build.GetFailuresInBuild()) self.assertTrue(mock_analysis.called)
def testLuciRerunBuildGetFailedTargets(self): build_id = 1234567890 commit_position = 65432 analysis = self._CreateCompileFailureAnalysis() self._CreateCompileRerunBuild(build_id, commit_position, analysis.key) rerun_build = CompileRerunBuild.get_by_id(build_id, parent=analysis.key) rerun_build.results = [] for target in self.target_entities: result = CompileFailureInRerunBuild( step_ui_name=target.step_ui_name, output_targets=target.output_targets) rerun_build.failures.append(result) result = rerun_build.GetFailuresInBuild() self.assertItemsEqual(['target1.o', 'target2.o'], result['compile'])
def testLuciRerunBuild(self): build_id = 1234567890 commit_position = 65432 analysis = self._CreateCompileFailureAnalysis() self._CreateCompileRerunBuild(build_id, commit_position, analysis.key) rerun_build = CompileRerunBuild.get_by_id(build_id, parent=analysis.key) self.assertIsNotNone(rerun_build) detailed_compile_failures = { 'compile': { 'failures': { frozenset(['target1.o', 'target2.o']): { 'rule': 'CXX', 'first_failed_build': { 'id': 8000000000121, 'number': 121, 'commit_id': 'git_sha' }, 'last_passed_build': { 'id': 8000000000120, 'number': 120, 'commit_id': 'git_sha' }, }, }, 'first_failed_build': { 'id': 8000000000121, 'number': 121, 'commit_id': 'git_sha' }, 'last_passed_build': { 'id': 8000000000120, 'number': 120, 'commit_id': 'git_sha' }, }, } rerun_build.SaveRerunBuildResults(common_pb2.FAILURE, detailed_compile_failures) result = rerun_build.GetFailedTargets() self.assertItemsEqual(['target1.o', 'target2.o'], result['compile'])
def _ProcessAndSaveRerunBuildResult(context, analyzed_build_id, rerun_build): """Gets results of a completed rerun build and save it in datastore. Args: context (findit_v2.services.context.Context): Scope of the analysis. analyzed_build_id (int): Id of the failed ci/post_submit build that's being analyzed. rerun_build (buildbucket build.proto): ALL info about the rerun build. Returns: True if the rerun build entity is updated, otherwise False. """ project_api = projects.GetProjectAPI(context.luci_project_name) analysis = CompileFailureAnalysis.GetVersion(analyzed_build_id) if not analysis: logging.error('CompileFailureAnalysis missing for %d.', analyzed_build_id) return False rerun_build_entity = CompileRerunBuild.get_by_id(rerun_build.id, parent=analysis.key) if not rerun_build_entity: logging.error('CompileRerunBuild entity for build %d missing.', rerun_build.id) return False detailed_compile_failures = {} if rerun_build.status == common_pb2.FAILURE: failed_steps = build_util.GetFailedStepsInBuild(context, rerun_build) compile_steps = [ fs[0] for fs in failed_steps if fs[1] == StepTypeEnum.COMPILE ] detailed_compile_failures = project_api.GetCompileFailures( rerun_build, compile_steps) if compile_steps else {} _SaveRerunBuildResults(rerun_build_entity, rerun_build.status, detailed_compile_failures, rerun_build.end_time.ToDatetime()) rerun_build_entity.put() return True
def testTriggerRerunBuild(self, mock_trigger_build, _): new_build_id = 800000024324 new_build = Build(id=new_build_id, number=300) new_build.status = common_pb2.SCHEDULED new_build.create_time.FromDatetime(datetime(2019, 4, 20)) rerun_builder = BuilderID(project='chromium', bucket='findit', builder='findit-variables') rerun_commit = GitilesCommit( gitiles_host=self.context.gitiles_host, gitiles_project=self.context.gitiles_project, gitiles_ref=self.context.gitiles_ref, gitiles_id='6000002', commit_position=6000002) output_targets = {'compile': ['a.o']} mock_trigger_build.return_value = new_build compile_failure_rerun_analysis.TriggerRerunBuild( self.context, self.build_id, self.build, self.analysis.key, rerun_builder, rerun_commit, output_targets) rerun_build = CompileRerunBuild.get_by_id(new_build_id, parent=self.analysis.key) self.assertIsNotNone(rerun_build) mock_trigger_build.assert_called_once_with( rerun_builder, common_pb2.GitilesCommit(project=rerun_commit.gitiles_project, host=rerun_commit.gitiles_host, ref=rerun_commit.gitiles_ref, id=rerun_commit.gitiles_id), {'recipe': 'compile'}, tags=[{ 'value': 'compile-failure-culprit-finding', 'key': 'purpose' }, { 'value': str(self.build.id), 'key': 'analyzed_build_id' }])
def testProcessRerunBuildResult(self, mock_compile_failures): build_id = 8000000000123 build_number = 123 builder = BuilderID(project='chromeos', bucket='postsubmit', builder='findit-variable') build = Build(id=build_id, builder=builder, number=build_number, status=common_pb2.FAILURE, tags=[{ 'key': 'analyzed_build_id', 'value': str(self.analyzed_build_id) }]) build.input.gitiles_commit.host = 'gitiles.host.com' build.input.gitiles_commit.project = 'project/name' build.input.gitiles_commit.ref = 'ref/heads/master' build.input.gitiles_commit.id = 'git_sha_6543221' build.create_time.FromDatetime(datetime(2019, 4, 9)) step1 = Step(name='s1', status=common_pb2.SUCCESS) step2 = Step(name=self.compile_step_name, status=common_pb2.FAILURE) build.steps.extend([step1, step2]) output_target = json.dumps({ 'category': 'chromeos-base', 'packageName': 'target2' }) build.output.properties['build_compile_failure_output'] = { 'failures': [ { 'output_targets': [output_target], 'rule': 'emerge' }, ], 'failed_step': self.compile_step_name } mock_compile_failures.return_value = { self.compile_step_name: { 'failures': { frozenset(['target1.o', 'target2.o']): { 'rule': 'CXX', 'first_failed_build': { 'id': build_id, 'number': build_number, 'commit_id': 'git_sha_6543221' }, 'last_passed_build': None }, }, 'first_failed_build': { 'id': build_id, 'number': build_number, 'commit_id': 'git_sha_6543221' }, 'last_passed_build': None }, } CompileRerunBuild.Create(luci_project=self.context.luci_project_name, luci_bucket=build.builder.bucket, luci_builder=build.builder.builder, build_id=build_id, legacy_build_number=build_number, gitiles_host=self.context.gitiles_host, gitiles_project=self.context.gitiles_project, gitiles_ref=self.context.gitiles_ref, gitiles_id='git_sha_6543221', commit_position=6543221, status=build.status, create_time=build.create_time.ToDatetime(), parent_key=self.analysis.key).put() self.assertTrue( compile_api._ProcessAndSaveRerunBuildResult( self.context, self.analyzed_build_id, build)) rerun_build = CompileRerunBuild.get_by_id(build_id, parent=self.analysis.key) self.assertItemsEqual( ['target1.o', 'target2.o'], rerun_build.GetFailedTargets()[self.compile_step_name])