diff --git a/tests/base.py b/tests/base.py index 3d87593acb..583d766ce0 100644 --- a/tests/base.py +++ b/tests/base.py @@ -4977,12 +4977,14 @@ class ZuulTestCase(BaseTestCase): self.assertNotEqual(job.name, name, 'Job %s found in history' % name) - def getJobFromHistory(self, name, project=None, result=None): + def getJobFromHistory(self, name, project=None, result=None, branch=None): for job in self.history: if (job.name == name and (project is None or job.parameters['zuul']['project']['name'] == project) and - (result is None or job.result == result)): + (result is None or job.result == result) and + (branch is None or + job.parameters['zuul']['branch'] == branch)): return job raise Exception("Unable to find job %s in history" % name) diff --git a/tests/fixtures/config/templated-project/git/untrusted-config/zuul.d/jobs.yaml b/tests/fixtures/config/templated-project/git/untrusted-config/zuul.d/jobs.yaml new file mode 100644 index 0000000000..0053480e4b --- /dev/null +++ b/tests/fixtures/config/templated-project/git/untrusted-config/zuul.d/jobs.yaml @@ -0,0 +1,3 @@ +- job: + name: project-test7 + parent: project-test1 diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py index 9860911584..3b28bf6e44 100644 --- a/tests/unit/test_scheduler.py +++ b/tests/unit/test_scheduler.py @@ -6846,6 +6846,9 @@ class TestSchedulerTemplatedProject(ZuulTestCase): name: untrusted-config templates: - test-three-and-four + check: + jobs: + - project-test7 """) file_dict = {'zuul.d/project.yaml': in_repo_conf} B = self.fake_gerrit.addFakeChange('untrusted-config', 'stable-foo', @@ -6856,12 +6859,26 @@ class TestSchedulerTemplatedProject(ZuulTestCase): self.assertHistory([ dict(name='project-test1', result='SUCCESS', changes='1,1'), dict(name='project-test2', result='SUCCESS', changes='1,1'), + dict(name='project-test7', result='SUCCESS', changes='2,1'), dict(name='layered-project-test3', result='SUCCESS', changes='2,1'), dict(name='layered-project-test4', result='SUCCESS', changes='2,1'), ], ordered=False) + # Inheritance path should not contain items from branch stable + # This tests that not only is it the case that the stable + # branch project-template did not apply, but also that the + # stable branch definitions of the project-test7 did not apply + # (since the job definitions also have implied branch + # matchers). + job = self.getJobFromHistory('project-test7', branch='stable-foo') + inheritance_path = job.parameters['zuul']['_inheritance_path'] + self.assertEqual(len(inheritance_path), 4) + stable_items = [x for x in inheritance_path + if 'untrusted-config/zuul.d/jobs.yaml@stable#' in x] + self.assertEqual(len(stable_items), 0) + class TestSchedulerSuccessURL(ZuulTestCase): tenant_config_file = 'config/success-url/main.yaml' diff --git a/zuul/configloader.py b/zuul/configloader.py index ffd8c892b2..7dedf919a3 100644 --- a/zuul/configloader.py +++ b/zuul/configloader.py @@ -931,12 +931,14 @@ class JobParser(object): job.allowed_projects = frozenset(allowed) branches = None + implied = False if 'branches' in conf: branches = as_list(conf['branches']) elif not project_pipeline: branches = self.pcontext.getImpliedBranches(job.source_context) + implied = True if branches: - job.setBranchMatcher(branches) + job.setBranchMatcher(branches, implied=implied) if 'files' in conf: job.setFileMatcher(as_list(conf['files'])) if 'irrelevant-files' in conf: diff --git a/zuul/model.py b/zuul/model.py index dede7c2cd1..855f6c7f6c 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -1430,12 +1430,16 @@ class Job(ConfigObject): # Return the raw branch list that match this job return self._branches - def setBranchMatcher(self, branches): + def setBranchMatcher(self, branches, implied=False): # Set the branch matcher to match any of the supplied branches self._branches = branches matchers = [] + if implied: + matcher_class = change_matcher.ImpliedBranchMatcher + else: + matcher_class = change_matcher.BranchMatcher for branch in branches: - matchers.append(change_matcher.BranchMatcher(branch)) + matchers.append(matcher_class(branch)) self.branch_matcher = change_matcher.MatchAny(matchers) def setFileMatcher(self, files):