blob: b86b630e04ad93401c5d1fbd3efbc7f6613fa6b5 [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
James E. Blair83005782015-12-11 14:46:03 -080029class TestMultipleTenants(ZuulTestCase):
James E. Blair59fdbac2015-12-07 17:08:06 -080030 # A temporary class to hold new tests while others are disabled
31
James E. Blair83005782015-12-11 14:46:03 -080032 config_file = 'config/multi-tenant/zuul.conf'
James E. Blair59fdbac2015-12-07 17:08:06 -080033
James E. Blair83005782015-12-11 14:46:03 -080034 def test_multiple_tenants(self):
James E. Blair96f26942015-12-09 10:15:59 -080035 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
James E. Blair59fdbac2015-12-07 17:08:06 -080036 A.addApproval('CRVW', 2)
37 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
38 self.waitUntilSettled()
James E. Blair96f26942015-12-09 10:15:59 -080039 self.assertEqual(self.getJobFromHistory('project1-test1').result,
James E. Blair59fdbac2015-12-07 17:08:06 -080040 'SUCCESS')
41 self.assertEqual(A.data['status'], 'MERGED')
James E. Blair96f26942015-12-09 10:15:59 -080042 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. Blair59fdbac2015-12-07 17:08:06 -080048
James E. Blair96f26942015-12-09 10:15:59 -080049 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
50 B.addApproval('CRVW', 2)
51 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
52 self.waitUntilSettled()
53 self.assertEqual(self.getJobFromHistory('project2-test1').result,
54 'SUCCESS')
55 self.assertEqual(B.data['status'], 'MERGED')
56 self.assertEqual(B.reported, 2,
57 "B should report start and success")
58 self.assertIn('tenant-two-gate', B.messages[1],
59 "B should transit tenant-two gate")
60 self.assertNotIn('tenant-one-gate', B.messages[1],
61 "B should *not* transit tenant-one gate")
James E. Blair59fdbac2015-12-07 17:08:06 -080062
James E. Blair96f26942015-12-09 10:15:59 -080063 self.assertEqual(A.reported, 2, "Activity in tenant two should"
64 "not affect tenant one")
James E. Blair14abdf42015-12-09 16:11:53 -080065
James E. Blair83005782015-12-11 14:46:03 -080066
67class TestInRepoConfig(ZuulTestCase):
68 # A temporary class to hold new tests while others are disabled
69
70 config_file = 'config/in-repo/zuul.conf'
71
72 def setup_repos(self):
James E. Blair14abdf42015-12-09 16:11:53 -080073 in_repo_conf = textwrap.dedent(
74 """
James E. Blaird8e778f2015-12-22 14:09:20 -080075 - job:
76 name: project-test1
James E. Blair83005782015-12-11 14:46:03 -080077
James E. Blaird8e778f2015-12-22 14:09:20 -080078 - project:
79 name: org/project
James E. Blair14abdf42015-12-09 16:11:53 -080080 tenant-one-gate:
James E. Blairb97ed802015-12-21 15:55:35 -080081 jobs:
82 - project-test1
James E. Blair14abdf42015-12-09 16:11:53 -080083 """)
84
85 self.addCommitToRepo('org/project', 'add zuul conf',
86 {'.zuul.yaml': in_repo_conf})
87
James E. Blair83005782015-12-11 14:46:03 -080088 def test_in_repo_config(self):
James E. Blair14abdf42015-12-09 16:11:53 -080089 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
90 A.addApproval('CRVW', 2)
91 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
92 self.waitUntilSettled()
93 self.assertEqual(self.getJobFromHistory('project-test1').result,
94 'SUCCESS')
95 self.assertEqual(A.data['status'], 'MERGED')
96 self.assertEqual(A.reported, 2,
97 "A should report start and success")
98 self.assertIn('tenant-one-gate', A.messages[1],
99 "A should transit tenant-one gate")
James E. Blairb97ed802015-12-21 15:55:35 -0800100
101
102class TestProjectTemplate(ZuulTestCase):
103 config_file = 'config/project-template/zuul.conf'
104
105 def test(self):
106 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
107 A.addApproval('CRVW', 2)
108 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
109 self.waitUntilSettled()
110 self.assertEqual(self.getJobFromHistory('project-test1').result,
111 'SUCCESS')
112 self.assertEqual(self.getJobFromHistory('project-test2').result,
113 'SUCCESS')
114 self.assertEqual(A.data['status'], 'MERGED')
115 self.assertEqual(A.reported, 2,
116 "A should report start and success")
117 self.assertIn('gate', A.messages[1],
118 "A should transit gate")