James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 1 | # Copyright 2017 Red Hat, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | |
| 16 | from tests.base import ZuulTestCase |
| 17 | |
| 18 | |
| 19 | class TenantParserTestCase(ZuulTestCase): |
| 20 | create_project_keys = True |
| 21 | |
| 22 | CONFIG_SET = set(['pipeline', 'job', 'semaphore', 'project', |
| 23 | 'project-template', 'nodeset', 'secret']) |
| 24 | UNTRUSTED_SET = CONFIG_SET - set(['pipeline']) |
| 25 | |
| 26 | def setupAllProjectKeys(self): |
| 27 | for project in ['common-config', 'org/project1', 'org/project2']: |
| 28 | self.setupProjectKeys('gerrit', project) |
| 29 | |
| 30 | |
| 31 | class TestTenantSimple(TenantParserTestCase): |
| 32 | tenant_config_file = 'config/tenant-parser/simple.yaml' |
| 33 | |
| 34 | def test_tenant_simple(self): |
| 35 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 36 | self.assertEqual(['common-config'], |
| 37 | [x.name for x in tenant.config_projects]) |
| 38 | self.assertEqual(['org/project1', 'org/project2'], |
| 39 | [x.name for x in tenant.untrusted_projects]) |
| 40 | self.assertEqual(self.CONFIG_SET, |
| 41 | tenant.config_projects[0].load_classes) |
| 42 | self.assertEqual(self.UNTRUSTED_SET, |
| 43 | tenant.untrusted_projects[0].load_classes) |
| 44 | self.assertEqual(self.UNTRUSTED_SET, |
| 45 | tenant.untrusted_projects[1].load_classes) |
| 46 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 47 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 48 | self.assertTrue('project2-job' in tenant.layout.jobs) |
| 49 | project1_config = tenant.layout.project_configs.get( |
| 50 | 'review.example.com/org/project1') |
| 51 | self.assertTrue('common-config-job' in |
| 52 | project1_config.pipelines['check'].job_list.jobs) |
| 53 | self.assertTrue('project1-job' in |
| 54 | project1_config.pipelines['check'].job_list.jobs) |
| 55 | project2_config = tenant.layout.project_configs.get( |
| 56 | 'review.example.com/org/project2') |
| 57 | self.assertTrue('common-config-job' in |
| 58 | project2_config.pipelines['check'].job_list.jobs) |
| 59 | self.assertTrue('project2-job' in |
| 60 | project2_config.pipelines['check'].job_list.jobs) |
| 61 | |
| 62 | |
| 63 | class TestTenantOverride(TenantParserTestCase): |
| 64 | tenant_config_file = 'config/tenant-parser/override.yaml' |
| 65 | |
| 66 | def test_tenant_override(self): |
| 67 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 68 | self.assertEqual(['common-config'], |
| 69 | [x.name for x in tenant.config_projects]) |
| 70 | self.assertEqual(['org/project1', 'org/project2'], |
| 71 | [x.name for x in tenant.untrusted_projects]) |
| 72 | self.assertEqual(self.CONFIG_SET, |
| 73 | tenant.config_projects[0].load_classes) |
| 74 | self.assertEqual(self.UNTRUSTED_SET - set(['project']), |
| 75 | tenant.untrusted_projects[0].load_classes) |
| 76 | self.assertEqual(set(['job']), |
| 77 | tenant.untrusted_projects[1].load_classes) |
| 78 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 79 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 80 | self.assertTrue('project2-job' in tenant.layout.jobs) |
| 81 | project1_config = tenant.layout.project_configs.get( |
| 82 | 'review.example.com/org/project1') |
| 83 | self.assertTrue('common-config-job' in |
| 84 | project1_config.pipelines['check'].job_list.jobs) |
| 85 | self.assertFalse('project1-job' in |
| 86 | project1_config.pipelines['check'].job_list.jobs) |
| 87 | project2_config = tenant.layout.project_configs.get( |
| 88 | 'review.example.com/org/project2') |
| 89 | self.assertTrue('common-config-job' in |
| 90 | project2_config.pipelines['check'].job_list.jobs) |
| 91 | self.assertFalse('project2-job' in |
| 92 | project2_config.pipelines['check'].job_list.jobs) |
| 93 | |
| 94 | |
| 95 | class TestTenantGroups(TenantParserTestCase): |
| 96 | tenant_config_file = 'config/tenant-parser/groups.yaml' |
| 97 | |
| 98 | def test_tenant_groups(self): |
| 99 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 100 | self.assertEqual(['common-config'], |
| 101 | [x.name for x in tenant.config_projects]) |
| 102 | self.assertEqual(['org/project1', 'org/project2'], |
| 103 | [x.name for x in tenant.untrusted_projects]) |
| 104 | self.assertEqual(self.CONFIG_SET, |
| 105 | tenant.config_projects[0].load_classes) |
| 106 | self.assertEqual(self.UNTRUSTED_SET - set(['project']), |
| 107 | tenant.untrusted_projects[0].load_classes) |
| 108 | self.assertEqual(self.UNTRUSTED_SET - set(['project']), |
| 109 | tenant.untrusted_projects[1].load_classes) |
| 110 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 111 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 112 | self.assertTrue('project2-job' in tenant.layout.jobs) |
| 113 | project1_config = tenant.layout.project_configs.get( |
| 114 | 'review.example.com/org/project1') |
| 115 | self.assertTrue('common-config-job' in |
| 116 | project1_config.pipelines['check'].job_list.jobs) |
| 117 | self.assertFalse('project1-job' in |
| 118 | project1_config.pipelines['check'].job_list.jobs) |
| 119 | project2_config = tenant.layout.project_configs.get( |
| 120 | 'review.example.com/org/project2') |
| 121 | self.assertTrue('common-config-job' in |
| 122 | project2_config.pipelines['check'].job_list.jobs) |
| 123 | self.assertFalse('project2-job' in |
| 124 | project2_config.pipelines['check'].job_list.jobs) |
| 125 | |
| 126 | |
| 127 | class TestTenantGroups2(TenantParserTestCase): |
| 128 | tenant_config_file = 'config/tenant-parser/groups2.yaml' |
| 129 | |
| 130 | def test_tenant_groups2(self): |
| 131 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 132 | self.assertEqual(['common-config'], |
| 133 | [x.name for x in tenant.config_projects]) |
| 134 | self.assertEqual(['org/project1', 'org/project2'], |
| 135 | [x.name for x in tenant.untrusted_projects]) |
| 136 | self.assertEqual(self.CONFIG_SET, |
| 137 | tenant.config_projects[0].load_classes) |
| 138 | self.assertEqual(self.UNTRUSTED_SET - set(['project']), |
| 139 | tenant.untrusted_projects[0].load_classes) |
| 140 | self.assertEqual(self.UNTRUSTED_SET - set(['project', 'job']), |
| 141 | tenant.untrusted_projects[1].load_classes) |
| 142 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 143 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 144 | self.assertFalse('project2-job' in tenant.layout.jobs) |
| 145 | project1_config = tenant.layout.project_configs.get( |
| 146 | 'review.example.com/org/project1') |
| 147 | self.assertTrue('common-config-job' in |
| 148 | project1_config.pipelines['check'].job_list.jobs) |
| 149 | self.assertFalse('project1-job' in |
| 150 | project1_config.pipelines['check'].job_list.jobs) |
| 151 | project2_config = tenant.layout.project_configs.get( |
| 152 | 'review.example.com/org/project2') |
| 153 | self.assertTrue('common-config-job' in |
| 154 | project2_config.pipelines['check'].job_list.jobs) |
| 155 | self.assertFalse('project2-job' in |
| 156 | project2_config.pipelines['check'].job_list.jobs) |
| 157 | |
| 158 | |
| 159 | class TestTenantGroups3(TenantParserTestCase): |
| 160 | tenant_config_file = 'config/tenant-parser/groups3.yaml' |
| 161 | |
| 162 | def test_tenant_groups3(self): |
| 163 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 164 | self.assertEqual(['common-config'], |
| 165 | [x.name for x in tenant.config_projects]) |
| 166 | self.assertEqual(['org/project1', 'org/project2'], |
| 167 | [x.name for x in tenant.untrusted_projects]) |
| 168 | self.assertEqual(self.CONFIG_SET, |
| 169 | tenant.config_projects[0].load_classes) |
| 170 | self.assertEqual(set(['job']), |
| 171 | tenant.untrusted_projects[0].load_classes) |
| 172 | self.assertEqual(set(['project', 'job']), |
| 173 | tenant.untrusted_projects[1].load_classes) |
| 174 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 175 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 176 | self.assertTrue('project2-job' in tenant.layout.jobs) |
| 177 | project1_config = tenant.layout.project_configs.get( |
| 178 | 'review.example.com/org/project1') |
| 179 | self.assertTrue('common-config-job' in |
| 180 | project1_config.pipelines['check'].job_list.jobs) |
| 181 | self.assertFalse('project1-job' in |
| 182 | project1_config.pipelines['check'].job_list.jobs) |
| 183 | project2_config = tenant.layout.project_configs.get( |
| 184 | 'review.example.com/org/project2') |
| 185 | self.assertTrue('common-config-job' in |
| 186 | project2_config.pipelines['check'].job_list.jobs) |
| 187 | self.assertTrue('project2-job' in |
| 188 | project2_config.pipelines['check'].job_list.jobs) |