Exemplo n.º 1
0
 def testTriggerTryJobsRequestFailure(self, mocked_fetch):
   response = 'Not Found'
   try_job = buildbucket_client.TryJob('m', 'b', {}, [], {})
   mocked_fetch.return_value = _Result(
       status_code=404, content=response, headers={})
   results = buildbucket_client.TriggerTryJobs([try_job])
   self.assertEqual(1, len(results))
   error, build = results[0]
   self.assertIsNotNone(error)
   self.assertEqual(404, error.reason)
   self.assertEqual('Not Found', error.message)
   self.assertIsNone(build)
 def testTriggerTryJobsRequestFailure(self):
     response = 'Not Found'
     try_job = buildbucket_client.TryJob('m', 'b', 'r', {}, [], {})
     self._MockUrlFetch(None, json.dumps(try_job.ToBuildbucketRequest()),
                        response, 404)
     results = buildbucket_client.TriggerTryJobs([try_job])
     self.assertEqual(1, len(results))
     error, build = results[0]
     self.assertIsNotNone(error)
     self.assertEqual(404, error.reason)
     self.assertEqual('Not Found', error.message)
     self.assertIsNone(build)
Exemplo n.º 3
0
def TriggerBuildAhead(wf_master, wf_builder, bot):
    """Starts a ToT compile tryjob on `bot`, in the appropriate cache.

  This function creates a request for a tryjob as similar as possible to what a
  compile failure analysis would be, except it does it at the most recent
  revision, and without specifying a target or a callback.

  Args:
    wf_master: The main waterfall master.
    wf_builder: The main waterfall builder whose configuration we want to match.
    bot: The 'id' dimension of the particular swarming bot that should run this.
  Returns:
    (buildbucket_client.BuildbucketError, buildbucket_client.BuildbucketBuild)
    The second element of the tuple can be used to get the buildbucket id, and
    later query the status of the job by calling buildbucket_client.GetTryjobs.
  """
    cache_name = swarmbot_util.GetCacheName(wf_master, wf_builder)
    recipe = 'findit/chromium/compile'
    dimensions = try_job_service.GetTrybotDimensions(wf_master, wf_builder)
    if bot:
        dimensions = try_job_service.MergeDimensions(dimensions,
                                                     ['id:%s' % bot])
    master_name, builder_name = try_job_service.GetTrybot()
    # By setting the revisions to (HEAD~1, HEAD), we get the findit compile recipe
    # to do a build at the tip of the tree without adding any special cases to the
    # recipe.
    good_revision = 'HEAD~1'
    bad_revision = 'HEAD'

    build_ahead_tryjob = buildbucket_client.TryJob(
        master_name=master_name,
        builder_name=builder_name,
        properties={
            'recipe': recipe,
            'bad_revision': bad_revision,
            'good_revision': good_revision,
            'target_mastername': wf_master,
            'target_buildername': wf_builder,
            # Setting this explicitly for backwards compatibility with pre-luci
            # recipe code, which may expect it to be set.
            'mastername': master_name,
            'suspected_revisions': [],
        },
        tags=[],
        cache_name=cache_name,
        dimensions=dimensions,
        priority=BUILD_AHEAD_PRIORITY,
        expiration_secs=BUILD_AHEAD_EXPIRATION_SECS,
    )
    return buildbucket_client.TriggerTryJobs([build_ahead_tryjob])[0]
 def testTriggerTryJobsFailure(self):
     response = {
         'error': {
             'reason': 'error',
             'message': 'message',
         }
     }
     try_job = buildbucket_client.TryJob('m', 'b', 'r', {}, [], {})
     self._MockUrlFetch(None, json.dumps(try_job.ToBuildbucketRequest()),
                        json.dumps(response))
     results = buildbucket_client.TriggerTryJobs([try_job])
     self.assertEqual(1, len(results))
     error, build = results[0]
     self.assertIsNotNone(error)
     self.assertEqual('error', error.reason)
     self.assertEqual('message', error.message)
     self.assertIsNone(build)
Exemplo n.º 5
0
 def testTriggerTryJobsFailure(self, mocked_fetch):
   response = {
       'error': {
           'reason': 'error',
           'message': 'message',
       }
   }
   try_job = buildbucket_client.TryJob('m', 'b', {}, [], {})
   mocked_fetch.return_value = _Result(
       status_code=200, content=json.dumps(response), headers={})
   results = buildbucket_client.TriggerTryJobs([try_job])
   self.assertEqual(1, len(results))
   error, build = results[0]
   self.assertIsNotNone(error)
   self.assertEqual('error', error.reason)
   self.assertEqual('message', error.message)
   self.assertIsNone(build)
 def testTriggerTryJobsSuccess(self):
     response = {
         'build': {
             'id': '1',
             'url': 'url',
             'status': 'SCHEDULED',
         }
     }
     try_job = buildbucket_client.TryJob('m', 'b', 'r', {'a': 'b'}, [], {})
     self._MockUrlFetch(None, json.dumps(try_job.ToBuildbucketRequest()),
                        json.dumps(response))
     results = buildbucket_client.TriggerTryJobs([try_job])
     self.assertEqual(1, len(results))
     error, build = results[0]
     self.assertIsNone(error)
     self.assertIsNotNone(build)
     self.assertEqual('1', build.id)
     self.assertEqual('url', build.url)
     self.assertEqual('SCHEDULED', build.status)
Exemplo n.º 7
0
 def testTriggerTryJobsSuccess(self, mocked_fetch):
   response = {
       'build': {
           'id': '1',
           'url': 'url',
           'status': 'SCHEDULED',
       }
   }
   try_job = buildbucket_client.TryJob('m', 'b', {'a': 'b'}, [], {})
   mocked_fetch.return_value = _Result(
       status_code=200, content=json.dumps(response), headers={})
   results = buildbucket_client.TriggerTryJobs([try_job])
   self.assertEqual(1, len(results))
   error, build = results[0]
   self.assertIsNone(error)
   self.assertIsNotNone(build)
   self.assertEqual('1', build.id)
   self.assertEqual('url', build.url)
   self.assertEqual('SCHEDULED', build.status)
Exemplo n.º 8
0
    def _TriggerTryJob(self, master_name, builder_name, properties,
                       additional_parameters, try_job_type, cache_name,
                       dimensions):

        tryserver_mastername, tryserver_buildername = self._GetTrybot(
            master_name, builder_name)

        try_job = buildbucket_client.TryJob(tryserver_mastername,
                                            tryserver_buildername, None,
                                            properties, [],
                                            additional_parameters, cache_name,
                                            dimensions)
        error, build = buildbucket_client.TriggerTryJobs([try_job])[0]

        self._OnTryJobTriggered(try_job_type, master_name, builder_name)

        if error:  # pragma: no cover
            raise pipeline.Retry('Error "%s" occurred. Reason: "%s"' %
                                 (error.message, error.reason))

        return build.id
Exemplo n.º 9
0
def TriggerTryJob(master_name, builder_name, tryserver_mastername,
                  tryserver_buildername, properties, try_job_type, cache_name,
                  dimensions, runner_id):
    """Triggers a try job through Buildbucket.

  Args:
    master_name (str): Name of the target master on Waterfall.
    builder_name (str): Name of the target builder/tester on Waterfall.
    tryserver_mastername (str): Name of the tryserver master for the try job.
    tryserver_buildername (str): Name of the tryserver builder for the try job.
    properties (dict): A key-value map of build properties for the try job.
    try_job_type (int): Type of the try job, either compile or test.
    cache_name (str): The name of the build cache.
    dimensions ([str]): The bot dimensions used to allocate a Swarming bot.
    runner_id (str): The id of the runner to trigger this try job. One runner
      could trigger only one try job.
  """

    # This could be a bucket name. Recipe code should use 'target_mastername' to
    # configure the recipe, 'mastername' may still be used by some code paths and
    # bucket is the logical successor to mastername.
    properties['mastername'] = tryserver_mastername

    try_job = buildbucket_client.TryJob(tryserver_mastername,
                                        tryserver_buildername, properties, [],
                                        cache_name, dimensions,
                                        CreatePubSubCallback(runner_id))
    swarmbot_util.AssignWarmCacheHost(try_job, cache_name, FinditHttpClient())
    error, build = buildbucket_client.TriggerTryJobs([try_job])[0]

    monitoring.OnTryJobTriggered(try_job_type, master_name, builder_name)

    if error:
        return None, error

    return build.id, None