Attach loading_errors to the ParseContext

We pass around a single LoadingErrors object in quite a bit of the
config parser, and upcoming changes will pass it around even more.
Most of those instances also have a ParseContext as well, and the
two objects have the same lifecycle and scope, so let's attach the
LoadingErrors to the ParseContext and simplify things.

Change-Id: I57d0edc3c69eace9ba12c2975278a1b9312f9d67
This commit is contained in:
James E. Blair 2023-06-06 13:29:45 -07:00
parent 5be57fb87e
commit 2ad18acb66
1 changed files with 18 additions and 19 deletions

View File

@ -1674,6 +1674,7 @@ class ParseContext(object):
"""Hold information about a particular run of the parser"""
def __init__(self, connections, scheduler, tenant, ansible_manager):
self.loading_errors = model.LoadingErrors()
self.connections = connections
self.scheduler = scheduler
self.tenant = tenant
@ -1845,9 +1846,6 @@ class TenantParser(object):
for tpc in untrusted_tpcs:
tenant.addUntrustedProject(tpc)
# We prepare a stack to store config loading issues
loading_errors = model.LoadingErrors()
# Get branches in parallel
branch_futures = {}
for tpc in config_tpcs + untrusted_tpcs:
@ -1862,7 +1860,7 @@ class TenantParser(object):
tpc.project.canonical_name, tpc.project.name,
tpc.project.connection_name, None, None, trusted)
with project_configuration_exceptions(source_context,
loading_errors):
pcontext.loading_errors):
self._getProjectBranches(tenant, tpc, branch_cache_min_ltimes)
self._resolveShadowProjects(tenant, tpc)
@ -1880,20 +1878,20 @@ class TenantParser(object):
# Start by fetching any YAML needed by this tenant which isn't
# already cached. Full reconfigurations start with an empty
# cache.
self._cacheTenantYAML(abide, tenant, loading_errors, min_ltimes,
executor, ignore_cat_exception)
self._cacheTenantYAML(abide, tenant, pcontext.loading_errors,
min_ltimes, executor, ignore_cat_exception)
# Then collect the appropriate YAML based on this tenant
# config.
config_projects_config, untrusted_projects_config = \
self._loadTenantYAML(abide, tenant, loading_errors)
self._loadTenantYAML(abide, tenant, pcontext.loading_errors)
# Then convert the YAML to configuration objects which we
# cache on the tenant.
tenant.config_projects_config = self.parseConfig(
tenant, config_projects_config, loading_errors, pcontext)
tenant, config_projects_config, pcontext)
tenant.untrusted_projects_config = self.parseConfig(
tenant, untrusted_projects_config, loading_errors, pcontext)
tenant, untrusted_projects_config, pcontext)
# Combine the trusted and untrusted config objects
parsed_config = model.ParsedConfig()
@ -1905,7 +1903,7 @@ class TenantParser(object):
self.cacheConfig(tenant, parsed_config)
tenant.layout = self._parseLayout(
tenant, parsed_config, loading_errors, layout_uuid)
tenant, parsed_config, pcontext.loading_errors, layout_uuid)
tenant.semaphore_handler = SemaphoreHandler(
self.zk_client, self.statsd, tenant.name, tenant.layout, abide,
@ -2431,8 +2429,9 @@ class TenantParser(object):
tpc = tenant.project_configs[project]
return tpc.load_classes
def parseConfig(self, tenant, unparsed_config, loading_errors, pcontext):
def parseConfig(self, tenant, unparsed_config, pcontext):
parsed_config = model.ParsedConfig()
loading_errors = pcontext.loading_errors
# Handle pragma items first since they modify the source context
# used by other classes.
@ -2916,7 +2915,7 @@ class ConfigLoader(object):
return new_tenant
def _loadDynamicProjectData(self, config, project,
files, trusted, item, loading_errors,
files, trusted, item,
pcontext):
tenant = item.pipeline.tenant
tpc = tenant.project_configs[project.canonical_name]
@ -2987,17 +2986,18 @@ class ConfigLoader(object):
loaded = conf_root
incdata = self.tenant_parser.loadProjectYAML(
data, source_context, loading_errors)
data, source_context, pcontext.loading_errors)
if trusted:
incdata = self.tenant_parser.filterConfigProjectYAML(
incdata)
else:
incdata = self.tenant_parser.\
filterUntrustedProjectYAML(incdata, loading_errors)
filterUntrustedProjectYAML(incdata,
pcontext.loading_errors)
config.extend(self.tenant_parser.parseConfig(
tenant, incdata, loading_errors, pcontext))
tenant, incdata, pcontext))
def createDynamicLayout(self, item, files, ansible_manager,
include_config_projects=False,
@ -3006,21 +3006,20 @@ class ConfigLoader(object):
log = get_annotated_logger(self.log, zuul_event_id)
pcontext = ParseContext(self.connections, self.scheduler,
tenant, ansible_manager)
loading_errors = model.LoadingErrors()
if include_config_projects:
config = model.ParsedConfig()
for project in tenant.config_projects:
self._loadDynamicProjectData(config, project, files, True,
item, loading_errors, pcontext)
item, pcontext)
else:
config = tenant.config_projects_config.copy()
for project in tenant.untrusted_projects:
self._loadDynamicProjectData(config, project, files, False, item,
loading_errors, pcontext)
pcontext)
layout = model.Layout(tenant, item.layout_uuid)
layout.loading_errors = loading_errors
layout.loading_errors = pcontext.loading_errors
log.debug("Created layout id %s", layout.uuid)
if not include_config_projects:
# NOTE: the actual pipeline objects (complete with queues