Browse Source

enqueue: make trigger deprecated

The patchset or ref, pipeline and project should be enough to trigger an
enqueue. The trigger argument is not validated or used anymore when
enqueueing via RPC.

Change-Id: I9166e6d44291070f01baca9238f04feedcee7f5b
changes/46/695446/7
Matthieu Huin 2 years ago
committed by Tobias Henkel
parent
commit
a0015014c9
No known key found for this signature in database GPG Key ID: 3750DEC158E5FA2
  1. 66
      tests/unit/test_scheduler.py
  2. 2
      tools/zuul-changes.py
  3. 8
      zuul/cmd/client.py
  4. 4
      zuul/rpcclient.py
  5. 7
      zuul/rpclistener.py
  6. 4
      zuul/web/__init__.py

66
tests/unit/test_scheduler.py

@ -4099,8 +4099,9 @@ class TestScheduler(ZuulTestCase):
self.worker.release('.*')
self.waitUntilSettled()
def test_client_enqueue_change(self):
"Test that the RPC client can enqueue a change"
def test_client_enqueue_change_with_trigger(self):
"""Test that the RPC client can enqueue a change with the deprecated
trigger argument"""
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
A.addApproval('Code-Review', 2)
A.addApproval('Approved', 1)
@ -4124,6 +4125,32 @@ class TestScheduler(ZuulTestCase):
self.assertEqual(A.reported, 2)
self.assertEqual(r, True)
def test_client_enqueue_change_no_trigger(self):
"""Test that the RPC client can enqueue a change without an explicit
trigger"""
A = self.fake_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='gate',
project='org/project',
trigger=None,
change='1,1')
self.waitUntilSettled()
self.assertEqual(self.getJobFromHistory('project-merge').result,
'SUCCESS')
self.assertEqual(self.getJobFromHistory('project-test1').result,
'SUCCESS')
self.assertEqual(self.getJobFromHistory('project-test2').result,
'SUCCESS')
self.assertEqual(A.data['status'], 'MERGED')
self.assertEqual(A.reported, 2)
self.assertEqual(r, True)
@simple_layout('layouts/three-projects.yaml')
def test_client_enqueue_change_wrong_project(self):
"Test that an enqueue fails if a change doesn't belong to the project"
@ -4144,7 +4171,7 @@ class TestScheduler(ZuulTestCase):
r = client.enqueue(tenant='tenant-one',
pipeline='gate',
project='org/project1',
trigger='gerrit',
trigger=None,
change='2,1')
self.assertEqual(r, False)
self.waitUntilSettled()
@ -4165,7 +4192,7 @@ class TestScheduler(ZuulTestCase):
tenant='tenant-one',
pipeline='post',
project='org/project',
trigger='gerrit',
trigger=None,
ref='master',
oldrev='90f173846e3af9154517b88543ffbd1691f31366',
newrev=A_commit)
@ -4195,7 +4222,7 @@ class TestScheduler(ZuulTestCase):
tenant='tenant-one',
pipeline='post',
project='org/project',
trigger='gerrit',
trigger=None,
ref='master',
oldrev='90f173846e3af9154517b88543ffbd1691f31366',
newrev=A_commit)
@ -4211,7 +4238,7 @@ class TestScheduler(ZuulTestCase):
tenant='tenant-one',
pipeline='post',
project='org/project1',
trigger='gerrit',
trigger=None,
ref='master',
oldrev='90f173846e3af9154517b88543ffbd1691f31366',
newrev=B_commit)
@ -4405,7 +4432,7 @@ class TestScheduler(ZuulTestCase):
r = client.enqueue(tenant='tenant-foo',
pipeline='gate',
project='org/project',
trigger='gerrit',
trigger=None,
change='1,1')
self.assertEqual(r, False)
@ -4414,7 +4441,7 @@ class TestScheduler(ZuulTestCase):
r = client.enqueue(tenant='tenant-one',
pipeline='gate',
project='project-does-not-exist',
trigger='gerrit',
trigger=None,
change='1,1')
self.assertEqual(r, False)
@ -4423,16 +4450,7 @@ class TestScheduler(ZuulTestCase):
r = client.enqueue(tenant='tenant-one',
pipeline='pipeline-does-not-exist',
project='org/project',
trigger='gerrit',
change='1,1')
self.assertEqual(r, False)
with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
"Invalid trigger"):
r = client.enqueue(tenant='tenant-one',
pipeline='gate',
project='org/project',
trigger='trigger-does-not-exist',
trigger=None,
change='1,1')
self.assertEqual(r, False)
@ -4441,7 +4459,7 @@ class TestScheduler(ZuulTestCase):
r = client.enqueue(tenant='tenant-one',
pipeline='gate',
project='org/project',
trigger='gerrit',
trigger=None,
change='1,1')
self.assertEqual(r, False)
@ -4460,7 +4478,7 @@ class TestScheduler(ZuulTestCase):
tenant='tenant-one',
pipeline='post',
project='org/project',
trigger='gerrit',
trigger=None,
ref='master',
oldrev='90f173846e3af9154517b88543ffbd1691f31366',
newrev='10054041')
@ -4471,7 +4489,7 @@ class TestScheduler(ZuulTestCase):
tenant='tenant-one',
pipeline='post',
project='org/project',
trigger='gerrit',
trigger=None,
ref='master',
oldrev='10054041',
newrev='90f173846e3af9154517b88543ffbd1691f31366')
@ -4482,7 +4500,7 @@ class TestScheduler(ZuulTestCase):
tenant='tenant-one',
pipeline='post',
project='org/project',
trigger='gerrit',
trigger=None,
ref='master',
oldrev='90f173846e3af9154517b88543ffbd1691f31366',
newrev='notbase16')
@ -4493,7 +4511,7 @@ class TestScheduler(ZuulTestCase):
tenant='tenant-one',
pipeline='post',
project='org/project',
trigger='gerrit',
trigger=None,
ref='master',
oldrev='notbase16',
newrev='90f173846e3af9154517b88543ffbd1691f31366')
@ -6204,7 +6222,7 @@ class TestAmbiguousProjectNames(ZuulTestCase):
r = client.enqueue(tenant='tenant-one',
pipeline='check',
project='review.example.com/org/project',
trigger='gerrit',
trigger=None,
change='1,1')
self.waitUntilSettled()
self.assertEqual(self.getJobFromHistory('project-merge').result,

2
tools/zuul-changes.py

@ -67,7 +67,6 @@ for tenant in tenants:
cid, cps = change['id'].split(',')
print("zuul enqueue"
" --tenant %s"
" --trigger gerrit"
" --pipeline %s"
" --project %s"
" --change %s,%s" % (tenant, pipeline['name'],
@ -78,7 +77,6 @@ for tenant in tenants:
cmd = 'zuul enqueue-ref' \
' --tenant %s' \
' --pipeline %s' \
' --trigger timer' \
' --project %s' \
' --ref %s' % (tenant, pipeline['name'],
change['project_canonical'],

8
zuul/cmd/client.py

@ -222,8 +222,10 @@ class Client(zuul.cmd.ZuulApp):
cmd_enqueue = subparsers.add_parser('enqueue', help='enqueue a change')
cmd_enqueue.add_argument('--tenant', help='tenant name',
required=True)
cmd_enqueue.add_argument('--trigger', help='trigger name',
required=True)
cmd_enqueue.add_argument('--trigger',
help='trigger name (deprecated and ignored. '
'Kept only for backward compatibility)',
required=False, default=None)
cmd_enqueue.add_argument('--pipeline', help='pipeline name',
required=True)
cmd_enqueue.add_argument('--project', help='project name',
@ -244,7 +246,7 @@ class Client(zuul.cmd.ZuulApp):
cmd_enqueue.add_argument('--tenant', help='tenant name',
required=True)
cmd_enqueue.add_argument('--trigger', help='trigger name',
required=True)
required=False, default=None)
cmd_enqueue.add_argument('--pipeline', help='pipeline name',
required=True)
cmd_enqueue.add_argument('--project', help='project name',

4
zuul/rpcclient.py

@ -84,6 +84,8 @@ class RPCClient(object):
return json.loads(job.data[0])
def enqueue(self, tenant, pipeline, project, trigger, change):
if trigger is not None:
self.log.info('enqueue: the "trigger" argument is deprecated')
data = {'tenant': tenant,
'pipeline': pipeline,
'project': project,
@ -94,6 +96,8 @@ class RPCClient(object):
def enqueue_ref(
self, tenant, pipeline, project, trigger, ref, oldrev, newrev):
if trigger is not None:
self.log.info('enqueue_ref: the "trigger" argument is deprecated')
data = {'tenant': tenant,
'pipeline': pipeline,
'project': project,

7
zuul/rpclistener.py

@ -189,13 +189,6 @@ class RPCListener(object):
pipeline = tenant.layout.pipelines.get(args['pipeline'])
if pipeline:
event.forced_pipeline = args['pipeline']
for trigger in pipeline.triggers:
if trigger.name == args['trigger']:
event.trigger_name = args['trigger']
continue
if not event.trigger_name:
errors += 'Invalid trigger: %s\n' % (args['trigger'],)
else:
errors += 'Invalid pipeline: %s\n' % (args['pipeline'],)
else:

4
zuul/web/__init__.py

@ -310,9 +310,9 @@ class ZuulWebAPI(object):
tenant, project))
body = cherrypy.request.json
if all(p in body for p in ['trigger', 'change', 'pipeline']):
if all(p in body for p in ['change', 'pipeline']):
return self._enqueue(tenant, project, **body)
elif all(p in body for p in ['trigger', 'ref', 'oldrev',
elif all(p in body for p in ['ref', 'oldrev',
'newrev', 'pipeline']):
return self._enqueue_ref(tenant, project, **body)
else:

Loading…
Cancel
Save