Exemple #1
0
def _CheckJob(job, issue_tracker):
    """Checks whether a try job is finished and updates a bug if applicable.

  This method returns nothing, but it may log errors.

  Args:
    job: A TryJob entity, which represents one bisect try job.
    issue_tracker: An issue_tracker_service.IssueTrackerService instance.
  """
    # Give up on stale try job.
    if job.use_buildbucket:
        stale_delta = _STALE_TRYJOB_DELTA_BUILDBUCKET
    else:
        stale_delta = _STALE_TRYJOB_DELTA
    if (job.last_ran_timestamp and
            job.last_ran_timestamp < datetime.datetime.now() - stale_delta):
        comment = 'Stale bisect job, will stop waiting for results.'
        comment += 'Rietveld issue: %s' % job.rietveld_issue_id
        start_try_job.LogBisectResult(job.bug_id, comment)
        job.SetFailed()
        return

    if job.job_type == 'perf-try':
        _CheckPerfTryJob(job)
    elif job.job_type == 'bisect-fyi':
        _CheckFYIBisectJob(job, issue_tracker)
    else:
        # Delete bisect jobs that aren't associated with any bug id.
        if job.bug_id is None or job.bug_id < 0:
            job.key.delete()
            return
        _CheckBisectJob(job, issue_tracker)
Exemple #2
0
def _RestartFailedBisectJobs():
  """Restarts failed bisect jobs.

  Bisect jobs that ran out of retries will be deleted.

  Returns:
    True if all bisect jobs that were retried were successfully triggered,
    and False otherwise.
  """
  bisect_jobs = try_job.TryJob.query(try_job.TryJob.status == 'failed').fetch()
  all_successful = True
  for job in bisect_jobs:
    if job.run_count > 0:
      if job.run_count <= len(_BISECT_RESTART_PERIOD_DAYS):
        if _IsBisectJobDueForRestart(job):
          # Start bisect right away if this is the first retry. Otherwise,
          # try bisect with different config.
          if job.run_count == 1:
            try:
              start_try_job.PerformBisect(job)
            except request_handler.InvalidInputError as e:
              logging.error(e.message)
              all_successful = False
          elif job.bug_id:
            restart_successful = _RestartBisect(job)
            if not restart_successful:
              all_successful = False
      else:
        if job.bug_id:
          comment = ('Failed to run bisect %s times.'
                     'Stopping automatic restart for this job.' %
                     job.run_count)
          start_try_job.LogBisectResult(job.bug_id, comment)
        job.key.delete()
  return all_successful
Exemple #3
0
def _PostSucessfulResult(job, bisect_results, issue_tracker):
    """Posts successful bisect results on logger and issue tracker."""
    # From the results, get the list of people to CC (if applicable), the bug
    # to merge into (if applicable) and the commit hash cache key, which
    # will be used below.
    authors_to_cc = []
    merge_issue = None
    bug = ndb.Key('Bug', job.bug_id).get()

    commit_cache_key = _GetCommitHashCacheKey(bisect_results['results'])
    result_is_positive = _BisectResultIsPositive(bisect_results['results'])
    if bug and result_is_positive:
        merge_issue = layered_cache.GetExternal(commit_cache_key)
        if not merge_issue:
            authors_to_cc = _GetAuthorsToCC(bisect_results['results'])

    comment = _BUG_COMMENT_TEMPLATE % bisect_results

    # Add a friendly message to author of culprit CL.
    owner = None
    if authors_to_cc:
        comment = '%s%s' % (_AUTO_ASSIGN_MSG % {
            'author': authors_to_cc[0]
        }, comment)
        owner = authors_to_cc[0]
    # Set restrict view label if the bisect results are internal only.
    labels = ['Restrict-View-Google'] if job.internal_only else None
    added_comment = issue_tracker.AddBugComment(job.bug_id,
                                                comment,
                                                cc_list=authors_to_cc,
                                                merge_issue=merge_issue,
                                                labels=labels,
                                                owner=owner)
    if not added_comment:
        raise BugUpdateFailure('Failed to update bug %s with comment %s' %
                               (job.bug_id, comment))

    start_try_job.LogBisectResult(job.bug_id, comment)
    logging.info('Updated bug %s with results from %s', job.bug_id,
                 job.rietveld_issue_id)

    if merge_issue:
        _MapAnomaliesToMergeIntoBug(merge_issue, job.bug_id)
        # Mark the duplicate bug's Bug entity status as closed so that
        # it doesn't get auto triaged.
        bug.status = bug_data.BUG_STATUS_CLOSED
        bug.put()

    # Cache the commit info and bug ID to datastore when there is no duplicate
    # issue that this issue is getting merged into. This has to be done only
    # after the issue is updated successfully with bisect information.
    if commit_cache_key and not merge_issue and result_is_positive:
        layered_cache.SetExternal(commit_cache_key,
                                  str(job.bug_id),
                                  days_to_keep=30)
        logging.info('Cached bug id %s and commit info %s in the datastore.',
                     job.bug_id, commit_cache_key)
def _PostFailedResult(
    job, bisect_results, issue_tracker, add_bug_comment=False):
  """Posts failed bisect results on logger and optional issue tracker."""
  comment = _BUG_COMMENT_TEMPLATE % bisect_results
  if add_bug_comment:
    # Set restrict view label if the bisect results are internal only.
    labels = ['Restrict-View-Google'] if job.internal_only else None
    added_comment = issue_tracker.AddBugComment(
        job.bug_id, comment, labels=labels)
    if not added_comment:
      raise BugUpdateFailure('Failed to update bug %s with comment %s'
                             % (job.bug_id, comment))
  start_try_job.LogBisectResult(job.bug_id, comment)
  logging.info('Updated bug %s with results from %s',
               job.bug_id, job.rietveld_issue_id)
Exemple #5
0
def _RestartFailedBisectJobs():
  """Restarts failed bisect jobs.

  Bisect jobs that ran out of retries will be deleted.
  """
  bisect_jobs = try_job.TryJob.query(try_job.TryJob.status == 'failed').fetch()
  for job in bisect_jobs:
    if job.run_count > 0:
      if job.run_count <= len(_BISECT_RESTART_PERIOD_DAYS):
        if _IsBisectJobDueForRestart(job):
          if job.run_count == 1:
            start_try_job.PerformBisect(job)
          elif job.bug_id:
            _RestartBisect(job)
      else:
        if job.bug_id:
          comment = ('Failed to run bisect %s times.'
                     'Stopping automatic restart for this job.' %
                     job.run_count)
          start_try_job.LogBisectResult(job.bug_id, comment)
        job.key.delete()