James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 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 | 14abdf4 | 2015-12-09 16:11:53 -0800 | [diff] [blame] | 18 | import textwrap |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 19 | |
James E. Blair | 3f876d5 | 2016-07-22 13:07:14 -0700 | [diff] [blame] | 20 | from tests.base import AnsibleZuulTestCase |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 21 | |
| 22 | logging.basicConfig(level=logging.DEBUG, |
| 23 | format='%(asctime)s %(name)-32s ' |
| 24 | '%(levelname)-8s %(message)s') |
| 25 | |
| 26 | |
James E. Blair | 3f876d5 | 2016-07-22 13:07:14 -0700 | [diff] [blame] | 27 | class TestMultipleTenants(AnsibleZuulTestCase): |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 28 | # A temporary class to hold new tests while others are disabled |
| 29 | |
James E. Blair | 2a629ec | 2015-12-22 15:32:02 -0800 | [diff] [blame] | 30 | tenant_config_file = 'config/multi-tenant/main.yaml' |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 31 | |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 32 | def test_multiple_tenants(self): |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 33 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 34 | A.addApproval('code-review', 2) |
| 35 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 36 | self.waitUntilSettled() |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 37 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 38 | 'SUCCESS') |
James E. Blair | 96c6bf8 | 2016-01-15 16:20:40 -0800 | [diff] [blame] | 39 | self.assertEqual(self.getJobFromHistory('python27').result, |
| 40 | 'SUCCESS') |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 41 | self.assertEqual(A.data['status'], 'MERGED') |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 42 | self.assertEqual(A.reported, 2, |
| 43 | "A should report start and success") |
| 44 | self.assertIn('tenant-one-gate', A.messages[1], |
| 45 | "A should transit tenant-one gate") |
| 46 | self.assertNotIn('tenant-two-gate', A.messages[1], |
| 47 | "A should *not* transit tenant-two gate") |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 48 | |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 49 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 50 | B.addApproval('code-review', 2) |
| 51 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 52 | self.waitUntilSettled() |
James E. Blair | 96c6bf8 | 2016-01-15 16:20:40 -0800 | [diff] [blame] | 53 | self.assertEqual(self.getJobFromHistory('python27', |
| 54 | 'org/project2').result, |
| 55 | 'SUCCESS') |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 56 | self.assertEqual(self.getJobFromHistory('project2-test1').result, |
| 57 | 'SUCCESS') |
| 58 | self.assertEqual(B.data['status'], 'MERGED') |
| 59 | self.assertEqual(B.reported, 2, |
| 60 | "B should report start and success") |
| 61 | self.assertIn('tenant-two-gate', B.messages[1], |
| 62 | "B should transit tenant-two gate") |
| 63 | self.assertNotIn('tenant-one-gate', B.messages[1], |
| 64 | "B should *not* transit tenant-one gate") |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 65 | |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 66 | self.assertEqual(A.reported, 2, "Activity in tenant two should" |
| 67 | "not affect tenant one") |
James E. Blair | 14abdf4 | 2015-12-09 16:11:53 -0800 | [diff] [blame] | 68 | |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 69 | |
James E. Blair | 3f876d5 | 2016-07-22 13:07:14 -0700 | [diff] [blame] | 70 | class TestInRepoConfig(AnsibleZuulTestCase): |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 71 | # A temporary class to hold new tests while others are disabled |
| 72 | |
James E. Blair | 2a629ec | 2015-12-22 15:32:02 -0800 | [diff] [blame] | 73 | tenant_config_file = 'config/in-repo/main.yaml' |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 74 | |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 75 | def test_in_repo_config(self): |
James E. Blair | 14abdf4 | 2015-12-09 16:11:53 -0800 | [diff] [blame] | 76 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 77 | A.addApproval('code-review', 2) |
| 78 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 14abdf4 | 2015-12-09 16:11:53 -0800 | [diff] [blame] | 79 | self.waitUntilSettled() |
| 80 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 81 | 'SUCCESS') |
| 82 | self.assertEqual(A.data['status'], 'MERGED') |
| 83 | self.assertEqual(A.reported, 2, |
| 84 | "A should report start and success") |
| 85 | self.assertIn('tenant-one-gate', A.messages[1], |
| 86 | "A should transit tenant-one gate") |
James E. Blair | b97ed80 | 2015-12-21 15:55:35 -0800 | [diff] [blame] | 87 | |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 88 | def test_dynamic_config(self): |
| 89 | in_repo_conf = textwrap.dedent( |
| 90 | """ |
| 91 | - job: |
| 92 | name: project-test2 |
| 93 | |
| 94 | - project: |
| 95 | name: org/project |
| 96 | tenant-one-gate: |
| 97 | jobs: |
| 98 | - project-test2 |
| 99 | """) |
| 100 | |
| 101 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 102 | files={'.zuul.yaml': in_repo_conf}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 103 | A.addApproval('code-review', 2) |
| 104 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 105 | self.waitUntilSettled() |
| 106 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 107 | 'SUCCESS') |
| 108 | self.assertEqual(A.data['status'], 'MERGED') |
| 109 | self.assertEqual(A.reported, 2, |
| 110 | "A should report start and success") |
| 111 | self.assertIn('tenant-one-gate', A.messages[1], |
| 112 | "A should transit tenant-one gate") |