blob: 50e20c8bda5fc70a6db9b52101992a5d968f8dd2 [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. Blair2a629ec2015-12-22 15:32:02 -080032 tenant_config_file = 'config/multi-tenant/main.yaml'
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')
James E. Blair96c6bf82016-01-15 16:20:40 -080041 self.assertEqual(self.getJobFromHistory('python27').result,
42 'SUCCESS')
James E. Blair59fdbac2015-12-07 17:08:06 -080043 self.assertEqual(A.data['status'], 'MERGED')
James E. Blair96f26942015-12-09 10:15:59 -080044 self.assertEqual(A.reported, 2,
45 "A should report start and success")
46 self.assertIn('tenant-one-gate', A.messages[1],
47 "A should transit tenant-one gate")
48 self.assertNotIn('tenant-two-gate', A.messages[1],
49 "A should *not* transit tenant-two gate")
James E. Blair59fdbac2015-12-07 17:08:06 -080050
James E. Blair96f26942015-12-09 10:15:59 -080051 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
52 B.addApproval('CRVW', 2)
53 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
54 self.waitUntilSettled()
James E. Blair96c6bf82016-01-15 16:20:40 -080055 self.assertEqual(self.getJobFromHistory('python27',
56 'org/project2').result,
57 'SUCCESS')
James E. Blair96f26942015-12-09 10:15:59 -080058 self.assertEqual(self.getJobFromHistory('project2-test1').result,
59 'SUCCESS')
60 self.assertEqual(B.data['status'], 'MERGED')
61 self.assertEqual(B.reported, 2,
62 "B should report start and success")
63 self.assertIn('tenant-two-gate', B.messages[1],
64 "B should transit tenant-two gate")
65 self.assertNotIn('tenant-one-gate', B.messages[1],
66 "B should *not* transit tenant-one gate")
James E. Blair59fdbac2015-12-07 17:08:06 -080067
James E. Blair96f26942015-12-09 10:15:59 -080068 self.assertEqual(A.reported, 2, "Activity in tenant two should"
69 "not affect tenant one")
James E. Blair14abdf42015-12-09 16:11:53 -080070
James E. Blair83005782015-12-11 14:46:03 -080071
72class TestInRepoConfig(ZuulTestCase):
73 # A temporary class to hold new tests while others are disabled
74
James E. Blair2a629ec2015-12-22 15:32:02 -080075 tenant_config_file = 'config/in-repo/main.yaml'
James E. Blair83005782015-12-11 14:46:03 -080076
James E. Blair83005782015-12-11 14:46:03 -080077 def test_in_repo_config(self):
James E. Blair14abdf42015-12-09 16:11:53 -080078 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
79 A.addApproval('CRVW', 2)
80 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
81 self.waitUntilSettled()
82 self.assertEqual(self.getJobFromHistory('project-test1').result,
83 'SUCCESS')
84 self.assertEqual(A.data['status'], 'MERGED')
85 self.assertEqual(A.reported, 2,
86 "A should report start and success")
87 self.assertIn('tenant-one-gate', A.messages[1],
88 "A should transit tenant-one gate")
James E. Blairb97ed802015-12-21 15:55:35 -080089
James E. Blair8b1dc3f2016-07-05 16:49:00 -070090 def test_dynamic_config(self):
91 in_repo_conf = textwrap.dedent(
92 """
93 - job:
94 name: project-test2
95
96 - project:
97 name: org/project
98 tenant-one-gate:
99 jobs:
100 - project-test2
101 """)
102
103 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
104 files={'.zuul.yaml': in_repo_conf})
105 A.addApproval('CRVW', 2)
106 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
107 self.waitUntilSettled()
108 self.assertEqual(self.getJobFromHistory('project-test2').result,
109 'SUCCESS')
110 self.assertEqual(A.data['status'], 'MERGED')
111 self.assertEqual(A.reported, 2,
112 "A should report start and success")
113 self.assertIn('tenant-one-gate', A.messages[1],
114 "A should transit tenant-one gate")
115
James E. Blairb97ed802015-12-21 15:55:35 -0800116
117class TestProjectTemplate(ZuulTestCase):
James E. Blair2a629ec2015-12-22 15:32:02 -0800118 tenant_config_file = 'config/project-template/main.yaml'
James E. Blairb97ed802015-12-21 15:55:35 -0800119
120 def test(self):
121 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
122 A.addApproval('CRVW', 2)
123 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
124 self.waitUntilSettled()
125 self.assertEqual(self.getJobFromHistory('project-test1').result,
126 'SUCCESS')
127 self.assertEqual(self.getJobFromHistory('project-test2').result,
128 'SUCCESS')
129 self.assertEqual(A.data['status'], 'MERGED')
130 self.assertEqual(A.reported, 2,
131 "A should report start and success")
132 self.assertIn('gate', A.messages[1],
133 "A should transit gate")