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 | |
| 17 | import logging |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 18 | |
| 19 | from tests.base import ZuulTestCase |
| 20 | |
| 21 | logging.basicConfig(level=logging.DEBUG, |
| 22 | format='%(asctime)s %(name)-32s ' |
| 23 | '%(levelname)-8s %(message)s') |
| 24 | |
| 25 | |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame^] | 26 | class TestZuulTriggerParentChangeEnqueued(ZuulTestCase): |
| 27 | tenant_config_file = 'config/zuultrigger/parent-change-enqueued/main.yaml' |
James E. Blair | 509cada | 2015-12-08 16:31:16 -0800 | [diff] [blame] | 28 | |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 29 | def test_zuul_trigger_parent_change_enqueued(self): |
| 30 | "Test Zuul trigger event: parent-change-enqueued" |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 31 | # 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. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame^] | 36 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 37 | 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. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame^] | 40 | 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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 48 | B1.setDependsOn(A, 1) |
| 49 | B2.setDependsOn(A, 1) |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame^] | 50 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 51 | # 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. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame^] | 55 | self.launch_server.hold_jobs_in_build = False |
| 56 | self.launch_server.release() |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 57 | 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. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 63 | elif job.changes == '1,1 2,1': |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 64 | 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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 70 | |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame^] | 71 | class 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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 79 | # 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. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 83 | # 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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 85 | 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. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 88 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 89 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame^] | 90 | 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. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 96 | 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. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 103 | self.assertEqual(D.reported, 0) |
| 104 | self.assertEqual(E.reported, 0) |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 105 | self.assertEqual( |
| 106 | B.messages[0], |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 107 | "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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 111 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 112 | self.assertTrue("project:org/project status:open" in |
| 113 | self.fake_gerrit.queries) |
James E. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 114 | |
| 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. Blair | a80ef4e | 2016-12-08 14:06:36 -0800 | [diff] [blame^] | 121 | D.addApproval('code-review', 2) |
| 122 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 123 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 132 | self.assertEqual( |
| 133 | E.messages[0], |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 134 | "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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 138 | self.assertEqual(self.fake_gerrit.queries[1], |
| 139 | "project:org/project status:open") |