Beispiel #1
0
  def _PutConfigToBuildBucket(self, buildbucket_client, dryrun):
    """Put the tryjob request to buildbucket.

    Args:
      buildbucket_client: The buildbucket client instance.
      dryrun: bool controlling dryrun behavior.

    Returns:
      ScheduledBuild describing the scheduled build.

    Raises:
      RemoteRequestFailure.
    """
    request_body = self._GetRequestBody()
    content = buildbucket_client.PutBuildRequest(
        json.dumps(request_body), dryrun)

    if buildbucket_lib.GetNestedAttr(content, ['error']):
      raise RemoteRequestFailure(
          'buildbucket error.\nReason: %s\n Message: %s' %
          (buildbucket_lib.GetErrorReason(content),
           buildbucket_lib.GetErrorMessage(content)))

    buildbucket_id = buildbucket_lib.GetBuildId(content)
    url = TryJobUrl(buildbucket_id)
    created_ts = buildbucket_lib.GetBuildCreated_ts(content)

    result = ScheduledBuild(buildbucket_id, self.build_config, url, created_ts)

    logging.info(self.BUILDBUCKET_PUT_RESP_FORMAT, result)

    return result
    def testRetryBuildRequest(self):
        """Test RetryBuild."""
        buildbucket_id = '001'
        buildbucket_id_2 = '002'

        content = json.dumps({
            'build': {
                'status': 'SCHEDULED',
                'id': buildbucket_id_2,
                'retry_of': buildbucket_id
            }
        })

        self.mock_http.request.return_value = (self.success_response, content)
        result_content = self.client.RetryBuildRequest(buildbucket_id, False)
        self.assertEqual(buildbucket_lib.GetBuildId(result_content),
                         buildbucket_id_2)

        reason = 'BUILD_NOT_FOUND'
        message = 'Build 001 not found'
        content = json.dumps({'error': {'message': message, 'reason': reason}})

        self.mock_http.request.return_value = (self.success_response, content)
        result_content = self.client.RetryBuildRequest(buildbucket_id, False)
        self.assertEqual(buildbucket_lib.GetErrorReason(result_content),
                         reason)
        self.assertEqual(buildbucket_lib.GetErrorMessage(result_content),
                         message)

        # Test dryrun
        result_content = self.client.RetryBuildRequest(buildbucket_id, True)
        self.assertIsNone(result_content)
Beispiel #3
0
    def _RetryBuilds(self, builds):
        """Retry builds with Buildbucket.

    Args:
      builds: config names of the builds to retry with Buildbucket.

    Returns:
      A set of retried builds.
    """
        assert builds is not None

        new_scheduled_important_slaves = []
        new_scheduled_build_reqs = []
        for build in builds:
            try:
                buildbucket_id = self.new_buildbucket_info_dict[
                    build].buildbucket_id
                build_retry = self.new_buildbucket_info_dict[build].retry

                logging.info(
                    'Going to retry build %s buildbucket_id %s '
                    'with retry # %d', build, buildbucket_id, build_retry + 1)

                if not self.dry_run:
                    fields = {
                        'build_type': self.config.build_type,
                        'build_name': self.config.name
                    }
                    metrics.Counter(
                        constants.MON_BB_RETRY_BUILD_COUNT).increment(
                            fields=fields)

                content = self.buildbucket_client.RetryBuildRequest(
                    buildbucket_id, dryrun=self.dry_run)

                new_buildbucket_id = buildbucket_lib.GetBuildId(content)
                new_created_ts = buildbucket_lib.GetBuildCreated_ts(content)

                new_scheduled_important_slaves.append(
                    (build, new_buildbucket_id, new_created_ts))
                new_scheduled_build_reqs.append(
                    build_requests.BuildRequest(
                        None, self.master_build_id, build, None,
                        new_buildbucket_id,
                        build_requests.REASON_IMPORTANT_CQ_SLAVE, None))

                logging.info(
                    'Retried build %s buildbucket_id %s created_ts %s', build,
                    new_buildbucket_id, new_created_ts)
            except buildbucket_lib.BuildbucketResponseException as e:
                logging.error('Failed to retry build %s buildbucket_id %s: %s',
                              build, buildbucket_id, e)

        if new_scheduled_important_slaves:
            self.metadata.ExtendKeyListWithList(
                constants.METADATA_SCHEDULED_IMPORTANT_SLAVES,
                new_scheduled_important_slaves)

        return set([build for build, _, _ in new_scheduled_important_slaves])
Beispiel #4
0
  def PostSlaveBuildToBuildbucket(self, build_name, build_config,
                                  master_build_id, master_buildbucket_id,
                                  buildset_tag, dryrun=False):
    """Send a Put slave build request to Buildbucket.

    Args:
      build_name: Salve build name to put to Buildbucket.
      build_config: Slave build config to put to Buildbucket.
      master_build_id: CIDB id of the master scheduling the slave build.
      master_buildbucket_id: buildbucket id of the master scheduling the
                             slave build.
      buildset_tag: The buildset tag for strong consistent tag queries.
                    More context: crbug.com/661689
      dryrun: Whether a dryrun, default to False.
    """
    current_buildername = os.environ.get('BUILDBOT_BUILDERNAME', None)
    builder_name = BuilderName(
        build_name, build_config.active_waterfall, current_buildername)

    # TODO: Find a way to unify these tags with
    #       remote_try._GetRequestBody
    tags = ['buildset:%s' % buildset_tag,
            'build_type:%s' % build_config.build_type,
            'master:False',
            'master_config:%s' % self._run.config.name,
            'cbb_display_label:%s' % build_config.display_label,
            'cbb_branch:%s' % self._run.manifest_branch,
            'cbb_config:%s' % build_name,
            'cbb_master_build_id:%s' % master_build_id,
            'cbb_master_buildbucket_id:%s' % master_buildbucket_id,
            'cbb_email:']

    if build_config.boards:
      for board in build_config.boards:
        tags.append('board:%s' % board)

    body = json.dumps({
        'bucket': self._GetBuildbucketBucket(build_name, build_config),
        'parameters_json': json.dumps({
            'builder_name': builder_name,
            'properties': {
                'cbb_config': build_name,
                'cbb_branch': self._run.manifest_branch,
                'cbb_master_build_id': master_build_id,
            }
        }),
        'tags': tags
    })

    content = self.buildbucket_client.PutBuildRequest(body, dryrun)

    buildbucket_id = buildbucket_lib.GetBuildId(content)
    created_ts = buildbucket_lib.GetBuildCreated_ts(content)

    logging.info('Build_name %s buildbucket_id %s created_timestamp %s',
                 build_name, buildbucket_id, created_ts)

    return (buildbucket_id, created_ts)
    def testPutBuildRequest(self):
        """Test PutBuildRequest."""
        buildbucket_id = 'test_buildbucket_id'
        content = json.dumps({'build': {'id': buildbucket_id}})
        self.mock_http.request.return_value = (self.success_response, content)

        body = json.dumps({
            'bucket': 'test-bucket',
        })

        result_content = self.client.PutBuildRequest(body, False)
        self.assertEqual(buildbucket_lib.GetBuildId(result_content),
                         buildbucket_id)

        # Test dryrun
        result_content_2 = self.client.PutBuildRequest(body, True)
        self.assertIsNone(result_content_2)