def OnBuildFailureAnalysisResultRequested(request): """Returns the findings of an analysis for a failed build. Since Findit v2 only supports compile failure on cros builds, this api will simply respond an empty response on other failures. This is to prevent Findit spending too many pixels to tell users many failures are not supported. Args: request(findit_result.BuildFailureAnalysisRequest): request for a build failure. Returns: (findit_result.BuildFailureAnalysisResponseCollection): Analysis results for the requested build. """ build_id = request.build_id build_alternative_id = request.build_alternative_id if build_id: build_entity = LuciFailedBuild.get_by_id(build_id) if not build_entity: logging.debug('No LuciFailedBuild entity for build %d.', request.build_id) return [] else: build_entity = LuciFailedBuild.GetBuildByNumber( build_alternative_id.project, build_alternative_id.bucket, build_alternative_id.builder, build_alternative_id.number) if not build_entity: logging.debug('No LuciFailedBuild entity for build %s/%s/%s/%d.', build_alternative_id.project, build_alternative_id.bucket, build_alternative_id.builder, build_alternative_id.number) return [] if build_entity.build_failure_type == StepTypeEnum.COMPILE: return compile_analysis.OnCompileFailureAnalysisResultRequested( request, build_entity) if build_entity.build_failure_type == StepTypeEnum.TEST: return test_analysis.OnTestFailureAnalysisResultRequested( request, build_entity) logging.debug( 'Findit v2 only supports compile or test failure analysis, ' 'so no results for %d with %s failures.', build_id, build_entity.build_failure_type) return []
def testCreateLuciFailedBuildForCompileFailure(self): build_id = 87654321 commit_position = 65432 legacy_build_number = 12345 build = LuciFailedBuild.Create( luci_project='chromium', luci_bucket='ci', luci_builder='Linux Builder', build_id=build_id, legacy_build_number=legacy_build_number, gitiles_host='chromium.googlesource.com', gitiles_project='chromium/src', gitiles_ref='refs/heads/master', gitiles_id='git_hash', commit_position=commit_position, status=20, create_time=datetime(2019, 3, 28), start_time=datetime(2019, 3, 28, 0, 1), end_time=datetime(2019, 3, 28, 1), build_failure_type=StepTypeEnum.COMPILE) build.put() # Get entity by build_id. build = LuciFailedBuild.get_by_id(build_id) self.assertIsNotNone(build) self.assertEqual(StepTypeEnum.COMPILE, build.build_failure_type) self.assertEqual(commit_position, build.gitiles_commit.commit_position) self.assertEqual('chromium/ci', build.bucket_id) self.assertEqual('chromium/ci/Linux Builder', build.builder_id) # Get entity by build number. res1 = LuciFailedBuild.GetBuildByNumber('chromium', 'ci', 'Linux Builder', legacy_build_number) self.assertEqual(build_id, res1.build_id) # Get entity by commit_position. res2 = LuciFailedBuild.query( ndb.AND( LuciFailedBuild.builder_id == 'chromium/ci/Linux Builder', LuciFailedBuild.gitiles_commit.commit_position == commit_position)).fetch() self.assertEqual(1, len(res2)) self.assertEqual(build_id, res2[0].build_id)