From 2f520fe720a214569aca431e9f970cc1bca7476f Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 4 Jul 2018 05:32:40 +0000 Subject: [PATCH] scheduler: fix enqueue event to use canonical project name When trying to enqueue an event using a canonical project name, we need to fix the doEnqueueEvent method to use the full project name. Otherwise it fails with: zuul.rpcclient.RPCFailure: Traceback (most recent call last): [...] File "zuul/scheduler.py", line 829, in _doEnqueueEvent (trusted, project) = tenant.getProject(event.project_name) File "zuul/model.py", line 3458, in getProject "with a hostname" % (name,)) Exception: Project name 'openstack/tripleo-heat-templates' is ambiguous, please fully qualify the project with a hostname Even when the enqueue command was done using the canonical project name. Change-Id: I68210993ca4d5917c40df9a198f2e47dd2b0399c --- .../playbooks/project-merge.yaml | 2 + .../git/common-config/zuul.yaml | 47 +++++++++++++++++++ .../ambiguous-names/git/org_project/README | 1 + .../fixtures/config/ambiguous-names/main.yaml | 11 +++++ tests/unit/test_scheduler.py | 24 ++++++++++ zuul/scheduler.py | 4 +- 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/config/ambiguous-names/git/common-config/playbooks/project-merge.yaml create mode 100644 tests/fixtures/config/ambiguous-names/git/common-config/zuul.yaml create mode 100644 tests/fixtures/config/ambiguous-names/git/org_project/README create mode 100644 tests/fixtures/config/ambiguous-names/main.yaml diff --git a/tests/fixtures/config/ambiguous-names/git/common-config/playbooks/project-merge.yaml b/tests/fixtures/config/ambiguous-names/git/common-config/playbooks/project-merge.yaml new file mode 100644 index 0000000000..f679dceaef --- /dev/null +++ b/tests/fixtures/config/ambiguous-names/git/common-config/playbooks/project-merge.yaml @@ -0,0 +1,2 @@ +- hosts: all + tasks: [] diff --git a/tests/fixtures/config/ambiguous-names/git/common-config/zuul.yaml b/tests/fixtures/config/ambiguous-names/git/common-config/zuul.yaml new file mode 100644 index 0000000000..af23e68565 --- /dev/null +++ b/tests/fixtures/config/ambiguous-names/git/common-config/zuul.yaml @@ -0,0 +1,47 @@ +- pipeline: + name: check + manager: independent + trigger: + review_gerrit: + - event: patchset-created + success: + review_gerrit: + Verified: 1 + another_gerrit: + Verified: 1 + failure: + review_gerrit: + Verified: -1 + another_gerrit: + Verified: -1 + +- job: + name: base + parent: null + +- job: + name: project-merge + hold-following-changes: true + nodeset: + nodes: + - name: controller + label: label1 + run: playbooks/project-merge.yaml + +- project: + name: review.example.com/org/project + check: + jobs: + - project-merge + +- project: + name: another.example.com/org/project + check: + jobs: + - project-merge + +- project: + name: common-config + check: + jobs: + - project-merge diff --git a/tests/fixtures/config/ambiguous-names/git/org_project/README b/tests/fixtures/config/ambiguous-names/git/org_project/README new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/tests/fixtures/config/ambiguous-names/git/org_project/README @@ -0,0 +1 @@ +test diff --git a/tests/fixtures/config/ambiguous-names/main.yaml b/tests/fixtures/config/ambiguous-names/main.yaml new file mode 100644 index 0000000000..bdcfc7c7ce --- /dev/null +++ b/tests/fixtures/config/ambiguous-names/main.yaml @@ -0,0 +1,11 @@ +- tenant: + name: tenant-one + source: + review_gerrit: + config-projects: + - common-config + untrusted-projects: + - org/project + another_gerrit: + untrusted-projects: + - org/project diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py index 158141b8d5..9d84c92df3 100755 --- a/tests/unit/test_scheduler.py +++ b/tests/unit/test_scheduler.py @@ -4983,6 +4983,30 @@ For CI problems and help debugging, contact ci@example.org""" ], ordered=False) +class TestAmbiguousProjectNames(ZuulTestCase): + config_file = 'zuul-connections-multiple-gerrits.conf' + tenant_config_file = 'config/ambiguous-names/main.yaml' + + def test_client_enqueue_canonical(self): + "Test that the RPC client can enqueue a change using canonical name" + A = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'A') + A.addApproval('Code-Review', 2) + A.addApproval('Approved', 1) + + client = zuul.rpcclient.RPCClient('127.0.0.1', + self.gearman_server.port) + self.addCleanup(client.shutdown) + r = client.enqueue(tenant='tenant-one', + pipeline='check', + project='review.example.com/org/project', + trigger='gerrit', + change='1,1') + self.waitUntilSettled() + self.assertEqual(self.getJobFromHistory('project-merge').result, + 'SUCCESS') + self.assertEqual(r, True) + + class TestExecutor(ZuulTestCase): tenant_config_file = 'config/single-tenant/main.yaml' diff --git a/zuul/scheduler.py b/zuul/scheduler.py index 04c56a469c..93d0448a54 100644 --- a/zuul/scheduler.py +++ b/zuul/scheduler.py @@ -828,7 +828,9 @@ class Scheduler(threading.Thread): def _doEnqueueEvent(self, event): tenant = self.abide.tenants.get(event.tenant_name) - (trusted, project) = tenant.getProject(event.project_name) + full_project_name = ('/'.join([event.project_hostname, + event.project_name])) + (trusted, project) = tenant.getProject(full_project_name) pipeline = tenant.layout.pipelines[event.forced_pipeline] change = project.source.getChange(event, project) self.log.debug("Event %s for change %s was directly assigned "