blob: 3954a215de61f1749feafa2d4293cc731b5dbb10 [file] [log] [blame]
James E. Blairc494d542014-08-06 09:23:52 -07001#!/usr/bin/env python
2
3# Copyright 2014 Hewlett-Packard Development Company, L.P.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
James E. Blairc494d542014-08-06 09:23:52 -070017from tests.base import ZuulTestCase
18
James E. Blairc494d542014-08-06 09:23:52 -070019
James E. Blaira80ef4e2016-12-08 14:06:36 -080020class TestZuulTriggerParentChangeEnqueued(ZuulTestCase):
21 tenant_config_file = 'config/zuultrigger/parent-change-enqueued/main.yaml'
James E. Blair509cada2015-12-08 16:31:16 -080022
James E. Blairc494d542014-08-06 09:23:52 -070023 def test_zuul_trigger_parent_change_enqueued(self):
24 "Test Zuul trigger event: parent-change-enqueued"
James E. Blairc494d542014-08-06 09:23:52 -070025 # This test has the following three changes:
26 # B1 -> A; B2 -> A
27 # When A is enqueued in the gate, B1 and B2 should both attempt
28 # to be enqueued in both pipelines. B1 should end up in check
29 # and B2 in gate because of differing pipeline requirements.
Paul Belanger174a8272017-03-14 13:20:10 -040030 self.executor_server.hold_jobs_in_build = True
James E. Blairc494d542014-08-06 09:23:52 -070031 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
32 B1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'B1')
33 B2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'B2')
Tobias Henkelbf24fd12017-07-27 06:13:07 +020034 A.addApproval('Code-Review', 2)
35 B1.addApproval('Code-Review', 2)
36 B2.addApproval('Code-Review', 2)
37 A.addApproval('Verified', 1) # required by gate
38 B1.addApproval('Verified', -1) # should go to check
39 B2.addApproval('Verified', 1) # should go to gate
40 B1.addApproval('Approved', 1)
41 B2.addApproval('Approved', 1)
James E. Blairc494d542014-08-06 09:23:52 -070042 B1.setDependsOn(A, 1)
43 B2.setDependsOn(A, 1)
Tobias Henkelbf24fd12017-07-27 06:13:07 +020044 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blairc494d542014-08-06 09:23:52 -070045 # Jobs are being held in build to make sure that 3,1 has time
46 # to enqueue behind 1,1 so that the test is more
47 # deterministic.
48 self.waitUntilSettled()
Paul Belanger174a8272017-03-14 13:20:10 -040049 self.executor_server.hold_jobs_in_build = False
50 self.executor_server.release()
James E. Blairc494d542014-08-06 09:23:52 -070051 self.waitUntilSettled()
52
53 self.assertEqual(len(self.history), 3)
54 for job in self.history:
55 if job.changes == '1,1':
56 self.assertEqual(job.name, 'project-gate')
James E. Blairbfb8e042014-12-30 17:01:44 -080057 elif job.changes == '1,1 2,1':
James E. Blairc494d542014-08-06 09:23:52 -070058 self.assertEqual(job.name, 'project-check')
59 elif job.changes == '1,1 3,1':
60 self.assertEqual(job.name, 'project-gate')
61 else:
62 raise Exception("Unknown job")
63
James E. Blairc494d542014-08-06 09:23:52 -070064
James E. Blaira80ef4e2016-12-08 14:06:36 -080065class TestZuulTriggerProjectChangeMerged(ZuulTestCase):
66
James E. Blaira80ef4e2016-12-08 14:06:36 -080067 tenant_config_file = 'config/zuultrigger/project-change-merged/main.yaml'
68
69 def test_zuul_trigger_project_change_merged(self):
James E. Blairc494d542014-08-06 09:23:52 -070070 # This test has the following three changes:
71 # A, B, C; B conflicts with A, but C does not.
72 # When A is merged, B and C should be checked for conflicts,
73 # and B should receive a -1.
James E. Blairc0acb552014-08-16 08:17:02 -070074 # D and E are used to repeat the test in the second part, but
75 # are defined here to that they end up in the trigger cache.
James E. Blairc494d542014-08-06 09:23:52 -070076 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
77 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
78 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blairc0acb552014-08-16 08:17:02 -070079 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
80 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blaira80ef4e2016-12-08 14:06:36 -080081 A.addPatchset({'conflict': 'foo'})
82 B.addPatchset({'conflict': 'bar'})
83 D.addPatchset({'conflict2': 'foo'})
84 E.addPatchset({'conflict2': 'bar'})
Tobias Henkelbf24fd12017-07-27 06:13:07 +020085 A.addApproval('Code-Review', 2)
86 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blairc494d542014-08-06 09:23:52 -070087 self.waitUntilSettled()
88
89 self.assertEqual(len(self.history), 1)
90 self.assertEqual(self.history[0].name, 'project-gate')
91 self.assertEqual(A.reported, 2)
92 self.assertEqual(B.reported, 1)
93 self.assertEqual(C.reported, 0)
James E. Blairc0acb552014-08-16 08:17:02 -070094 self.assertEqual(D.reported, 0)
95 self.assertEqual(E.reported, 0)
Joshua Hesketh29d99b72014-08-19 16:27:42 +100096 self.assertEqual(
97 B.messages[0],
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +000098 "Merge Failed.\n\nThis change or one of its cross-repo "
99 "dependencies was unable to be automatically merged with the "
100 "current state of its repository. Please rebase the change and "
101 "upload a new patchset.")
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000102
James E. Blair96698e22015-04-02 07:48:21 -0700103 self.assertTrue("project:org/project status:open" in
104 self.fake_gerrit.queries)
James E. Blairc0acb552014-08-16 08:17:02 -0700105
106 # Reconfigure and run the test again. This is a regression
107 # check to make sure that we don't end up with a stale trigger
108 # cache that has references to projects from the old
109 # configuration.
110 self.sched.reconfigure(self.config)
111
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200112 D.addApproval('Code-Review', 2)
113 self.fake_gerrit.addEvent(D.addApproval('Approved', 1))
James E. Blairc0acb552014-08-16 08:17:02 -0700114 self.waitUntilSettled()
115
116 self.assertEqual(len(self.history), 2)
117 self.assertEqual(self.history[1].name, 'project-gate')
118 self.assertEqual(A.reported, 2)
119 self.assertEqual(B.reported, 1)
120 self.assertEqual(C.reported, 0)
121 self.assertEqual(D.reported, 2)
122 self.assertEqual(E.reported, 1)
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000123 self.assertEqual(
124 E.messages[0],
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +0000125 "Merge Failed.\n\nThis change or one of its cross-repo "
126 "dependencies was unable to be automatically merged with the "
127 "current state of its repository. Please rebase the change and "
128 "upload a new patchset.")
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000129 self.assertEqual(self.fake_gerrit.queries[1],
130 "project:org/project status:open")