blob: fff29249cd78353afd86f7a5cd445202689a4359 [file] [log] [blame]
James E. Blaircdd00072012-06-08 19:17:28 -07001:title: Project Gating
2
3Project Gating
4==============
5
6Traditionally, many software development projects merge changes from
7developers into the repository, and then identify regressions
8resulting from those changes (perhaps by running a test suite with a
9continuous integration system such as Jenkins), followed by more
10patches to fix those bugs. When the mainline of development is
11broken, it can be very frustrating for developers and can cause lost
12productivity, particularly so when the number of contributors or
13contributions is large.
14
15The process of gating attempts to prevent changes that introduce
16regressions from being merged. This keeps the mainline of development
17open and working for all developers, and only when a change is
18confirmed to work without disruption is it merged.
19
20Many projects practice an informal method of gating where developers
21with mainline commit access ensure that a test suite runs before
22merging a change. With more developers, more changes, and more
23comprehensive test suites, that process does not scale very well, and
24is not the best use of a developer's time. Zuul can help automate
25this process, with a particular emphasis on ensuring large numbers of
26changes are tested correctly.
27
28Zuul was designed to handle the workflow of the OpenStack project, but
29can be used with any project.
30
Antoine Musso55867532014-01-10 18:24:35 +010031Testing in parallel
32-------------------
33
James E. Blaircdd00072012-06-08 19:17:28 -070034A particular focus of Zuul is ensuring correctly ordered testing of
35changes in parallel. A gating system should always test each change
36applied to the tip of the branch exactly as it is going to be merged.
37A simple way to do that would be to test one change at a time, and
38merge it only if it passes tests. That works very well, but if
39changes take a long time to test, developers may have to wait a long
40time for their changes to make it into the repository. With some
41projects, it may take hours to test changes, and it is easy for
42developers to create changes at a rate faster than they can be tested
43and merged.
44
Clark Boylan00635dc2012-09-19 14:03:08 -070045Zuul's DependentPipelineManager allows for parallel execution of test
James E. Blaircdd00072012-06-08 19:17:28 -070046jobs for gating while ensuring changes are tested correctly, exactly
47as if they had been tested one at a time. It does this by performing
48speculative execution of test jobs; it assumes that all jobs will
49succeed and tests them in parallel accordingly. If they do succeed,
50they can all be merged. However, if one fails, then changes that were
51expecting it to succeed are re-tested without the failed change. In
52the best case, as many changes as execution contexts are available may
53be tested in parallel and merged at once. In the worst case, changes
54are tested one at a time (as each subsequent change fails, changes
55behind it start again). In practice, the OpenStack project observes
56something closer to the best case.
57
58For example, if a core developer approves five changes in rapid
59succession::
60
61 A, B, C, D, E
62
63Zuul queues those changes in the order they were approved, and notes
Antoine Musso3a43e142013-10-30 23:51:58 +010064that each subsequent change depends on the one ahead of it merging:
James E. Blaircdd00072012-06-08 19:17:28 -070065
Antoine Musso3a43e142013-10-30 23:51:58 +010066.. blockdiag::
67
68 blockdiag foo {
69 node_width = 40;
70 span_width = 40;
71 A <- B <- C <- D <- E;
72 }
James E. Blaircdd00072012-06-08 19:17:28 -070073
74Zuul then starts immediately testing all of the changes in parallel.
75But in the case of changes that depend on others, it instructs the
76test system to include the changes ahead of it, with the assumption
77they pass. That means jobs testing change *B* include change *A* as
78well::
79
80 Jobs for A: merge change A, then test
81 Jobs for B: merge changes A and B, then test
82 Jobs for C: merge changes A, B and C, then test
83 Jobs for D: merge changes A, B, C and D, then test
84 Jobs for E: merge changes A, B, C, D and E, then test
85
Antoine Musso3a43e142013-10-30 23:51:58 +010086Hence jobs triggered to tests A will only test A and ignore B, C, D:
James E. Blaircdd00072012-06-08 19:17:28 -070087
Antoine Musso3a43e142013-10-30 23:51:58 +010088.. blockdiag::
James E. Blaircdd00072012-06-08 19:17:28 -070089
Antoine Musso3a43e142013-10-30 23:51:58 +010090 blockdiag foo {
91 node_width = 40;
92 span_width = 40;
93 master -> A -> B -> C -> D -> E;
94 group jobs_for_A {
95 label = "Merged changes for A";
96 master -> A;
97 }
98 group ignored_to_test_A {
99 label = "Ignored changes";
100 color = "lightgray";
101 B -> C -> D -> E;
102 }
103 }
James E. Blaircdd00072012-06-08 19:17:28 -0700104
Antoine Musso3a43e142013-10-30 23:51:58 +0100105The jobs for E would include the whole dependency chain: A, B, C, D, and E.
106E will be tested assuming A, B, C, and D passed:
107
108.. blockdiag::
109
110 blockdiag foo {
111 node_width = 40;
112 span_width = 40;
113 group jobs_for_E {
114 label = "Merged changes for E";
115 master -> A -> B -> C -> D -> E;
116 }
117 }
118
119If changes *A* and *B* pass tests (green), and *C*, *D*, and *E* fail (red):
120
121.. blockdiag::
122
123 blockdiag foo {
124 node_width = 40;
125 span_width = 40;
126
127 A [color = lightgreen];
128 B [color = lightgreen];
129 C [color = pink];
130 D [color = pink];
131 E [color = pink];
132
133 master <- A <- B <- C <- D <- E;
134 }
135
136Zuul will merge change *A* followed by change *B*, leaving this queue:
137
138.. blockdiag::
139
140 blockdiag foo {
141 node_width = 40;
142 span_width = 40;
143
144 C [color = pink];
145 D [color = pink];
146 E [color = pink];
147
148 C <- D <- E;
149 }
James E. Blaircdd00072012-06-08 19:17:28 -0700150
151Since *D* was dependent on *C*, it is not clear whether *D*'s failure is the
Antoine Musso3a43e142013-10-30 23:51:58 +0100152result of a defect in *D* or *C*:
James E. Blaircdd00072012-06-08 19:17:28 -0700153
Antoine Musso3a43e142013-10-30 23:51:58 +0100154.. blockdiag::
James E. Blaircdd00072012-06-08 19:17:28 -0700155
Antoine Musso3a43e142013-10-30 23:51:58 +0100156 blockdiag foo {
157 node_width = 40;
158 span_width = 40;
James E. Blaircdd00072012-06-08 19:17:28 -0700159
Antoine Musso3a43e142013-10-30 23:51:58 +0100160 C [color = pink];
161 D [label = "D\n?"];
162 E [label = "E\n?"];
163
164 C <- D <- E;
165 }
166
167Since *C* failed, Zuul will report its failure and drop *C* from the queue,
168keeping D and E:
169
170.. blockdiag::
171
172 blockdiag foo {
173 node_width = 40;
174 span_width = 40;
175
176 D [label = "D\n?"];
177 E [label = "E\n?"];
178
179 D <- E;
180 }
James E. Blaircdd00072012-06-08 19:17:28 -0700181
182This queue is the same as if two new changes had just arrived, so Zuul
183starts the process again testing *D* against the tip of the branch, and
Antoine Musso3a43e142013-10-30 23:51:58 +0100184*E* against *D*:
185
186.. blockdiag::
187
188 blockdiag foo {
189 node_width = 40;
190 span_width = 40;
191 master -> D -> E;
192 group jobs_for_D {
193 label = "Merged changes for D";
194 master -> D;
195 }
196 group ignored_to_test_D {
197 label = "Skip";
198 color = "lightgray";
199 E;
200 }
201 }
202
203.. blockdiag::
204
205 blockdiag foo {
206 node_width = 40;
207 span_width = 40;
208 group jobs_for_E {
209 label = "Merged changes for E";
210 master -> D -> E;
211 }
212 }
213
Antoine Musso55867532014-01-10 18:24:35 +0100214
James E. Blair096a80a2015-09-28 14:19:31 -0700215Cross Project Testing
216---------------------
Antoine Musso55867532014-01-10 18:24:35 +0100217
218When your projects are closely coupled together, you want to make sure
219changes entering the gate are going to be tested with the version of
220other projects currently enqueued in the gate (since they will
221eventually be merged and might introduce breaking features).
222
James E. Blair096a80a2015-09-28 14:19:31 -0700223Such relationships can be defined in Zuul configuration by registering
224a job in a DependentPipeline of several projects. Whenever a change
225enters such a pipeline, it will create references for the other
226projects as well. As an example, given a main project ``acme`` and a
227plugin ``plugin`` you can define a job ``acme-tests`` which should be
228run for both projects:
Antoine Musso55867532014-01-10 18:24:35 +0100229
230.. code-block:: yaml
231
232 pipelines:
233 - name: gate
234 manager: DependentPipelineManager
235
236 projects::
237 - name: acme
238 gate:
239 - acme-tests
240 - name: plugin
241 gate:
242 - acme-tests # Register job again
243
244Whenever a change enters the ``gate`` pipeline queue, Zuul creates a reference
245for it. For each subsequent change, an additional reference is created for the
246changes ahead in the queue. As a result, you will always be able to fetch the
247future state of your project dependencies for each change in the queue.
248
249Based on the pipeline and project definitions above, three changes are
250inserted in the ``gate`` pipeline with the associated references:
251
252 ======== ======= ====== =========
253 Change Project Branch Zuul Ref.
254 ======== ======= ====== =========
255 Change 1 acme master master/Z1
256 Change 2 plugin stable stable/Z2
257 Change 3 plugin master master/Z3
258 ======== ======= ====== =========
259
260Since the changes enter a DependentPipelineManager pipeline, Zuul creates
261additional references:
262
263 ====== ======= ========= =============================
264 Change Project Zuul Ref. Description
265 ====== ======= ========= =============================
266 1 acme master/Z1 acme master + change 1
267 ------ ------- --------- -----------------------------
268 2 acme master/Z2 acme master + change 1
269 2 plugin stable/Z2 plugin stable + change 2
270 ------ ------- --------- -----------------------------
271 3 acme master/Z3 acme master + change 1
272 3 plugin stable/Z3 plugin stable + change 2
273 3 plugin master/Z3 plugin master + change 3
274 ====== ======= ========= =============================
275
276In order to test change 3, you would clone both repositories and simply
277fetch the Z3 reference for each combination of project/branch you are
278interested in testing. For example, you could fetch ``acme`` with
279master/Z3 and ``plugin`` with master/Z3 and thus have ``acme`` with
280change 1 applied as the expected state for when Change 3 would merge.
281When your job fetches several repositories without changes ahead in the
282queue, they may not have a Z reference in which case you can just check
283out the branch.
James E. Blair096a80a2015-09-28 14:19:31 -0700284
285
286Cross Repository Dependencies
287-----------------------------
288
289Zuul permits users to specify dependencies across repositories. Using
290a special header in Git commit messages, Users may specify that a
291change depends on another change in any repository known to Zuul.
292
293Zuul's cross-repository dependencies (CRD) behave like a directed
294acyclic graph (DAG), like git itself, to indicate a one-way dependency
295relationship between changes in different git repositories. Change A
296may depend on B, but B may not depend on A.
297
298To use them, include "Depends-On: <gerrit-change-id>" in the footer of
299a commit message. Use the full Change-ID ('I' + 40 characters).
300
301
302Gate Pipeline
303~~~~~~~~~~~~~
304
305When Zuul sees CRD changes, it serializes them in the usual manner when
306enqueuing them into a pipeline. This means that if change A depends on
307B, then when they are added to the gate pipeline, B will appear first
308and A will follow. If tests for B fail, both B and A will be removed
309from the pipeline, and it will not be possible for A to merge until B
310does.
311
312Note that if changes with CRD do not share a change queue then Zuul
313is unable to enqueue them together, and the first will be required to
314merge before the second is enqueued.
315
316Check Pipeline
317~~~~~~~~~~~~~~
318
319When changes are enqueued into the check pipeline, all of the related
320dependencies (both normal git-dependencies that come from parent commits
321as well as CRD changes) appear in a dependency graph, as in gate. This
322means that even in the check pipeline, your change will be tested with
323its dependency. So changes that were previously unable to be fully
324tested until a related change landed in a different repo may now be
325tested together from the start.
326
327All of the changes are still independent (so you will note that the
328whole pipeline does not share a graph as in gate), but for each change
329tested, all of its dependencies are visually connected to it, and they
330are used to construct the git references that Zuul uses when testing.
331When looking at this graph on the status page, you will note that the
332dependencies show up as grey dots, while the actual change tested shows
333up as red or green. This is to indicate that the grey changes are only
334there to establish dependencies. Even if one of the dependencies is
335also being tested, it will show up as a grey dot when used as a
336dependency, but separately and additionally will appear as its own red
337or green dot for its test.
338
339Multiple Changes
340~~~~~~~~~~~~~~~~
341
342A Gerrit change ID may refer to multiple changes (on multiple branches
343of the same project, or even multiple projects). In these cases, Zuul
344will treat all of the changes with that change ID as dependencies. So
345if you say that change in project A Depends-On a change ID that has
346changes in two branches of project B, then when testing the change to
347project A, both project B changes will be applied, and when deciding
348whether the project A change can merge, both changes must merge ahead
349of it.
350
351A change may depend on more than one Gerrit change ID as well. So it
352is possible for a change in project A to depend on a change in project
353B and a change in project C. Simply add more "Depends-On:" lines to
354the footer.
355
356Cycles
357~~~~~~
358
359If a cycle is created by use of CRD, Zuul will abort its work very
360early. There will be no message in Gerrit and no changes that are part
361of the cycle will be enqueued into any pipeline. This is to protect
362Zuul from infinite loops.