示例#1
0
    def get(self, job_id):
        try:
            job = job_module.JobFromId(job_id)
            if not job:
                raise results2.Results2Error('Error: Unknown job %s' % job_id)

            if not job.completed:
                self.response.out.write(
                    json.dumps({'status': 'job-incomplete'}))
                return

            url = results2.GetCachedResults2(job)
            if url:
                self.response.out.write(
                    json.dumps({
                        'status': 'complete',
                        'url': url,
                        'updated': job.updated.isoformat(),
                    }))
                return

            if results2.ScheduleResults2Generation(job):
                self.response.out.write(json.dumps({'status': 'pending'}))
                return

            self.response.out.write(json.dumps({'status': 'failed'}))

        except results2.Results2Error as e:
            self.response.set_status(400)
            self.response.out.write(e.message)
示例#2
0
def _ProcessJob(job_id, queue_status, configuration):
  job = job_model.JobFromId(job_id)
  if not job:
    logging.error('Failed to load job with id: %s', job_id)
    scheduler.Remove(configuration, job_id)
    return False

  logging.info('Job "%s" status: "%s" queue: "%s"', job_id, job.status,
               configuration)

  if queue_status == 'Running':
    if job.status in {'Failed', 'Completed'}:
      scheduler.Complete(job)
      return True  # Continue processing this queue.

  if queue_status == 'Queued':
    job.Start()
    # TODO(dberris): Remove this when the execution engine is the default.
    if job.use_execution_engine:
      logging.info(
          'Skipping Job that uses the experimental execution engine: %s (%s)',
          job.job_id, job.url)
      scheduler.Complete(job)

  return False
示例#3
0
  def Post(self):
    # Pull out the Job ID and reason in the request.
    args = self.request.params.mixed()
    job_id = args.get('job_id')
    reason = args.get('reason')
    if not job_id or not reason:
      raise api_request_handler.BadRequestError()

    job = job_module.JobFromId(job_id)
    if not job:
      raise api_request_handler.NotFoundError()

    # Enforce first that only the users that started the job and administrators
    # can cancel jobs.
    email = utils.GetEmail()
    if not utils.IsAdministrator() and email != job.user:
      raise api_request_handler.ForbiddenError()

    # Truncate the reason down to 255 caracters including ellipses.
    try:
      job.Cancel(email, reason[:252] + '...' if len(reason) > 255 else reason)
      return {'job_id': job.job_id, 'state': 'Cancelled'}
    except errors.CancelError as e:
      self.response.set_status(400)
      return {'job_id': job.job_id, 'message': e.message}
示例#4
0
 def testPost_UserFromParams(self):
     request = dict(_BASE_REQUEST)
     request['user'] = '******'
     response = self.testapp.post('/api/new', request, status=200)
     result = json.loads(response.body)
     job = job_module.JobFromId(result['jobId'])
     self.assertEqual(job.user, '*****@*****.**')
示例#5
0
def _GetJobData(job_id):
  job = job_module.JobFromId(job_id)
  if not job:
    raise Results2Error('Error: Job %s missing' % job_id)

  job_data = job.AsDict()
  return job_data
示例#6
0
    def testPin(self):
        request = dict(_BASE_REQUEST)
        request['pin'] = 'https://codereview.com/c/foo/bar/+/123'

        response = self.Post('/api/new', request, status=200)
        job = job_module.JobFromId(json.loads(response.body)['jobId'])
        self.assertEqual(job.state._pin, change_test.Change(patch=True))
示例#7
0
    def testWithPatch(self):
        request = dict(_BASE_REQUEST)
        request['patch'] = 'https://lalala/c/foo/bar/+/123'

        response = self.Post('/api/new', request, status=200)
        job = job_module.JobFromId(json.loads(response.body)['jobId'])
        self.assertEqual('https://lalala', job.gerrit_server)
        self.assertEqual('repo~branch~id', job.gerrit_change_id)
示例#8
0
 def testComparisonModeFunctional(self):
     request = dict(_BASE_REQUEST)
     request['comparison_mode'] = 'functional'
     response = self.testapp.post('/api/new', request, status=200)
     result = json.loads(response.body)
     self.assertIn('jobId', result)
     job = job_module.JobFromId(result['jobId'])
     self.assertEqual(job.state.comparison_mode, 'functional')
示例#9
0
 def testComparisonMagnitude(self):
     request = dict(_BASE_REQUEST)
     request['comparison_magnitude'] = '123.456'
     response = self.Post('/api/new', request, status=200)
     result = json.loads(response.body)
     self.assertIn('jobId', result)
     job = job_module.JobFromId(result['jobId'])
     self.assertEqual(job.state._comparison_magnitude, 123.456)
示例#10
0
 def testComparisonModeTry(self):
     request = dict(_BASE_REQUEST)
     request['comparison_mode'] = 'try'
     response = self.Post('/api/new', request, status=200)
     job = job_module.JobFromId(json.loads(response.body)['jobId'])
     self.assertEqual(job.comparison_mode, 'try')
     self.assertEqual(job.state._changes[0].id_string, 'chromium@3')
     self.assertEqual(job.state._changes[1].id_string, 'chromium@3')
示例#11
0
 def testAutoExploreTrue(self):
     request = dict(_BASE_REQUEST)
     request['auto_explore'] = True
     response = self.testapp.post('/api/new', request, status=200)
     result = json.loads(response.body)
     self.assertIn('jobId', result)
     job = job_module.JobFromId(result['jobId'])
     self.assertTrue(job.auto_explore)
示例#12
0
 def testBrowserOverride(self):
   request = dict(_BASE_REQUEST)
   request['browser'] = 'debug'
   response = self.Post('/api/new', request, status=200)
   job = job_module.JobFromId(json.loads(response.body)['jobId'])
   self.assertIsInstance(job.state._quests[1], quest_module.RunTelemetryTest)
   self.assertIn('debug', job.state._quests[1]._extra_args)
   self.assertNotIn('release', job.state._quests[1]._extra_args)
示例#13
0
 def testQuestsString(self):
   request = dict(_BASE_REQUEST)
   request['quests'] = 'FindIsolate,RunTelemetryTest'
   response = self.Post('/api/new', request, status=200)
   job = job_module.JobFromId(json.loads(response.body)['jobId'])
   self.assertEqual(len(job.state._quests), 2)
   self.assertIsInstance(job.state._quests[0], quest_module.FindIsolate)
   self.assertIsInstance(job.state._quests[1], quest_module.RunTelemetryTest)
示例#14
0
 def post(self, job_id):
   try:
     job = job_module.JobFromId(job_id)
     if not job:
       raise results2.Results2Error('Error: Unknown job %s' % job_id)
     results2.GenerateResults2(job)
   except results2.Results2Error as e:
     self.response.out.write(e.message)
示例#15
0
 def testComparisonModePerformance(self):
   request = dict(_BASE_REQUEST)
   request['comparison_mode'] = 'performance'
   response = self.Post('/api/new', request, status=200)
   result = json.loads(response.body)
   self.assertIn('jobId', result)
   job = job_module.JobFromId(result['jobId'])
   self.assertEqual(job.state.comparison_mode, 'performance')
示例#16
0
 def testPost_AutoExploreTrue(self):
     params = {}
     params.update(_BASE_REQUEST)
     params['auto_explore'] = True
     response = self.testapp.post('/api/new', params, status=200)
     result = json.loads(response.body)
     self.assertIn('jobId', result)
     job = job_module.JobFromId(result['jobId'])
     self.assertTrue(job.auto_explore)
示例#17
0
 def testCancelCancelledJob(self):
     job = job_module.Job.New((), (), user='******')
     scheduler.Schedule(job)
     self.Post('/api/job/cancel', {
         'job_id': job.job_id,
         'reason': 'testing!'
     },
               status=200)
     job = job_module.JobFromId(job.job_id)
     self.assertTrue(job.cancelled)
     self.assertIn('[email protected]: testing!', job.cancel_reason)
     self.Post('/api/job/cancel', {
         'job_id': job.job_id,
         'reason': 'cancelling again!'
     },
               status=400)
     job = job_module.JobFromId(job.job_id)
     self.assertTrue(job.cancelled)
     self.assertIn('[email protected]: testing!', job.cancel_reason)
示例#18
0
 def testCancelUnknownJob(self):
     job = job_module.Job.New((), (), user='******')
     scheduler.Schedule(job)
     self.addCleanup(scheduler.Cancel, job)
     self.Post('/api/job/cancel', {
         'job_id': job.job_id + '1',
         'reason': 'testing!'
     },
               status=404)
     job = job_module.JobFromId(job.job_id + '1')
     self.assertIsNone(job)
示例#19
0
文件: run.py 项目: zloop1982/catapult
 def post(self, job_id):
     job = job_module.JobFromId(job_id)
     if job.use_execution_engine:
         event = event_module.Event(type='initiate',
                                    target_task=None,
                                    payload={})
         logging.info('Execution Engine: Evaluating initiate event.')
         task_module.Evaluate(job, event, evaluator.ExecutionEngine(job))
         logging.info('Execution Engine: Evaluation done.')
     else:
         job.Run()
示例#20
0
 def testComparisonModeTry_ApplyPatch(self):
     request = dict(_BASE_REQUEST)
     request['comparison_mode'] = 'try'
     request['patch'] = 'https://lalala/c/foo/bar/+/123'
     response = self.Post('/api/new', request, status=200)
     job = job_module.JobFromId(json.loads(response.body)['jobId'])
     self.assertEqual(job.comparison_mode, 'try')
     self.assertEqual(job.state._changes[0].id_string, 'chromium@3')
     self.assertEqual(
         job.state._changes[1].id_string,
         'chromium@3 + %s' % ('https://lalala/repo~branch~id/abc123', ))
示例#21
0
 def testPost_EmptyBug(self):
     request = dict(_BASE_REQUEST)
     request['bug_id'] = ''
     response = self.testapp.post('/api/new', request, status=200)
     result = json.loads(response.body)
     self.assertIn('jobId', result)
     self.assertEqual(
         result['jobUrl'],
         'https://testbed.example.com/job/%s' % result['jobId'])
     job = job_module.JobFromId(result['jobId'])
     self.assertIsNone(job.bug_id)
示例#22
0
 def testVrQuest(self):
   request = dict(_BASE_REQUEST)
   request['target'] = 'vr_perf_tests'
   configuration = dict(_CONFIGURATION_ARGUMENTS)
   configuration['browser'] = 'android-chromium-bundle'
   request.update(configuration)
   del request['configuration']
   response = self.Post('/api/new', request, status=200)
   job = job_module.JobFromId(json.loads(response.body)['jobId'])
   self.assertEqual(len(job.state._quests), 3)
   self.assertIsInstance(job.state._quests[0], quest_module.FindIsolate)
   self.assertIsInstance(job.state._quests[1], quest_module.RunVrTelemetryTest)
   self.assertIsInstance(job.state._quests[2], quest_module.ReadValue)
示例#23
0
 def testCancelKnownJobByAdmin(self):
   job = job_module.Job.New((), (), user='******', bug_id=123)
   scheduler.Schedule(job)
   self.Post(
       '/api/job/cancel', {
           'job_id': job.job_id,
           'reason': 'testing!'
       },
       status=200)
   job = job_module.JobFromId(job.job_id)
   self.assertTrue(job.cancelled)
   self.assertIn('[email protected]: testing!', job.cancel_reason)
   self.ExecuteDeferredTasks('default')
   self.assertTrue(self.add_bug_comment.called)
示例#24
0
 def testPost_AutoExploreTrue(self, mock_commit_range):
   mock_commit_range.return_value = [
       {'commit': '1'},
       {'commit': '2'},
       {'commit': '3'},
   ]
   params = {}
   params.update(_BASE_REQUEST)
   params['auto_explore'] = True
   response = self.testapp.post('/api/new', params, status=200)
   result = json.loads(response.body)
   self.assertIn('jobId', result)
   job = job_module.JobFromId(result['jobId'])
   self.assertTrue(job.auto_explore)
示例#25
0
    def get(self, job_id):
        # Validate parameters.
        try:
            job = job_module.JobFromId(job_id)
        except:  # pylint: disable=bare-except
            # There's no narrower exception we can catch. Catching
            # google.net.proto.ProtocolBuffer.ProtocolBufferDecodeError
            # doesn't appear to work here.
            # https://github.com/googlecloudplatform/datastore-ndb-python/issues/143
            self.response.write('Unknown job id.')
            return

        # Generate an excellent Polymer UI.
        # TODO: This.
        del job
示例#26
0
    def post(self, job_id):
        job = job_module.JobFromId(job_id)

        # Run task.
        # TODO: Do.
        if True:
            return

        # Schedule moar task.
        task = taskqueue.add(queue_name='job-queue',
                             target='pinpoint',
                             url='/run/' + job_id,
                             countdown=60)
        job.task = task.name
        job.put()
示例#27
0
  def testWithPatch(self, mock_patch):
    mock_patch.return_value = patch_module.GerritPatch(
        'https://lalala', '123', None)
    request = dict(_BASE_REQUEST)
    request['patch'] = 'https://lalala/c/foo/bar/+/123'

    response = self.Post('/api/new', request, status=200)
    result = json.loads(response.body)
    self.assertIn('jobId', result)
    self.assertEqual(
        result['jobUrl'],
        'https://testbed.example.com/job/%s' % result['jobId'])
    mock_patch.assert_called_with(request['patch'])
    job = job_module.JobFromId(result['jobId'])
    self.assertEqual('123', job.gerrit_change_id)
    self.assertEqual('https://lalala', job.gerrit_server)
示例#28
0
 def testNewHasBenchmarkArgs(self):
     request = dict(_BASE_REQUEST)
     request.update({
         'chart': 'some_chart',
         'story': 'some_story',
         'story_tags': 'some_tag,some_other_tag'
     })
     response = self.Post('/api/new', request, status=200)
     job = job_module.JobFromId(json.loads(response.body)['jobId'])
     self.assertIsNotNone(job.benchmark_arguments)
     self.assertEqual('speedometer', job.benchmark_arguments.benchmark)
     self.assertEqual('some_story', job.benchmark_arguments.story)
     self.assertEqual('some_tag,some_other_tag',
                      job.benchmark_arguments.story_tags)
     self.assertEqual('some_chart', job.benchmark_arguments.chart)
     self.assertEqual(None, job.benchmark_arguments.statistic)
示例#29
0
  def get(self, job_id):
    # Validate parameters.
    try:
      job = job_module.JobFromId(job_id)
    except ValueError:
      self.response.set_status(400)
      self.response.write(json.dumps({'error': 'Invalid job id.'}))
      return

    if not job:
      self.response.set_status(404)
      self.response.write(json.dumps({'error': 'Unknown job id.'}))
      return

    opts = self.request.get_all('o')
    self.response.write(json.dumps(job.AsDict(opts)))
示例#30
0
    def post(self):
        job_id = self.request.get('job_id')

        # Validate parameters.
        try:
            job = job_module.JobFromId(job_id)
        except Exception as e:  # pylint: disable=broad-except
            # Catching google.net.proto.ProtocolBuffer.ProtocolBufferDecodeError
            # directly doesn't work.
            # https://github.com/googlecloudplatform/datastore-ndb-python/issues/143
            if e.__class__.__name__ == 'ProtocolBufferDecodeError':
                self.response.write(json.dumps({'error': 'Unknown job id.'}))
                return
            raise

        self.response.write(json.dumps({'data': job.AsDict()}))