blob: 69e66a0113452c17868f8a50bdec0b4312b0cf07 [file] [log] [blame]
James E. Blair59fdbac2015-12-07 17:08:06 -08001#!/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
17import logging
James E. Blair14abdf42015-12-09 16:11:53 -080018import textwrap
James E. Blair59fdbac2015-12-07 17:08:06 -080019
20from tests.base import (
21 ZuulTestCase,
22)
23
24logging.basicConfig(level=logging.DEBUG,
25 format='%(asctime)s %(name)-32s '
26 '%(levelname)-8s %(message)s')
27
28
29class TestV3(ZuulTestCase):
30 # A temporary class to hold new tests while others are disabled
31
James E. Blair96f26942015-12-09 10:15:59 -080032 def test_multiple_tenants(self):
33 self.setup_config('config/multi-tenant/zuul.conf')
34 self.sched.reconfigure(self.config)
James E. Blair59fdbac2015-12-07 17:08:06 -080035
James E. Blair96f26942015-12-09 10:15:59 -080036 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
James E. Blair59fdbac2015-12-07 17:08:06 -080037 A.addApproval('CRVW', 2)
38 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
39 self.waitUntilSettled()
James E. Blair96f26942015-12-09 10:15:59 -080040 self.assertEqual(self.getJobFromHistory('project1-test1').result,
James E. Blair59fdbac2015-12-07 17:08:06 -080041 'SUCCESS')
42 self.assertEqual(A.data['status'], 'MERGED')
James E. Blair96f26942015-12-09 10:15:59 -080043 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. Blair59fdbac2015-12-07 17:08:06 -080049
James E. Blair96f26942015-12-09 10:15:59 -080050 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. Blair59fdbac2015-12-07 17:08:06 -080063
James E. Blair96f26942015-12-09 10:15:59 -080064 self.assertEqual(A.reported, 2, "Activity in tenant two should"
65 "not affect tenant one")
James E. Blair14abdf42015-12-09 16:11:53 -080066
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")