blob: b36e5a4fe7f19bc7f4095136d01b3f03456721c3 [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
17import logging
James E. Blairc494d542014-08-06 09:23:52 -070018
19from tests.base import ZuulTestCase
20
21logging.basicConfig(level=logging.DEBUG,
22 format='%(asctime)s %(name)-32s '
23 '%(levelname)-8s %(message)s')
24
25
James E. Blaira80ef4e2016-12-08 14:06:36 -080026class TestZuulTriggerParentChangeEnqueued(ZuulTestCase):
27 tenant_config_file = 'config/zuultrigger/parent-change-enqueued/main.yaml'
James E. Blair509cada2015-12-08 16:31:16 -080028
James E. Blairc494d542014-08-06 09:23:52 -070029 def test_zuul_trigger_parent_change_enqueued(self):
30 "Test Zuul trigger event: parent-change-enqueued"
James E. Blairc494d542014-08-06 09:23:52 -070031 # This test has the following three changes:
32 # B1 -> A; B2 -> A
33 # When A is enqueued in the gate, B1 and B2 should both attempt
34 # to be enqueued in both pipelines. B1 should end up in check
35 # and B2 in gate because of differing pipeline requirements.
James E. Blaira80ef4e2016-12-08 14:06:36 -080036 self.launch_server.hold_jobs_in_build = True
James E. Blairc494d542014-08-06 09:23:52 -070037 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
38 B1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'B1')
39 B2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'B2')
James E. Blaira80ef4e2016-12-08 14:06:36 -080040 A.addApproval('code-review', 2)
41 B1.addApproval('code-review', 2)
42 B2.addApproval('code-review', 2)
43 A.addApproval('verified', 1) # required by gate
44 B1.addApproval('verified', -1) # should go to check
45 B2.addApproval('verified', 1) # should go to gate
46 B1.addApproval('approved', 1)
47 B2.addApproval('approved', 1)
James E. Blairc494d542014-08-06 09:23:52 -070048 B1.setDependsOn(A, 1)
49 B2.setDependsOn(A, 1)
James E. Blaira80ef4e2016-12-08 14:06:36 -080050 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairc494d542014-08-06 09:23:52 -070051 # Jobs are being held in build to make sure that 3,1 has time
52 # to enqueue behind 1,1 so that the test is more
53 # deterministic.
54 self.waitUntilSettled()
James E. Blaira80ef4e2016-12-08 14:06:36 -080055 self.launch_server.hold_jobs_in_build = False
56 self.launch_server.release()
James E. Blairc494d542014-08-06 09:23:52 -070057 self.waitUntilSettled()
58
59 self.assertEqual(len(self.history), 3)
60 for job in self.history:
61 if job.changes == '1,1':
62 self.assertEqual(job.name, 'project-gate')
James E. Blairbfb8e042014-12-30 17:01:44 -080063 elif job.changes == '1,1 2,1':
James E. Blairc494d542014-08-06 09:23:52 -070064 self.assertEqual(job.name, 'project-check')
65 elif job.changes == '1,1 3,1':
66 self.assertEqual(job.name, 'project-gate')
67 else:
68 raise Exception("Unknown job")
69
James E. Blairc494d542014-08-06 09:23:52 -070070
James E. Blaira80ef4e2016-12-08 14:06:36 -080071class TestZuulTriggerProjectChangeMerged(ZuulTestCase):
72
73 def setUp(self):
74 self.skip("Disabled because v3 noop job does not perform merge")
75
76 tenant_config_file = 'config/zuultrigger/project-change-merged/main.yaml'
77
78 def test_zuul_trigger_project_change_merged(self):
James E. Blairc494d542014-08-06 09:23:52 -070079 # This test has the following three changes:
80 # A, B, C; B conflicts with A, but C does not.
81 # When A is merged, B and C should be checked for conflicts,
82 # and B should receive a -1.
James E. Blairc0acb552014-08-16 08:17:02 -070083 # D and E are used to repeat the test in the second part, but
84 # are defined here to that they end up in the trigger cache.
James E. Blairc494d542014-08-06 09:23:52 -070085 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
86 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
87 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blairc0acb552014-08-16 08:17:02 -070088 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
89 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blaira80ef4e2016-12-08 14:06:36 -080090 A.addPatchset({'conflict': 'foo'})
91 B.addPatchset({'conflict': 'bar'})
92 D.addPatchset({'conflict2': 'foo'})
93 E.addPatchset({'conflict2': 'bar'})
94 A.addApproval('code-review', 2)
95 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairc494d542014-08-06 09:23:52 -070096 self.waitUntilSettled()
97
98 self.assertEqual(len(self.history), 1)
99 self.assertEqual(self.history[0].name, 'project-gate')
100 self.assertEqual(A.reported, 2)
101 self.assertEqual(B.reported, 1)
102 self.assertEqual(C.reported, 0)
James E. Blairc0acb552014-08-16 08:17:02 -0700103 self.assertEqual(D.reported, 0)
104 self.assertEqual(E.reported, 0)
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000105 self.assertEqual(
106 B.messages[0],
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +0000107 "Merge Failed.\n\nThis change or one of its cross-repo "
108 "dependencies was unable to be automatically merged with the "
109 "current state of its repository. Please rebase the change and "
110 "upload a new patchset.")
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000111
James E. Blair96698e22015-04-02 07:48:21 -0700112 self.assertTrue("project:org/project status:open" in
113 self.fake_gerrit.queries)
James E. Blairc0acb552014-08-16 08:17:02 -0700114
115 # Reconfigure and run the test again. This is a regression
116 # check to make sure that we don't end up with a stale trigger
117 # cache that has references to projects from the old
118 # configuration.
119 self.sched.reconfigure(self.config)
120
James E. Blaira80ef4e2016-12-08 14:06:36 -0800121 D.addApproval('code-review', 2)
122 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blairc0acb552014-08-16 08:17:02 -0700123 self.waitUntilSettled()
124
125 self.assertEqual(len(self.history), 2)
126 self.assertEqual(self.history[1].name, 'project-gate')
127 self.assertEqual(A.reported, 2)
128 self.assertEqual(B.reported, 1)
129 self.assertEqual(C.reported, 0)
130 self.assertEqual(D.reported, 2)
131 self.assertEqual(E.reported, 1)
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000132 self.assertEqual(
133 E.messages[0],
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +0000134 "Merge Failed.\n\nThis change or one of its cross-repo "
135 "dependencies was unable to be automatically merged with the "
136 "current state of its repository. Please rebase the change and "
137 "upload a new patchset.")
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000138 self.assertEqual(self.fake_gerrit.queries[1],
139 "project:org/project status:open")