예제 #1
0
def CMDbuilders(parser, args):
    """Prints json-formatted list of builders given a path to cq.cfg file.

  The output is a dictionary in the following format:
    {
      'master_name': [
        'builder_name',
        'another_builder'
      ],
      'another_master': [
        'third_builder'
      ]
    }
  """
    _, args = parser.parse_args(args)
    if len(args) != 1:
        parser.error('Expected a single path to CQ config. Got: %s' %
                     ' '.join(args))

    with open(args[0]) as config_file:
        cq_config = config_file.read()

    config = cq_pb2.Config()
    text_format.Merge(cq_config, config)
    masters = {}
    if config.HasField('verifiers') and config.verifiers.HasField('try_job'):
        for bucket in config.verifiers.try_job.buckets:
            masters.setdefault(bucket.name, [])
            for builder in bucket.builders:
                if not builder.HasField('experiment_percentage'):
                    masters[bucket.name].append(builder.name)
    print json.dumps(masters)
예제 #2
0
def get_master_builder_map(
      config_path, include_experimental=True, include_triggered=True):
  """Returns a map of master -> [builders] from cq config."""
  with open(config_path) as config_file:
    cq_config = config_file.read()

  config = cq_pb2.Config()
  text_format.Merge(cq_config, config)
  masters = {}
  if config.HasField('verifiers') and config.verifiers.HasField('try_job'):
    for bucket in config.verifiers.try_job.buckets:
      masters.setdefault(bucket.name, [])
      for builder in bucket.builders:
        if (not include_experimental and
            builder.HasField('experiment_percentage')):
          continue
        if (not include_triggered and
            builder.HasField('triggered_by')):
          continue
        masters[bucket.name].append(builder.name)
  return masters
예제 #3
0
def CMDvalidate(parser, args):
    """Validates a CQ config, returns 0 on valid config.

  BUGS: this doesn't do semantic validation, only verifies validity of protobuf.
    But don't worry - bad cq.cfg won't cause outages, luci-config service will
    not accept them, will send warning email, and continue using previous
    version.
  """
    _, args = parser.parse_args(args)
    if len(args) != 1:
        parser.error('Expected a single path to CQ config. Got: %s' %
                     ' '.join(args))

    config = cq_pb2.Config()
    try:
        with open(args[0]) as config_file:
            text_config = config_file.read()
        text_format.Merge(text_config, config)
        # TODO(tandrii): provide an option to actually validate semantics of CQ
        # config.
        return 0
    except text_format.ParseError as e:
        print 'failed to parse cq.cfg: %s' % e
        return 1