blob: 124bbe00bf73bed3a36e4d4c9cf319fac958d53f [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Checks that the main console and subconsole configs are consistent."""
import collections
import difflib
import os
import sys
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
SRC_ROOT = os.path.join(THIS_DIR, '..', '..')
sys.path.insert(1, os.path.join(
SRC_ROOT, "third_party", "protobuf", "python"))
import google.protobuf.text_format
import project_pb2
def compare_builders(name, main_builders, sub_builders):
# Checks that the builders on a subwaterfall on the main waterfall
# are consistent with the builders on that subwaterfall's main page.
# For example, checks that the builders on the "" section
# are the same as on the dedicated standalone waterfall.
def to_list(builders, category_prefix=''):
desc_list = []
for builder in builders:
desc_list.append('name: ' + ', '.join(
# A bot with "|foo|bar" on the main waterfall should have
# a category of "foo|bar" on the "" subwaterfall.
category = builder.category
if category_prefix:
if category:
category = category_prefix + '|' + category
category = category_prefix
desc_list.append('category: ' + category)
desc_list.append('short_name: ' + builder.short_name)
return desc_list
main_desc = to_list(main_builders)
sub_desc = to_list(sub_builders, name)
if main_desc != sub_desc:
print ('bot lists different between main waterfall ' +
'and stand-alone %s waterfall:' % name)
print '\n'.join(difflib.unified_diff(main_desc, sub_desc,
fromfile='main', tofile=name,
return False
return True
def main():
project = project_pb2.Project()
with open(os.path.join(THIS_DIR, 'luci-milo.cfg'), 'rb') as f:
google.protobuf.text_format.Parse(, project)
# Maps subwaterfall name to list of builders on that subwaterfall
# on the main waterfall.
subwaterfalls = collections.defaultdict(list)
for console in project.consoles:
if == 'main':
# Chromium main waterfall console.
for builder in
subwaterfall = builder.category.split('|', 1)[0]
# subwaterfalls contains the waterfalls referenced by the main console
# Check that every referenced subwaterfall has its own console.
all_console_names = set([ for console in project.consoles])
referenced_names = set(subwaterfalls.keys())
missing_names = referenced_names - all_console_names
if missing_names:
print 'Missing subwaterfall console for', missing_names
return 1
# Check that the bots on a subwaterfall match the corresponding bots on the
# main waterfall
all_good = True
for console in project.consoles:
if in subwaterfalls:
if not compare_builders(, subwaterfalls[],
all_good = False
return 0 if all_good else 1
if __name__ == '__main__':