Ejemplo n.º 1
0
 def testGetRecentCompletedBuilds(self, mock_fn):
     mock_fn.return_value = SearchBuildsResponse(
         builds=[Build(number=34),
                 Build(number=33),
                 Build(number=32)])
     self.assertEqual([34, 33, 32],
                      buildbot.GetRecentCompletedBuilds(
                          'm', 'b', RetryHttpClient()))
Ejemplo n.º 2
0
def GetLatestBuildNumber(master_name, builder_name):
    """Attempts to get the latest build number on master_name/builder_name."""
    recent_builds = buildbot.GetRecentCompletedBuilds(master_name,
                                                      builder_name,
                                                      page_size=1)

    if recent_builds is None:
        # Likely a network error.
        logging.error('Failed to detect latest build number on %s, %s',
                      master_name, builder_name)
        return None

    if not recent_builds:
        # In case the builder is new or was recently reset.
        logging.warning('No recent builds found on %s %s', master_name,
                        builder_name)
        return None

    return recent_builds[0]
Ejemplo n.º 3
0
def GetLaterBuildsWithAnySameStepFailure(master_name,
                                         builder_name,
                                         build_number,
                                         failed_steps=None):
  """Gets successive failed builds with the same failure as the referred build.

    The function will stop looking further and abandon all its findings if:
      - find a non-failed build (build ends in success or warning) or
      - find a build with non-overlapping failures.
  """
  latest_build_numbers = buildbot.GetRecentCompletedBuilds(
      master_name, builder_name)
  builds_with_same_failed_steps = defaultdict(list)

  if not latest_build_numbers:
    # Failed to get later builds, cannot check their failures. Returns an empty
    # dict to skip actions on the culprit.
    # This should be rare, possible cause is builder rename.
    logging.error(
        'Failed to get latest build numbers for builder %s/%s since %d.',
        master_name, builder_name, build_number)
    return {}

  for newer_build_number in latest_build_numbers:
    if newer_build_number <= build_number:
      break

    # Checks all builds after current build.
    newer_build_info = build_util.GetBuildInfo(master_name, builder_name,
                                               newer_build_number)
    if newer_build_info and newer_build_info.result == common_pb2.SUCCESS:
      return {}

    for failed_step in failed_steps or []:
      if failed_step in newer_build_info.failed_steps:
        builds_with_same_failed_steps[newer_build_number].append(failed_step)

    if not builds_with_same_failed_steps[newer_build_number]:
      # No same failed steps.
      return {}

  return builds_with_same_failed_steps
Ejemplo n.º 4
0
  def testGetRecentCompletedBuilds(self, mock_fn):
    builders_data = {
        'builders': {
            'b': {
                'cachedBuilds': [33, 32, 34, 35],
                'currentBuilds': [35]
            }
        }
    }

    builders_json_data = json.dumps(builders_data)
    compressed_file = io.BytesIO()
    with gzip.GzipFile(fileobj=compressed_file, mode='w') as compressed:
      compressed.write(builders_json_data)

    data = {
      'data': base64.b64encode(compressed_file.getvalue())
    }
    compressed_file.close()
    mock_fn.return_value = json.dumps(data)
    self.assertEqual(
      [34, 33, 32],
      buildbot.GetRecentCompletedBuilds('m', 'b', RetryHttpClient()))
def _LatestBuildFailed(master_name, builder_name, build_number):
    http_client = HttpClientAppengine()
    latest_build_numbers = buildbot.GetRecentCompletedBuilds(
        master_name, builder_name, http_client)

    for checked_build_number in latest_build_numbers:
        if checked_build_number <= build_number:
            return True

        checked_build_data = buildbot.GetBuildDataFromBuildMaster(
            master_name, builder_name, checked_build_number, http_client)

        if not checked_build_data:
            logging.error("Failed to get build data for %s/%s/%d" %
                          (master_name, builder_name, checked_build_number))
            return False

        checked_build_result = buildbot.GetBuildResult(
            json.loads(checked_build_data))

        if checked_build_result in [buildbot.SUCCESS, buildbot.WARNINGS]:
            return False

    return True
Ejemplo n.º 6
0
def _GetMatchingWaterfallBuildStep(cq_build_step, http_client):
    """Returns the matching Waterfall build step of the given CQ one.

  Args:
    cq_build_step (BuildStep): A build step on Commit Queue.
    http_client (RetryHttpClient): A http client to send http requests.

  Returns:
      (master_name, builder_name, build_number, step_name, step_metadata)
    or
      None
  """
    no_matching_result = (None, None, None, None, None)

    # 0. Get step_metadata.
    step_metadata = cq_build_step.step_metadata or step_util.GetStepMetadata(
        cq_build_step.master_name, cq_build_step.builder_name,
        cq_build_step.build_number, cq_build_step.step_name)
    if not step_metadata:
        logging.error('Couldn\'t get step_metadata')
        return no_matching_result

    # 1. Map a cq trybot to the matching waterfall buildbot:
    # get master_name and builder_name.
    wf_master_name = step_metadata.get('waterfall_mastername')
    wf_builder_name = step_metadata.get('waterfall_buildername')
    if not wf_master_name or not wf_builder_name:
        # Either waterfall_mastername or waterfall_buildername doesn't exist.
        logging.info('%s/%s has no matching Waterfall buildbot',
                     cq_build_step.master_name, cq_build_step.builder_name)
        return no_matching_result  # No matching Waterfall buildbot.

    # 2. Get "name" of the CQ trybot step.

    # Name of the step in the tags of a Swarming task.
    # Can't use step name, as cq one is with "(with patch)" while waterfall one
    # without.
    name = step_metadata.get('canonical_step_name')
    # The OS in which the test runs on. The same test binary might run on two
    # different OS platforms.
    os_name = step_metadata.get('dimensions', {}).get('os')
    if not name or not os_name:
        logging.error('Couldn\'t find name/os')
        return no_matching_result  # No name of the step.

    # TODO: cache and throttle QPS to the same master.
    # 3. Retrieve latest completed build cycle on the buildbot.
    builds = buildbot.GetRecentCompletedBuilds(wf_master_name,
                                               wf_builder_name,
                                               page_size=1)
    if not builds:
        logging.error('Couldn\'t find latest builds.')
        return no_matching_result  # No name of the step.

    # 4. Check whether there is matching step.
    tasks = swarming.ListSwarmingTasksDataByTags(http_client,
                                                 wf_master_name,
                                                 wf_builder_name,
                                                 builds[0],
                                                 additional_tag_filters={
                                                     'name': name,
                                                     'os': os_name
                                                 })
    if tasks:  # One matching buildbot is found.
        wf_step_name = tasks[0].tags['stepname'][0] if 'stepname' in tasks[
            0].tags else ''
        logging.info('%s/%s/%s is mapped to %s/%s/%s',
                     cq_build_step.master_name, cq_build_step.builder_name,
                     cq_build_step.step_name, wf_master_name, wf_builder_name,
                     wf_step_name)
        return (wf_master_name, wf_builder_name, builds[0], wf_step_name,
                step_metadata)

    return no_matching_result
Ejemplo n.º 7
0
 def testFailToGetRecentCompletedBuilds(self, _):
   self.assertEqual(
     [], buildbot.GetRecentCompletedBuilds('m', 'b', _))