Fix zuul.(yaml|d) loading order and add tests

This change fixes the configloader to load file in a more logical order:
zuul.yaml, zuul.d, .zuul.yaml then .zuul.d.

This change also adds negative test for config path conflicts.

Change-Id: Ifbbfb4389b7aa0a641b95b5947abc8a56e362ee3
changes/11/482411/3
Tristan Cacqueray 5 years ago
parent 9a4d73f34f
commit 8688306f59
  1. 2
      tests/fixtures/config/conflict-config/git/common-config/.zuul.d/jobs.yaml
  2. 2
      tests/fixtures/config/conflict-config/git/common-config/.zuul.yaml
  3. 2
      tests/fixtures/config/conflict-config/git/common-config/zuul.d/jobs.yaml
  4. 2
      tests/fixtures/config/conflict-config/git/common-config/zuul.yaml
  5. 2
      tests/fixtures/config/conflict-config/git/org_project/.zuul.yaml
  6. 2
      tests/fixtures/config/conflict-config/git/org_project/zuul.yaml
  7. 8
      tests/fixtures/config/conflict-config/main.yaml
  8. 38
      tests/unit/test_configloader.py
  9. 5
      zuul/configloader.py

@ -0,0 +1,2 @@
- job:
name: trusted-.zuul.yaml-job

@ -0,0 +1,2 @@
- job:
name: trusted-zuul.yaml-job

@ -0,0 +1,2 @@
- job:
name: untrusted-.zuul.yaml-job

@ -0,0 +1,2 @@
- job:
name: untrusted-zuul.yaml-job

@ -0,0 +1,8 @@
- tenant:
name: tenant-one
source:
gerrit:
config-projects:
- common-config
untrusted-projects:
- org/project

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
import logging
import textwrap
from tests.base import ZuulTestCase
@ -245,3 +247,39 @@ class TestSplitConfig(ZuulTestCase):
# project1-project2-integration test removed, only want project-test1
self.assertHistory([
dict(name='project-test1', result='SUCCESS', changes='1,1')])
def test_config_path_conflict(self):
def add_file(project, path):
new_file = textwrap.dedent(
"""
- job:
name: test-job
"""
)
file_dict = {path: new_file}
A = self.fake_gerrit.addFakeChange(project, 'master', 'A',
files=file_dict)
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
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)
log_fixture._output.truncate(0)
add_file("org/project1", ".zuul.yaml")
self.assertIn("Multiple configuration", log_fixture.output)
class TestConfigConflict(ZuulTestCase):
tenant_config_file = 'config/conflict-config/main.yaml'
def test_conflict_config(self):
tenant = self.sched.abide.tenants.get('tenant-one')
jobs = sorted(tenant.layout.jobs.keys())
self.assertEquals(
['noop', 'trusted-zuul.yaml-job', 'untrusted-zuul.yaml-job'],
jobs)

@ -1186,7 +1186,7 @@ class TenantParser(object):
(job, job.files))
loaded = False
files = sorted(job.files.keys())
for conf_root in ['zuul.yaml', '.zuul.yaml', 'zuul.d', '.zuul.d']:
for conf_root in ['zuul.yaml', 'zuul.d', '.zuul.yaml', '.zuul.d']:
for fn in files:
fn_root = fn.split('/')[0]
if fn_root != conf_root or not job.files.get(fn):
@ -1389,8 +1389,7 @@ class ConfigLoader(object):
fns1.append(fn)
if fn.startswith(".zuul.d/"):
fns2.append(fn)
fns = ['zuul.yaml', '.zuul.yaml'] + sorted(fns1) + sorted(fns2)
fns = ["zuul.yaml"] + sorted(fns1) + [".zuul.yaml"] + sorted(fns2)
incdata = None
loaded = None
for fn in fns:

Loading…
Cancel
Save