diff --git a/tests/unit/test_configloader.py b/tests/unit/test_configloader.py index 6857035e9d..2840c94924 100644 --- a/tests/unit/test_configloader.py +++ b/tests/unit/test_configloader.py @@ -1427,6 +1427,10 @@ class TestNodepoolConfig(ZuulTestCase): - section: name: badsection parent: aws-base + - provider: + name: badprovider + section: badsection + region: foo """) file_dict = {'zuul.yaml': in_repo_conf} A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', @@ -1436,3 +1440,8 @@ class TestNodepoolConfig(ZuulTestCase): self.assertEqual(A.reported, 1) self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '-1') self.assertIn('references a section', A.messages[0]) + A.setMerged() + self.fake_gerrit.addEvent(A.getChangeMergedEvent()) + self.waitUntilSettled() + tenant = self.scheds.first.sched.abide.tenants.get('tenant-one') + self.assertFalse('badprovider' in tenant.layout.providers) diff --git a/zuul/model.py b/zuul/model.py index f442ef9ac4..0ba726dd40 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -1834,12 +1834,21 @@ class ProviderConfig(ConfigObject): def flattenConfig(self, layout): config = copy.deepcopy(Freezable.thaw(self.config)) parent_name = self.section + previous_section = None while parent_name: parent_section = layout.sections[parent_name] + # Prevent sections from referencing sections in other projects + if (previous_section and + parent_section.source_context.project_canonical_name != + previous_section.source_context.project_canonical_name): + raise Exception( + f'The section "{previous_section.name}" references a ' + 'section in a different project.') parent_config = copy.deepcopy(Freezable.thaw( parent_section.config)) config = ProviderConfig._mergeDict(parent_config, config) parent_name = parent_section.parent + previous_section = parent_section # Provide defaults from the images/flavors/labels objects for image in config.get('images', []): layout_image = self._dropNone(