예제 #1
0
    def __call__(self, _):
        logging.debug('Scheduling a Swarming task to run a test.')
        self.properties.update(run_test_quest.VPYTHON_PARAMS)
        body = {
            'name':
            'Pinpoint job',
            'user':
            '******',
            # TODO(dberris): Make these constants configurable?
            'priority':
            '100',
            'task_slices': [{
                'properties': self.properties,
                'expiration_secs': '86400',  # 1 day.
            }],

            # Since we're always going to be using the PubSub handling, we add the
            # tags unconditionally.
            'tags': [
                '%s:%s' % (k, v) for k, v in
                run_test_quest.SwarmingTagsFromJob(self.job).items()
            ],

            # TODO(dberris): Consolidate constants in environment vars?
            'pubsub_topic':
            'projects/chromeperf/topics/pinpoint-swarming-updates',
            'pubsub_auth_token':
            'UNUSED',
            'pubsub_userdata':
            json.dumps({
                'job_id': self.job.job_id,
                'task': {
                    'type': 'run_test',
                    'id': self.task.id,
                },
            }),
        }
        self.task.payload.update({
            'swarming_request_body': body,
        })

        # At this point we know we were successful in transitioning to 'ongoing'.
        # TODO(dberris): Figure out error-handling for Swarming request failures?
        response = swarming.Swarming(
            self.task.payload.get('swarming_server')).Tasks().New(body)
        logging.debug('Swarming response: %s', response)
        self.task.payload.update({
            'swarming_task_id': response.get('task_id'),
            'tries': self.task.payload.get('tries', 0) + 1
        })

        # Update the payload with the task id from the Swarming request.
        task_module.UpdateTask(self.job,
                               self.task.id,
                               new_state='ongoing',
                               payload=self.task.payload)
예제 #2
0
    def __call__(self, _):
        logging.debug('Scheduling a Swarming task to run a test.')
        body = {
            'name':
            'Pinpoint job',
            'user':
            '******',
            # TODO(dberris): Make these constants configurable?
            'priority':
            '100',
            'task_slices': [{
                'properties': self.properties,
                'expiration_secs': '86400',  # 1 day.
            }],

            # Since we're always going to be using the PubSub handling, we add the
            # tags unconditionally.
            'tags': [
                '%s:%s' % (k, v) for k, v in
                run_test_quest.SwarmingTagsFromJob(self.job).items()
            ],

            # Use an explicit service account.
            'service_account':
            run_test_quest._TESTER_SERVICE_ACCOUNT,

            # TODO(dberris): Consolidate constants in environment vars?
            'pubsub_topic':
            'projects/chromeperf/topics/pinpoint-swarming-updates',
            'pubsub_auth_token':
            'UNUSED',
            'pubsub_userdata':
            json.dumps({
                'job_id': self.job.job_id,
                'task': {
                    'type': 'run_test',
                    'id': self.task.id,
                },
            }),
        }
        self.task.payload.update({
            'swarming_request_body': body,
        })

        # Ensure that this thread/process/handler is the first to mark this task
        # 'ongoing'. Only proceed in scheduling a Swarming request if we're the
        # first one to do so.
        task_module.UpdateTask(self.job,
                               self.task.id,
                               new_state='ongoing',
                               payload=self.task.payload)

        # At this point we know we were successful in transitioning to 'ongoing'.
        try:
            response = swarming.Swarming(
                self.task.payload.get('swarming_server')).Tasks().New(body)
            self.task.payload.update({
                'swarming_task_id':
                response.get('task_id'),
                'tries':
                self.task.payload.get('tries', 0) + 1
            })
        except request.RequestError as e:
            self.task.payload.update({
                'errors':
                self.task.payload.get('errors', []) + [{
                    'reason':
                    type(e).__name__,
                    'message':
                    'Encountered failure in swarming request: %s' % (e, ),
                }]
            })

        # Update the payload with the task id from the Swarming request. Note that
        # this could also fail to commit.
        task_module.UpdateTask(self.job,
                               self.task.id,
                               payload=self.task.payload)