Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 1 | # Copyright 2015 Red Hat, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Joshua Hesketh | 0aa7e8b | 2016-07-14 00:12:25 +1000 | [diff] [blame] | 15 | |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 16 | import os |
| 17 | import random |
| 18 | |
| 19 | import fixtures |
James E. Blair | 4317e9f | 2016-07-15 10:05:47 -0700 | [diff] [blame] | 20 | import testtools |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 21 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 22 | from zuul import model |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 23 | from zuul import configloader |
James E. Blair | bf1a4f2 | 2017-03-17 10:59:37 -0700 | [diff] [blame] | 24 | from zuul.lib import encryption |
Clint Byrum | 88fdfde | 2017-03-28 16:22:42 -0700 | [diff] [blame] | 25 | from zuul.lib import yamlutil as yaml |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 26 | |
James E. Blair | 18f86a3 | 2017-03-15 14:43:26 -0700 | [diff] [blame] | 27 | from tests.base import BaseTestCase, FIXTURE_DIR |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 28 | |
| 29 | |
James E. Blair | 0a89975 | 2017-03-29 13:22:16 -0700 | [diff] [blame] | 30 | class Dummy(object): |
| 31 | def __init__(self, **kw): |
| 32 | for k, v in kw.items(): |
| 33 | setattr(self, k, v) |
James E. Blair | b3f5db1 | 2017-03-17 12:57:39 -0700 | [diff] [blame] | 34 | |
| 35 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 36 | class TestJob(BaseTestCase): |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 37 | def setUp(self): |
| 38 | super(TestJob, self).setUp() |
James E. Blair | 0a89975 | 2017-03-29 13:22:16 -0700 | [diff] [blame] | 39 | self.connection = Dummy(connection_name='dummy_connection') |
| 40 | self.source = Dummy(canonical_hostname='git.example.com', |
James E. Blair | 0a89975 | 2017-03-29 13:22:16 -0700 | [diff] [blame] | 41 | connection=self.connection) |
James E. Blair | b3f5db1 | 2017-03-17 12:57:39 -0700 | [diff] [blame] | 42 | self.tenant = model.Tenant('tenant') |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 43 | self.layout = model.Layout(self.tenant) |
James E. Blair | 0a89975 | 2017-03-29 13:22:16 -0700 | [diff] [blame] | 44 | self.project = model.Project('project', self.source) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 45 | self.tpc = model.TenantProjectConfig(self.project) |
| 46 | self.tenant.addUntrustedProject(self.tpc) |
James E. Blair | b3f5db1 | 2017-03-17 12:57:39 -0700 | [diff] [blame] | 47 | self.pipeline = model.Pipeline('gate', self.layout) |
| 48 | self.layout.addPipeline(self.pipeline) |
| 49 | self.queue = model.ChangeQueue(self.pipeline) |
| 50 | |
James E. Blair | 18f86a3 | 2017-03-15 14:43:26 -0700 | [diff] [blame] | 51 | private_key_file = os.path.join(FIXTURE_DIR, 'private.pem') |
| 52 | with open(private_key_file, "rb") as f: |
James E. Blair | bf1a4f2 | 2017-03-17 10:59:37 -0700 | [diff] [blame] | 53 | self.project.private_key, self.project.public_key = \ |
| 54 | encryption.deserialize_rsa_keypair(f.read()) |
James E. Blair | 6f140c7 | 2017-03-03 10:32:07 -0800 | [diff] [blame] | 55 | self.context = model.SourceContext(self.project, 'master', |
| 56 | 'test', True) |
James E. Blair | 1cebebf | 2017-07-14 11:39:03 -0700 | [diff] [blame] | 57 | m = yaml.Mark('name', 0, 0, 0, '', 0) |
| 58 | self.start_mark = configloader.ZuulMark(m, m, '') |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 59 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 60 | @property |
| 61 | def job(self): |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 62 | tenant = model.Tenant('tenant') |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 63 | layout = model.Layout(tenant) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 64 | job = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 65 | '_source_context': self.context, |
| 66 | '_start_mark': self.start_mark, |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 67 | 'name': 'job', |
James E. Blair | 2bab6e7 | 2017-08-07 09:52:45 -0700 | [diff] [blame] | 68 | 'parent': None, |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 69 | 'irrelevant-files': [ |
| 70 | '^docs/.*$' |
| 71 | ]}) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 72 | return job |
| 73 | |
| 74 | def test_change_matches_returns_false_for_matched_skip_if(self): |
| 75 | change = model.Change('project') |
Alexander Evseev | dbe6fab | 2015-11-19 12:46:34 +0300 | [diff] [blame] | 76 | change.files = ['/COMMIT_MSG', 'docs/foo'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 77 | self.assertFalse(self.job.changeMatches(change)) |
| 78 | |
Jan Hruban | 570d01c | 2016-03-10 21:51:32 +0100 | [diff] [blame] | 79 | def test_change_matches_returns_false_for_single_matched_skip_if(self): |
| 80 | change = model.Change('project') |
| 81 | change.files = ['docs/foo'] |
| 82 | self.assertFalse(self.job.changeMatches(change)) |
| 83 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 84 | def test_change_matches_returns_true_for_unmatched_skip_if(self): |
| 85 | change = model.Change('project') |
Alexander Evseev | dbe6fab | 2015-11-19 12:46:34 +0300 | [diff] [blame] | 86 | change.files = ['/COMMIT_MSG', 'foo'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 87 | self.assertTrue(self.job.changeMatches(change)) |
| 88 | |
Jan Hruban | 570d01c | 2016-03-10 21:51:32 +0100 | [diff] [blame] | 89 | def test_change_matches_returns_true_for_single_unmatched_skip_if(self): |
| 90 | change = model.Change('project') |
| 91 | change.files = ['foo'] |
| 92 | self.assertTrue(self.job.changeMatches(change)) |
| 93 | |
Maru Newby | 79427a4 | 2015-02-17 17:54:45 +0000 | [diff] [blame] | 94 | def test_job_sets_defaults_for_boolean_attributes(self): |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 95 | self.assertIsNotNone(self.job.voting) |
| 96 | |
| 97 | def test_job_inheritance(self): |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 98 | # This is standard job inheritance. |
| 99 | |
James E. Blair | 74a82cf | 2017-07-12 17:23:08 -0700 | [diff] [blame] | 100 | base_pre = model.PlaybookContext(self.context, 'base-pre', []) |
| 101 | base_run = model.PlaybookContext(self.context, 'base-run', []) |
| 102 | base_post = model.PlaybookContext(self.context, 'base-post', []) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 103 | |
| 104 | base = model.Job('base') |
| 105 | base.timeout = 30 |
| 106 | base.pre_run = [base_pre] |
| 107 | base.run = [base_run] |
| 108 | base.post_run = [base_post] |
James E. Blair | 8525e2b | 2017-03-15 14:05:47 -0700 | [diff] [blame] | 109 | base.auth = model.AuthContext() |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 110 | |
| 111 | py27 = model.Job('py27') |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 112 | self.assertIsNone(py27.timeout) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 113 | py27.inheritFrom(base) |
| 114 | self.assertEqual(30, py27.timeout) |
| 115 | self.assertEqual(['base-pre'], |
| 116 | [x.path for x in py27.pre_run]) |
| 117 | self.assertEqual(['base-run'], |
| 118 | [x.path for x in py27.run]) |
| 119 | self.assertEqual(['base-post'], |
| 120 | [x.path for x in py27.post_run]) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 121 | self.assertIsNone(py27.auth) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 122 | |
| 123 | def test_job_variants(self): |
| 124 | # This simulates freezing a job. |
| 125 | |
James E. Blair | 74a82cf | 2017-07-12 17:23:08 -0700 | [diff] [blame] | 126 | py27_pre = model.PlaybookContext(self.context, 'py27-pre', []) |
| 127 | py27_run = model.PlaybookContext(self.context, 'py27-run', []) |
| 128 | py27_post = model.PlaybookContext(self.context, 'py27-post', []) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 129 | |
| 130 | py27 = model.Job('py27') |
| 131 | py27.timeout = 30 |
| 132 | py27.pre_run = [py27_pre] |
| 133 | py27.run = [py27_run] |
| 134 | py27.post_run = [py27_post] |
James E. Blair | 8525e2b | 2017-03-15 14:05:47 -0700 | [diff] [blame] | 135 | auth = model.AuthContext() |
| 136 | auth.secrets.append('foo') |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 137 | py27.auth = auth |
| 138 | |
| 139 | job = py27.copy() |
| 140 | self.assertEqual(30, job.timeout) |
| 141 | |
| 142 | # Apply the diablo variant |
| 143 | diablo = model.Job('py27') |
| 144 | diablo.timeout = 40 |
| 145 | job.applyVariant(diablo) |
| 146 | |
| 147 | self.assertEqual(40, job.timeout) |
| 148 | self.assertEqual(['py27-pre'], |
| 149 | [x.path for x in job.pre_run]) |
| 150 | self.assertEqual(['py27-run'], |
| 151 | [x.path for x in job.run]) |
| 152 | self.assertEqual(['py27-post'], |
| 153 | [x.path for x in job.post_run]) |
| 154 | self.assertEqual(auth, job.auth) |
| 155 | |
| 156 | # Set the job to final for the following checks |
| 157 | job.final = True |
| 158 | self.assertTrue(job.voting) |
| 159 | |
| 160 | good_final = model.Job('py27') |
| 161 | good_final.voting = False |
| 162 | job.applyVariant(good_final) |
| 163 | self.assertFalse(job.voting) |
| 164 | |
| 165 | bad_final = model.Job('py27') |
| 166 | bad_final.timeout = 600 |
| 167 | with testtools.ExpectedException( |
| 168 | Exception, |
| 169 | "Unable to modify final job"): |
| 170 | job.applyVariant(bad_final) |
| 171 | |
| 172 | def test_job_inheritance_configloader(self): |
| 173 | # TODO(jeblair): move this to a configloader test |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 174 | tenant = model.Tenant('tenant') |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 175 | layout = model.Layout(tenant) |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 176 | |
| 177 | pipeline = model.Pipeline('gate', layout) |
| 178 | layout.addPipeline(pipeline) |
| 179 | queue = model.ChangeQueue(pipeline) |
James E. Blair | 0a89975 | 2017-03-29 13:22:16 -0700 | [diff] [blame] | 180 | project = model.Project('project', self.source) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 181 | tpc = model.TenantProjectConfig(project) |
| 182 | tenant.addUntrustedProject(tpc) |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 183 | |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 184 | base = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 185 | '_source_context': self.context, |
| 186 | '_start_mark': self.start_mark, |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 187 | 'name': 'base', |
James E. Blair | 2bab6e7 | 2017-08-07 09:52:45 -0700 | [diff] [blame] | 188 | 'parent': None, |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 189 | 'timeout': 30, |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 190 | 'pre-run': 'base-pre', |
| 191 | 'post-run': 'base-post', |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 192 | 'nodes': [{ |
| 193 | 'name': 'controller', |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 194 | 'label': 'base', |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 195 | }], |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 196 | }) |
| 197 | layout.addJob(base) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 198 | python27 = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 199 | '_source_context': self.context, |
| 200 | '_start_mark': self.start_mark, |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 201 | 'name': 'python27', |
| 202 | 'parent': 'base', |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 203 | 'pre-run': 'py27-pre', |
| 204 | 'post-run': 'py27-post', |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 205 | 'nodes': [{ |
| 206 | 'name': 'controller', |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 207 | 'label': 'new', |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 208 | }], |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 209 | 'timeout': 40, |
| 210 | }) |
| 211 | layout.addJob(python27) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 212 | python27diablo = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 213 | '_source_context': self.context, |
| 214 | '_start_mark': self.start_mark, |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 215 | 'name': 'python27', |
| 216 | 'branches': [ |
| 217 | 'stable/diablo' |
| 218 | ], |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 219 | 'pre-run': 'py27-diablo-pre', |
| 220 | 'run': 'py27-diablo', |
| 221 | 'post-run': 'py27-diablo-post', |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 222 | 'nodes': [{ |
| 223 | 'name': 'controller', |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 224 | 'label': 'old', |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 225 | }], |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 226 | 'timeout': 50, |
| 227 | }) |
| 228 | layout.addJob(python27diablo) |
| 229 | |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 230 | python27essex = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 231 | '_source_context': self.context, |
| 232 | '_start_mark': self.start_mark, |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 233 | 'name': 'python27', |
| 234 | 'branches': [ |
| 235 | 'stable/essex' |
| 236 | ], |
| 237 | 'pre-run': 'py27-essex-pre', |
| 238 | 'post-run': 'py27-essex-post', |
| 239 | }) |
| 240 | layout.addJob(python27essex) |
| 241 | |
James E. Blair | ff55574 | 2017-02-19 11:34:27 -0800 | [diff] [blame] | 242 | project_config = configloader.ProjectParser.fromYaml(tenant, layout, [{ |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 243 | '_source_context': self.context, |
| 244 | '_start_mark': self.start_mark, |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 245 | 'name': 'project', |
| 246 | 'gate': { |
| 247 | 'jobs': [ |
| 248 | 'python27' |
| 249 | ] |
| 250 | } |
James E. Blair | ff55574 | 2017-02-19 11:34:27 -0800 | [diff] [blame] | 251 | }]) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 252 | layout.addProjectConfig(project_config) |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 253 | |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 254 | change = model.Change(project) |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 255 | # Test master |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 256 | change.branch = 'master' |
| 257 | item = queue.enqueueChange(change) |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 258 | item.current_build_set.layout = layout |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 259 | |
| 260 | self.assertTrue(base.changeMatches(change)) |
| 261 | self.assertTrue(python27.changeMatches(change)) |
| 262 | self.assertFalse(python27diablo.changeMatches(change)) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 263 | self.assertFalse(python27essex.changeMatches(change)) |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 264 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 265 | item.freezeJobGraph() |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 266 | self.assertEqual(len(item.getJobs()), 1) |
| 267 | job = item.getJobs()[0] |
| 268 | self.assertEqual(job.name, 'python27') |
| 269 | self.assertEqual(job.timeout, 40) |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 270 | nodes = job.nodeset.getNodes() |
| 271 | self.assertEqual(len(nodes), 1) |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 272 | self.assertEqual(nodes[0].label, 'new') |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 273 | self.assertEqual([x.path for x in job.pre_run], |
Tobias Henkel | 165450e | 2017-06-26 22:53:45 +0200 | [diff] [blame] | 274 | ['base-pre', |
| 275 | 'py27-pre']) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 276 | self.assertEqual([x.path for x in job.post_run], |
Tobias Henkel | 165450e | 2017-06-26 22:53:45 +0200 | [diff] [blame] | 277 | ['py27-post', |
| 278 | 'base-post']) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 279 | self.assertEqual([x.path for x in job.run], |
| 280 | ['playbooks/python27', |
| 281 | 'playbooks/base']) |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 282 | |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 283 | # Test diablo |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 284 | change.branch = 'stable/diablo' |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 285 | item = queue.enqueueChange(change) |
| 286 | item.current_build_set.layout = layout |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 287 | |
| 288 | self.assertTrue(base.changeMatches(change)) |
| 289 | self.assertTrue(python27.changeMatches(change)) |
| 290 | self.assertTrue(python27diablo.changeMatches(change)) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 291 | self.assertFalse(python27essex.changeMatches(change)) |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 292 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 293 | item.freezeJobGraph() |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 294 | self.assertEqual(len(item.getJobs()), 1) |
| 295 | job = item.getJobs()[0] |
| 296 | self.assertEqual(job.name, 'python27') |
| 297 | self.assertEqual(job.timeout, 50) |
James E. Blair | 1774dd5 | 2017-02-03 10:52:32 -0800 | [diff] [blame] | 298 | nodes = job.nodeset.getNodes() |
| 299 | self.assertEqual(len(nodes), 1) |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 300 | self.assertEqual(nodes[0].label, 'old') |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 301 | self.assertEqual([x.path for x in job.pre_run], |
Tobias Henkel | 165450e | 2017-06-26 22:53:45 +0200 | [diff] [blame] | 302 | ['base-pre', |
| 303 | 'py27-pre', |
| 304 | 'py27-diablo-pre']) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 305 | self.assertEqual([x.path for x in job.post_run], |
Tobias Henkel | 165450e | 2017-06-26 22:53:45 +0200 | [diff] [blame] | 306 | ['py27-diablo-post', |
| 307 | 'py27-post', |
| 308 | 'base-post']) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 309 | self.assertEqual([x.path for x in job.run], |
Tobias Henkel | 165450e | 2017-06-26 22:53:45 +0200 | [diff] [blame] | 310 | ['py27-diablo']), |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 311 | |
| 312 | # Test essex |
| 313 | change.branch = 'stable/essex' |
| 314 | item = queue.enqueueChange(change) |
| 315 | item.current_build_set.layout = layout |
| 316 | |
| 317 | self.assertTrue(base.changeMatches(change)) |
| 318 | self.assertTrue(python27.changeMatches(change)) |
| 319 | self.assertFalse(python27diablo.changeMatches(change)) |
| 320 | self.assertTrue(python27essex.changeMatches(change)) |
| 321 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 322 | item.freezeJobGraph() |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 323 | self.assertEqual(len(item.getJobs()), 1) |
| 324 | job = item.getJobs()[0] |
| 325 | self.assertEqual(job.name, 'python27') |
| 326 | self.assertEqual([x.path for x in job.pre_run], |
Tobias Henkel | 165450e | 2017-06-26 22:53:45 +0200 | [diff] [blame] | 327 | ['base-pre', |
| 328 | 'py27-pre', |
| 329 | 'py27-essex-pre']) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 330 | self.assertEqual([x.path for x in job.post_run], |
Tobias Henkel | 165450e | 2017-06-26 22:53:45 +0200 | [diff] [blame] | 331 | ['py27-essex-post', |
| 332 | 'py27-post', |
| 333 | 'base-post']) |
James E. Blair | a7f51ca | 2017-02-07 16:01:26 -0800 | [diff] [blame] | 334 | self.assertEqual([x.path for x in job.run], |
| 335 | ['playbooks/python27', |
| 336 | 'playbooks/base']) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 337 | |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 338 | def test_job_auth_inheritance(self): |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 339 | tenant = self.tenant |
| 340 | layout = self.layout |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 341 | |
James E. Blair | 01f83b7 | 2017-03-15 13:03:40 -0700 | [diff] [blame] | 342 | conf = yaml.safe_load(''' |
| 343 | - secret: |
| 344 | name: pypi-credentials |
| 345 | data: |
| 346 | username: test-username |
James E. Blair | 9118c01 | 2017-08-03 11:19:16 -0700 | [diff] [blame] | 347 | longpassword: !encrypted/pkcs1-oaep |
| 348 | - BFhtdnm8uXx7kn79RFL/zJywmzLkT1GY78P3bOtp4WghUFWobkifSu7ZpaV4NeO0s71Y |
| 349 | Usi1wGZZL0LveZjUN0t6OU1VZKSG8R5Ly7urjaSo1pPVIq5Rtt/H7W14Lecd+cUeKb4j |
| 350 | oeusC9drN3AA8a4oykcVpt1wVqUnTbMGC9ARMCQP6eopcs1l7tzMseprW4RDNhIuz3CR |
| 351 | gd0QBMPl6VDoFgBPB8vxtJw+3m0rqBYZCLZgCXekqlny8s2s92nJMuUABbJOEcDRarzi |
| 352 | bDsSXsfJt1y+5n7yOURsC7lovMg4GF/vCl/0YMKjBO5bpv9EM5fToeKYyPGSKQoHOnCY |
| 353 | ceb3cAVcv5UawcCic8XjhEhp4K7WPdYf2HVAC/qtxhbpjTxG4U5Q/SoppOJ60WqEkQvb |
| 354 | Xs6n5Dvy7xmph6GWmU/bAv3eUK3pdD3xa2Ue1lHWz3U+rsYraI+AKYsMYx3RBlfAmCeC |
| 355 | 1ve2BXPrqnOo7G8tnUvfdYPbK4Aakk0ds/AVqFHEZN+S6hRBmBjLaRFWZ3QSO1NjbBxW |
| 356 | naHKZYT7nkrJm8AMCgZU0ZArFLpaufKCeiK5ECSsDxic4FIsY1OkWT42qEUfL0Wd+150 |
| 357 | AKGNZpPJnnP3QYY4W/MWcKH/zdO400+zWN52WevbSqZy90tqKDJrBkMl1ydqbuw1E4ZH |
| 358 | vIs= |
| 359 | - BFhtdnm8uXx7kn79RFL/zJywmzLkT1GY78P3bOtp4WghUFWobkifSu7ZpaV4NeO0s71Y |
| 360 | Usi1wGZZL0LveZjUN0t6OU1VZKSG8R5Ly7urjaSo1pPVIq5Rtt/H7W14Lecd+cUeKb4j |
| 361 | oeusC9drN3AA8a4oykcVpt1wVqUnTbMGC9ARMCQP6eopcs1l7tzMseprW4RDNhIuz3CR |
| 362 | gd0QBMPl6VDoFgBPB8vxtJw+3m0rqBYZCLZgCXekqlny8s2s92nJMuUABbJOEcDRarzi |
| 363 | bDsSXsfJt1y+5n7yOURsC7lovMg4GF/vCl/0YMKjBO5bpv9EM5fToeKYyPGSKQoHOnCY |
| 364 | ceb3cAVcv5UawcCic8XjhEhp4K7WPdYf2HVAC/qtxhbpjTxG4U5Q/SoppOJ60WqEkQvb |
| 365 | Xs6n5Dvy7xmph6GWmU/bAv3eUK3pdD3xa2Ue1lHWz3U+rsYraI+AKYsMYx3RBlfAmCeC |
| 366 | 1ve2BXPrqnOo7G8tnUvfdYPbK4Aakk0ds/AVqFHEZN+S6hRBmBjLaRFWZ3QSO1NjbBxW |
| 367 | naHKZYT7nkrJm8AMCgZU0ZArFLpaufKCeiK5ECSsDxic4FIsY1OkWT42qEUfL0Wd+150 |
| 368 | AKGNZpPJnnP3QYY4W/MWcKH/zdO400+zWN52WevbSqZy90tqKDJrBkMl1ydqbuw1E4ZH |
| 369 | vIs= |
James E. Blair | 717e8e9 | 2017-03-17 11:03:27 -0700 | [diff] [blame] | 370 | password: !encrypted/pkcs1-oaep | |
James E. Blair | 9118c01 | 2017-08-03 11:19:16 -0700 | [diff] [blame] | 371 | BFhtdnm8uXx7kn79RFL/zJywmzLkT1GY78P3bOtp4WghUFWobkifSu7ZpaV4NeO0s71Y |
| 372 | Usi1wGZZL0LveZjUN0t6OU1VZKSG8R5Ly7urjaSo1pPVIq5Rtt/H7W14Lecd+cUeKb4j |
| 373 | oeusC9drN3AA8a4oykcVpt1wVqUnTbMGC9ARMCQP6eopcs1l7tzMseprW4RDNhIuz3CR |
| 374 | gd0QBMPl6VDoFgBPB8vxtJw+3m0rqBYZCLZgCXekqlny8s2s92nJMuUABbJOEcDRarzi |
| 375 | bDsSXsfJt1y+5n7yOURsC7lovMg4GF/vCl/0YMKjBO5bpv9EM5fToeKYyPGSKQoHOnCY |
| 376 | ceb3cAVcv5UawcCic8XjhEhp4K7WPdYf2HVAC/qtxhbpjTxG4U5Q/SoppOJ60WqEkQvb |
| 377 | Xs6n5Dvy7xmph6GWmU/bAv3eUK3pdD3xa2Ue1lHWz3U+rsYraI+AKYsMYx3RBlfAmCeC |
| 378 | 1ve2BXPrqnOo7G8tnUvfdYPbK4Aakk0ds/AVqFHEZN+S6hRBmBjLaRFWZ3QSO1NjbBxW |
| 379 | naHKZYT7nkrJm8AMCgZU0ZArFLpaufKCeiK5ECSsDxic4FIsY1OkWT42qEUfL0Wd+150 |
| 380 | AKGNZpPJnnP3QYY4W/MWcKH/zdO400+zWN52WevbSqZy90tqKDJrBkMl1ydqbuw1E4ZH |
| 381 | vIs= |
James E. Blair | 01f83b7 | 2017-03-15 13:03:40 -0700 | [diff] [blame] | 382 | ''')[0]['secret'] |
| 383 | |
| 384 | conf['_source_context'] = self.context |
| 385 | conf['_start_mark'] = self.start_mark |
| 386 | |
| 387 | secret = configloader.SecretParser.fromYaml(layout, conf) |
| 388 | layout.addSecret(secret) |
| 389 | |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 390 | base = configloader.JobParser.fromYaml(self.tenant, self.layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 391 | '_source_context': self.context, |
| 392 | '_start_mark': self.start_mark, |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 393 | 'name': 'base', |
James E. Blair | 2bab6e7 | 2017-08-07 09:52:45 -0700 | [diff] [blame] | 394 | 'parent': None, |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 395 | 'timeout': 30, |
| 396 | }) |
| 397 | layout.addJob(base) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 398 | pypi_upload_without_inherit = configloader.JobParser.fromYaml( |
| 399 | tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 400 | '_source_context': self.context, |
| 401 | '_start_mark': self.start_mark, |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 402 | 'name': 'pypi-upload-without-inherit', |
| 403 | 'parent': 'base', |
| 404 | 'timeout': 40, |
| 405 | 'auth': { |
| 406 | 'secrets': [ |
| 407 | 'pypi-credentials', |
| 408 | ] |
| 409 | } |
| 410 | }) |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 411 | layout.addJob(pypi_upload_without_inherit) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 412 | pypi_upload_with_inherit = configloader.JobParser.fromYaml( |
| 413 | tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 414 | '_source_context': self.context, |
| 415 | '_start_mark': self.start_mark, |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 416 | 'name': 'pypi-upload-with-inherit', |
| 417 | 'parent': 'base', |
| 418 | 'timeout': 40, |
| 419 | 'auth': { |
| 420 | 'inherit': True, |
| 421 | 'secrets': [ |
| 422 | 'pypi-credentials', |
| 423 | ] |
| 424 | } |
| 425 | }) |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 426 | layout.addJob(pypi_upload_with_inherit) |
| 427 | pypi_upload_with_inherit_false = configloader.JobParser.fromYaml( |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 428 | tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 429 | '_source_context': self.context, |
| 430 | '_start_mark': self.start_mark, |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 431 | 'name': 'pypi-upload-with-inherit-false', |
| 432 | 'parent': 'base', |
| 433 | 'timeout': 40, |
| 434 | 'auth': { |
| 435 | 'inherit': False, |
Ricardo Carrillo Cruz | 12c892b | 2016-11-18 15:35:49 +0000 | [diff] [blame] | 436 | 'secrets': [ |
| 437 | 'pypi-credentials', |
| 438 | ] |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 439 | } |
| 440 | }) |
| 441 | layout.addJob(pypi_upload_with_inherit_false) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 442 | in_repo_job_without_inherit = configloader.JobParser.fromYaml( |
| 443 | tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 444 | '_source_context': self.context, |
| 445 | '_start_mark': self.start_mark, |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 446 | 'name': 'in-repo-job-without-inherit', |
| 447 | 'parent': 'pypi-upload-without-inherit', |
| 448 | }) |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 449 | layout.addJob(in_repo_job_without_inherit) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 450 | in_repo_job_with_inherit = configloader.JobParser.fromYaml( |
| 451 | tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 452 | '_source_context': self.context, |
| 453 | '_start_mark': self.start_mark, |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 454 | 'name': 'in-repo-job-with-inherit', |
| 455 | 'parent': 'pypi-upload-with-inherit', |
| 456 | }) |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 457 | layout.addJob(in_repo_job_with_inherit) |
| 458 | in_repo_job_with_inherit_false = configloader.JobParser.fromYaml( |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 459 | tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 460 | '_source_context': self.context, |
| 461 | '_start_mark': self.start_mark, |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 462 | 'name': 'in-repo-job-with-inherit-false', |
| 463 | 'parent': 'pypi-upload-with-inherit-false', |
| 464 | }) |
| 465 | layout.addJob(in_repo_job_with_inherit_false) |
| 466 | |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 467 | self.assertIsNone(in_repo_job_without_inherit.auth) |
James E. Blair | 8525e2b | 2017-03-15 14:05:47 -0700 | [diff] [blame] | 468 | self.assertEqual(1, len(in_repo_job_with_inherit.auth.secrets)) |
| 469 | self.assertEqual(in_repo_job_with_inherit.auth.secrets[0].name, |
| 470 | 'pypi-credentials') |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 471 | self.assertIsNone(in_repo_job_with_inherit_false.auth) |
James E. Blair | 9118c01 | 2017-08-03 11:19:16 -0700 | [diff] [blame] | 472 | self.assertEqual(in_repo_job_with_inherit.auth.secrets[0]. |
| 473 | secret_data['longpassword'], |
| 474 | 'test-passwordtest-password') |
| 475 | self.assertEqual(in_repo_job_with_inherit.auth.secrets[0]. |
| 476 | secret_data['password'], |
| 477 | 'test-password') |
Ricardo Carrillo Cruz | 4e94f61 | 2016-07-25 16:11:56 +0000 | [diff] [blame] | 478 | |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 479 | def test_job_inheritance_job_tree(self): |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 480 | tenant = model.Tenant('tenant') |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 481 | layout = model.Layout(tenant) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 482 | tpc = model.TenantProjectConfig(self.project) |
| 483 | tenant.addUntrustedProject(tpc) |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 484 | |
| 485 | pipeline = model.Pipeline('gate', layout) |
| 486 | layout.addPipeline(pipeline) |
| 487 | queue = model.ChangeQueue(pipeline) |
| 488 | |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 489 | base = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 490 | '_source_context': self.context, |
| 491 | '_start_mark': self.start_mark, |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 492 | 'name': 'base', |
James E. Blair | 2bab6e7 | 2017-08-07 09:52:45 -0700 | [diff] [blame] | 493 | 'parent': None, |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 494 | 'timeout': 30, |
| 495 | }) |
| 496 | layout.addJob(base) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 497 | python27 = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 498 | '_source_context': self.context, |
| 499 | '_start_mark': self.start_mark, |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 500 | 'name': 'python27', |
| 501 | 'parent': 'base', |
| 502 | 'timeout': 40, |
| 503 | }) |
| 504 | layout.addJob(python27) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 505 | python27diablo = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 506 | '_source_context': self.context, |
| 507 | '_start_mark': self.start_mark, |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 508 | 'name': 'python27', |
| 509 | 'branches': [ |
| 510 | 'stable/diablo' |
| 511 | ], |
| 512 | 'timeout': 50, |
| 513 | }) |
| 514 | layout.addJob(python27diablo) |
| 515 | |
James E. Blair | ff55574 | 2017-02-19 11:34:27 -0800 | [diff] [blame] | 516 | project_config = configloader.ProjectParser.fromYaml(tenant, layout, [{ |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 517 | '_source_context': self.context, |
| 518 | '_start_mark': self.start_mark, |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 519 | 'name': 'project', |
| 520 | 'gate': { |
| 521 | 'jobs': [ |
| 522 | {'python27': {'timeout': 70}} |
| 523 | ] |
| 524 | } |
James E. Blair | ff55574 | 2017-02-19 11:34:27 -0800 | [diff] [blame] | 525 | }]) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 526 | layout.addProjectConfig(project_config) |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 527 | |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 528 | change = model.Change(self.project) |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 529 | change.branch = 'master' |
| 530 | item = queue.enqueueChange(change) |
| 531 | item.current_build_set.layout = layout |
| 532 | |
| 533 | self.assertTrue(base.changeMatches(change)) |
| 534 | self.assertTrue(python27.changeMatches(change)) |
| 535 | self.assertFalse(python27diablo.changeMatches(change)) |
| 536 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 537 | item.freezeJobGraph() |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 538 | self.assertEqual(len(item.getJobs()), 1) |
| 539 | job = item.getJobs()[0] |
| 540 | self.assertEqual(job.name, 'python27') |
| 541 | self.assertEqual(job.timeout, 70) |
| 542 | |
| 543 | change.branch = 'stable/diablo' |
| 544 | item = queue.enqueueChange(change) |
| 545 | item.current_build_set.layout = layout |
| 546 | |
| 547 | self.assertTrue(base.changeMatches(change)) |
| 548 | self.assertTrue(python27.changeMatches(change)) |
| 549 | self.assertTrue(python27diablo.changeMatches(change)) |
| 550 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 551 | item.freezeJobGraph() |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 552 | self.assertEqual(len(item.getJobs()), 1) |
| 553 | job = item.getJobs()[0] |
| 554 | self.assertEqual(job.name, 'python27') |
| 555 | self.assertEqual(job.timeout, 70) |
| 556 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 557 | def test_inheritance_keeps_matchers(self): |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 558 | tenant = model.Tenant('tenant') |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 559 | layout = model.Layout(tenant) |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 560 | |
| 561 | pipeline = model.Pipeline('gate', layout) |
| 562 | layout.addPipeline(pipeline) |
| 563 | queue = model.ChangeQueue(pipeline) |
James E. Blair | 0a89975 | 2017-03-29 13:22:16 -0700 | [diff] [blame] | 564 | project = model.Project('project', self.source) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 565 | tpc = model.TenantProjectConfig(project) |
| 566 | tenant.addUntrustedProject(tpc) |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 567 | |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 568 | base = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 569 | '_source_context': self.context, |
| 570 | '_start_mark': self.start_mark, |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 571 | 'name': 'base', |
James E. Blair | 2bab6e7 | 2017-08-07 09:52:45 -0700 | [diff] [blame] | 572 | 'parent': None, |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 573 | 'timeout': 30, |
| 574 | }) |
| 575 | layout.addJob(base) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 576 | python27 = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 577 | '_source_context': self.context, |
| 578 | '_start_mark': self.start_mark, |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 579 | 'name': 'python27', |
| 580 | 'parent': 'base', |
| 581 | 'timeout': 40, |
| 582 | 'irrelevant-files': ['^ignored-file$'], |
| 583 | }) |
| 584 | layout.addJob(python27) |
| 585 | |
James E. Blair | ff55574 | 2017-02-19 11:34:27 -0800 | [diff] [blame] | 586 | project_config = configloader.ProjectParser.fromYaml(tenant, layout, [{ |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 587 | '_source_context': self.context, |
| 588 | '_start_mark': self.start_mark, |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 589 | 'name': 'project', |
| 590 | 'gate': { |
| 591 | 'jobs': [ |
| 592 | 'python27', |
| 593 | ] |
| 594 | } |
James E. Blair | ff55574 | 2017-02-19 11:34:27 -0800 | [diff] [blame] | 595 | }]) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 596 | layout.addProjectConfig(project_config) |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 597 | |
| 598 | change = model.Change(project) |
| 599 | change.branch = 'master' |
| 600 | change.files = ['/COMMIT_MSG', 'ignored-file'] |
| 601 | item = queue.enqueueChange(change) |
| 602 | item.current_build_set.layout = layout |
| 603 | |
| 604 | self.assertTrue(base.changeMatches(change)) |
| 605 | self.assertFalse(python27.changeMatches(change)) |
| 606 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 607 | item.freezeJobGraph() |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 608 | self.assertEqual([], item.getJobs()) |
| 609 | |
James E. Blair | 4317e9f | 2016-07-15 10:05:47 -0700 | [diff] [blame] | 610 | def test_job_source_project(self): |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 611 | tenant = self.tenant |
| 612 | layout = self.layout |
James E. Blair | 0a89975 | 2017-03-29 13:22:16 -0700 | [diff] [blame] | 613 | base_project = model.Project('base_project', self.source) |
James E. Blair | 6f140c7 | 2017-03-03 10:32:07 -0800 | [diff] [blame] | 614 | base_context = model.SourceContext(base_project, 'master', |
| 615 | 'test', True) |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 616 | tpc = model.TenantProjectConfig(base_project) |
| 617 | tenant.addUntrustedProject(tpc) |
James E. Blair | cdab203 | 2017-02-01 09:09:29 -0800 | [diff] [blame] | 618 | |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 619 | base = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | cdab203 | 2017-02-01 09:09:29 -0800 | [diff] [blame] | 620 | '_source_context': base_context, |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 621 | '_start_mark': self.start_mark, |
James E. Blair | 2bab6e7 | 2017-08-07 09:52:45 -0700 | [diff] [blame] | 622 | 'parent': None, |
James E. Blair | 4317e9f | 2016-07-15 10:05:47 -0700 | [diff] [blame] | 623 | 'name': 'base', |
| 624 | }) |
| 625 | layout.addJob(base) |
| 626 | |
James E. Blair | 0a89975 | 2017-03-29 13:22:16 -0700 | [diff] [blame] | 627 | other_project = model.Project('other_project', self.source) |
James E. Blair | 6f140c7 | 2017-03-03 10:32:07 -0800 | [diff] [blame] | 628 | other_context = model.SourceContext(other_project, 'master', |
| 629 | 'test', True) |
James E. Blair | 6459db1 | 2017-06-29 14:57:20 -0700 | [diff] [blame] | 630 | tpc = model.TenantProjectConfig(other_project) |
| 631 | tenant.addUntrustedProject(tpc) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 632 | base2 = configloader.JobParser.fromYaml(tenant, layout, { |
James E. Blair | cdab203 | 2017-02-01 09:09:29 -0800 | [diff] [blame] | 633 | '_source_context': other_context, |
James E. Blair | ec7ff30 | 2017-03-04 07:31:32 -0800 | [diff] [blame] | 634 | '_start_mark': self.start_mark, |
James E. Blair | 4317e9f | 2016-07-15 10:05:47 -0700 | [diff] [blame] | 635 | 'name': 'base', |
| 636 | }) |
| 637 | with testtools.ExpectedException( |
| 638 | Exception, |
| 639 | "Job base in other_project is not permitted " |
| 640 | "to shadow job base in base_project"): |
| 641 | layout.addJob(base2) |
| 642 | |
James E. Blair | b3f5db1 | 2017-03-17 12:57:39 -0700 | [diff] [blame] | 643 | def test_job_allowed_projects(self): |
| 644 | job = configloader.JobParser.fromYaml(self.tenant, self.layout, { |
| 645 | '_source_context': self.context, |
| 646 | '_start_mark': self.start_mark, |
| 647 | 'name': 'job', |
James E. Blair | 2bab6e7 | 2017-08-07 09:52:45 -0700 | [diff] [blame] | 648 | 'parent': None, |
James E. Blair | b3f5db1 | 2017-03-17 12:57:39 -0700 | [diff] [blame] | 649 | 'allowed-projects': ['project'], |
| 650 | }) |
| 651 | self.layout.addJob(job) |
| 652 | |
James E. Blair | 0a89975 | 2017-03-29 13:22:16 -0700 | [diff] [blame] | 653 | project2 = model.Project('project2', self.source) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 654 | tpc2 = model.TenantProjectConfig(project2) |
| 655 | self.tenant.addUntrustedProject(tpc2) |
James E. Blair | b3f5db1 | 2017-03-17 12:57:39 -0700 | [diff] [blame] | 656 | context2 = model.SourceContext(project2, 'master', |
| 657 | 'test', True) |
| 658 | |
| 659 | project2_config = configloader.ProjectParser.fromYaml( |
| 660 | self.tenant, self.layout, [{ |
| 661 | '_source_context': context2, |
| 662 | '_start_mark': self.start_mark, |
| 663 | 'name': 'project2', |
| 664 | 'gate': { |
| 665 | 'jobs': [ |
| 666 | 'job' |
| 667 | ] |
| 668 | } |
| 669 | }] |
| 670 | ) |
| 671 | self.layout.addProjectConfig(project2_config) |
| 672 | |
| 673 | change = model.Change(project2) |
| 674 | # Test master |
| 675 | change.branch = 'master' |
| 676 | item = self.queue.enqueueChange(change) |
| 677 | item.current_build_set.layout = self.layout |
| 678 | with testtools.ExpectedException( |
| 679 | Exception, |
| 680 | "Project project2 is not allowed to run job job"): |
| 681 | item.freezeJobGraph() |
| 682 | |
James E. Blair | d234836 | 2017-03-17 13:59:35 -0700 | [diff] [blame] | 683 | def test_job_pipeline_allow_secrets(self): |
| 684 | self.pipeline.allow_secrets = False |
| 685 | job = configloader.JobParser.fromYaml(self.tenant, self.layout, { |
| 686 | '_source_context': self.context, |
| 687 | '_start_mark': self.start_mark, |
| 688 | 'name': 'job', |
James E. Blair | 2bab6e7 | 2017-08-07 09:52:45 -0700 | [diff] [blame] | 689 | 'parent': None, |
James E. Blair | d234836 | 2017-03-17 13:59:35 -0700 | [diff] [blame] | 690 | }) |
| 691 | auth = model.AuthContext() |
| 692 | auth.secrets.append('foo') |
| 693 | job.auth = auth |
| 694 | |
| 695 | self.layout.addJob(job) |
| 696 | |
| 697 | project_config = configloader.ProjectParser.fromYaml( |
| 698 | self.tenant, self.layout, [{ |
| 699 | '_source_context': self.context, |
| 700 | '_start_mark': self.start_mark, |
| 701 | 'name': 'project', |
| 702 | 'gate': { |
| 703 | 'jobs': [ |
| 704 | 'job' |
| 705 | ] |
| 706 | } |
| 707 | }] |
| 708 | ) |
| 709 | self.layout.addProjectConfig(project_config) |
| 710 | |
| 711 | change = model.Change(self.project) |
| 712 | # Test master |
| 713 | change.branch = 'master' |
| 714 | item = self.queue.enqueueChange(change) |
| 715 | item.current_build_set.layout = self.layout |
| 716 | with testtools.ExpectedException( |
| 717 | Exception, |
| 718 | "Pipeline gate does not allow jobs with secrets"): |
| 719 | item.freezeJobGraph() |
| 720 | |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 721 | |
| 722 | class TestJobTimeData(BaseTestCase): |
| 723 | def setUp(self): |
| 724 | super(TestJobTimeData, self).setUp() |
| 725 | self.tmp_root = self.useFixture(fixtures.TempDir( |
| 726 | rootdir=os.environ.get("ZUUL_TEST_ROOT")) |
| 727 | ).path |
| 728 | |
| 729 | def test_empty_timedata(self): |
| 730 | path = os.path.join(self.tmp_root, 'job-name') |
| 731 | self.assertFalse(os.path.exists(path)) |
| 732 | self.assertFalse(os.path.exists(path + '.tmp')) |
| 733 | td = model.JobTimeData(path) |
| 734 | self.assertEqual(td.success_times, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 735 | self.assertEqual(td.failure_times, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 736 | self.assertEqual(td.results, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 737 | |
| 738 | def test_save_reload(self): |
| 739 | path = os.path.join(self.tmp_root, 'job-name') |
| 740 | self.assertFalse(os.path.exists(path)) |
| 741 | self.assertFalse(os.path.exists(path + '.tmp')) |
| 742 | td = model.JobTimeData(path) |
| 743 | self.assertEqual(td.success_times, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 744 | self.assertEqual(td.failure_times, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 745 | self.assertEqual(td.results, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 746 | success_times = [] |
| 747 | failure_times = [] |
| 748 | results = [] |
| 749 | for x in range(10): |
| 750 | success_times.append(int(random.random() * 1000)) |
| 751 | failure_times.append(int(random.random() * 1000)) |
| 752 | results.append(0) |
| 753 | results.append(1) |
| 754 | random.shuffle(results) |
| 755 | s = f = 0 |
| 756 | for result in results: |
| 757 | if result: |
| 758 | td.add(failure_times[f], 'FAILURE') |
| 759 | f += 1 |
| 760 | else: |
| 761 | td.add(success_times[s], 'SUCCESS') |
| 762 | s += 1 |
| 763 | self.assertEqual(td.success_times, success_times) |
| 764 | self.assertEqual(td.failure_times, failure_times) |
| 765 | self.assertEqual(td.results, results[10:]) |
| 766 | td.save() |
| 767 | self.assertTrue(os.path.exists(path)) |
| 768 | self.assertFalse(os.path.exists(path + '.tmp')) |
| 769 | td = model.JobTimeData(path) |
| 770 | td.load() |
| 771 | self.assertEqual(td.success_times, success_times) |
| 772 | self.assertEqual(td.failure_times, failure_times) |
| 773 | self.assertEqual(td.results, results[10:]) |
| 774 | |
| 775 | |
| 776 | class TestTimeDataBase(BaseTestCase): |
| 777 | def setUp(self): |
| 778 | super(TestTimeDataBase, self).setUp() |
| 779 | self.tmp_root = self.useFixture(fixtures.TempDir( |
| 780 | rootdir=os.environ.get("ZUUL_TEST_ROOT")) |
| 781 | ).path |
| 782 | self.db = model.TimeDataBase(self.tmp_root) |
| 783 | |
| 784 | def test_timedatabase(self): |
| 785 | self.assertEqual(self.db.getEstimatedTime('job-name'), 0) |
| 786 | self.db.update('job-name', 50, 'SUCCESS') |
| 787 | self.assertEqual(self.db.getEstimatedTime('job-name'), 50) |
| 788 | self.db.update('job-name', 100, 'SUCCESS') |
| 789 | self.assertEqual(self.db.getEstimatedTime('job-name'), 75) |
| 790 | for x in range(10): |
| 791 | self.db.update('job-name', 100, 'SUCCESS') |
| 792 | self.assertEqual(self.db.getEstimatedTime('job-name'), 100) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 793 | |
| 794 | |
| 795 | class TestGraph(BaseTestCase): |
| 796 | def test_job_graph_disallows_multiple_jobs_with_same_name(self): |
| 797 | graph = model.JobGraph() |
| 798 | job1 = model.Job('job') |
| 799 | job2 = model.Job('job') |
| 800 | graph.addJob(job1) |
| 801 | with testtools.ExpectedException(Exception, |
| 802 | "Job job already added"): |
| 803 | graph.addJob(job2) |
| 804 | |
| 805 | def test_job_graph_disallows_circular_dependencies(self): |
| 806 | graph = model.JobGraph() |
| 807 | jobs = [model.Job('job%d' % i) for i in range(0, 10)] |
| 808 | prevjob = None |
| 809 | for j in jobs[:3]: |
| 810 | if prevjob: |
| 811 | j.dependencies = frozenset([prevjob.name]) |
| 812 | graph.addJob(j) |
| 813 | prevjob = j |
| 814 | # 0 triggers 1 triggers 2 triggers 3... |
| 815 | |
| 816 | # Cannot depend on itself |
| 817 | with testtools.ExpectedException( |
| 818 | Exception, |
| 819 | "Dependency cycle detected in job jobX"): |
| 820 | j = model.Job('jobX') |
| 821 | j.dependencies = frozenset([j.name]) |
| 822 | graph.addJob(j) |
| 823 | |
| 824 | # Disallow circular dependencies |
| 825 | with testtools.ExpectedException( |
| 826 | Exception, |
| 827 | "Dependency cycle detected in job job3"): |
| 828 | jobs[4].dependencies = frozenset([jobs[3].name]) |
| 829 | graph.addJob(jobs[4]) |
| 830 | jobs[3].dependencies = frozenset([jobs[4].name]) |
| 831 | graph.addJob(jobs[3]) |
| 832 | |
| 833 | jobs[5].dependencies = frozenset([jobs[4].name]) |
| 834 | graph.addJob(jobs[5]) |
| 835 | |
| 836 | with testtools.ExpectedException( |
| 837 | Exception, |
| 838 | "Dependency cycle detected in job job3"): |
| 839 | jobs[3].dependencies = frozenset([jobs[5].name]) |
| 840 | graph.addJob(jobs[3]) |
| 841 | |
| 842 | jobs[3].dependencies = frozenset([jobs[2].name]) |
| 843 | graph.addJob(jobs[3]) |
| 844 | jobs[6].dependencies = frozenset([jobs[2].name]) |
| 845 | graph.addJob(jobs[6]) |
James E. Blair | c2a54fd | 2017-03-29 15:19:26 -0700 | [diff] [blame] | 846 | |
| 847 | |
| 848 | class TestTenant(BaseTestCase): |
| 849 | def test_add_project(self): |
| 850 | tenant = model.Tenant('tenant') |
| 851 | connection1 = Dummy(connection_name='dummy_connection1') |
| 852 | source1 = Dummy(canonical_hostname='git1.example.com', |
| 853 | name='dummy', # TODOv3(jeblair): remove |
| 854 | connection=connection1) |
| 855 | |
| 856 | source1_project1 = model.Project('project1', source1) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 857 | source1_project1_tpc = model.TenantProjectConfig(source1_project1) |
| 858 | tenant.addConfigProject(source1_project1_tpc) |
James E. Blair | c2a54fd | 2017-03-29 15:19:26 -0700 | [diff] [blame] | 859 | d = {'project1': |
| 860 | {'git1.example.com': source1_project1}} |
| 861 | self.assertEqual(d, tenant.projects) |
| 862 | self.assertEqual((True, source1_project1), |
| 863 | tenant.getProject('project1')) |
| 864 | self.assertEqual((True, source1_project1), |
| 865 | tenant.getProject('git1.example.com/project1')) |
| 866 | |
| 867 | source1_project2 = model.Project('project2', source1) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 868 | tpc = model.TenantProjectConfig(source1_project2) |
| 869 | tenant.addUntrustedProject(tpc) |
James E. Blair | c2a54fd | 2017-03-29 15:19:26 -0700 | [diff] [blame] | 870 | d = {'project1': |
| 871 | {'git1.example.com': source1_project1}, |
| 872 | 'project2': |
| 873 | {'git1.example.com': source1_project2}} |
| 874 | self.assertEqual(d, tenant.projects) |
| 875 | self.assertEqual((False, source1_project2), |
| 876 | tenant.getProject('project2')) |
| 877 | self.assertEqual((False, source1_project2), |
| 878 | tenant.getProject('git1.example.com/project2')) |
| 879 | |
| 880 | connection2 = Dummy(connection_name='dummy_connection2') |
| 881 | source2 = Dummy(canonical_hostname='git2.example.com', |
| 882 | name='dummy', # TODOv3(jeblair): remove |
| 883 | connection=connection2) |
| 884 | |
| 885 | source2_project1 = model.Project('project1', source2) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 886 | tpc = model.TenantProjectConfig(source2_project1) |
| 887 | tenant.addUntrustedProject(tpc) |
James E. Blair | c2a54fd | 2017-03-29 15:19:26 -0700 | [diff] [blame] | 888 | d = {'project1': |
| 889 | {'git1.example.com': source1_project1, |
| 890 | 'git2.example.com': source2_project1}, |
| 891 | 'project2': |
| 892 | {'git1.example.com': source1_project2}} |
| 893 | self.assertEqual(d, tenant.projects) |
| 894 | with testtools.ExpectedException( |
| 895 | Exception, |
| 896 | "Project name 'project1' is ambiguous"): |
| 897 | tenant.getProject('project1') |
| 898 | self.assertEqual((False, source1_project2), |
| 899 | tenant.getProject('project2')) |
| 900 | self.assertEqual((True, source1_project1), |
| 901 | tenant.getProject('git1.example.com/project1')) |
| 902 | self.assertEqual((False, source2_project1), |
| 903 | tenant.getProject('git2.example.com/project1')) |
| 904 | |
| 905 | source2_project2 = model.Project('project2', source2) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 906 | tpc = model.TenantProjectConfig(source2_project2) |
| 907 | tenant.addConfigProject(tpc) |
James E. Blair | c2a54fd | 2017-03-29 15:19:26 -0700 | [diff] [blame] | 908 | d = {'project1': |
| 909 | {'git1.example.com': source1_project1, |
| 910 | 'git2.example.com': source2_project1}, |
| 911 | 'project2': |
| 912 | {'git1.example.com': source1_project2, |
| 913 | 'git2.example.com': source2_project2}} |
| 914 | self.assertEqual(d, tenant.projects) |
| 915 | with testtools.ExpectedException( |
| 916 | Exception, |
| 917 | "Project name 'project1' is ambiguous"): |
| 918 | tenant.getProject('project1') |
| 919 | with testtools.ExpectedException( |
| 920 | Exception, |
| 921 | "Project name 'project2' is ambiguous"): |
| 922 | tenant.getProject('project2') |
| 923 | self.assertEqual((True, source1_project1), |
| 924 | tenant.getProject('git1.example.com/project1')) |
| 925 | self.assertEqual((False, source2_project1), |
| 926 | tenant.getProject('git2.example.com/project1')) |
| 927 | self.assertEqual((False, source1_project2), |
| 928 | tenant.getProject('git1.example.com/project2')) |
| 929 | self.assertEqual((True, source2_project2), |
| 930 | tenant.getProject('git2.example.com/project2')) |
| 931 | |
| 932 | source1_project2b = model.Project('subpath/project2', source1) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 933 | tpc = model.TenantProjectConfig(source1_project2b) |
| 934 | tenant.addConfigProject(tpc) |
James E. Blair | c2a54fd | 2017-03-29 15:19:26 -0700 | [diff] [blame] | 935 | d = {'project1': |
| 936 | {'git1.example.com': source1_project1, |
| 937 | 'git2.example.com': source2_project1}, |
| 938 | 'project2': |
| 939 | {'git1.example.com': source1_project2, |
| 940 | 'git2.example.com': source2_project2}, |
| 941 | 'subpath/project2': |
| 942 | {'git1.example.com': source1_project2b}} |
| 943 | self.assertEqual(d, tenant.projects) |
| 944 | self.assertEqual((False, source1_project2), |
| 945 | tenant.getProject('git1.example.com/project2')) |
| 946 | self.assertEqual((True, source2_project2), |
| 947 | tenant.getProject('git2.example.com/project2')) |
| 948 | self.assertEqual((True, source1_project2b), |
| 949 | tenant.getProject('subpath/project2')) |
| 950 | self.assertEqual( |
| 951 | (True, source1_project2b), |
| 952 | tenant.getProject('git1.example.com/subpath/project2')) |
| 953 | |
| 954 | source2_project2b = model.Project('subpath/project2', source2) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 955 | tpc = model.TenantProjectConfig(source2_project2b) |
| 956 | tenant.addConfigProject(tpc) |
James E. Blair | c2a54fd | 2017-03-29 15:19:26 -0700 | [diff] [blame] | 957 | d = {'project1': |
| 958 | {'git1.example.com': source1_project1, |
| 959 | 'git2.example.com': source2_project1}, |
| 960 | 'project2': |
| 961 | {'git1.example.com': source1_project2, |
| 962 | 'git2.example.com': source2_project2}, |
| 963 | 'subpath/project2': |
| 964 | {'git1.example.com': source1_project2b, |
| 965 | 'git2.example.com': source2_project2b}} |
| 966 | self.assertEqual(d, tenant.projects) |
| 967 | self.assertEqual((False, source1_project2), |
| 968 | tenant.getProject('git1.example.com/project2')) |
| 969 | self.assertEqual((True, source2_project2), |
| 970 | tenant.getProject('git2.example.com/project2')) |
| 971 | with testtools.ExpectedException( |
| 972 | Exception, |
| 973 | "Project name 'subpath/project2' is ambiguous"): |
| 974 | tenant.getProject('subpath/project2') |
| 975 | self.assertEqual( |
| 976 | (True, source1_project2b), |
| 977 | tenant.getProject('git1.example.com/subpath/project2')) |
| 978 | self.assertEqual( |
| 979 | (True, source2_project2b), |
| 980 | tenant.getProject('git2.example.com/subpath/project2')) |
| 981 | |
| 982 | with testtools.ExpectedException( |
| 983 | Exception, |
| 984 | "Project project1 is already in project index"): |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame] | 985 | tenant._addProject(source1_project1_tpc) |