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 | |
| 20 | from tests.base import ( |
| 21 | ZuulTestCase, |
| 22 | ) |
| 23 | |
| 24 | logging.basicConfig(level=logging.DEBUG, |
| 25 | format='%(asctime)s %(name)-32s ' |
| 26 | '%(levelname)-8s %(message)s') |
| 27 | |
| 28 | |
| 29 | class TestV3(ZuulTestCase): |
| 30 | # A temporary class to hold new tests while others are disabled |
| 31 | |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 32 | def test_multiple_tenants(self): |
| 33 | self.setup_config('config/multi-tenant/zuul.conf') |
| 34 | self.sched.reconfigure(self.config) |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 35 | |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 36 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 37 | A.addApproval('CRVW', 2) |
| 38 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 39 | self.waitUntilSettled() |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 40 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 41 | 'SUCCESS') |
| 42 | self.assertEqual(A.data['status'], 'MERGED') |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 43 | self.assertEqual(A.reported, 2, |
| 44 | "A should report start and success") |
| 45 | self.assertIn('tenant-one-gate', A.messages[1], |
| 46 | "A should transit tenant-one gate") |
| 47 | self.assertNotIn('tenant-two-gate', A.messages[1], |
| 48 | "A should *not* transit tenant-two gate") |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 49 | |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 50 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 51 | B.addApproval('CRVW', 2) |
| 52 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 53 | self.waitUntilSettled() |
| 54 | self.assertEqual(self.getJobFromHistory('project2-test1').result, |
| 55 | 'SUCCESS') |
| 56 | self.assertEqual(B.data['status'], 'MERGED') |
| 57 | self.assertEqual(B.reported, 2, |
| 58 | "B should report start and success") |
| 59 | self.assertIn('tenant-two-gate', B.messages[1], |
| 60 | "B should transit tenant-two gate") |
| 61 | self.assertNotIn('tenant-one-gate', B.messages[1], |
| 62 | "B should *not* transit tenant-one gate") |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 63 | |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 64 | self.assertEqual(A.reported, 2, "Activity in tenant two should" |
| 65 | "not affect tenant one") |
James E. Blair | 14abdf4 | 2015-12-09 16:11:53 -0800 | [diff] [blame] | 66 | |
| 67 | def test_in_repo_config(self): |
| 68 | in_repo_conf = textwrap.dedent( |
| 69 | """ |
| 70 | projects: |
| 71 | - name: org/project |
| 72 | tenant-one-gate: |
| 73 | - project-test1 |
| 74 | """) |
| 75 | |
| 76 | self.addCommitToRepo('org/project', 'add zuul conf', |
| 77 | {'.zuul.yaml': in_repo_conf}) |
| 78 | |
| 79 | self.setup_config('config/in-repo/zuul.conf') |
| 80 | self.sched.reconfigure(self.config) |
| 81 | |
| 82 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 83 | A.addApproval('CRVW', 2) |
| 84 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 85 | self.waitUntilSettled() |
| 86 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 87 | 'SUCCESS') |
| 88 | self.assertEqual(A.data['status'], 'MERGED') |
| 89 | self.assertEqual(A.reported, 2, |
| 90 | "A should report start and success") |
| 91 | self.assertIn('tenant-one-gate', A.messages[1], |
| 92 | "A should transit tenant-one gate") |