Fix source context in split config
If a repo has multiple config files, we would previously share the source context between all of those files. However, one of the attributes of a source context is the path from which the config file was loaded, so debugging statements would show that all of the config objects loaded from that repo came from the last filename Zuul read. Instead, make a copy of the source context for each path loaded. Change-Id: Ib22da429b484a99c86c2e620d97f655710460df4
This commit is contained in:
parent
c2fe7713fe
commit
ed792c9a2e
3
tests/fixtures/config/split-config/git/common-config/zuul.d/more-jobs.yaml
vendored
Normal file
3
tests/fixtures/config/split-config/git/common-config/zuul.d/more-jobs.yaml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
- job:
|
||||
name: project-test2
|
||||
run: playbooks/project-test1.yaml
|
@ -309,6 +309,22 @@ class TestSplitConfig(ZuulTestCase):
|
||||
def test_split_config(self):
|
||||
tenant = self.sched.abide.tenants.get('tenant-one')
|
||||
self.assertIn('project-test1', tenant.layout.jobs)
|
||||
self.assertIn('project-test2', tenant.layout.jobs)
|
||||
test1 = tenant.layout.getJob('project-test1')
|
||||
self.assertEqual(test1.source_context.project.name, 'common-config')
|
||||
self.assertEqual(test1.source_context.branch, 'master')
|
||||
self.assertEqual(test1.source_context.path, 'zuul.d/jobs.yaml')
|
||||
self.assertEqual(test1.source_context.trusted, True)
|
||||
test2 = tenant.layout.getJob('project-test2')
|
||||
self.assertEqual(test2.source_context.project.name, 'common-config')
|
||||
self.assertEqual(test2.source_context.branch, 'master')
|
||||
self.assertEqual(test2.source_context.path, 'zuul.d/more-jobs.yaml')
|
||||
self.assertEqual(test2.source_context.trusted, True)
|
||||
|
||||
self.assertNotEqual(test1.source_context, test2.source_context)
|
||||
self.assertTrue(test1.source_context.isSameProject(
|
||||
test2.source_context))
|
||||
|
||||
project_config = tenant.layout.project_configs.get(
|
||||
'review.example.com/org/project')
|
||||
self.assertIn('project-test1',
|
||||
|
@ -1526,7 +1526,8 @@ class TenantParser(object):
|
||||
(job.source_context,))
|
||||
continue
|
||||
loaded = conf_root
|
||||
source_context = job.source_context
|
||||
# Create a new source_context so we have unique filenames.
|
||||
source_context = job.source_context.copy()
|
||||
source_context.path = fn
|
||||
self.log.info(
|
||||
"Loading configuration from %s" %
|
||||
|
Loading…
Reference in New Issue
Block a user