Esempio n. 1
0
def _ParseFlakeSwarmingTaskOutput(task_data, output_json, error, parameters):
    """Returns swarming task results as a FlakeswarmingTaskOutput object.

  Assumption: only 1 test was run in the Swarming task.
  """
    assert task_data

    iterations = parameters.iterations

    if output_json:
        # Gets the total numbers of runs and number of successful runs from
        # test results
        tries, successes = flake_test_results.GetCountsFromSwarmingRerun(
            output_json)

        if tries is None or successes is None:
            # Something went wrong preventing even a single test from being processed
            # which counts as an error.
            error = error or SwarmingTaskError.GenerateError(
                code=swarming_task_error.UNKNOWN)
            tries = None
            successes = None
        elif (tries == 1 and task_data['state'] == constants.STATE_COMPLETED
              and not task_data.get('failure')
              and not task_data.get('infra_failure')):
            # webkit_layout_tests special case: test results will be combined into
            # one if all results are the same.
            # Use iterations instead assuming the test repeated that many times.
            # Currently only do this if task completes successfully.
            tries = iterations
            successes = iterations * successes

        return FlakeSwarmingTaskOutput(
            completed_time=time_util.DatetimeFromString(
                task_data.get('completed_ts')),
            error=error,
            iterations=tries,
            pass_count=successes,
            started_time=time_util.DatetimeFromString(
                task_data.get('started_ts')),
            task_id=task_data['task_id'])
    else:
        return FlakeSwarmingTaskOutput(
            completed_time=time_util.DatetimeFromString(
                task_data.get('completed_ts')),
            error=error or
            SwarmingTaskError.GenerateError(code=swarming_task_error.UNKNOWN),
            iterations=None,
            pass_count=None,
            started_time=time_util.DatetimeFromString(
                task_data.get('started_ts')),
            task_id=task_data['task_id'])
Esempio n. 2
0
    def testOnSwarmingTaskTimeout(self, mocked_parse, mocked_result):
        error = SwarmingTaskError.GenerateError(
            swarming_task_error.RUNNER_TIMEOUT)
        task_id = 'task_id'

        task_data = {
            'state': 'COMPLETE',
        }
        mocked_result.return_value = task_data, 'content', None

        commit_position = 1000
        isolate_sha = 'sha1'
        iterations = 50
        timeout_seconds = 1200

        parameters = RunFlakeSwarmingTaskInput(builder_name='b',
                                               commit_position=commit_position,
                                               isolate_sha=isolate_sha,
                                               iterations=iterations,
                                               master_name='m',
                                               reference_build_number=123,
                                               step_name='s',
                                               test_name='t',
                                               timeout_seconds=timeout_seconds)

        flake_swarming.OnSwarmingTaskTimeout(parameters, task_id)
        mocked_parse.assert_called_once_with(task_data, 'content', error,
                                             parameters)
Esempio n. 3
0
def GetIsolatedOuptputFileToHashMap(digest, name_space, isolated_server,
                                    http_client):
    """Gets the mapping of all files and their hashes and other info.

  Args:
    digest(str): Hash to file for retrieve request.
    name_space(str): Name space info for retrieve request.
    isolated_server(str): Host to isolate server.
    http_client(RetryHttpClient): Http client to send the request.

  Returns:
    (dict): Mapping from file names to hashes.
  """
    content, error = isolate_util.FetchFileFromIsolatedServer(
        digest, name_space, isolated_server, http_client)
    if not content:
        return None, error

    file_hash_mapping = {}
    content_json = json.loads(content)
    if not content_json.get('files'):
        return None, SwarmingTaskError.GenerateError(
            swarming_task_error.NO_ISOLATED_FILES)
    for file_name, info in content_json['files'].iteritems():
        file_hash_mapping[file_name] = info.get('h')
    return file_hash_mapping, None
Esempio n. 4
0
def OnSwarmingTaskError(task_id, error):
    """Returns a FlakeSwarmingTaskOutput object representing a failed task."""
    return FlakeSwarmingTaskOutput(
        completed_time=None,
        error=error
        or SwarmingTaskError.GenerateError(code=swarming_task_error.UNKNOWN),
        iterations=None,
        pass_count=None,
        started_time=None,
        task_id=task_id)
Esempio n. 5
0
def GetSwarmingTaskDataAndResult(task_id, http_client=_FINDIT_HTTP_CLIENT):
  """Gets information about a swarming task.

  Returns:
       (str, dict, dict): The state, test result and error for a swarming task.
  """
  data, error = swarming_util.GetSwarmingTaskResultById(swarming.SwarmingHost(),
                                                        task_id, http_client)

  error = SwarmingTaskError.FromSerializable(error)
  if not data:
    return None, None, error

  task_state = data['state']
  output_json = None
  if task_state not in constants.STATE_NOT_STOP:
    if task_state == constants.STATE_COMPLETED:
      outputs_ref = data.get('outputs_ref')

      # If swarming task aborted because of errors in request arguments,
      # it's possible that there is no outputs_ref.
      if not outputs_ref:
        error = error or SwarmingTaskError.GenerateError(
            swarming_task_error.NO_TASK_OUTPUTS)
      else:
        output_json, error = GetOutputJsonByOutputsRef(outputs_ref, http_client)
        if not output_json:
          error = error or SwarmingTaskError.GenerateError(
              swarming_task_error.NO_OUTPUT_JSON)
    else:
      # The swarming task did not complete successfully.
      logging.error('Swarming task %s stopped with status: %s', task_id,
                    task_state)
      error = SwarmingTaskError.GenerateError(
          swarming_task_error.STATES_NOT_RUNNING_TO_ERROR_CODES[task_state])
  return data, output_json, error
Esempio n. 6
0
def OnSwarmingTaskTimeout(parameters, task_id):
    """To be called when waiting for a swarming task times out."""
    timeout_error = SwarmingTaskError.GenerateError(
        swarming_task_error.RUNNER_TIMEOUT)

    if not task_id:
        # The pipeline timedout without successfully triggering a task.
        return OnSwarmingTaskError(None, timeout_error)

    task_data, output_json, error = (
        swarmed_test_util.GetSwarmingTaskDataAndResult(task_id))

    if not task_data or not task_data.get('state'):
        return OnSwarmingTaskError(task_id, error or timeout_error)

    # Attempt to salvage whatever is available, but still report an error.
    return _ParseFlakeSwarmingTaskOutput(task_data, output_json, error
                                         or timeout_error, parameters)
Esempio n. 7
0
def OnSwarmingTaskTimeout(run_swarming_task_params, task_id):
    master_name, builder_name, build_number = (
        run_swarming_task_params.build_key.GetParts())
    step_name = run_swarming_task_params.step_name

    error = SwarmingTaskError.GenerateError(swarming_task_error.RUNNER_TIMEOUT)

    data, output_json, _ = swarmed_test_util.GetSwarmingTaskDataAndResult(
        task_id)
    if output_json and test_results_util.IsTestResultsValid(output_json):
        test_results = test_results_util.GetTestResultObject(output_json)
        classified_test_results = (test_results.GetClassifiedTestResults()
                                   if test_results else {})
        _UpdateSwarmingTaskEntity(
            master_name,
            builder_name,
            build_number,
            step_name,
            status=analysis_status.COMPLETED,
            error=error,
            classified_test_results=classified_test_results,
            created_ts=data.get('created_ts'),
            started_ts=data.get('started_ts'),
            completed_ts=data.get('completed_ts'))
        _RecordSwarmingTaskStateChange(master_name, builder_name, build_number,
                                       step_name, analysis_status.COMPLETED,
                                       analysis_approach_type.SWARMING)
    else:
        _UpdateSwarmingTaskEntity(master_name,
                                  builder_name,
                                  build_number,
                                  step_name,
                                  status=analysis_status.ERROR,
                                  error=error)
        _RecordSwarmingTaskStateChange(master_name, builder_name, build_number,
                                       step_name, analysis_status.ERROR,
                                       analysis_approach_type.SWARMING)
 def testGenerateError(self):
     expected_error = {'code': 1000, 'message': 'Unknown error'}
     self.assertEqual(
         expected_error,
         SwarmingTaskError.GenerateError(
             swarming_task_error.UNKNOWN).ToSerializable())