Warn user when dynamic layout ignores zuul config

Zuul loads configuration files in a distinct order and currently only
warns to the zuul log if some files got ignored. This can be confusing
to the user so plumb this warning through to the buildset which then
gets reported to a change.

Change-Id: I68f729c83cf6c16fd1f490a60b269401236ef6d9
This commit is contained in:
Tobias Henkel 2020-04-15 19:30:48 +02:00
parent 7c0bd56aa4
commit 6dc9577b44
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
4 changed files with 30 additions and 10 deletions

View File

@ -1,3 +1,8 @@
- project:
check:
jobs:
- project-test1
- project:
name: org/project
check:

View File

@ -433,17 +433,25 @@ class TestSplitConfig(ZuulTestCase):
files=file_dict)
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
return A
log_fixture = self.useFixture(
fixtures.FakeLogger(level=logging.WARNING))
log_fixture._output.truncate(0)
add_file("common-config", "zuul.yaml")
self.assertIn("Multiple configuration", log_fixture.output)
A = add_file("common-config", "zuul.yaml")
self.assertIn("Configuration in common-config/zuul.d/jobs.yaml@master "
"ignored because project-branch is already configured",
log_fixture.output)
self.assertIn("Configuration in common-config/zuul.d/jobs.yaml@master "
"ignored because project-branch is already configured",
A.messages[0])
log_fixture._output.truncate(0)
add_file("org/project1", ".zuul.yaml")
self.assertIn("Multiple configuration", log_fixture.output)
self.assertIn("Configuration in org/project1/.zuul.d/gate.yaml@master "
"ignored because project-branch is already configured",
log_fixture.output)
class TestConfigConflict(ZuulTestCase):

View File

@ -2260,8 +2260,9 @@ class ConfigLoader(object):
return new_abide
def _loadDynamicProjectData(self, config, project,
files, trusted, tenant, loading_errors,
files, trusted, item, loading_errors,
pcontext):
tenant = item.pipeline.tenant
tpc = tenant.project_configs[project.canonical_name]
if trusted:
branches = ['master']
@ -2318,7 +2319,12 @@ class ConfigLoader(object):
conf_root not in tpc.extra_config_dirs):
if loaded and loaded != conf_root:
self.log.warning(
"Multiple configuration in %s" %
"Configuration in %s ignored because "
"project-branch is already configured",
source_context)
item.warning(
"Configuration in %s ignored because "
"project-branch is already configured" %
source_context)
continue
loaded = conf_root
@ -2336,9 +2342,10 @@ class ConfigLoader(object):
config.extend(self.tenant_parser.parseConfig(
tenant, incdata, loading_errors, pcontext))
def createDynamicLayout(self, tenant, files, ansible_manager,
def createDynamicLayout(self, item, files, ansible_manager,
include_config_projects=False,
zuul_event_id=None):
tenant = item.pipeline.tenant
log = get_annotated_logger(self.log, zuul_event_id)
pcontext = ParseContext(self.connections, self.scheduler,
tenant, ansible_manager)
@ -2347,12 +2354,12 @@ class ConfigLoader(object):
config = model.ParsedConfig()
for project in tenant.config_projects:
self._loadDynamicProjectData(config, project, files, True,
tenant, loading_errors, pcontext)
item, loading_errors, pcontext)
else:
config = tenant.config_projects_config.copy()
for project in tenant.untrusted_projects:
self._loadDynamicProjectData(config, project, files, False, tenant,
self._loadDynamicProjectData(config, project, files, False, item,
loading_errors, pcontext)
layout = model.Layout(tenant)

View File

@ -568,7 +568,7 @@ class PipelineManager(metaclass=ABCMeta):
if trusted_updates:
log.debug("Loading dynamic layout (phase 1)")
trusted_layout = loader.createDynamicLayout(
item.pipeline.tenant,
item,
build_set.files,
self.sched.ansible_manager,
include_config_projects=True,
@ -580,7 +580,7 @@ class PipelineManager(metaclass=ABCMeta):
if untrusted_updates:
log.debug("Loading dynamic layout (phase 2)")
untrusted_layout = loader.createDynamicLayout(
item.pipeline.tenant,
item,
build_set.files,
self.sched.ansible_manager,
include_config_projects=False,