Commit 4f3e9215 authored by Garrett Beaty's avatar Garrett Beaty Committed by Commit Bot

Generate a pyl file with project details that presubmits can read.

This allows the generate_buildbot_json presubmit check to determine
whether or not it should validate that builders exist without having to
parse or scrape starlark source files.

Bug: 1056428
Change-Id: I9540512275d9c8235e92870670d60a2809b1fcdc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2268118
Auto-Submit: Garrett Beaty <gbeaty@chromium.org>
Reviewed-by: default avatarStephen Martinis <martiniss@chromium.org>
Commit-Queue: Stephen Martinis <martiniss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782623}
parent 80a2bd30
# This is a non-LUCI generated file
# This is consumed by presubmit checks that need to validate the config
{"validate_source_side_specs_have_builder": True}
......@@ -28,6 +28,7 @@ lucicfg.config(
'luci-notify.cfg',
'luci-scheduler.cfg',
'project.cfg',
'project.pyl',
'realms.cfg',
'tricium-prod.cfg',
],
......
......@@ -23,6 +23,23 @@ settings = struct(
)
def _generate_project_pyl(ctx):
ctx.output['project.pyl'] = '\n'.join([
'# This is a non-LUCI generated file',
'# This is consumed by presubmit checks that need to validate the config',
repr(dict(
# On master, we want to ensure that we don't have source side specs
# defined for non-existent builders
# On branches, we don't want to re-generate the source side specs as
# that would increase branch day toil and complicate cherry-picks
validate_source_side_specs_have_builder = settings.is_master,
)),
'',
])
lucicfg.generator(_generate_project_pyl)
def master_only_exec(f):
if settings.is_master:
exec(f)
......
......@@ -1397,16 +1397,18 @@ class BBJSONGenerator(object):
# references to configs outside of this directory are added, please change
# their presubmit to run `generate_buildbot_json.py -c`, so that the tree
# never ends up in an invalid state.
project_star = glob.glob(
os.path.join(self.args.infra_config_dir, 'project.star'))
if project_star:
is_master_pattern = re.compile('is_master\s*=\s*(True|False)')
for l in self.read_file(project_star[0]).splitlines():
match = is_master_pattern.search(l)
if match:
if match.group(1) == 'False':
return None
break
# Get the generated project.pyl so we can check if we should be enforcing
# that the specs are for builders that actually exist
# If not, return None to indicate that we won't enforce that builders in
# waterfalls.pyl are defined in LUCI
project_pyl_path = os.path.join(self.args.infra_config_dir, 'generated',
'project.pyl')
if os.path.exists(project_pyl_path):
settings = ast.literal_eval(self.read_file(project_pyl_path))
if not settings.get('validate_source_side_specs_have_builder', True):
return None
bot_names = set()
milo_configs = glob.glob(
os.path.join(self.args.infra_config_dir, 'generated', 'luci-milo*.cfg'))
......
......@@ -55,7 +55,7 @@ class FakeBBGen(generate_buildbot_json.BBJSONGenerator):
waterfalls,
test_suites,
luci_milo_cfg,
project_star='is_master = True',
project_pyl='{"validate_source_side_specs_have_builder": True}',
exceptions=EMPTY_PYL_FILE,
mixins=EMPTY_PYL_FILE,
gn_isolate_map=EMPTY_PYL_FILE,
......@@ -72,11 +72,13 @@ class FakeBBGen(generate_buildbot_json.BBJSONGenerator):
(pyl_files_dir, 'mixins.pyl'): mixins,
(pyl_files_dir, 'gn_isolate_map.pyl'): gn_isolate_map,
(pyl_files_dir, 'variants.pyl'): variants,
(infra_config_dir, 'project.star'): project_star,
(infra_config_dir, 'generated/project.pyl'): project_pyl,
(infra_config_dir, 'generated/luci-milo.cfg'): luci_milo_cfg,
(infra_config_dir, 'generated/luci-milo-dev.cfg'): '',
}
for (d, filename), content in files.iteritems():
if content is None:
continue
path = os.path.join(d, filename)
parent = os.path.abspath(os.path.dirname(path))
if not os.path.exists(parent):
......@@ -2896,12 +2898,23 @@ class UnitTest(TestCase):
fbb.check_input_file_consistency(verbose=True)
self.assertFalse(fbb.printed_lines)
def test_nonexistent_bot_does_not_raise_on_branch(self):
def test_nonexistent_bot_raises_when_no_project_pyl_exists(self):
fbb = FakeBBGen(self.args,
UNKNOWN_BOT_GTESTS_WATERFALL,
FOO_TEST_SUITE,
LUCI_MILO_CFG,
project_star='is_master = False')
project_pyl=None)
with self.assertRaises(generate_buildbot_json.BBGenErr):
fbb.check_input_file_consistency(verbose=True)
self.assertFalse(fbb.printed_lines)
def test_nonexistent_bot_does_not_raise_when_validation_disabled(self):
fbb = FakeBBGen(
self.args,
UNKNOWN_BOT_GTESTS_WATERFALL,
FOO_TEST_SUITE,
LUCI_MILO_CFG,
project_pyl='{"validate_source_side_specs_have_builder": False}')
fbb.check_input_file_consistency(verbose=True)
def test_waterfalls_must_be_sorted(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment