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
This commit is contained in:
Tristan Cacqueray 2018-07-04 05:32:40 +00:00
parent 11709e7044
commit 2f520fe720
6 changed files with 88 additions and 1 deletions

View File

@ -0,0 +1,2 @@
- hosts: all
tasks: []

View File

@ -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

View File

@ -0,0 +1 @@
test

View File

@ -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

View File

@ -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'

View File

@ -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 "