コード例 #1
0
def _apply_builder_config_async(builder_cfg, build_proto):
    """Applies project_config_pb2.Builder to a builds_pb2.Build."""
    # Decide if the build will be canary.
    canary_percentage = _DEFAULT_CANARY_PERCENTAGE
    if builder_cfg.HasField(  # pragma: no branch
            'task_template_canary_percentage'):
        canary_percentage = builder_cfg.task_template_canary_percentage.value
    build_proto.canary = _should_be_canary(canary_percentage)

    # Populate timeouts.
    build_proto.scheduling_timeout.seconds = builder_cfg.expiration_secs
    if not build_proto.scheduling_timeout.seconds:
        build_proto.scheduling_timeout.FromTimedelta(
            _DEFAULT_SCHEDULING_TIMEOUT)

    build_proto.execution_timeout.seconds = builder_cfg.execution_timeout_secs
    if not build_proto.execution_timeout.seconds:
        build_proto.execution_timeout.FromTimedelta(_DEFAULT_EXECUTION_TIMEOUT)

    # Populate input.
    build_proto.input.properties.update(
        flatten_swarmingcfg.read_properties(builder_cfg.recipe))

    is_prod = yield _is_migrating_builder_prod_async(builder_cfg, build_proto)
    if is_prod is not None:  # pragma: no cover | TODO(nodir): remove branch
        build_proto.input.experimental = not is_prod
    else:
        build_proto.input.experimental = (
            builder_cfg.experimental == project_config_pb2.YES)

    # Populate exe.
    build_proto.exe.CopyFrom(builder_cfg.exe)
    # TODO(nodir): remove builder_cfg.recipe. Use only builder_cfg.exe.
    if builder_cfg.HasField('recipe'):  # pragma: no branch
        build_proto.exe.cipd_package = builder_cfg.recipe.cipd_package
        build_proto.exe.cipd_version = (builder_cfg.recipe.cipd_version
                                        or 'refs/heads/master')
        build_proto.input.properties['recipe'] = builder_cfg.recipe.name
        build_proto.infra.recipe.cipd_package = builder_cfg.recipe.cipd_package
        build_proto.infra.recipe.name = builder_cfg.recipe.name

    # Populate swarming fields.
    sw = build_proto.infra.swarming
    sw.hostname = builder_cfg.swarming_host
    sw.task_service_account = builder_cfg.service_account
    sw.priority = builder_cfg.priority or _DEFAULT_SWARMING_PRIORITY

    for key, vs in swarmingcfg.read_dimensions(builder_cfg).iteritems():
        if vs == {('', 0)}:
            # This is a tombstone left from merging.
            # Skip it.
            continue

        for value, expiration_sec in vs:
            sw.task_dimensions.add(key=key,
                                   value=value,
                                   expiration=dict(seconds=expiration_sec))

    _apply_caches_in_builder_cfg(build_proto, builder_cfg)
コード例 #2
0
    def get_builders(self, request):
        """Returns defined swarmbucket builders.

    Returns legacy bucket names, e.g. "luci.chromium.try", not "chromium/try".

    Can be used to discover builders.
    """
        if len(request.bucket) > 100:
            raise endpoints.BadRequestException(
                'Number of buckets cannot be greater than 100')
        if request.bucket:
            # Buckets were specified explicitly.
            bucket_ids = map(api_common.parse_luci_bucket, request.bucket)
            bucket_ids = [bid for bid in bucket_ids if bid]
            # Filter out inaccessible ones.
            bids_can = utils.async_apply(bucket_ids,
                                         user.can_access_bucket_async)
            bucket_ids = [bid for bid, can in bids_can if can]
        else:
            # Buckets were not specified explicitly.
            # Use the available ones.
            bucket_ids = user.get_accessible_buckets_async().get_result()
            # bucket_ids is None => all buckets are available.

        res = GetBuildersResponseMessage()
        buckets = config.get_buckets_async(bucket_ids).get_result()
        for bucket_id, cfg in buckets.iteritems():
            if not cfg or not cfg.swarming.builders:
                continue

            def to_dims(b):
                return flatten_swarmingcfg.format_dimensions(
                    swarmingcfg.read_dimensions(b))

            res.buckets.append(
                BucketMessage(
                    name=api_common.format_luci_bucket(bucket_id),
                    builders=[
                        BuilderMessage(name=builder.name,
                                       category=builder.category,
                                       properties_json=json.dumps(
                                           flatten_swarmingcfg.read_properties(
                                               builder.recipe)),
                                       swarming_hostname=builder.swarming_host,
                                       swarming_dimensions=to_dims(builder))
                        for builder in cfg.swarming.builders
                    ],
                    swarming_hostname=cfg.swarming.hostname,
                ))
        return res
コード例 #3
0
def _is_migrating_builder_prod_async(
        builder_cfg,
        build_proto):  # pragma: no cover | TODO(nodir): delete this code
    """Returns True if the builder is prod according to the migration app.

  See also 'luci_migration_host' in the project config.

  If unknown, returns None.
  On failures, logs them and returns None.

  TODO(nodir): remove this function when Buildbot is turned down.
  """
    ret = None

    master = None
    props_list = (
        build_proto.input.properties,
        bbutil.dict_to_struct(
            flatten_swarmingcfg.read_properties(builder_cfg.recipe)),
    )
    for prop_name in ('luci_migration_master_name', 'mastername'):
        for props in props_list:
            if prop_name in props:
                master = props[prop_name]
                break
        if master:  # pragma: no branch
            break

    host = _clear_dash(builder_cfg.luci_migration_host)
    if master and host:
        try:
            url = 'https://%s/masters/%s/builders/%s/' % (host, master,
                                                          builder_cfg.name)
            res = yield net.json_request_async(url,
                                               params={'format': 'json'},
                                               scopes=net.EMAIL_SCOPE)
            ret = res.get('luci_is_prod')
        except net.NotFoundError:
            logging.warning('missing migration status for %r/%r', master,
                            builder_cfg.name)
        except net.Error:
            logging.exception('failed to get migration status for %r/%r',
                              master, builder_cfg.name)
    raise ndb.Return(ret)