blob: 94f169a6723c607f755e0e485240d52463c7a853 [file] [log] [blame]
James E. Blair59fdbac2015-12-07 17:08:06 -08001#!/usr/bin/env python
2
3# Copyright 2012 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. Blaira00910c2017-08-23 09:15:04 -070017import json
James E. Blaira92cbc82017-01-23 14:56:49 -080018import os
James E. Blair14abdf42015-12-09 16:11:53 -080019import textwrap
James E. Blair59fdbac2015-12-07 17:08:06 -080020
James E. Blairb9c0d772017-03-03 14:34:49 -080021import testtools
22
23import zuul.configloader
James E. Blairbf1a4f22017-03-17 10:59:37 -070024from zuul.lib import encryption
Ricardo Carrillo Cruz22994f92016-12-02 11:41:58 +000025from tests.base import AnsibleZuulTestCase, ZuulTestCase, FIXTURE_DIR
James E. Blair59fdbac2015-12-07 17:08:06 -080026
James E. Blair59fdbac2015-12-07 17:08:06 -080027
James E. Blair3f876d52016-07-22 13:07:14 -070028class TestMultipleTenants(AnsibleZuulTestCase):
James E. Blair59fdbac2015-12-07 17:08:06 -080029 # A temporary class to hold new tests while others are disabled
30
James E. Blair2a629ec2015-12-22 15:32:02 -080031 tenant_config_file = 'config/multi-tenant/main.yaml'
James E. Blair59fdbac2015-12-07 17:08:06 -080032
James E. Blair83005782015-12-11 14:46:03 -080033 def test_multiple_tenants(self):
James E. Blair96f26942015-12-09 10:15:59 -080034 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
Tobias Henkelbf24fd12017-07-27 06:13:07 +020035 A.addApproval('Code-Review', 2)
36 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blair59fdbac2015-12-07 17:08:06 -080037 self.waitUntilSettled()
James E. Blair96f26942015-12-09 10:15:59 -080038 self.assertEqual(self.getJobFromHistory('project1-test1').result,
James E. Blair59fdbac2015-12-07 17:08:06 -080039 'SUCCESS')
James E. Blair96c6bf82016-01-15 16:20:40 -080040 self.assertEqual(self.getJobFromHistory('python27').result,
41 'SUCCESS')
James E. Blair59fdbac2015-12-07 17:08:06 -080042 self.assertEqual(A.data['status'], 'MERGED')
James E. Blair96f26942015-12-09 10:15:59 -080043 self.assertEqual(A.reported, 2,
44 "A should report start and success")
45 self.assertIn('tenant-one-gate', A.messages[1],
46 "A should transit tenant-one gate")
47 self.assertNotIn('tenant-two-gate', A.messages[1],
48 "A should *not* transit tenant-two gate")
James E. Blair59fdbac2015-12-07 17:08:06 -080049
James E. Blair96f26942015-12-09 10:15:59 -080050 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
Tobias Henkelbf24fd12017-07-27 06:13:07 +020051 B.addApproval('Code-Review', 2)
52 self.fake_gerrit.addEvent(B.addApproval('Approved', 1))
James E. Blair96f26942015-12-09 10:15:59 -080053 self.waitUntilSettled()
James E. Blair96c6bf82016-01-15 16:20:40 -080054 self.assertEqual(self.getJobFromHistory('python27',
55 'org/project2').result,
56 'SUCCESS')
James E. Blair96f26942015-12-09 10:15:59 -080057 self.assertEqual(self.getJobFromHistory('project2-test1').result,
58 'SUCCESS')
59 self.assertEqual(B.data['status'], 'MERGED')
60 self.assertEqual(B.reported, 2,
61 "B should report start and success")
62 self.assertIn('tenant-two-gate', B.messages[1],
63 "B should transit tenant-two gate")
64 self.assertNotIn('tenant-one-gate', B.messages[1],
65 "B should *not* transit tenant-one gate")
James E. Blair59fdbac2015-12-07 17:08:06 -080066
James E. Blair96f26942015-12-09 10:15:59 -080067 self.assertEqual(A.reported, 2, "Activity in tenant two should"
68 "not affect tenant one")
James E. Blair14abdf42015-12-09 16:11:53 -080069
James E. Blair83005782015-12-11 14:46:03 -080070
Tobias Henkel83167622017-06-30 19:45:03 +020071class TestFinal(ZuulTestCase):
72
73 tenant_config_file = 'config/final/main.yaml'
74
75 def test_final_variant_ok(self):
76 # test clean usage of final parent job
77 in_repo_conf = textwrap.dedent(
78 """
79 - project:
80 name: org/project
81 check:
82 jobs:
83 - job-final
84 """)
85
86 file_dict = {'.zuul.yaml': in_repo_conf}
87 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
88 files=file_dict)
89 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
90 self.waitUntilSettled()
91
92 self.assertEqual(A.reported, 1)
93 self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '1')
94
95 def test_final_variant_error(self):
96 # test misuse of final parent job
97 in_repo_conf = textwrap.dedent(
98 """
99 - project:
100 name: org/project
101 check:
102 jobs:
103 - job-final:
104 vars:
105 dont_override_this: bar
106 """)
107 file_dict = {'.zuul.yaml': in_repo_conf}
108 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
109 files=file_dict)
110 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
111 self.waitUntilSettled()
112
113 # The second patch tried to override some variables.
114 # Thus it should fail.
115 self.assertEqual(A.reported, 1)
116 self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '-1')
117 self.assertIn('Unable to modify final job', A.messages[0])
118
119 def test_final_inheritance(self):
120 # test misuse of final parent job
121 in_repo_conf = textwrap.dedent(
122 """
123 - job:
124 name: project-test
125 parent: job-final
126
127 - project:
128 name: org/project
129 check:
130 jobs:
131 - project-test
132 """)
133
134 in_repo_playbook = textwrap.dedent(
135 """
136 - hosts: all
137 tasks: []
138 """)
139
140 file_dict = {'.zuul.yaml': in_repo_conf,
141 'playbooks/project-test.yaml': in_repo_playbook}
142 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
143 files=file_dict)
144 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
145 self.waitUntilSettled()
146
147 # The second patch tried to override some variables.
148 # Thus it should fail.
149 self.assertEqual(A.reported, 1)
150 self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '-1')
151 self.assertIn('Unable to inherit from final job', A.messages[0])
152
153
James E. Blairff555742017-02-19 11:34:27 -0800154class TestInRepoConfig(ZuulTestCase):
James E. Blair83005782015-12-11 14:46:03 -0800155 # A temporary class to hold new tests while others are disabled
156
Tobias Henkelabf973e2017-07-28 10:07:34 +0200157 config_file = 'zuul-connections-gerrit-and-github.conf'
James E. Blair2a629ec2015-12-22 15:32:02 -0800158 tenant_config_file = 'config/in-repo/main.yaml'
James E. Blair83005782015-12-11 14:46:03 -0800159
James E. Blair83005782015-12-11 14:46:03 -0800160 def test_in_repo_config(self):
James E. Blair14abdf42015-12-09 16:11:53 -0800161 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200162 A.addApproval('Code-Review', 2)
163 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blair14abdf42015-12-09 16:11:53 -0800164 self.waitUntilSettled()
165 self.assertEqual(self.getJobFromHistory('project-test1').result,
166 'SUCCESS')
167 self.assertEqual(A.data['status'], 'MERGED')
168 self.assertEqual(A.reported, 2,
169 "A should report start and success")
170 self.assertIn('tenant-one-gate', A.messages[1],
171 "A should transit tenant-one gate")
James E. Blairb97ed802015-12-21 15:55:35 -0800172
James E. Blair8b1dc3f2016-07-05 16:49:00 -0700173 def test_dynamic_config(self):
174 in_repo_conf = textwrap.dedent(
175 """
176 - job:
Tobias Henkelf02cf512017-07-21 22:55:34 +0200177 name: project-test1
178
179 - job:
James E. Blair8b1dc3f2016-07-05 16:49:00 -0700180 name: project-test2
181
182 - project:
183 name: org/project
184 tenant-one-gate:
185 jobs:
186 - project-test2
187 """)
188
James E. Blairc73c73a2017-01-20 15:15:15 -0800189 in_repo_playbook = textwrap.dedent(
190 """
191 - hosts: all
192 tasks: []
193 """)
194
195 file_dict = {'.zuul.yaml': in_repo_conf,
196 'playbooks/project-test2.yaml': in_repo_playbook}
James E. Blair8b1dc3f2016-07-05 16:49:00 -0700197 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
James E. Blairc73c73a2017-01-20 15:15:15 -0800198 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200199 A.addApproval('Code-Review', 2)
200 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blair8b1dc3f2016-07-05 16:49:00 -0700201 self.waitUntilSettled()
James E. Blair8b1dc3f2016-07-05 16:49:00 -0700202 self.assertEqual(A.data['status'], 'MERGED')
203 self.assertEqual(A.reported, 2,
204 "A should report start and success")
205 self.assertIn('tenant-one-gate', A.messages[1],
206 "A should transit tenant-one gate")
James E. Blair646322f2017-01-27 15:50:34 -0800207 self.assertHistory([
208 dict(name='project-test2', result='SUCCESS', changes='1,1')])
209
James E. Blairc2a5ed72017-02-20 14:12:01 -0500210 self.fake_gerrit.addEvent(A.getChangeMergedEvent())
James E. Blair7bbd7a32017-03-06 11:36:13 -0800211 self.waitUntilSettled()
James E. Blairc2a5ed72017-02-20 14:12:01 -0500212
James E. Blair646322f2017-01-27 15:50:34 -0800213 # Now that the config change is landed, it should be live for
214 # subsequent changes.
215 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200216 B.addApproval('Code-Review', 2)
217 self.fake_gerrit.addEvent(B.addApproval('Approved', 1))
James E. Blair646322f2017-01-27 15:50:34 -0800218 self.waitUntilSettled()
219 self.assertEqual(self.getJobFromHistory('project-test2').result,
220 'SUCCESS')
221 self.assertHistory([
222 dict(name='project-test2', result='SUCCESS', changes='1,1'),
223 dict(name='project-test2', result='SUCCESS', changes='2,1')])
James E. Blairc73c73a2017-01-20 15:15:15 -0800224
Tobias Henkelf02cf512017-07-21 22:55:34 +0200225 def test_dynamic_config_non_existing_job(self):
226 """Test that requesting a non existent job fails"""
227 in_repo_conf = textwrap.dedent(
228 """
229 - job:
230 name: project-test1
231
232 - project:
233 name: org/project
234 check:
235 jobs:
236 - non-existent-job
237 """)
238
239 in_repo_playbook = textwrap.dedent(
240 """
241 - hosts: all
242 tasks: []
243 """)
244
245 file_dict = {'.zuul.yaml': in_repo_conf,
246 'playbooks/project-test2.yaml': in_repo_playbook}
247 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
248 files=file_dict)
249 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
250 self.waitUntilSettled()
251 self.assertEqual(A.reported, 1,
252 "A should report failure")
253 self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1")
254 self.assertIn('Job non-existent-job not defined', A.messages[0],
255 "A should have failed the check pipeline")
256 self.assertHistory([])
257
258 def test_dynamic_config_non_existing_job_in_template(self):
259 """Test that requesting a non existent job fails"""
260 in_repo_conf = textwrap.dedent(
261 """
262 - job:
263 name: project-test1
264
265 - project-template:
266 name: test-template
267 check:
268 jobs:
269 - non-existent-job
270
271 - project:
272 name: org/project
273 templates:
274 - test-template
275 """)
276
277 in_repo_playbook = textwrap.dedent(
278 """
279 - hosts: all
280 tasks: []
281 """)
282
283 file_dict = {'.zuul.yaml': in_repo_conf,
284 'playbooks/project-test2.yaml': in_repo_playbook}
285 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
286 files=file_dict)
287 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
288 self.waitUntilSettled()
289 self.assertEqual(A.reported, 1,
290 "A should report failure")
291 self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1")
292 self.assertIn('Job non-existent-job not defined', A.messages[0],
293 "A should have failed the check pipeline")
294 self.assertHistory([])
295
Tobias Henkel0f714002017-06-30 23:30:52 +0200296 def test_dynamic_config_new_patchset(self):
297 self.executor_server.hold_jobs_in_build = True
298
299 tenant = self.sched.abide.tenants.get('tenant-one')
300 check_pipeline = tenant.layout.pipelines['check']
301
302 in_repo_conf = textwrap.dedent(
303 """
304 - job:
Tobias Henkelf02cf512017-07-21 22:55:34 +0200305 name: project-test1
306
307 - job:
Tobias Henkel0f714002017-06-30 23:30:52 +0200308 name: project-test2
309
310 - project:
311 name: org/project
312 check:
313 jobs:
314 - project-test2
315 """)
316
317 in_repo_playbook = textwrap.dedent(
318 """
319 - hosts: all
320 tasks: []
321 """)
322
323 file_dict = {'.zuul.yaml': in_repo_conf,
324 'playbooks/project-test2.yaml': in_repo_playbook}
325 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
326 files=file_dict)
327 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
328 self.waitUntilSettled()
329
330 items = check_pipeline.getAllItems()
331 self.assertEqual(items[0].change.number, '1')
332 self.assertEqual(items[0].change.patchset, '1')
333 self.assertTrue(items[0].live)
334
335 in_repo_conf = textwrap.dedent(
336 """
337 - job:
Tobias Henkel0ce7ec62017-07-21 22:50:17 +0200338 name: project-test1
339
340 - job:
Tobias Henkel0f714002017-06-30 23:30:52 +0200341 name: project-test2
342
343 - project:
344 name: org/project
345 check:
346 jobs:
347 - project-test1
348 - project-test2
349 """)
350 file_dict = {'.zuul.yaml': in_repo_conf,
351 'playbooks/project-test2.yaml': in_repo_playbook}
352
353 A.addPatchset(files=file_dict)
354 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
355
356 self.waitUntilSettled()
357
358 items = check_pipeline.getAllItems()
359 self.assertEqual(items[0].change.number, '1')
360 self.assertEqual(items[0].change.patchset, '2')
361 self.assertTrue(items[0].live)
362
363 self.executor_server.hold_jobs_in_build = False
Tobias Henkel0ce7ec62017-07-21 22:50:17 +0200364 self.executor_server.release('project-test1')
365 self.waitUntilSettled()
Tobias Henkel0f714002017-06-30 23:30:52 +0200366 self.executor_server.release()
367 self.waitUntilSettled()
368
Tobias Henkel0ce7ec62017-07-21 22:50:17 +0200369 self.assertHistory([
370 dict(name='project-test2', result='ABORTED', changes='1,1'),
371 dict(name='project-test1', result='SUCCESS', changes='1,2'),
372 dict(name='project-test2', result='SUCCESS', changes='1,2')])
373
James E. Blairff555742017-02-19 11:34:27 -0800374 def test_in_repo_branch(self):
375 in_repo_conf = textwrap.dedent(
376 """
377 - job:
Tobias Henkelf02cf512017-07-21 22:55:34 +0200378 name: project-test1
379
380 - job:
James E. Blairff555742017-02-19 11:34:27 -0800381 name: project-test2
382
383 - project:
384 name: org/project
385 tenant-one-gate:
386 jobs:
387 - project-test2
388 """)
389
390 in_repo_playbook = textwrap.dedent(
391 """
392 - hosts: all
393 tasks: []
394 """)
395
396 file_dict = {'.zuul.yaml': in_repo_conf,
397 'playbooks/project-test2.yaml': in_repo_playbook}
398 self.create_branch('org/project', 'stable')
James E. Blair72facdc2017-08-17 10:29:12 -0700399 self.fake_gerrit.addEvent(
400 self.fake_gerrit.getFakeBranchCreatedEvent(
401 'org/project', 'stable'))
James E. Blairff555742017-02-19 11:34:27 -0800402 A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A',
403 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200404 A.addApproval('Code-Review', 2)
405 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blairff555742017-02-19 11:34:27 -0800406 self.waitUntilSettled()
407 self.assertEqual(A.data['status'], 'MERGED')
408 self.assertEqual(A.reported, 2,
409 "A should report start and success")
410 self.assertIn('tenant-one-gate', A.messages[1],
411 "A should transit tenant-one gate")
412 self.assertHistory([
413 dict(name='project-test2', result='SUCCESS', changes='1,1')])
414 self.fake_gerrit.addEvent(A.getChangeMergedEvent())
James E. Blair7bbd7a32017-03-06 11:36:13 -0800415 self.waitUntilSettled()
James E. Blairff555742017-02-19 11:34:27 -0800416
417 # The config change should not affect master.
418 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200419 B.addApproval('Code-Review', 2)
420 self.fake_gerrit.addEvent(B.addApproval('Approved', 1))
James E. Blairff555742017-02-19 11:34:27 -0800421 self.waitUntilSettled()
422 self.assertHistory([
423 dict(name='project-test2', result='SUCCESS', changes='1,1'),
424 dict(name='project-test1', result='SUCCESS', changes='2,1')])
425
426 # The config change should be live for further changes on
427 # stable.
428 C = self.fake_gerrit.addFakeChange('org/project', 'stable', 'C')
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200429 C.addApproval('Code-Review', 2)
430 self.fake_gerrit.addEvent(C.addApproval('Approved', 1))
James E. Blairff555742017-02-19 11:34:27 -0800431 self.waitUntilSettled()
432 self.assertHistory([
433 dict(name='project-test2', result='SUCCESS', changes='1,1'),
434 dict(name='project-test1', result='SUCCESS', changes='2,1'),
435 dict(name='project-test2', result='SUCCESS', changes='3,1')])
436
James E. Blaira5a12492017-05-03 11:40:48 -0700437 def test_crd_dynamic_config_branch(self):
438 # Test that we can create a job in one repo and be able to use
439 # it from a different branch on a different repo.
440
441 self.create_branch('org/project1', 'stable')
James E. Blair72facdc2017-08-17 10:29:12 -0700442 self.fake_gerrit.addEvent(
443 self.fake_gerrit.getFakeBranchCreatedEvent(
444 'org/project1', 'stable'))
James E. Blaira5a12492017-05-03 11:40:48 -0700445
446 in_repo_conf = textwrap.dedent(
447 """
448 - job:
Tobias Henkelf02cf512017-07-21 22:55:34 +0200449 name: project-test1
450
451 - job:
James E. Blaira5a12492017-05-03 11:40:48 -0700452 name: project-test2
453
454 - project:
455 name: org/project
456 check:
457 jobs:
458 - project-test2
459 """)
460
461 in_repo_playbook = textwrap.dedent(
462 """
463 - hosts: all
464 tasks: []
465 """)
466
467 file_dict = {'.zuul.yaml': in_repo_conf,
468 'playbooks/project-test2.yaml': in_repo_playbook}
469 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
470 files=file_dict)
471
472 second_repo_conf = textwrap.dedent(
473 """
474 - project:
475 name: org/project1
476 check:
477 jobs:
478 - project-test2
479 """)
480
481 second_file_dict = {'.zuul.yaml': second_repo_conf}
482 B = self.fake_gerrit.addFakeChange('org/project1', 'stable', 'B',
483 files=second_file_dict)
484 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
485 B.subject, A.data['id'])
486
487 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
488 self.waitUntilSettled()
489 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
490 self.waitUntilSettled()
491
492 self.assertEqual(A.reported, 1, "A should report")
493 self.assertHistory([
494 dict(name='project-test2', result='SUCCESS', changes='1,1'),
495 dict(name='project-test2', result='SUCCESS', changes='1,1 2,1'),
496 ])
497
James E. Blair97043882017-09-06 15:51:17 -0700498 def test_yaml_list_error(self):
499 in_repo_conf = textwrap.dedent(
500 """
501 job: foo
502 """)
503
504 file_dict = {'.zuul.yaml': in_repo_conf}
505 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
506 files=file_dict)
507 A.addApproval('Code-Review', 2)
508 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
509 self.waitUntilSettled()
510
511 self.assertEqual(A.data['status'], 'NEW')
512 self.assertEqual(A.reported, 1,
513 "A should report failure")
514 self.assertIn('not a list', A.messages[0],
515 "A should have a syntax error reported")
516
517 def test_yaml_dict_error(self):
518 in_repo_conf = textwrap.dedent(
519 """
520 - job
521 """)
522
523 file_dict = {'.zuul.yaml': in_repo_conf}
524 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
525 files=file_dict)
526 A.addApproval('Code-Review', 2)
527 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
528 self.waitUntilSettled()
529
530 self.assertEqual(A.data['status'], 'NEW')
531 self.assertEqual(A.reported, 1,
532 "A should report failure")
533 self.assertIn('not a dictionary', A.messages[0],
534 "A should have a syntax error reported")
535
536 def test_yaml_key_error(self):
537 in_repo_conf = textwrap.dedent(
538 """
539 - job:
540 name: project-test2
541 """)
542
543 file_dict = {'.zuul.yaml': in_repo_conf}
544 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
545 files=file_dict)
546 A.addApproval('Code-Review', 2)
547 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
548 self.waitUntilSettled()
549
550 self.assertEqual(A.data['status'], 'NEW')
551 self.assertEqual(A.reported, 1,
552 "A should report failure")
553 self.assertIn('has more than one key', A.messages[0],
554 "A should have a syntax error reported")
555
556 def test_yaml_unknown_error(self):
557 in_repo_conf = textwrap.dedent(
558 """
559 - foobar:
560 foo: bar
561 """)
562
563 file_dict = {'.zuul.yaml': in_repo_conf}
564 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
565 files=file_dict)
566 A.addApproval('Code-Review', 2)
567 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
568 self.waitUntilSettled()
569
570 self.assertEqual(A.data['status'], 'NEW')
571 self.assertEqual(A.reported, 1,
572 "A should report failure")
573 self.assertIn('not recognized', A.messages[0],
574 "A should have a syntax error reported")
575
James E. Blair149b69c2017-03-02 10:48:16 -0800576 def test_untrusted_syntax_error(self):
James E. Blaire53250c2017-03-01 14:34:36 -0800577 in_repo_conf = textwrap.dedent(
578 """
579 - job:
580 name: project-test2
581 foo: error
582 """)
583
584 file_dict = {'.zuul.yaml': in_repo_conf}
585 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
586 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200587 A.addApproval('Code-Review', 2)
588 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blaire53250c2017-03-01 14:34:36 -0800589 self.waitUntilSettled()
590
591 self.assertEqual(A.data['status'], 'NEW')
Tobias Henkel9842bd72017-05-16 13:40:03 +0200592 self.assertEqual(A.reported, 1,
593 "A should report failure")
594 self.assertIn('syntax error', A.messages[0],
James E. Blaire53250c2017-03-01 14:34:36 -0800595 "A should have a syntax error reported")
596
James E. Blair149b69c2017-03-02 10:48:16 -0800597 def test_trusted_syntax_error(self):
598 in_repo_conf = textwrap.dedent(
599 """
600 - job:
601 name: project-test2
602 foo: error
603 """)
604
605 file_dict = {'zuul.yaml': in_repo_conf}
606 A = self.fake_gerrit.addFakeChange('common-config', 'master', 'A',
607 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200608 A.addApproval('Code-Review', 2)
609 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blair149b69c2017-03-02 10:48:16 -0800610 self.waitUntilSettled()
611
612 self.assertEqual(A.data['status'], 'NEW')
Tobias Henkel9842bd72017-05-16 13:40:03 +0200613 self.assertEqual(A.reported, 1,
614 "A should report failure")
615 self.assertIn('syntax error', A.messages[0],
James E. Blair149b69c2017-03-02 10:48:16 -0800616 "A should have a syntax error reported")
617
James E. Blair6f140c72017-03-03 10:32:07 -0800618 def test_untrusted_yaml_error(self):
619 in_repo_conf = textwrap.dedent(
620 """
621 - job:
622 foo: error
623 """)
624
625 file_dict = {'.zuul.yaml': in_repo_conf}
626 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
627 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200628 A.addApproval('Code-Review', 2)
629 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blair6f140c72017-03-03 10:32:07 -0800630 self.waitUntilSettled()
631
632 self.assertEqual(A.data['status'], 'NEW')
Tobias Henkel9842bd72017-05-16 13:40:03 +0200633 self.assertEqual(A.reported, 1,
634 "A should report failure")
635 self.assertIn('syntax error', A.messages[0],
James E. Blair6f140c72017-03-03 10:32:07 -0800636 "A should have a syntax error reported")
637
James E. Blairdb04e6a2017-05-03 14:49:36 -0700638 def test_untrusted_shadow_error(self):
639 in_repo_conf = textwrap.dedent(
640 """
641 - job:
642 name: common-config-test
643 """)
644
645 file_dict = {'.zuul.yaml': in_repo_conf}
646 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
647 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200648 A.addApproval('Code-Review', 2)
649 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blairdb04e6a2017-05-03 14:49:36 -0700650 self.waitUntilSettled()
651
652 self.assertEqual(A.data['status'], 'NEW')
Tobias Henkel9842bd72017-05-16 13:40:03 +0200653 self.assertEqual(A.reported, 1,
654 "A should report failure")
655 self.assertIn('not permitted to shadow', A.messages[0],
James E. Blairdb04e6a2017-05-03 14:49:36 -0700656 "A should have a syntax error reported")
657
James E. Blaird5656ad2017-06-02 14:29:41 -0700658 def test_untrusted_pipeline_error(self):
659 in_repo_conf = textwrap.dedent(
660 """
661 - pipeline:
662 name: test
663 """)
664
665 file_dict = {'.zuul.yaml': in_repo_conf}
666 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
667 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200668 A.addApproval('Code-Review', 2)
669 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blaird5656ad2017-06-02 14:29:41 -0700670 self.waitUntilSettled()
671
672 self.assertEqual(A.data['status'], 'NEW')
673 self.assertEqual(A.reported, 1,
674 "A should report failure")
675 self.assertIn('Pipelines may not be defined', A.messages[0],
676 "A should have a syntax error reported")
677
678 def test_untrusted_project_error(self):
679 in_repo_conf = textwrap.dedent(
680 """
681 - project:
682 name: org/project1
683 """)
684
685 file_dict = {'.zuul.yaml': in_repo_conf}
686 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
687 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200688 A.addApproval('Code-Review', 2)
689 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blaird5656ad2017-06-02 14:29:41 -0700690 self.waitUntilSettled()
691
692 self.assertEqual(A.data['status'], 'NEW')
693 self.assertEqual(A.reported, 1,
694 "A should report failure")
695 self.assertIn('the only project definition permitted', A.messages[0],
696 "A should have a syntax error reported")
697
James E. Blaire64b0e42017-06-08 11:23:34 -0700698 def test_duplicate_node_error(self):
699 in_repo_conf = textwrap.dedent(
700 """
701 - nodeset:
702 name: duplicate
703 nodes:
704 - name: compute
James E. Blair16d96a02017-06-08 11:32:56 -0700705 label: foo
James E. Blaire64b0e42017-06-08 11:23:34 -0700706 - name: compute
James E. Blair16d96a02017-06-08 11:32:56 -0700707 label: foo
James E. Blaire64b0e42017-06-08 11:23:34 -0700708 """)
709
710 file_dict = {'.zuul.yaml': in_repo_conf}
711 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
712 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200713 A.addApproval('Code-Review', 2)
714 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blaire64b0e42017-06-08 11:23:34 -0700715 self.waitUntilSettled()
716
717 self.assertEqual(A.data['status'], 'NEW')
718 self.assertEqual(A.reported, 1,
719 "A should report failure")
720 self.assertIn('appears multiple times', A.messages[0],
721 "A should have a syntax error reported")
722
723 def test_duplicate_group_error(self):
724 in_repo_conf = textwrap.dedent(
725 """
726 - nodeset:
727 name: duplicate
728 nodes:
729 - name: compute
James E. Blair16d96a02017-06-08 11:32:56 -0700730 label: foo
James E. Blaire64b0e42017-06-08 11:23:34 -0700731 groups:
732 - name: group
733 nodes: compute
734 - name: group
735 nodes: compute
736 """)
737
738 file_dict = {'.zuul.yaml': in_repo_conf}
739 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
740 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200741 A.addApproval('Code-Review', 2)
742 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blaire64b0e42017-06-08 11:23:34 -0700743 self.waitUntilSettled()
744
745 self.assertEqual(A.data['status'], 'NEW')
746 self.assertEqual(A.reported, 1,
747 "A should report failure")
748 self.assertIn('appears multiple times', A.messages[0],
749 "A should have a syntax error reported")
750
James E. Blair4ae399f2017-09-20 17:15:09 -0700751 def test_secret_not_found_error(self):
752 in_repo_conf = textwrap.dedent(
753 """
754 - job:
755 name: test
756 secrets: does-not-exist
757 """)
758
759 file_dict = {'.zuul.yaml': in_repo_conf}
760 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
761 files=file_dict)
762 A.addApproval('Code-Review', 2)
763 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
764 self.waitUntilSettled()
765
766 self.assertEqual(A.data['status'], 'NEW')
767 self.assertEqual(A.reported, 1,
768 "A should report failure")
769 self.assertIn('secret "does-not-exist" was not found', A.messages[0],
770 "A should have a syntax error reported")
771
772 def test_nodeset_not_found_error(self):
773 in_repo_conf = textwrap.dedent(
774 """
775 - job:
776 name: test
777 nodeset: does-not-exist
778 """)
779
780 file_dict = {'.zuul.yaml': in_repo_conf}
781 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
782 files=file_dict)
783 A.addApproval('Code-Review', 2)
784 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
785 self.waitUntilSettled()
786
787 self.assertEqual(A.data['status'], 'NEW')
788 self.assertEqual(A.reported, 1,
789 "A should report failure")
790 self.assertIn('nodeset "does-not-exist" was not found', A.messages[0],
791 "A should have a syntax error reported")
792
James E. Blair09f9ffe2017-07-11 15:30:25 -0700793 def test_multi_repo(self):
794 downstream_repo_conf = textwrap.dedent(
795 """
796 - project:
797 name: org/project1
798 tenant-one-gate:
799 jobs:
800 - project-test1
801
802 - job:
803 name: project1-test1
804 parent: project-test1
805 """)
806
807 file_dict = {'.zuul.yaml': downstream_repo_conf}
808 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A',
809 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200810 A.addApproval('Code-Review', 2)
811 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blair09f9ffe2017-07-11 15:30:25 -0700812 self.waitUntilSettled()
813
814 self.assertEqual(A.data['status'], 'MERGED')
815 self.fake_gerrit.addEvent(A.getChangeMergedEvent())
816 self.waitUntilSettled()
817
818 upstream_repo_conf = textwrap.dedent(
819 """
820 - job:
821 name: project-test1
822
823 - job:
824 name: project-test2
825
826 - project:
827 name: org/project
828 tenant-one-gate:
829 jobs:
830 - project-test1
831 """)
832
833 file_dict = {'.zuul.yaml': upstream_repo_conf}
834 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B',
835 files=file_dict)
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200836 B.addApproval('Code-Review', 2)
837 self.fake_gerrit.addEvent(B.addApproval('Approved', 1))
James E. Blair09f9ffe2017-07-11 15:30:25 -0700838 self.waitUntilSettled()
839
840 self.assertEqual(B.data['status'], 'MERGED')
841 self.fake_gerrit.addEvent(B.getChangeMergedEvent())
842 self.waitUntilSettled()
843
844 tenant = self.sched.abide.tenants.get('tenant-one')
845 # Ensure the latest change is reflected in the config; if it
846 # isn't this will raise an exception.
847 tenant.layout.getJob('project-test2')
848
James E. Blair332636e2017-09-05 10:14:35 -0700849 def test_pipeline_error(self):
850 with open(os.path.join(FIXTURE_DIR,
851 'config/in-repo/git/',
852 'common-config/zuul.yaml')) as f:
853 base_common_config = f.read()
854
855 in_repo_conf_A = textwrap.dedent(
856 """
857 - pipeline:
858 name: periodic
859 foo: error
860 """)
861
862 file_dict = {'zuul.yaml': None,
863 'zuul.d/main.yaml': base_common_config,
864 'zuul.d/test1.yaml': in_repo_conf_A}
865 A = self.fake_gerrit.addFakeChange('common-config', 'master', 'A',
866 files=file_dict)
867 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
868 self.waitUntilSettled()
869 self.assertEqual(A.reported, 1,
870 "A should report failure")
871 self.assertIn('syntax error',
872 A.messages[0],
873 "A should have an error reported")
874
875 def test_change_series_error(self):
876 with open(os.path.join(FIXTURE_DIR,
877 'config/in-repo/git/',
878 'common-config/zuul.yaml')) as f:
879 base_common_config = f.read()
880
881 in_repo_conf_A = textwrap.dedent(
882 """
883 - pipeline:
884 name: periodic
885 foo: error
886 """)
887
888 file_dict = {'zuul.yaml': None,
889 'zuul.d/main.yaml': base_common_config,
890 'zuul.d/test1.yaml': in_repo_conf_A}
891 A = self.fake_gerrit.addFakeChange('common-config', 'master', 'A',
892 files=file_dict)
893
894 in_repo_conf_B = textwrap.dedent(
895 """
896 - job:
897 name: project-test2
898 foo: error
899 """)
900
901 file_dict = {'zuul.yaml': None,
902 'zuul.d/main.yaml': base_common_config,
903 'zuul.d/test1.yaml': in_repo_conf_A,
904 'zuul.d/test2.yaml': in_repo_conf_B}
905 B = self.fake_gerrit.addFakeChange('common-config', 'master', 'B',
906 files=file_dict)
907 B.setDependsOn(A, 1)
908 C = self.fake_gerrit.addFakeChange('common-config', 'master', 'C')
909 C.setDependsOn(B, 1)
910 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
911 self.waitUntilSettled()
912
913 self.assertEqual(C.reported, 1,
914 "C should report failure")
915 self.assertIn('depends on a change that failed to merge',
916 C.messages[0],
917 "C should have an error reported")
918
James E. Blairc73c73a2017-01-20 15:15:15 -0800919
James E. Blairc9455002017-09-06 09:22:19 -0700920class TestInRepoJoin(ZuulTestCase):
921 # In this config, org/project is not a member of any pipelines, so
922 # that we may test the changes that cause it to join them.
923
924 tenant_config_file = 'config/in-repo-join/main.yaml'
925
926 def test_dynamic_dependent_pipeline(self):
927 # Test dynamically adding a project to a
928 # dependent pipeline for the first time
929 self.executor_server.hold_jobs_in_build = True
930
931 tenant = self.sched.abide.tenants.get('tenant-one')
932 gate_pipeline = tenant.layout.pipelines['gate']
933
934 in_repo_conf = textwrap.dedent(
935 """
936 - job:
937 name: project-test1
938
939 - job:
940 name: project-test2
941
942 - project:
943 name: org/project
944 gate:
945 jobs:
946 - project-test2
947 """)
948
949 in_repo_playbook = textwrap.dedent(
950 """
951 - hosts: all
952 tasks: []
953 """)
954
955 file_dict = {'.zuul.yaml': in_repo_conf,
956 'playbooks/project-test2.yaml': in_repo_playbook}
957 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
958 files=file_dict)
959 A.addApproval('Code-Review', 2)
960 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
961 self.waitUntilSettled()
962
963 items = gate_pipeline.getAllItems()
964 self.assertEqual(items[0].change.number, '1')
965 self.assertEqual(items[0].change.patchset, '1')
966 self.assertTrue(items[0].live)
967
968 self.executor_server.hold_jobs_in_build = False
969 self.executor_server.release()
970 self.waitUntilSettled()
971
972 # Make sure the dynamic queue got cleaned up
973 self.assertEqual(gate_pipeline.queues, [])
974
975 def test_dynamic_dependent_pipeline_failure(self):
976 # Test that a change behind a failing change adding a project
977 # to a dependent pipeline is dequeued.
978 self.executor_server.hold_jobs_in_build = True
979
980 in_repo_conf = textwrap.dedent(
981 """
982 - job:
983 name: project-test1
984
985 - project:
986 name: org/project
987 gate:
988 jobs:
989 - project-test1
990 """)
991
992 file_dict = {'.zuul.yaml': in_repo_conf}
993 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
994 files=file_dict)
995 self.executor_server.failJob('project-test1', A)
996 A.addApproval('Code-Review', 2)
997 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
998 self.waitUntilSettled()
999
1000 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1001 B.addApproval('Code-Review', 2)
1002 self.fake_gerrit.addEvent(B.addApproval('Approved', 1))
1003 self.waitUntilSettled()
1004
James E. Blair3490c5d2017-09-07 08:33:23 -07001005 self.orderedRelease()
James E. Blairc9455002017-09-06 09:22:19 -07001006 self.waitUntilSettled()
1007 self.assertEqual(A.reported, 2,
1008 "A should report start and failure")
1009 self.assertEqual(A.data['status'], 'NEW')
1010 self.assertEqual(B.reported, 1,
1011 "B should report start")
1012 self.assertHistory([
1013 dict(name='project-test1', result='FAILURE', changes='1,1'),
James E. Blair3490c5d2017-09-07 08:33:23 -07001014 dict(name='project-test1', result='ABORTED', changes='1,1 2,1'),
James E. Blairc9455002017-09-06 09:22:19 -07001015 ], ordered=False)
1016
James E. Blair0af198f2017-09-06 09:52:35 -07001017 def test_dynamic_dependent_pipeline_absent(self):
1018 # Test that a series of dependent changes don't report merge
1019 # failures to a pipeline they aren't in.
1020 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1021 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1022 B.setDependsOn(A, 1)
1023
1024 A.addApproval('Code-Review', 2)
1025 A.addApproval('Approved', 1)
1026 B.addApproval('Code-Review', 2)
1027 self.fake_gerrit.addEvent(B.addApproval('Approved', 1))
1028 self.waitUntilSettled()
1029 self.assertEqual(A.reported, 0,
1030 "A should not report")
1031 self.assertEqual(A.data['status'], 'NEW')
1032 self.assertEqual(B.reported, 0,
1033 "B should not report")
1034 self.assertEqual(B.data['status'], 'NEW')
1035 self.assertHistory([])
1036
James E. Blairc9455002017-09-06 09:22:19 -07001037
James E. Blairc73c73a2017-01-20 15:15:15 -08001038class TestAnsible(AnsibleZuulTestCase):
1039 # A temporary class to hold new tests while others are disabled
1040
1041 tenant_config_file = 'config/ansible/main.yaml'
1042
1043 def test_playbook(self):
Jamie Lennox7655b552017-03-17 12:33:38 +11001044 # Keep the jobdir around so we can inspect contents if an
1045 # assert fails.
1046 self.executor_server.keep_jobdir = True
1047 # Output extra ansible info so we might see errors.
1048 self.executor_server.verbose = True
1049 # Add a site variables file, used by check-vars
1050 path = os.path.join(FIXTURE_DIR, 'config', 'ansible',
1051 'variables.yaml')
1052 self.config.set('executor', 'variables', path)
James E. Blairc73c73a2017-01-20 15:15:15 -08001053 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1054 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1055 self.waitUntilSettled()
Tobias Henkel077f2f32017-05-30 20:16:46 +02001056 build_timeout = self.getJobFromHistory('timeout')
Jamie Lennox7655b552017-03-17 12:33:38 +11001057 with self.jobLog(build_timeout):
1058 self.assertEqual(build_timeout.result, 'TIMED_OUT')
Tobias Henkel077f2f32017-05-30 20:16:46 +02001059 build_faillocal = self.getJobFromHistory('faillocal')
Jamie Lennox7655b552017-03-17 12:33:38 +11001060 with self.jobLog(build_faillocal):
1061 self.assertEqual(build_faillocal.result, 'FAILURE')
Tobias Henkel077f2f32017-05-30 20:16:46 +02001062 build_failpost = self.getJobFromHistory('failpost')
Jamie Lennox7655b552017-03-17 12:33:38 +11001063 with self.jobLog(build_failpost):
1064 self.assertEqual(build_failpost.result, 'POST_FAILURE')
Tobias Henkel077f2f32017-05-30 20:16:46 +02001065 build_check_vars = self.getJobFromHistory('check-vars')
Jamie Lennox7655b552017-03-17 12:33:38 +11001066 with self.jobLog(build_check_vars):
1067 self.assertEqual(build_check_vars.result, 'SUCCESS')
Monty Tayloraff8b402017-08-16 18:40:41 -05001068 build_check_secret_names = self.getJobFromHistory('check-secret-names')
1069 with self.jobLog(build_check_secret_names):
1070 self.assertEqual(build_check_secret_names.result, 'SUCCESS')
Tobias Henkel077f2f32017-05-30 20:16:46 +02001071 build_hello = self.getJobFromHistory('hello-world')
Jamie Lennox7655b552017-03-17 12:33:38 +11001072 with self.jobLog(build_hello):
1073 self.assertEqual(build_hello.result, 'SUCCESS')
Tobias Henkel077f2f32017-05-30 20:16:46 +02001074 build_python27 = self.getJobFromHistory('python27')
Jamie Lennox7655b552017-03-17 12:33:38 +11001075 with self.jobLog(build_python27):
1076 self.assertEqual(build_python27.result, 'SUCCESS')
1077 flag_path = os.path.join(self.test_root,
1078 build_python27.uuid + '.flag')
1079 self.assertTrue(os.path.exists(flag_path))
1080 copied_path = os.path.join(self.test_root, build_python27.uuid +
1081 '.copied')
1082 self.assertTrue(os.path.exists(copied_path))
1083 failed_path = os.path.join(self.test_root, build_python27.uuid +
1084 '.failed')
1085 self.assertFalse(os.path.exists(failed_path))
1086 pre_flag_path = os.path.join(self.test_root, build_python27.uuid +
1087 '.pre.flag')
1088 self.assertTrue(os.path.exists(pre_flag_path))
1089 post_flag_path = os.path.join(self.test_root, build_python27.uuid +
1090 '.post.flag')
1091 self.assertTrue(os.path.exists(post_flag_path))
1092 bare_role_flag_path = os.path.join(self.test_root,
1093 build_python27.uuid +
1094 '.bare-role.flag')
1095 self.assertTrue(os.path.exists(bare_role_flag_path))
1096 secrets_path = os.path.join(self.test_root,
1097 build_python27.uuid + '.secrets')
1098 with open(secrets_path) as f:
1099 self.assertEqual(f.read(), "test-username test-password")
James E. Blairb9c0d772017-03-03 14:34:49 -08001100
Jamie Lennox7655b552017-03-17 12:33:38 +11001101 msg = A.messages[0]
1102 success = "{} https://success.example.com/zuul-logs/{}"
1103 fail = "{} https://failure.example.com/zuul-logs/{}"
1104 self.assertIn(success.format("python27", build_python27.uuid), msg)
1105 self.assertIn(fail.format("faillocal", build_faillocal.uuid), msg)
1106 self.assertIn(success.format("check-vars",
1107 build_check_vars.uuid), msg)
1108 self.assertIn(success.format("hello-world", build_hello.uuid), msg)
1109 self.assertIn(fail.format("timeout", build_timeout.uuid), msg)
1110 self.assertIn(fail.format("failpost", build_failpost.uuid), msg)
Tobias Henkel077f2f32017-05-30 20:16:46 +02001111
James E. Blairabbaa6f2017-04-06 16:11:44 -07001112 def _add_job(self, job_name):
1113 conf = textwrap.dedent(
1114 """
1115 - job:
1116 name: %s
1117
1118 - project:
1119 name: org/plugin-project
1120 check:
1121 jobs:
1122 - %s
1123 """ % (job_name, job_name))
1124
1125 file_dict = {'.zuul.yaml': conf}
1126 A = self.fake_gerrit.addFakeChange('org/plugin-project', 'master', 'A',
1127 files=file_dict)
1128 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1129 self.waitUntilSettled()
1130
1131 def test_plugins(self):
1132 # Keep the jobdir around so we can inspect contents if an
1133 # assert fails.
1134 self.executor_server.keep_jobdir = True
1135 # Output extra ansible info so we might see errors.
1136 self.executor_server.verbose = True
1137
1138 count = 0
1139 plugin_tests = [
1140 ('passwd', 'FAILURE'),
1141 ('cartesian', 'SUCCESS'),
1142 ('consul_kv', 'FAILURE'),
1143 ('credstash', 'FAILURE'),
1144 ('csvfile_good', 'SUCCESS'),
1145 ('csvfile_bad', 'FAILURE'),
Monty Taylor93ad2212017-08-02 14:59:50 -05001146 ('uri_bad_path', 'FAILURE'),
1147 ('uri_bad_scheme', 'FAILURE'),
Monty Taylor788a40e2017-08-02 16:14:05 -05001148 ('block_local_override', 'FAILURE'),
Monty Taylor8da768f2017-08-31 14:15:35 -05001149 ('file_local_good', 'SUCCESS'),
1150 ('file_local_bad', 'FAILURE'),
James E. Blairabbaa6f2017-04-06 16:11:44 -07001151 ]
1152 for job_name, result in plugin_tests:
1153 count += 1
1154 self._add_job(job_name)
1155
1156 job = self.getJobFromHistory(job_name)
1157 with self.jobLog(job):
1158 self.assertEqual(count, len(self.history))
1159 build = self.history[-1]
1160 self.assertEqual(build.result, result)
1161
1162 # TODOv3(jeblair): parse the ansible output and verify we're
1163 # getting the exception we expect.
1164
James E. Blairb9c0d772017-03-03 14:34:49 -08001165
James E. Blaira4d4eef2017-06-30 14:49:17 -07001166class TestPrePlaybooks(AnsibleZuulTestCase):
1167 # A temporary class to hold new tests while others are disabled
1168
1169 tenant_config_file = 'config/pre-playbook/main.yaml'
1170
1171 def test_pre_playbook_fail(self):
1172 # Test that we run the post playbooks (but not the actual
1173 # playbook) when a pre-playbook fails.
1174 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1175 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1176 self.waitUntilSettled()
1177 build = self.getJobFromHistory('python27')
1178 self.assertIsNone(build.result)
1179 self.assertIn('RETRY_LIMIT', A.messages[0])
1180 flag_path = os.path.join(self.test_root, build.uuid +
1181 '.main.flag')
1182 self.assertFalse(os.path.exists(flag_path))
1183 pre_flag_path = os.path.join(self.test_root, build.uuid +
1184 '.pre.flag')
1185 self.assertFalse(os.path.exists(pre_flag_path))
1186 post_flag_path = os.path.join(self.test_root, build.uuid +
1187 '.post.flag')
James E. Blair21037782017-07-19 11:56:55 -07001188 self.assertTrue(os.path.exists(post_flag_path),
1189 "The file %s should exist" % post_flag_path)
James E. Blaira4d4eef2017-06-30 14:49:17 -07001190
1191
James E. Blairb9c0d772017-03-03 14:34:49 -08001192class TestBrokenConfig(ZuulTestCase):
1193 # Test that we get an appropriate syntax error if we start with a
1194 # broken config.
1195
1196 tenant_config_file = 'config/broken/main.yaml'
1197
1198 def setUp(self):
1199 with testtools.ExpectedException(
1200 zuul.configloader.ConfigurationSyntaxError,
1201 "\nZuul encountered a syntax error"):
1202 super(TestBrokenConfig, self).setUp()
1203
1204 def test_broken_config_on_startup(self):
1205 pass
Ricardo Carrillo Cruz22994f92016-12-02 11:41:58 +00001206
1207
1208class TestProjectKeys(ZuulTestCase):
1209 # Test that we can generate project keys
1210
1211 # Normally the test infrastructure copies a static key in place
1212 # for each project before starting tests. This saves time because
1213 # Zuul's automatic key-generation on startup can be slow. To make
1214 # sure we exercise that code, in this test we allow Zuul to create
1215 # keys for the project on startup.
1216 create_project_keys = True
Tobias Henkelabf973e2017-07-28 10:07:34 +02001217 config_file = 'zuul-connections-gerrit-and-github.conf'
Ricardo Carrillo Cruz22994f92016-12-02 11:41:58 +00001218 tenant_config_file = 'config/in-repo/main.yaml'
1219
1220 def test_key_generation(self):
1221 key_root = os.path.join(self.state_root, 'keys')
1222 private_key_file = os.path.join(key_root, 'gerrit/org/project.pem')
1223 # Make sure that a proper key was created on startup
1224 with open(private_key_file, "rb") as f:
James E. Blairbf1a4f22017-03-17 10:59:37 -07001225 private_key, public_key = \
1226 encryption.deserialize_rsa_keypair(f.read())
Ricardo Carrillo Cruz22994f92016-12-02 11:41:58 +00001227
1228 with open(os.path.join(FIXTURE_DIR, 'private.pem')) as i:
1229 fixture_private_key = i.read()
1230
1231 # Make sure that we didn't just end up with the static fixture
1232 # key
1233 self.assertNotEqual(fixture_private_key, private_key)
1234
1235 # Make sure it's the right length
1236 self.assertEqual(4096, private_key.key_size)
James E. Blairbce76932017-05-04 10:03:15 -07001237
1238
James E. Blairbb94dfa2017-07-11 07:45:19 -07001239class RoleTestCase(ZuulTestCase):
James E. Blair1b27f6a2017-07-14 14:09:07 -07001240 def _assertRolePath(self, build, playbook, content):
1241 path = os.path.join(self.test_root, build.uuid,
1242 'ansible', playbook, 'ansible.cfg')
1243 roles_paths = []
1244 with open(path) as f:
1245 for line in f:
1246 if line.startswith('roles_path'):
1247 roles_paths.append(line)
1248 print(roles_paths)
1249 if content:
1250 self.assertEqual(len(roles_paths), 1,
1251 "Should have one roles_path line in %s" %
1252 (playbook,))
1253 self.assertIn(content, roles_paths[0])
1254 else:
1255 self.assertEqual(len(roles_paths), 0,
1256 "Should have no roles_path line in %s" %
1257 (playbook,))
1258
James E. Blairbb94dfa2017-07-11 07:45:19 -07001259
1260class TestRoles(RoleTestCase):
1261 tenant_config_file = 'config/roles/main.yaml'
1262
James E. Blairbce76932017-05-04 10:03:15 -07001263 def test_role(self):
1264 # This exercises a proposed change to a role being checked out
1265 # and used.
1266 A = self.fake_gerrit.addFakeChange('bare-role', 'master', 'A')
1267 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1268 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
1269 B.subject, A.data['id'])
1270 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1271 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1272 self.waitUntilSettled()
1273 self.assertHistory([
1274 dict(name='project-test', result='SUCCESS', changes='1,1 2,1'),
1275 ])
James E. Blair6459db12017-06-29 14:57:20 -07001276
James E. Blair1b27f6a2017-07-14 14:09:07 -07001277 def test_role_inheritance(self):
1278 self.executor_server.hold_jobs_in_build = True
1279 conf = textwrap.dedent(
1280 """
1281 - job:
1282 name: parent
1283 roles:
1284 - zuul: bare-role
1285 pre-run: playbooks/parent-pre
1286 post-run: playbooks/parent-post
1287
1288 - job:
1289 name: project-test
1290 parent: parent
1291 roles:
1292 - zuul: org/project
1293
1294 - project:
1295 name: org/project
1296 check:
1297 jobs:
1298 - project-test
1299 """)
1300
1301 file_dict = {'.zuul.yaml': conf}
1302 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
1303 files=file_dict)
1304 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1305 self.waitUntilSettled()
1306
1307 self.assertEqual(len(self.builds), 1)
1308 build = self.getBuildByName('project-test')
1309 self._assertRolePath(build, 'pre_playbook_0', 'role_0')
1310 self._assertRolePath(build, 'playbook_0', 'role_0')
1311 self._assertRolePath(build, 'playbook_0', 'role_1')
1312 self._assertRolePath(build, 'post_playbook_0', 'role_0')
1313
1314 self.executor_server.hold_jobs_in_build = False
1315 self.executor_server.release()
1316 self.waitUntilSettled()
1317
1318 self.assertHistory([
1319 dict(name='project-test', result='SUCCESS', changes='1,1'),
1320 ])
1321
James E. Blair6f699732017-07-18 14:19:11 -07001322 def test_role_error(self):
1323 conf = textwrap.dedent(
1324 """
1325 - job:
1326 name: project-test
1327 roles:
1328 - zuul: common-config
1329
1330 - project:
1331 name: org/project
1332 check:
1333 jobs:
1334 - project-test
1335 """)
1336
1337 file_dict = {'.zuul.yaml': conf}
1338 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
1339 files=file_dict)
1340 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1341 self.waitUntilSettled()
1342 self.assertIn(
1343 '- project-test project-test : ERROR Unable to find role',
1344 A.messages[-1])
1345
James E. Blair6459db12017-06-29 14:57:20 -07001346
James E. Blairbb94dfa2017-07-11 07:45:19 -07001347class TestImplicitRoles(RoleTestCase):
1348 tenant_config_file = 'config/implicit-roles/main.yaml'
1349
1350 def test_missing_roles(self):
1351 # Test implicit and explicit roles for a project which does
1352 # not have roles. The implicit role should be silently
1353 # ignored since the project doesn't supply roles, but if a
1354 # user declares an explicit role, it should error.
1355 self.executor_server.hold_jobs_in_build = True
1356 A = self.fake_gerrit.addFakeChange('org/norole-project', 'master', 'A')
1357 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1358 self.waitUntilSettled()
1359
1360 self.assertEqual(len(self.builds), 2)
1361 build = self.getBuildByName('implicit-role-fail')
1362 self._assertRolePath(build, 'playbook_0', None)
1363
1364 self.executor_server.hold_jobs_in_build = False
1365 self.executor_server.release()
1366 self.waitUntilSettled()
1367 # The retry_limit doesn't get recorded
1368 self.assertHistory([
1369 dict(name='implicit-role-fail', result='SUCCESS', changes='1,1'),
1370 ])
1371
1372 def test_roles(self):
1373 # Test implicit and explicit roles for a project which does
1374 # have roles. In both cases, we should end up with the role
1375 # in the path. In the explicit case, ensure we end up with
1376 # the name we specified.
1377 self.executor_server.hold_jobs_in_build = True
1378 A = self.fake_gerrit.addFakeChange('org/role-project', 'master', 'A')
1379 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1380 self.waitUntilSettled()
1381
1382 self.assertEqual(len(self.builds), 2)
1383 build = self.getBuildByName('implicit-role-ok')
1384 self._assertRolePath(build, 'playbook_0', 'role_0')
1385
1386 build = self.getBuildByName('explicit-role-ok')
1387 self._assertRolePath(build, 'playbook_0', 'role_0')
1388
1389 self.executor_server.hold_jobs_in_build = False
1390 self.executor_server.release()
1391 self.waitUntilSettled()
1392 self.assertHistory([
1393 dict(name='implicit-role-ok', result='SUCCESS', changes='1,1'),
1394 dict(name='explicit-role-ok', result='SUCCESS', changes='1,1'),
1395 ], ordered=False)
1396
1397
James E. Blair6459db12017-06-29 14:57:20 -07001398class TestShadow(ZuulTestCase):
1399 tenant_config_file = 'config/shadow/main.yaml'
1400
1401 def test_shadow(self):
1402 # Test that a repo is allowed to shadow another's job definitions.
1403 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1404 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1405 self.waitUntilSettled()
1406 self.assertHistory([
1407 dict(name='test1', result='SUCCESS', changes='1,1'),
1408 dict(name='test2', result='SUCCESS', changes='1,1'),
James E. Blairadafa6c2017-07-12 08:50:56 -07001409 ], ordered=False)
James E. Blair196f61a2017-06-30 15:42:29 -07001410
1411
1412class TestDataReturn(AnsibleZuulTestCase):
1413 tenant_config_file = 'config/data-return/main.yaml'
1414
1415 def test_data_return(self):
1416 # This exercises a proposed change to a role being checked out
1417 # and used.
1418 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1419 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1420 self.waitUntilSettled()
1421 self.assertHistory([
1422 dict(name='data-return', result='SUCCESS', changes='1,1'),
James E. Blair88e79c02017-07-07 13:36:54 -07001423 dict(name='data-return-relative', result='SUCCESS', changes='1,1'),
1424 ], ordered=False)
1425 self.assertIn('- data-return http://example.com/test/log/url/',
1426 A.messages[-1])
1427 self.assertIn('- data-return-relative '
1428 'http://example.com/test/log/url/docs/index.html',
James E. Blair196f61a2017-06-30 15:42:29 -07001429 A.messages[-1])
Clint Byrumdc8a0902017-07-20 16:36:27 -07001430
1431
1432class TestDiskAccounting(AnsibleZuulTestCase):
1433 config_file = 'zuul-disk-accounting.conf'
1434 tenant_config_file = 'config/disk-accountant/main.yaml'
1435
1436 def test_disk_accountant_kills_job(self):
1437 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1438 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1439 self.waitUntilSettled()
1440 self.assertHistory([
1441 dict(name='dd-big-empty-file', result='ABORTED', changes='1,1')])
Tristan Cacqueray82f864b2017-08-01 05:54:42 +00001442
1443
1444class TestMaxNodesPerJob(AnsibleZuulTestCase):
1445 tenant_config_file = 'config/multi-tenant/main.yaml'
1446
Tristan Cacquerayc98bff72017-09-10 15:25:26 +00001447 def test_max_timeout_exceeded(self):
Tristan Cacqueray82f864b2017-08-01 05:54:42 +00001448 in_repo_conf = textwrap.dedent(
1449 """
1450 - job:
1451 name: test-job
James E. Blair7e3e6882017-09-20 15:47:13 -07001452 nodeset:
1453 nodes:
1454 - name: node01
1455 label: fake
1456 - name: node02
1457 label: fake
1458 - name: node03
1459 label: fake
1460 - name: node04
1461 label: fake
1462 - name: node05
1463 label: fake
1464 - name: node06
1465 label: fake
Tristan Cacqueray82f864b2017-08-01 05:54:42 +00001466 """)
1467 file_dict = {'.zuul.yaml': in_repo_conf}
1468 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A',
1469 files=file_dict)
1470 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1471 self.waitUntilSettled()
1472 self.assertIn('The job "test-job" exceeds tenant max-nodes-per-job 5.',
1473 A.messages[0], "A should fail because of nodes limit")
1474
1475 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A',
1476 files=file_dict)
1477 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1478 self.waitUntilSettled()
1479 self.assertNotIn("exceeds tenant max-nodes", B.messages[0],
1480 "B should not fail because of nodes limit")
James E. Blair2bab6e72017-08-07 09:52:45 -07001481
1482
Tristan Cacquerayc98bff72017-09-10 15:25:26 +00001483class TestMaxTimeout(AnsibleZuulTestCase):
1484 tenant_config_file = 'config/multi-tenant/main.yaml'
1485
1486 def test_max_nodes_reached(self):
1487 in_repo_conf = textwrap.dedent(
1488 """
1489 - job:
1490 name: test-job
1491 timeout: 3600
1492 """)
1493 file_dict = {'.zuul.yaml': in_repo_conf}
1494 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A',
1495 files=file_dict)
1496 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1497 self.waitUntilSettled()
1498 self.assertIn('The job "test-job" exceeds tenant max-job-timeout',
1499 A.messages[0], "A should fail because of timeout limit")
1500
1501 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A',
1502 files=file_dict)
1503 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1504 self.waitUntilSettled()
1505 self.assertNotIn("exceeds tenant max-job-timeout", B.messages[0],
1506 "B should not fail because of timeout limit")
1507
1508
James E. Blair2bab6e72017-08-07 09:52:45 -07001509class TestBaseJobs(ZuulTestCase):
1510 tenant_config_file = 'config/base-jobs/main.yaml'
1511
1512 def test_multiple_base_jobs(self):
1513 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1514 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1515 self.waitUntilSettled()
1516 self.assertHistory([
1517 dict(name='my-job', result='SUCCESS', changes='1,1'),
1518 dict(name='other-job', result='SUCCESS', changes='1,1'),
1519 ], ordered=False)
1520 self.assertEqual(self.getJobFromHistory('my-job').
1521 parameters['zuul']['jobtags'],
1522 ['mybase'])
1523 self.assertEqual(self.getJobFromHistory('other-job').
1524 parameters['zuul']['jobtags'],
1525 ['otherbase'])
1526
1527 def test_untrusted_base_job(self):
1528 """Test that a base job may not be defined in an untrusted repo"""
1529 in_repo_conf = textwrap.dedent(
1530 """
1531 - job:
1532 name: fail-base
1533 parent: null
1534 """)
1535
1536 file_dict = {'.zuul.yaml': in_repo_conf}
1537 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
1538 files=file_dict)
1539 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1540 self.waitUntilSettled()
1541 self.assertEqual(A.reported, 1,
1542 "A should report failure")
1543 self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1")
1544 self.assertIn('Base jobs must be defined in config projects',
1545 A.messages[0])
1546 self.assertHistory([])
James E. Blairdb089032017-08-15 13:42:12 -07001547
1548
1549class TestSecretLeaks(AnsibleZuulTestCase):
1550 tenant_config_file = 'config/secret-leaks/main.yaml'
1551
1552 def searchForContent(self, path, content):
1553 matches = []
1554 for (dirpath, dirnames, filenames) in os.walk(path):
1555 for filename in filenames:
1556 filepath = os.path.join(dirpath, filename)
1557 with open(filepath, 'rb') as f:
1558 if content in f.read():
1559 matches.append(filepath[len(path):])
1560 return matches
1561
1562 def _test_secret_file(self):
1563 # Or rather -- test that they *don't* leak.
1564 # Keep the jobdir around so we can inspect contents.
1565 self.executor_server.keep_jobdir = True
1566 conf = textwrap.dedent(
1567 """
1568 - project:
1569 name: org/project
1570 check:
1571 jobs:
1572 - secret-file
1573 """)
1574
1575 file_dict = {'.zuul.yaml': conf}
1576 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
1577 files=file_dict)
1578 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1579 self.waitUntilSettled()
1580 self.assertHistory([
1581 dict(name='secret-file', result='SUCCESS', changes='1,1'),
1582 ], ordered=False)
1583 matches = self.searchForContent(self.history[0].jobdir.root,
1584 b'test-password')
James E. Blaird6a71ca2017-08-18 14:15:05 -07001585 self.assertEqual(set(['/work/secret-file.txt']),
James E. Blairdb089032017-08-15 13:42:12 -07001586 set(matches))
1587
1588 def test_secret_file(self):
1589 self._test_secret_file()
1590
1591 def test_secret_file_verbose(self):
1592 # Output extra ansible info to exercise alternate logging code
1593 # paths.
1594 self.executor_server.verbose = True
1595 self._test_secret_file()
1596
1597 def _test_secret_file_fail(self):
1598 # Or rather -- test that they *don't* leak.
1599 # Keep the jobdir around so we can inspect contents.
1600 self.executor_server.keep_jobdir = True
1601 conf = textwrap.dedent(
1602 """
1603 - project:
1604 name: org/project
1605 check:
1606 jobs:
1607 - secret-file-fail
1608 """)
1609
1610 file_dict = {'.zuul.yaml': conf}
1611 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
1612 files=file_dict)
1613 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1614 self.waitUntilSettled()
1615 self.assertHistory([
1616 dict(name='secret-file-fail', result='FAILURE', changes='1,1'),
1617 ], ordered=False)
1618 matches = self.searchForContent(self.history[0].jobdir.root,
1619 b'test-password')
James E. Blaird6a71ca2017-08-18 14:15:05 -07001620 self.assertEqual(set(['/work/failure-file.txt']),
James E. Blairdb089032017-08-15 13:42:12 -07001621 set(matches))
1622
1623 def test_secret_file_fail(self):
1624 self._test_secret_file_fail()
1625
1626 def test_secret_file_fail_verbose(self):
1627 # Output extra ansible info to exercise alternate logging code
1628 # paths.
1629 self.executor_server.verbose = True
1630 self._test_secret_file_fail()
James E. Blaira00910c2017-08-23 09:15:04 -07001631
1632
1633class TestJobOutput(AnsibleZuulTestCase):
1634 tenant_config_file = 'config/job-output/main.yaml'
1635
1636 def _get_file(self, build, path):
1637 p = os.path.join(build.jobdir.root, path)
1638 with open(p) as f:
1639 return f.read()
1640
1641 def test_job_output(self):
1642 # Verify that command standard output appears in the job output
1643
1644 # This currently only verifies we receive output from
1645 # localhost. Notably, it does not verify we receive output
1646 # via zuul_console streaming.
1647 self.executor_server.keep_jobdir = True
1648 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1649 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1650 self.waitUntilSettled()
1651 self.assertHistory([
1652 dict(name='job-output', result='SUCCESS', changes='1,1'),
1653 ], ordered=False)
1654
1655 token = 'Standard output test %s' % (self.history[0].jobdir.src_root)
1656 j = json.loads(self._get_file(self.history[0],
1657 'work/logs/job-output.json'))
1658 self.assertEqual(token,
1659 j[0]['plays'][0]['tasks'][0]
1660 ['hosts']['localhost']['stdout'])
1661
1662 print(self._get_file(self.history[0],
1663 'work/logs/job-output.txt'))
1664 self.assertIn(token,
1665 self._get_file(self.history[0],
1666 'work/logs/job-output.txt'))