blob: 3c4dead9f6deecd0396c0ea4e326be0e5ef0d510 [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
67 def setUp(self):
68 self.skip("Disabled because v3 noop job does not perform merge")
69
70 tenant_config_file = 'config/zuultrigger/project-change-merged/main.yaml'
71
72 def test_zuul_trigger_project_change_merged(self):
James E. Blairc494d542014-08-06 09:23:52 -070073 # This test has the following three changes:
74 # A, B, C; B conflicts with A, but C does not.
75 # When A is merged, B and C should be checked for conflicts,
76 # and B should receive a -1.
James E. Blairc0acb552014-08-16 08:17:02 -070077 # D and E are used to repeat the test in the second part, but
78 # are defined here to that they end up in the trigger cache.
James E. Blairc494d542014-08-06 09:23:52 -070079 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
80 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
81 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blairc0acb552014-08-16 08:17:02 -070082 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
83 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blaira80ef4e2016-12-08 14:06:36 -080084 A.addPatchset({'conflict': 'foo'})
85 B.addPatchset({'conflict': 'bar'})
86 D.addPatchset({'conflict2': 'foo'})
87 E.addPatchset({'conflict2': 'bar'})
Tobias Henkelbf24fd12017-07-27 06:13:07 +020088 A.addApproval('Code-Review', 2)
89 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
James E. Blairc494d542014-08-06 09:23:52 -070090 self.waitUntilSettled()
91
92 self.assertEqual(len(self.history), 1)
93 self.assertEqual(self.history[0].name, 'project-gate')
94 self.assertEqual(A.reported, 2)
95 self.assertEqual(B.reported, 1)
96 self.assertEqual(C.reported, 0)
James E. Blairc0acb552014-08-16 08:17:02 -070097 self.assertEqual(D.reported, 0)
98 self.assertEqual(E.reported, 0)
Joshua Hesketh29d99b72014-08-19 16:27:42 +100099 self.assertEqual(
100 B.messages[0],
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +0000101 "Merge Failed.\n\nThis change or one of its cross-repo "
102 "dependencies was unable to be automatically merged with the "
103 "current state of its repository. Please rebase the change and "
104 "upload a new patchset.")
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000105
James E. Blair96698e22015-04-02 07:48:21 -0700106 self.assertTrue("project:org/project status:open" in
107 self.fake_gerrit.queries)
James E. Blairc0acb552014-08-16 08:17:02 -0700108
109 # Reconfigure and run the test again. This is a regression
110 # check to make sure that we don't end up with a stale trigger
111 # cache that has references to projects from the old
112 # configuration.
113 self.sched.reconfigure(self.config)
114
Tobias Henkelbf24fd12017-07-27 06:13:07 +0200115 D.addApproval('Code-Review', 2)
116 self.fake_gerrit.addEvent(D.addApproval('Approved', 1))
James E. Blairc0acb552014-08-16 08:17:02 -0700117 self.waitUntilSettled()
118
119 self.assertEqual(len(self.history), 2)
120 self.assertEqual(self.history[1].name, 'project-gate')
121 self.assertEqual(A.reported, 2)
122 self.assertEqual(B.reported, 1)
123 self.assertEqual(C.reported, 0)
124 self.assertEqual(D.reported, 2)
125 self.assertEqual(E.reported, 1)
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000126 self.assertEqual(
127 E.messages[0],
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +0000128 "Merge Failed.\n\nThis change or one of its cross-repo "
129 "dependencies was unable to be automatically merged with the "
130 "current state of its repository. Please rebase the change and "
131 "upload a new patchset.")
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000132 self.assertEqual(self.fake_gerrit.queries[1],
133 "project:org/project status:open")