James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 1 | #!/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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 17 | from tests.base import ZuulTestCase |
| 18 | |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 19 | |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame] | 20 | class TestZuulTriggerParentChangeEnqueued(ZuulTestCase): |
| 21 | tenant_config_file = 'config/zuultrigger/parent-change-enqueued/main.yaml' |
James E. Blair | 509cada | 2015-12-08 16:31:16 -0800 | [diff] [blame] | 22 | |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 23 | def test_zuul_trigger_parent_change_enqueued(self): |
| 24 | "Test Zuul trigger event: parent-change-enqueued" |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 25 | # 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 Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 30 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 31 | 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') |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame] | 34 | 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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 42 | B1.setDependsOn(A, 1) |
| 43 | B2.setDependsOn(A, 1) |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame] | 44 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 45 | # 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 Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 49 | self.executor_server.hold_jobs_in_build = False |
| 50 | self.executor_server.release() |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 51 | 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. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 57 | elif job.changes == '1,1 2,1': |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 58 | 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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 64 | |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame] | 65 | class 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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 73 | # 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. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 77 | # 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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 79 | 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. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 82 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 83 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame] | 84 | A.addPatchset({'conflict': 'foo'}) |
| 85 | B.addPatchset({'conflict': 'bar'}) |
| 86 | D.addPatchset({'conflict2': 'foo'}) |
| 87 | E.addPatchset({'conflict2': 'bar'}) |
| 88 | A.addApproval('code-review', 2) |
| 89 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 90 | 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. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 97 | self.assertEqual(D.reported, 0) |
| 98 | self.assertEqual(E.reported, 0) |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 99 | self.assertEqual( |
| 100 | B.messages[0], |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 101 | "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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 105 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 106 | self.assertTrue("project:org/project status:open" in |
| 107 | self.fake_gerrit.queries) |
James E. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 108 | |
| 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 | |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame] | 115 | D.addApproval('code-review', 2) |
| 116 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 117 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 126 | self.assertEqual( |
| 127 | E.messages[0], |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 128 | "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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 132 | self.assertEqual(self.fake_gerrit.queries[1], |
| 133 | "project:org/project status:open") |