コード例 #1
0
    def _DownloadBuildData(self, master_name, builder_name, build_number):
        """Downloads build data and returns a WfBuild instance."""
        build = WfBuild.Get(master_name, builder_name, build_number)
        if not build:
            build = WfBuild.Create(master_name, builder_name, build_number)

        # Cache the data to avoid pulling from master again.
        if self._BuildDataNeedUpdating(build):
            # Retrieve build data from build archive first.
            build.data = buildbot.GetBuildDataFromArchive(
                build.master_name, build.builder_name, build.build_number,
                self.HTTP_CLIENT_NO_404_ERROR)

            if build.data is None:
                if not lock_util.WaitUntilDownloadAllowed(
                        master_name):  # pragma: no cover
                    raise pipeline.Retry('Too many download from %s' %
                                         master_name)

                # Retrieve build data from build master.
                build.data = buildbot.GetBuildDataFromBuildMaster(
                    build.master_name, build.builder_name, build.build_number,
                    self.HTTP_CLIENT_LOGGING_ERRORS)

            build.last_crawled_time = datetime.utcnow()
            build.put()

        return build
コード例 #2
0
def DownloadBuildData(master_name, builder_name, build_number):
    """Downloads build data and returns a WfBuild instance."""
    build = WfBuild.Get(master_name, builder_name, build_number)
    if not build:
        build = WfBuild.Create(master_name, builder_name, build_number)

    # Cache the data to avoid pulling from master again.
    if _BuildDataNeedUpdating(build):
        use_cbe = waterfall_config.GetDownloadBuildDataSettings().get(
            'use_chrome_build_extract')

        if use_cbe:
            # Retrieve build data from build archive first.
            build.data = buildbot.GetBuildDataFromArchive(
                master_name, builder_name, build_number,
                HTTP_CLIENT_NO_404_ERROR)

            if build.data:
                build.data_source = CHROME_BUILD_EXTRACT
            elif not lock_util.WaitUntilDownloadAllowed(
                    master_name):  # pragma: no cover
                return None

        if not build.data or not use_cbe:
            # Retrieve build data from build master.
            build.data = buildbot.GetBuildDataFromBuildMaster(
                master_name, builder_name, build_number,
                HTTP_CLIENT_LOGGING_ERRORS)
            build.data_source = BUILDBOT_MASTER

        build.last_crawled_time = time_util.GetUTCNow()
        build.put()

    return build
コード例 #3
0
    def testTriggerTryJob(self, mock_module):
        master_name = 'm'
        builder_name = 'b'
        build_number = 1
        build = WfBuild.Create(master_name, builder_name, build_number)
        build.data = {
            'properties': {
                'parent_mastername': 'pm',
                'parent_buildername': 'pb'
            }
        }
        build.put()
        response = {
            'build': {
                'id': '1',
                'url': 'url',
                'status': 'SCHEDULED',
            }
        }
        results = [(None,
                    buildbucket_client.BuildbucketBuild(response['build']))]
        mock_module.TriggerTryJobs.return_value = results

        build_id = ScheduleFlakeTryJobPipeline()._TriggerTryJob(
            master_name, builder_name, {}, [],
            failure_type.GetDescriptionForFailureType(failure_type.FLAKY_TEST),
            None, None)

        self.assertEqual(build_id, '1')
コード例 #4
0
    def testBailOutForTryJobWithOutdatedTimestamp(self, mock_fn):
        master_name = 'master1'
        builder_name = 'builder1'
        build_number = 223
        WfAnalysis.Create(master_name, builder_name, build_number).put()
        failure_info = {
            'master_name': master_name,
            'builder_name': builder_name,
            'build_number': build_number,
            'failed_steps': {
                'compile': {
                    'current_failure': 221,
                    'first_failure': 221,
                    'last_pass': 220
                }
            },
            'failure_type': failure_type.COMPILE
        }

        yesterday = datetime.utcnow() - timedelta(days=1)
        build = WfBuild.Create(master_name, builder_name, build_number)
        build.start_time = yesterday
        build.put()

        mock_fn.return_value = True

        need_try_job, try_job_key = try_job_util.NeedANewWaterfallTryJob(
            master_name, builder_name, build_number, failure_info, None, None)

        self.assertFalse(need_try_job)
        self.assertIsNone(try_job_key)
コード例 #5
0
    def testShouldBailOutforOutdatedBuild(self):
        yesterday = datetime.utcnow() - timedelta(days=1)
        build = WfBuild.Create('m', 'b', 1)
        build.start_time = yesterday
        self.assertTrue(try_job_util._ShouldBailOutForOutdatedBuild(build))

        build.start_time = yesterday + timedelta(hours=1)
        self.assertFalse(try_job_util._ShouldBailOutForOutdatedBuild(build))
コード例 #6
0
 def _MockDownloadBuildData(self, master_name, builder_name, build_number):
     build = WfBuild.Get(master_name, builder_name, build_number)
     if not build:  # pragma: no cover
         build = WfBuild.Create(master_name, builder_name, build_number)
     build.data = self._GetBuildInfo(master_name, builder_name,
                                     build_number)
     build.put()
     return build
コード例 #7
0
 def testLegacyGetStepMetadataFromLUCIBuild(self, mock_build, _):
     build = WfBuild.Create('m', 'b', 123)
     build.build_id = '8948240770002521488'
     build.put()
     mock_build.return_value = build
     step_metadata = step_util.GetWaterfallBuildStepLog(
         'm', 'b', 123, 's', None, 'step_metadata')
     self.assertEqual(step_metadata, wf_testcase.SAMPLE_STEP_METADATA)
コード例 #8
0
    def testLookBackUntilGreenBuild(self):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123

        self._CreateAndSaveWfAnanlysis(master_name, builder_name, build_number,
                                       wf_analysis_status.ANALYZING)

        # Setup build data for builds:
        # 123: mock urlfetch to ensure it is fetched.
        self._MockUrlfetchWithBuildData(master_name, builder_name, 123)
        # 122: mock a build in datastore to ensure it is not fetched again.
        build = WfBuild.Create(master_name, builder_name, 122)
        build.data = self._GetBuildData(master_name, builder_name, 122)
        build.completed = True
        build.put()
        self._MockUrlfetchWithBuildData(master_name,
                                        builder_name,
                                        122,
                                        build_data='Blow up if used!')
        # 121: mock a build in datastore to ensure it is updated.
        build = WfBuild.Create(master_name, builder_name, 121)
        build.data = 'Blow up if used!'
        build.last_crawled_time = self._TimeBeforeNowBySeconds(7200)
        build.completed = False
        build.put()
        self._MockUrlfetchWithBuildData(master_name, builder_name, 121)

        pipeline = DetectFirstFailurePipeline()
        failure_info = pipeline.run(master_name, builder_name, build_number)

        expected_failed_steps = {
            'net_unittests': {
                'last_pass': 122,
                'current_failure': 123,
                'first_failure': 123
            },
            'unit_tests': {
                'last_pass': 121,
                'current_failure': 123,
                'first_failure': 122
            }
        }

        self.assertEqual(expected_failed_steps, failure_info['failed_steps'])
コード例 #9
0
ファイル: ci_failure_test.py プロジェクト: xinghun61/infra
  def testGetBuildFailureInfo(self, mock_build, *_):
    master_name = 'm'
    builder_name = 'b'
    build_number = 223

    self._CreateAndSaveWfAnanlysis(master_name, builder_name, build_number,
                                   analysis_status.PENDING)

    build = WfBuild.Create(master_name, builder_name, build_number)
    build.build_id = '80000000223'
    build.completed = True
    build.put()

    build_223 = Build(
        id=80000000223, number=build_number, status=common_pb2.FAILURE)
    build_223.input.gitiles_commit.id = 'rev223'
    step1 = Step(name='compile', status=common_pb2.SUCCESS)
    log = step1.logs.add()
    log.name = 'stdout'
    step2 = Step(name='abc_test', status=common_pb2.FAILURE)
    log = step2.logs.add()
    log.name = 'stdout'
    build_223.steps.extend([step1, step2])
    mock_build.return_value = build_223

    failure_info, should_proceed = ci_failure.GetBuildFailureInfo(
        master_name, builder_name, build_number)

    expected_failure_info = {
        'failed': True,
        'master_name': master_name,
        'builder_name': builder_name,
        'build_number': build_number,
        'is_luci': None,
        'buildbucket_bucket': '',
        'buildbucket_id': '80000000223',
        'chromium_revision': 'rev223',
        'builds': {
            build_number: {
                'blame_list': ['rev223'],
                'chromium_revision': 'rev223'
            }
        },
        'failed_steps': {
            'abc_test': {
                'current_failure': build_number,
                'first_failure': build_number,
                'supported': True
            }
        },
        'failure_type': failure_type.TEST,
        'parent_mastername': None,
        'parent_buildername': None,
    }

    self.assertEqual(expected_failure_info, failure_info)
    self.assertTrue(should_proceed)
コード例 #10
0
    def testGetBuildInfo(self, mocked_fn):
        build = WfBuild.Create('m', 'b', 123)
        build.data = json.dumps({
            'properties': [['got_revision', 'a_git_hash'],
                           ['got_revision_cp', 'refs/heads/master@{#12345}']],
        })
        mocked_fn.return_value = build

        build_info = build_util.GetBuildInfo('m', 'b', 123)
        self.assertEqual(build_info.chromium_revision, 'a_git_hash')
コード例 #11
0
    def testGetBuildInfoBuildNotAvailable(self, mocked_fn):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123
        build = WfBuild.Create(master_name, builder_name, build_number)
        build.data = {}
        mocked_fn.return_value = build

        self.assertIsNone(
            build_util.GetBuildInfo(master_name, builder_name, build_number))
コード例 #12
0
ファイル: ci_failure_test.py プロジェクト: xinghun61/infra
  def testGetBuildFailureInfoBuildSuccess(self, mock_monitoring, mock_build,
                                          *_):
    master_name = 'm'
    builder_name = 'b'
    build_number = 121

    self._CreateAndSaveWfAnanlysis(master_name, builder_name, build_number,
                                   analysis_status.PENDING)

    build = WfBuild.Create(master_name, builder_name, build_number)
    build.build_id = '80000000223'
    build.completed = True
    build.put()

    build_121 = Build(
        id=80000000121, number=build_number, status=common_pb2.FAILURE)
    build_121.input.gitiles_commit.id = 'rev121'
    step1 = Step(name='net_unittests', status=common_pb2.SUCCESS)
    log = step1.logs.add()
    log.name = 'stdout'
    step2 = Step(name='unit_tests', status=common_pb2.SUCCESS)
    log = step2.logs.add()
    log.name = 'stdout'
    build_121.steps.extend([step1, step2])
    mock_build.return_value = build_121

    failure_info, should_proceed = ci_failure.GetBuildFailureInfo(
        master_name, builder_name, build_number)

    expected_failure_info = {
        'failed': False,
        'master_name': master_name,
        'builder_name': builder_name,
        'build_number': build_number,
        'chromium_revision': 'rev121',
        'builds': {},
        'failed_steps': {},
        'failure_type': failure_type.UNKNOWN,
        'parent_mastername': None,
        'parent_buildername': None,
        'is_luci': None,
        'buildbucket_bucket': '',
        'buildbucket_id': '80000000121',
    }

    self.assertEqual(expected_failure_info, failure_info)
    self.assertFalse(should_proceed)
    mock_monitoring.assert_called_once_with(
        master_name='m',
        builder_name='b',
        failure_type='unknown',
        canonical_step_name='unknown',
        isolate_target_name='unknown',
        status='Completed',
        analysis_type='Pre-Analysis')
コード例 #13
0
    def testBuildDataNeedUpdating(self):
        build = WfBuild.Create('m', 'b', 1)

        # Build data is not available.
        self.assertTrue(build_util._BuildDataNeedUpdating(build))

        # Build was not completed and data is not recent.
        build.data = 'dummy'
        build.completed = False
        build.last_crawled_time = self._TimeBeforeNowBySeconds(360)
        self.assertTrue(build_util._BuildDataNeedUpdating(build))
コード例 #14
0
    def testSuccessfullyScheduleNewTryJobForCompileWithSuspectedRevisions(
            self, mock_module):
        master_name = 'm'
        builder_name = 'b'
        build_number = 223
        good_revision = 'rev1'
        bad_revision = 'rev2'
        build_id = '1'
        url = 'url'
        build = WfBuild.Create(master_name, builder_name, build_number)
        build.data = {
            'properties': {
                'parent_mastername': 'pm',
                'parent_buildername': 'pb'
            }
        }
        build.put()

        response = {
            'build': {
                'id': build_id,
                'url': url,
                'status': 'SCHEDULED',
            }
        }
        results = [(None,
                    buildbucket_client.BuildbucketBuild(response['build']))]
        mock_module.TriggerTryJobs.return_value = results

        WfTryJob.Create(master_name, builder_name, build_number).put()

        try_job_pipeline = ScheduleCompileTryJobPipeline()
        try_job_id = try_job_pipeline.run(master_name, builder_name,
                                          build_number, good_revision,
                                          bad_revision, failure_type.COMPILE,
                                          None, ['r5'], None, None)

        try_job = WfTryJob.Get(master_name, builder_name, build_number)
        try_job_data = WfTryJobData.Get(build_id)

        expected_try_job_id = '1'
        self.assertEqual(expected_try_job_id, try_job_id)
        self.assertEqual(expected_try_job_id,
                         try_job.compile_results[-1]['try_job_id'])
        self.assertTrue(expected_try_job_id in try_job.try_job_ids)
        self.assertIsNotNone(try_job_data)
        self.assertEqual(try_job_data.master_name, master_name)
        self.assertEqual(try_job_data.builder_name, builder_name)
        self.assertEqual(try_job_data.build_number, build_number)
        self.assertEqual(
            try_job_data.try_job_type,
            failure_type.GetDescriptionForFailureType(failure_type.COMPILE))
        self.assertFalse(try_job_data.has_compile_targets)
        self.assertTrue(try_job_data.has_heuristic_results)
コード例 #15
0
    def testGetBuildInfo(self, mocked_fn, mock_build_info, _):
        build = WfBuild.Create('m', 'b', 123)
        build.build_id = '8000000123'
        mocked_fn.return_value = build

        expected_build_info = BuildInfo('m', 'b', 123)
        expected_build_info.chromium_revision = 'a_git_hash'
        mock_build_info.return_value = expected_build_info

        build_info = build_util.GetBuildInfo('m', 'b', 123)
        self.assertEqual(build_info.chromium_revision, 'a_git_hash')
コード例 #16
0
    def testDownloadBuildDataSourceFromBM(self, _):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123
        build = WfBuild.Create(master_name, builder_name, build_number)
        build.put()

        self.UpdateUnitTestConfigSettings('download_build_data_settings',
                                          {'use_chrome_build_extract': False})

        build_util.DownloadBuildData(master_name, builder_name, build_number)

        self.assertEqual(build.data_source, build_util.BUILDBOT_MASTER)
コード例 #17
0
    def testHelpTriageHandlerReturnNoneForGreenBuild(self):
        build_url = buildbot.CreateBuildUrl(self.master_name,
                                            self.builder_name, 123)
        build = WfBuild.Create(self.master_name, self.builder_name, 123)
        build.data = self._GetBuildInfo(self.master_name, self.builder_name,
                                        123)
        build.put()

        response = self.test_app.get('/help-triage', params={'url': build_url})
        expected_results = {}

        self.assertEqual(200, response.status_int)
        self.assertEqual(expected_results, response.json_body)
コード例 #18
0
    def testBuildDataNotNeedUpdating(self):
        build = WfBuild.Create('m', 'b', 1)

        # Build is not completed yet but data is recent.
        build.data = 'dummy'
        build.completed = False
        build.last_crawled_time = self._TimeBeforeNowBySeconds(60)
        self.assertFalse(build_util._BuildDataNeedUpdating(build))

        # Build was completed and data is final.
        build.data = 'dummy'
        build.completed = True
        build.last_crawled_time = self._TimeBeforeNowBySeconds(360)
        self.assertFalse(build_util._BuildDataNeedUpdating(build))
コード例 #19
0
    def testGetBuildDataNotDownloadAgain(self):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123
        build = WfBuild.Create(master_name, builder_name, build_number)

        build.data = 'dummy'
        build.completed = False
        build.last_crawled_time = self._TimeBeforeNowBySeconds(60)
        build.put()

        build_util.DownloadBuildData(master_name, builder_name, build_number)

        expected_build_data = 'dummy'

        self.assertEqual(expected_build_data, build.data)
コード例 #20
0
    def testDownloadBuildDataSourceFromBMUpateBuildData(self, _):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123
        build = WfBuild.Create(master_name, builder_name, build_number)
        build.data = 'Original build data'
        build.last_crawled_time = self._TimeBeforeNowBySeconds(360)
        build.put()

        self.UpdateUnitTestConfigSettings('download_build_data_settings',
                                          {'use_chrome_build_extract': False})

        build_util.DownloadBuildData(master_name, builder_name, build_number)

        self.assertEqual(build.data_source, build_util.BUILDBOT_MASTER)
        self.assertEqual(build.data, 'Test get build data from build master')
コード例 #21
0
    def testScheduleFlakeTryJob(self, mock_module):
        master_name = 'm'
        builder_name = 'b'
        build_number = 1
        step_name = 's'
        test_name = 't'
        git_hash = 'a1b2c3d4'
        build_id = '1'
        url = 'url'
        analysis_key = ndb.Key('key', 1)
        build = WfBuild.Create(master_name, builder_name, build_number)
        build.data = {
            'properties': {
                'parent_mastername': 'pm',
                'parent_buildername': 'pb'
            }
        }
        build.put()
        response = {
            'build': {
                'id': build_id,
                'url': url,
                'status': 'SCHEDULED',
            }
        }
        results = [(None,
                    buildbucket_client.BuildbucketBuild(response['build']))]
        mock_module.TriggerTryJobs.return_value = results

        FlakeTryJob.Create(master_name, builder_name, step_name, test_name,
                           git_hash).put()

        try_job_pipeline = ScheduleFlakeTryJobPipeline()
        try_job_id = try_job_pipeline.run(master_name, builder_name, step_name,
                                          test_name, git_hash,
                                          analysis_key.urlsafe(), None, None)

        try_job = FlakeTryJob.Get(master_name, builder_name, step_name,
                                  test_name, git_hash)
        try_job_data = FlakeTryJobData.Get(build_id)

        self.assertEqual(build_id, try_job_id)
        self.assertEqual(build_id, try_job.flake_results[-1]['try_job_id'])
        self.assertTrue(build_id in try_job.try_job_ids)
        self.assertEqual(try_job_data.try_job_key, try_job.key)
        self.assertEqual(analysis_key, try_job_data.analysis_key)
コード例 #22
0
ファイル: build_util.py プロジェクト: xinghun61/infra
def DownloadBuildData(master_name, builder_name, build_number):
    """Downloads build data and returns a WfBuild instance."""
    build = WfBuild.Get(master_name, builder_name, build_number)
    if not build:
        build = WfBuild.Create(master_name, builder_name, build_number)

    if build.build_id:
        return build

    luci_project, luci_bucket = buildbot.GetLuciProjectAndBucketForMaster(
        master_name)
    bb_build = buildbucket_client.GetV2BuildByBuilderAndBuildNumber(
        luci_project, luci_bucket, builder_name, build_number)
    build.last_crawled_time = time_util.GetUTCNow()
    build.build_id = str(bb_build.id)
    build.put()
    return build
コード例 #23
0
    def testDownloadBuildDataSourceFromCBE(self):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123
        build = WfBuild.Create(master_name, builder_name, build_number)
        build.put()

        self.UpdateUnitTestConfigSettings('download_build_data_settings',
                                          {'use_chrome_build_extract': True})
        self._MockUrlfetchWithBuildDataFromArchive(
            master_name,
            builder_name,
            build_number,
            build_data='Test get build data')

        build_util.DownloadBuildData(master_name, builder_name, build_number)

        self.assertEqual(build.data_source, build_util.CHROME_BUILD_EXTRACT)
コード例 #24
0
    def testGetBuildDataFromArchive(self):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123

        build = WfBuild.Create(master_name, builder_name, build_number)
        build.put()
        self._MockUrlfetchWithBuildDataFromArchive(
            master_name,
            builder_name,
            build_number,
            build_data='Test get build data')

        build_util.DownloadBuildData(master_name, builder_name, build_number)

        expected_build_data = 'Test get build data from archive'

        self.assertEqual(expected_build_data, build.data)
コード例 #25
0
  def testSuccessfullyScheduleNewTryJobForTest(self, mock_module):
    master_name = 'm'
    builder_name = 'b'
    build_number = 223
    good_revision = 'rev1'
    bad_revision = 'rev2'
    targeted_tests = ['a on platform', ['a', ['test1', 'test2']]]
    build_id = '1'
    build = WfBuild.Create(master_name, builder_name, build_number)
    build.data = {'properties': {'parent_mastername': 'pm',
                                 'parent_buildername': 'pb'}}
    build.put()

    response = {
        'build': {
            'id': build_id,
            'url': 'url',
            'status': 'SCHEDULED',
        }
    }
    results = [(None, buildbucket_client.BuildbucketBuild(response['build']))]
    mock_module.TriggerTryJobs.return_value = results

    WfTryJob.Create(master_name, builder_name, build_number).put()

    try_job_pipeline = ScheduleTestTryJobPipeline()
    try_job_id = try_job_pipeline.run(
        master_name, builder_name, build_number, good_revision, bad_revision,
        failure_type.TEST, None, None, None, targeted_tests)

    try_job = WfTryJob.Get(master_name, builder_name, build_number)
    self.assertEqual(try_job_id, build_id)
    self.assertEqual(try_job.test_results[-1]['try_job_id'], build_id)

    try_job_data = WfTryJobData.Get(try_job_id)
    self.assertIsNotNone(try_job_data)
    self.assertEqual(try_job_data.master_name, master_name)
    self.assertEqual(try_job_data.builder_name, builder_name)
    self.assertEqual(try_job_data.build_number, build_number)
    self.assertEqual(
        try_job_data.try_job_type,
        failure_type.GetDescriptionForFailureType(failure_type.TEST))
    self.assertFalse(try_job_data.has_compile_targets)
    self.assertFalse(try_job_data.has_heuristic_results)
コード例 #26
0
  def testStoreDetectedCIFlakes(self, *_):
    master_name = 'm'
    builder_name = 'b'
    build_number = 123
    build = WfBuild.Create(master_name, builder_name, build_number)
    build.build_id = '87654321'
    build.put()

    flaky_tests = {'s': ['t1', 't2']}

    detect_flake_occurrences.StoreDetectedCIFlakes(master_name, builder_name,
                                                   build_number, flaky_tests)

    flake = Flake.Get('chromium', 'normalized_step_name', 't1')
    self.assertIsNotNone(flake)

    occurrences = FlakeOccurrence.query(ancestor=flake.key).fetch()
    self.assertEqual(1, len(occurrences))
    self.assertEqual(FlakeType.CI_FAILED_STEP, occurrences[0].flake_type)
コード例 #27
0
    def testGetBuildEndTime(self):
        cases = {
            'null': None,
            '1467740016': datetime.datetime(2016, 7, 5, 17, 33, 36),
        }
        for end_time, expected_time in cases.iteritems():
            master_name = 'm'
            builder_name = 'b'
            build_number = 123
            build = WfBuild.Create(master_name, builder_name, build_number)
            build.data = '{"times": [1467738821, %s]}' % end_time
            build.completed = True
            build.last_crawled_time = self._TimeBeforeNowBySeconds(10)
            build.put()

            self.assertEqual(
                expected_time,
                build_util.GetBuildEndTime(master_name, builder_name,
                                           build_number))
コード例 #28
0
ファイル: ci_failure_test.py プロジェクト: xinghun61/infra
  def testStopLookingBackIfFindTheFirstBuild(self, mock_search_builds, *_):
    master_name = 'm'
    builder_name = 'b'
    build_number = 2
    failed_steps = {
        'a_tests': {
            'current_failure': 2,
            'first_failure': 2,
            'supported': True
        },
        'unit_tests': {
            'current_failure': 2,
            'first_failure': 2,
            'supported': True
        }
    }
    builds = {'2': {'chromium_revision': 'rev2', 'blame_list': ['rev2']}}
    failed_steps = BaseFailedSteps.FromSerializable(failed_steps)
    builds = FailureInfoBuilds.FromSerializable(builds)
    build = WfBuild.Create(master_name, builder_name, build_number)
    build.build_id = '80000000124'
    build.completed = True
    build.put()
    self._CreateAndSaveWfAnanlysis(master_name, builder_name, build_number,
                                   analysis_status.RUNNING)

    # Setup build data for builds:
    step1 = Step(name='a_tests', status=common_pb2.FAILURE)
    log = step1.logs.add()
    log.name = 'stdout'

    step2 = Step(name='unit_tests', status=common_pb2.FAILURE)
    log = step2.logs.add()
    log.name = 'stdout'

    build_1 = Build(number=1, status=common_pb2.FAILURE, id=80000000001)
    build_1.steps.extend([step1, step2])
    build_1.input.gitiles_commit.id = 'rev1'

    build_0 = Build(number=0, status=common_pb2.FAILURE, id=80000000000)
    build_0.steps.extend([step1, step2])
    build_0.input.gitiles_commit.id = 'rev0'

    mock_search_builds.side_effect = [
        SearchBuildsResponse(builds=[build_1]),
        SearchBuildsResponse(builds=[build_0]),
        SearchBuildsResponse(builds=[])
    ]

    expected_failed_steps = {
        'a_tests': {
            'current_failure': 2,
            'first_failure': 0,
            'last_pass': None,
            'supported': True
        },
        'unit_tests': {
            'current_failure': 2,
            'first_failure': 0,
            'last_pass': None,
            'supported': True
        }
    }

    expected_builds = {
        2: {
            'chromium_revision': 'rev2',
            'blame_list': ['rev2']
        },
        1: {
            'chromium_revision': 'rev1',
            'blame_list': ['rev1']
        },
        0: {
            'chromium_revision': 'rev0',
            'blame_list': ['rev0']
        },
    }
    failure_info = CompileFailureInfo(failed_steps=failed_steps, builds=builds)

    ci_failure.CheckForFirstKnownFailure(master_name, builder_name,
                                         build_number, failure_info)

    self.assertEqual(expected_failed_steps,
                     failure_info.failed_steps.ToSerializable())
    self.assertEqual(expected_builds, failure_info.builds.ToSerializable())
コード例 #29
0
ファイル: ci_failure_test.py プロジェクト: xinghun61/infra
  def testStopLookingBackIfAllFailedStepsPassedInLastBuild(
      self, mock_search_builds, *_):
    master_name = 'm'
    builder_name = 'b'
    build_number = 124
    failed_steps = {
        'a': {
            'current_failure': 124,
            'first_failure': 124,
            'supported': True
        }
    }
    builds = {124: {'chromium_revision': 'rev124', 'blame_list': ['rev124']}}
    failed_steps = BaseFailedSteps.FromSerializable(failed_steps)
    builds = FailureInfoBuilds.FromSerializable(builds)
    build = WfBuild.Create(master_name, builder_name, build_number)
    build.build_id = '80000000124'
    build.completed = True
    build.put()
    self._CreateAndSaveWfAnanlysis(master_name, builder_name, build_number,
                                   analysis_status.RUNNING)

    build_123 = Build(number=123, status=common_pb2.FAILURE)
    step1 = Step(name='a', status=common_pb2.SUCCESS)
    log = step1.logs.add()
    log.name = 'stdout'
    step2 = Step(name='net_unittests', status=common_pb2.FAILURE)
    log = step2.logs.add()
    log.name = 'stdout'
    step3 = Step(name='unit_tests', status=common_pb2.FAILURE)
    log = step3.logs.add()
    log.name = 'stdout'
    build_123.steps.extend([step1, step2, step3])
    build_123.input.gitiles_commit.id = 'rev123'
    mock_search_builds.side_effect = [SearchBuildsResponse(builds=[build_123])]

    expected_failed_steps = {
        'a': {
            'last_pass': 123,
            'current_failure': 124,
            'first_failure': 124,
            'supported': True
        }
    }

    expected_builds = {
        124: {
            'chromium_revision': 'rev124',
            'blame_list': ['rev124']
        },
        123: {
            'chromium_revision': 'rev123',
            'blame_list': ['rev123']
        }
    }

    failure_info = CompileFailureInfo(failed_steps=failed_steps, builds=builds)
    failure_info = ci_failure.CheckForFirstKnownFailure(
        master_name, builder_name, build_number, failure_info)

    self.assertEqual(expected_failed_steps,
                     failure_info.failed_steps.ToSerializable())
    self.assertEqual(expected_builds, failure_info.builds.ToSerializable())
コード例 #30
0
    def testGetTryJobResultForCompileFailure(self, mock_fn1, mock_fn2, _):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123

        build = WfBuild.Create(master_name, builder_name, build_number)
        build.build_id = '8000000000000123'
        build.put()
        mock_fn1.return_value = build

        build_info = BuildInfo(master_name, builder_name, build_number)
        build_info.completed = False
        mock_fn2.return_value = build_info

        analysis = WfAnalysis.Create(master_name, builder_name, build_number)
        analysis.result = {
            'failures': [
                {
                    'step_name': 'compile',
                    'first_failure': 122,
                    'last_pass': 121,
                    'suspected_cls': [],
                },
                {
                    'step_name': 'steps',
                },
            ]
        }
        analysis.failure_result_map = {
            'compile': 'm/b/122',
        }
        analysis.status = analysis_status.COMPLETED
        analysis.suspected_cls = [{
            'repo_name': 'chromium',
            'revision': 'rev',
            'commit_position': 122,
            'url': None
        }]
        analysis.put()

        try_job = WfTryJob.Create('m', 'b', 122)
        try_job.status = analysis_status.COMPLETED
        try_job.compile_results = [{
            'url': 'build/url',
            'culprit': {
                'compile': {
                    'revision': 'rev',
                }
            }
        }]
        try_job.put()

        suspected_cl = WfSuspectedCL.Create('chromium', 'rev', 122)
        suspected_cl.builds = {
            'm/b/123': {
                'failure_type':
                failure_type.COMPILE,
                'failures':
                None,
                'status':
                suspected_cl_status.CORRECT,
                'approaches': [
                    analysis_approach_type.HEURISTIC,
                    analysis_approach_type.TRY_JOB
                ],
                'top_score':
                5
            }
        }
        suspected_cl.put()

        expected_try_job_result = {
            'status': 'completed',
            'url': 'build/url',
            'completed': True,
            'culprit': {
                'revision': 'rev',
            },
            'failed': False,
        }

        expected_suspected_cls = [{
            'repo_name':
            'chromium',
            'revision':
            'rev',
            'commit_position':
            122,
            'url':
            None,
            'status':
            suspected_cl_status.CORRECT,
            'confidence':
            self._PercentFormat(
                self.cl_confidences.compile_heuristic_try_job.confidence)
        }]

        build_url = buildbot.CreateBuildUrl('m', 'b', 123)
        response = self.test_app.get('/failure',
                                     params={
                                         'url': build_url,
                                         'format': 'json'
                                     })

        self.assertEquals(200, response.status_int)
        self.assertEqual(expected_try_job_result,
                         response.json_body['try_job'])
        self.assertEqual(expected_suspected_cls,
                         response.json_body['suspected_cls'])