def testMonitorSwarmingTaskBuildException(self, mocked_fn, _):
        task_id = NO_TASK_EXCEPTION

        build_info = BuildInfo(self.master_name, self.build_number,
                               self.build_number)
        build_info.commit_position = 12345
        build_info.chromium_revision = 'a1b2c3d4'
        mocked_fn.return_value = build_info

        task = FlakeSwarmingTask.Create(self.master_name, self.builder_name,
                                        self.build_number, self.step_name,
                                        self.test_name)
        task.task_id = 'task_id'
        task.put()

        analysis = MasterFlakeAnalysis.Create(self.master_name,
                                              self.builder_name,
                                              self.build_number,
                                              self.step_name, self.test_name)
        analysis.Save()

        pipeline = ProcessFlakeSwarmingTaskResultPipeline()
        pipeline.start_test()
        pipeline.run(self.master_name, self.builder_name, self.build_number,
                     self.step_name, task_id, self.build_number,
                     self.test_name, 1)

        self.assertIsNone(task.task_id)
        self.assertEqual(analysis_status.SKIPPED, task.status)
        self.assertEqual(-1, analysis.data_points[-1].pass_rate)
        self.assertFalse(analysis.data_points[-1].has_valid_artifact)
    def testCheckTestsRunStatuses(self, mocked_fn, _):
        build_info = BuildInfo(self.master_name, self.build_number,
                               self.build_number)
        build_info.commit_position = 12345
        build_info.chromium_revision = 'a1b2c3d4'
        mocked_fn.return_value = build_info
        analysis = MasterFlakeAnalysis.Create(self.master_name,
                                              self.builder_name,
                                              self.build_number,
                                              self.step_name, self.test_name)
        analysis.Save()

        task = FlakeSwarmingTask.Create(self.master_name, self.builder_name,
                                        self.build_number, self.step_name,
                                        self.test_name)
        task.put()

        call_params = ProcessFlakeSwarmingTaskResultPipeline._GetArgs(
            self.pipeline, self.master_name, self.builder_name,
            self.build_number, self.step_name, self.build_number,
            self.test_name, self.version_number)

        tests_statuses = (
            ProcessFlakeSwarmingTaskResultPipeline._CheckTestsRunStatuses(
                self.pipeline, base_test._SAMPLE_FAILURE_LOG, *call_params))
        self.assertEqual(base_test._EXPECTED_TESTS_STATUS, tests_statuses)
Beispiel #3
0
def ExtractBuildInfo(master_name, builder_name, build_number, build_data):
    """Extracts and returns build information as an instance of BuildInfo."""
    build_info = BuildInfo(master_name, builder_name, build_number)
    data_json = json.loads(build_data)
    chromium_revision = GetBuildProperty(data_json.get('properties', []),
                                         'got_revision')
    commit_position_line = GetBuildProperty(data_json.get('properties', []),
                                            'got_revision_cp')
    parent_buildername = GetBuildProperty(data_json.get('properties', []),
                                          'parent_buildername')
    parent_mastername = GetBuildProperty(data_json.get('properties', []),
                                         'parent_mastername')

    build_info.build_start_time = GetBuildStartTime(data_json)
    build_info.build_end_time = GetBuildEndTime(data_json)
    build_info.chromium_revision = chromium_revision
    build_info.commit_position = _GetCommitPosition(commit_position_line)
    build_info.completed = data_json.get('currentStep') is None
    build_info.result = GetBuildResult(data_json)
    build_info.parent_buildername = parent_buildername
    build_info.parent_mastername = parent_mastername

    changes = data_json.get('sourceStamp', {}).get('changes', [])
    for change in changes:
        if change['revision'] not in build_info.blame_list:
            build_info.blame_list.append(change['revision'])

    # Step categories:
    # 1. A step is passed if it is in SUCCESS or WARNINGS status.
    # 2. A step is failed if it is in FAILED status.
    # 3. A step is not passed if it is not in SUCCESS or WARNINGS status. This
    #    category includes steps in statuses: FAILED, SKIPPED, EXCEPTION, RETRY,
    #    CANCELLED, etc.
    steps = data_json.get('steps', [])
    for step_data in steps:
        step_name = step_data['name']

        if not step_data.get('isFinished', False):
            # Skip steps that haven't started yet or are still running.
            continue

        step_result = GetStepResult(step_data)
        if step_result not in (SUCCESS, WARNINGS):
            build_info.not_passed_steps.append(step_name)

        step_logs = step_data.get('logs')
        if step_logs and 'preamble' == step_logs[0][0]:
            # Skip a annotating step like "steps" or "slave_steps", which wraps other
            # steps. A failed annotated step like "content_browsertests" will make
            # the annotating step like "steps" fail too. Such annotating steps have a
            # log with name "preamble".
            continue

        if step_result in (SUCCESS, WARNINGS):
            build_info.passed_steps.append(step_name)
        elif step_result == FAILURE:
            build_info.failed_steps.append(step_name)

    return build_info
Beispiel #4
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')
  def testRerunAnalysisWithAnalyzeFlakePipeline(
      self, mocked_analysis, mocked_pipeline, mocked_need_analysis,
      mocked_build_info, mock_dimensions, *_):
    buildbucket_id = 'id'
    mock_dimensions.return_value = ['os:Mac', 'cpu:x86']
    start_commit_position = 1000
    start_build_info = BuildInfo('m', 'b 1', 123)
    start_build_info.commit_position = start_commit_position
    start_build_info.chromium_revision = 'r1000'
    start_build_info.buildbucket_id = buildbucket_id
    mocked_build_info.return_value = start_build_info
    mocked_analysis.pipeline_status_path.return_value = 'status'
    mocked_analysis.key.urlsafe.return_value = 'urlsafe_key'
    mocked_need_analysis.return_value = (True, mocked_analysis)
    test = TestInfo('m', 'b 1', 123, 's', 't')
    manually_triggered = False
    flake = Flake.Create('chromium', 's', 't', 'l')

    analysis = initialize_flake_pipeline.ScheduleAnalysisIfNeeded(
        test,
        test,
        flake.key,
        bug_id=None,
        allow_new_analysis=True,
        manually_triggered=manually_triggered,
        force=True,
        queue_name=constants.DEFAULT_QUEUE)

    self.assertIsNotNone(analysis)
    self.assertEqual(buildbucket_id, analysis.build_id)
    self.assertEqual(buildbucket_id, analysis.original_build_id)

    analyze_flake_input = AnalyzeFlakeInput(
        analysis_urlsafe_key='urlsafe_key',
        analyze_commit_position_parameters=NextCommitPositionOutput(
            culprit_commit_id=None,
            next_commit_id=CommitID(
                commit_position=start_commit_position,
                revision=start_build_info.chromium_revision)),
        commit_position_range=IntRange(lower=None, upper=start_commit_position),
        dimensions=ListOfBasestring.FromSerializable(
            ['os:Mac', 'cpu:x86', 'pool:luci.chromium.findit']),
        manually_triggered=manually_triggered,
        rerun=True,
        retries=0,
        step_metadata=StepMetadata.FromSerializable({}))

    mocked_pipeline.assert_has_calls([
        mock.call(analyze_flake_input),
        mock.call().start(queue_name=constants.DEFAULT_QUEUE)
    ])
Beispiel #6
0
def ExtractBuildInfo(master_name, builder_name, build_number, build_data):
  """Extracts and returns build information as an instance of BuildInfo."""
  build_info = BuildInfo(master_name, builder_name, build_number)

  data_json = json.loads(build_data)
  chromium_revision = GetBuildProperty(
      data_json.get('properties', []), 'got_revision')

  build_info.build_start_time = GetBuildStartTime(data_json)
  build_info.chromium_revision = chromium_revision
  build_info.completed = data_json.get('currentStep') is None
  build_info.result = GetBuildResult(data_json)

  changes = data_json.get('sourceStamp', {}).get('changes', [])
  for change in changes:
    if change['revision'] not in build_info.blame_list:
      build_info.blame_list.append(change['revision'])

  # Step categories:
  # 1. A step is passed if it is in SUCCESS or WARNINGS status.
  # 2. A step is failed if it is in FAILED status.
  # 3. A step is not passed if it is not in SUCCESS or WARNINGS status. This
  #    category includes steps in statuses: FAILED, SKIPPED, EXCEPTION, RETRY,
  #    CANCELLED, etc.
  steps = data_json.get('steps', [])
  for step_data in steps:
    step_name = step_data['name']

    if not step_data.get('isFinished', False):
      # Skip steps that haven't started yet or are still running.
      continue

    step_result = GetStepResult(step_data)
    if step_result not in (SUCCESS, WARNINGS):
      build_info.not_passed_steps.append(step_name)

    step_logs = step_data.get('logs')
    if step_logs and 'preamble' == step_logs[0][0]:
      # Skip a annotating step like "steps" or "slave_steps", which wraps other
      # steps. A failed annotated step like "content_browsertests" will make
      # the annotating step like "steps" fail too. Such annotating steps have a
      # log with name "preamble".
      continue

    if step_result in (SUCCESS, WARNINGS):
      build_info.passed_steps.append(step_name)
    elif step_result == FAILURE:
      build_info.failed_steps.append(step_name)

  return build_info
    def testMonitorSwarmingTaskTimeOut(self, mocked_fn, _):
        build_info = BuildInfo(self.master_name, self.builder_name,
                               self.build_number)
        build_info.commit_position = 12345
        build_info.chromium_revision = 'a1b2c3d4'
        mocked_fn.return_value = build_info

        # Override swarming config settings to force a timeout.
        override_swarming_settings = {'task_timeout_hours': -1}
        self.UpdateUnitTestConfigSettings('swarming_settings',
                                          override_swarming_settings)

        task = FlakeSwarmingTask.Create(self.master_name, self.builder_name,
                                        self.build_number, self.step_name,
                                        self.test_name)
        task.task_id = 'task_id1'
        task.put()

        analysis = MasterFlakeAnalysis.Create(self.master_name,
                                              self.builder_name,
                                              self.build_number,
                                              self.step_name, self.test_name)
        analysis.Save()

        pipeline = ProcessFlakeSwarmingTaskResultPipeline(self.master_name,
                                                          self.builder_name,
                                                          self.build_number,
                                                          self.step_name,
                                                          self.build_number,
                                                          self.test_name,
                                                          1,
                                                          task_id='task_id1')
        pipeline.start_test()
        pipeline.run(self.master_name, self.builder_name, self.build_number,
                     self.step_name, 'task_id1', self.build_number,
                     self.test_name, 1)
        pipeline.callback(callback_params=pipeline.last_params)
        # Reload from ID to get all internal properties in sync.
        pipeline = ProcessFlakeSwarmingTaskResultPipeline.from_id(
            pipeline.pipeline_id)
        pipeline.finalized()
        step_name, task_info = pipeline.outputs.default.value
        self.assertEqual('abc_tests', task_info)
        self.assertEqual(self.step_name, step_name)

        task = FlakeSwarmingTask.Get(self.master_name, self.builder_name,
                                     self.build_number, self.step_name,
                                     self.test_name)
        self.assertEqual(analysis_status.ERROR, task.status)
        self.assertEqual({}, task.tests_statuses)
    def testCheckTestsRunStatusesZeroBuildNumber(self, mocked_fn, _):
        build_info = BuildInfo(self.master_name, self.build_number, 0)
        build_info.commit_position = 12345
        build_info.chromium_revision = 'a1b2c3d4'
        mocked_fn.return_value = build_info

        analysis = MasterFlakeAnalysis.Create(self.master_name,
                                              self.builder_name, 0,
                                              self.step_name, self.test_name)
        analysis.Save()

        task = FlakeSwarmingTask.Create(self.master_name, self.builder_name, 0,
                                        self.step_name, self.test_name)
        task.put()

        ProcessFlakeSwarmingTaskResultPipeline()._CheckTestsRunStatuses(
            {}, self.master_name, self.builder_name, 0, self.step_name, 0,
            self.test_name, 1)
        self.assertIsNone(
            analysis.data_points[0].previous_build_commit_position)
    def testCheckTestsRunStatusesWhenTestDoesNotExist(self, mocked_fn, _):
        build_info = BuildInfo(self.master_name, self.builder_name,
                               self.build_number)
        build_info.commit_position = 12345
        build_info.chromium_revision = 'a1b2c3d4'
        mocked_fn.return_value = build_info

        test_name = 'TestSuite1.new_test'
        analysis = MasterFlakeAnalysis.Create(self.master_name,
                                              self.builder_name,
                                              self.build_number,
                                              self.step_name, test_name)
        analysis.Save()

        task = FlakeSwarmingTask.Create(self.master_name, self.builder_name,
                                        self.build_number, self.step_name,
                                        test_name)
        task.put()

        pipeline = ProcessFlakeSwarmingTaskResultPipeline()
        tests_statuses = pipeline._CheckTestsRunStatuses(
            base_test._SAMPLE_FAILURE_LOG, self.master_name, self.builder_name,
            self.build_number, self.step_name, self.build_number, test_name,
            self.version_number)

        self.assertEqual(base_test._EXPECTED_TESTS_STATUS, tests_statuses)

        task = FlakeSwarmingTask.Get(self.master_name, self.builder_name,
                                     self.build_number, self.step_name,
                                     test_name)
        self.assertEqual(0, task.tries)
        self.assertEqual(0, task.successes)

        analysis = MasterFlakeAnalysis.GetVersion(self.master_name,
                                                  self.builder_name,
                                                  self.build_number,
                                                  self.step_name, test_name,
                                                  self.version_number)
        self.assertTrue(analysis.data_points[-1].pass_rate < 0)
    def testMonitorSwarmingTaskStepNotExist(self, mocked_fn, _):
        task_id = NO_TASK

        build_info = BuildInfo(self.master_name, self.build_number,
                               self.build_number)
        build_info.commit_position = 12345
        build_info.chromium_revision = 'a1b2c3d4'
        mocked_fn.return_value = build_info

        task = FlakeSwarmingTask.Create(self.master_name, self.builder_name,
                                        self.build_number, self.step_name,
                                        self.test_name)
        task.put()

        analysis = MasterFlakeAnalysis.Create(self.master_name,
                                              self.builder_name,
                                              self.build_number,
                                              self.step_name, self.test_name)
        analysis.Save()

        pipeline = ProcessFlakeSwarmingTaskResultPipeline(
            self.master_name, self.builder_name, self.build_number,
            self.step_name, task_id, self.build_number, self.test_name, 1)
        pipeline.start_test()
        pipeline.run(self.master_name, self.builder_name, self.build_number,
                     self.step_name, task_id, self.build_number,
                     self.test_name, 1)
        # Reload from ID to get all internal properties in sync.
        pipeline = ProcessFlakeSwarmingTaskResultPipeline.from_id(
            pipeline.pipeline_id)
        pipeline.finalized()
        _, step_name_no_platform = pipeline.outputs.default.value

        self.assertIsNone(task.task_id)
        self.assertEqual(analysis_status.SKIPPED, task.status)
        self.assertEqual(-1, analysis.data_points[-1].pass_rate)
        self.assertIsNone(step_name_no_platform)
Beispiel #11
0
def ExtractBuildInfoFromV2Build(master_name, builder_name, build_number, build):
  """Generates BuildInfo using bb v2 build info.

  This conversion is needed to keep Findit v1 running, will be deprecated in
  v2 (TODO: crbug.com/966982).

  Args:
    master_name (str): The name of the master.
    builder_name (str): The name of the builder.
    build_number (int): The build number.
    build (build_pb2.Build): All info about the build.

  Returns:
    (BuildInfo)
  """
  build_info = BuildInfo(master_name, builder_name, build_number)

  input_properties = json_format.MessageToDict(build.input.properties)

  chromium_revision = build.input.gitiles_commit.id
  runtime = input_properties.get('$recipe_engine/runtime') or {}

  build_info.chromium_revision = chromium_revision

  repo_url = git.GetRepoUrlFromV2Build(build)
  build_info.commit_position = git.GetCommitPositionFromRevision(
      build.input.gitiles_commit.id, repo_url=repo_url)

  build_info.build_start_time = build.create_time.ToDatetime()
  build_info.build_end_time = build.end_time.ToDatetime()
  build_info.completed = bool(build_info.build_end_time)
  build_info.result = build.status
  build_info.parent_buildername = input_properties.get('parent_buildername')
  build_info.parent_mastername = input_properties.get('parent_mastername')
  build_info.buildbucket_id = str(build.id)
  build_info.buildbucket_bucket = build.builder.bucket
  build_info.is_luci = runtime.get('is_luci')

  build_info.blame_list = GetBlameListForV2Build(build)

  # Step categories:
  # 1. A step is passed if it is in SUCCESS status.
  # 2. A step is failed if it is in FAILURE status.
  # 3. A step is not passed if it is not in SUCCESS status. This category
  #   includes steps in statuses: FAILURE, INFRA_FAILURE, CANCELED, etc.
  for step in build.steps:
    step_name = step.name
    step_status = step.status

    if step_status in [
        common_pb2.STATUS_UNSPECIFIED, common_pb2.SCHEDULED, common_pb2.STARTED
    ]:
      continue

    if step_status != common_pb2.SUCCESS:
      build_info.not_passed_steps.append(step_name)

    if step_name == 'Failure reason':
      # 'Failure reason' is always red when the build breaks or has exception,
      # but it is not a failed step.
      continue

    if not step.logs:
      # Skip wrapping steps.
      continue

    if step_status == common_pb2.SUCCESS:
      build_info.passed_steps.append(step_name)
    elif step_status == common_pb2.FAILURE:
      build_info.failed_steps.append(step_name)

  return build_info
  def testNextCommitPositionPipelineContinueAnalysisFallbackToBuildInfo(
      self, mock_update, mock_heuristic, mock_targets, mock_bounding_builds,
      mock_next_commit, mock_reference_build):
    master_name = 'm'
    builder_name = 'b'
    build_number = 100
    step_name = 's'
    test_name = 't'
    start_commit_position = 1000
    expected_next_commit_id = CommitID(commit_position=990, revision='r990')

    mock_heuristic.return_value = False

    calculated_next_commit_id = CommitID(commit_position=999, revision='r999')
    mock_next_commit.return_value = (calculated_next_commit_id, None)

    target_name = 'browser_tests'
    step_metadata = StepMetadata(
        canonical_step_name=None,
        dimensions=None,
        full_step_name=None,
        isolate_target_name=target_name,
        patched=True,
        swarm_task_ids=None,
        waterfall_buildername=None,
        waterfall_mastername=None)

    reference_build = BuildInfo(master_name, builder_name, build_number)
    reference_build.commit_position = start_commit_position
    mock_reference_build.return_value = reference_build

    lower_bound_build = BuildInfo(master_name, builder_name, build_number - 1)
    lower_bound_build.commit_position = expected_next_commit_id.commit_position
    lower_bound_build.chromium_revision = expected_next_commit_id.revision
    upper_bound_build = BuildInfo(master_name, builder_name, build_number)
    upper_bound_build.commit_position = start_commit_position
    mock_bounding_builds.return_value = (lower_bound_build, upper_bound_build)

    mock_targets.side_effect = AssertionError()

    analysis = MasterFlakeAnalysis.Create(master_name, builder_name,
                                          build_number, step_name, test_name)
    analysis.data_points = [
        DataPoint.Create(commit_position=start_commit_position)
    ]
    analysis.Save()

    next_commit_position_input = NextCommitPositionInput(
        analysis_urlsafe_key=analysis.key.urlsafe(),
        commit_position_range=IntRange(lower=None, upper=start_commit_position),
        step_metadata=step_metadata)

    pipeline_job = NextCommitPositionPipeline(next_commit_position_input)
    pipeline_job.start()
    self.execute_queued_tasks()

    mock_update.assert_called_once_with(lower_bound_build, upper_bound_build)
    pipeline_job = pipelines.pipeline.Pipeline.from_id(pipeline_job.pipeline_id)
    next_commit_position_output = pipeline_job.outputs.default.value

    self.assertFalse(pipeline_job.was_aborted)
    self.assertIsNone(next_commit_position_output['culprit_commit_id'])
    self.assertEqual(expected_next_commit_id.ToSerializable(),
                     next_commit_position_output['next_commit_id'])