Esempio n. 1
0
def TriggerSwarmingTask(run_swarming_task_parameters, runner_id):
    """Triggers a swarming rerun for the given tests in a given build."""

    master_name, builder_name, build_number = (
        run_swarming_task_parameters.build_key.GetParts())
    step_name = run_swarming_task_parameters.step_name
    tests = run_swarming_task_parameters.tests

    assert tests, 'No tests to trigger swarming task for.'
    http_client = FinditHttpClient()

    # 1. Retrieve Swarming task parameters from a given Swarming task id.
    ref_task_id, ref_request = swarming.GetReferredSwarmingTaskRequestInfo(
        master_name, builder_name, build_number, step_name, http_client)

    # 2. Update/Overwrite parameters for the re-run.
    iterations_to_rerun = waterfall_config.GetSwarmingSettings().get(
        'iterations_to_rerun')
    new_request = CreateNewSwarmingTaskRequest(runner_id, ref_task_id,
                                               ref_request, master_name,
                                               builder_name, build_number,
                                               step_name, tests,
                                               iterations_to_rerun)

    # 3. Trigger a new Swarming task to re-run the failed tests.
    task_id, _ = swarming_util.TriggerSwarmingTask(swarming.SwarmingHost(),
                                                   new_request, http_client)

    if task_id:  # pragma: no branch.
        # 4. Update swarming task.
        OnSwarmingTaskTriggered(master_name, builder_name, build_number,
                                step_name, tests, task_id, iterations_to_rerun,
                                new_request)

    return task_id
Esempio n. 2
0
def TriggerSwarmingTask(master_name, builder_name, reference_build_number,
                        step_name, test_name, isolate_sha, iterations,
                        timeout_seconds, runner_id):
    """Triggers a flake swarming rerun of a test against a given isolate sha.

  Args:
    master_name (str): The name of the master to find a reference task.
    builder_name (str): The name of the builder to find a reference task.
    reference_build_number (int): A representative build number to find a
        reference build.
    step_name (str): The name of the step on which the flaky test lives.
    test_name (str): The name of the test to trigger the swarming task against.
    isolate_sha (str): The location of the compiled binares to trigger a task
        against.
    timeout_seconds (int): The maximum allotted time for the task to complete.
    runner_id (str): The identifier for the caller of this function to post
        pubsub notifications to about task state changes.

  Returns:
    task_id (str): The resulting task id that is triggered on Swarming.
  """
    # 1. Retrieve the reference swarming task with matching configuration of the
    # build that flakiness was first identified in.
    ref_task_id, ref_request = swarming.GetReferredSwarmingTaskRequestInfo(
        master_name, builder_name, reference_build_number, step_name,
        _FINDIT_HTTP_CLIENT)

    # 2. Create a swarming task request from the reference request with desired
    # fields updated.
    new_request = CreateNewSwarmingTaskRequest(runner_id, ref_task_id,
                                               ref_request, master_name,
                                               builder_name, step_name,
                                               test_name, isolate_sha,
                                               iterations, timeout_seconds)

    # 3. Trigger a new swarming task.
    task_id, _ = swarming_util.TriggerSwarmingTask(swarming.SwarmingHost(),
                                                   new_request,
                                                   _FINDIT_HTTP_CLIENT)

    # Monitoring.
    monitoring.OnSwarmingTaskStatusChange('trigger',
                                          'identify-regression-range')

    return task_id
Esempio n. 3
0
    def testTriggerSwarmingTask(self, mock_post):
        task_request_json = {
            'expiration_secs': '72000',
            'name': 'name',
            'parent_task_id': 'pti',
            'priority': '150',
            'properties': {
                'command': 'cmd',
                'dimensions': [{
                    'key': 'd',
                    'value': 'dv'
                }],
                'env': [{
                    'key': 'e',
                    'value': 'ev'
                }],
                'execution_timeout_secs': '4',
                'extra_args': ['--flag'],
                'grace_period_secs': '5',
                'idempotent': True,
                'inputs_ref': {
                    'isolated': 'i'
                },
                'io_timeout_secs': '3',
            },
            'tags':
            ['tag', 'findit:1', 'project:Chromium', 'purpose:post-commit'],
            'user': '******',
            'pubsub_topic': None,
            'pubsub_auth_token': None,
            'pubsub_userdata': None,
        }

        mock_post.return_value = json.dumps({'task_id': '1'}), None

        task_id, error = swarming_util.TriggerSwarmingTask(
            'host', SwarmingTaskRequest.FromSerializable(task_request_json),
            None)
        self.assertEqual('1', task_id)
        self.assertIsNone(error)
Esempio n. 4
0
def TriggerSwarmingTask(request, http_client):
    """Triggers a new Swarming task for the given request.

  The Swarming task priority will be overwritten, and extra tags might be added.
  Args:
    request (SwarmingTaskRequest): A Swarming task request.
    http_client (RetryHttpClient): An http client with automatic retry.
  """
    # Use a priority much lower than CQ for now (CQ's priority is 30).
    # Later we might use a higher priority -- a lower value here.
    # Note: the smaller value, the higher priority.
    swarming_settings = waterfall_config.GetSwarmingSettings()
    request_expiration_hours = swarming_settings.get(
        'request_expiration_hours')
    request.priority = str(
        max(100, swarming_settings.get('default_request_priority')))
    request.expiration_secs = str(request_expiration_hours * 60 * 60)

    request.tags.extend(
        ['findit:1', 'project:Chromium', 'purpose:post-commit'])

    return swarming_util.TriggerSwarmingTask(SwarmingHost(), request,
                                             http_client)
Esempio n. 5
0
 def testTriggerSwarmingTaskError(self, _):
     request = SwarmingTaskRequest.FromSerializable({})
     task_id, error = swarming_util.TriggerSwarmingTask(
         'host', request, None)
     self.assertIsNone(task_id)
     self.assertIsNotNone(error)