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]) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 40 | |
| 41 | project = tenant.config_projects[0] |
| 42 | tpc = tenant.project_configs[project.canonical_name] |
| 43 | self.assertEqual(self.CONFIG_SET, tpc.load_classes) |
| 44 | project = tenant.untrusted_projects[0] |
| 45 | tpc = tenant.project_configs[project.canonical_name] |
| 46 | self.assertEqual(self.UNTRUSTED_SET, tpc.load_classes) |
| 47 | project = tenant.untrusted_projects[1] |
| 48 | tpc = tenant.project_configs[project.canonical_name] |
| 49 | self.assertEqual(self.UNTRUSTED_SET, tpc.load_classes) |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 50 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 51 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 52 | self.assertTrue('project2-job' in tenant.layout.jobs) |
| 53 | project1_config = tenant.layout.project_configs.get( |
| 54 | 'review.example.com/org/project1') |
| 55 | self.assertTrue('common-config-job' in |
| 56 | project1_config.pipelines['check'].job_list.jobs) |
| 57 | self.assertTrue('project1-job' in |
| 58 | project1_config.pipelines['check'].job_list.jobs) |
| 59 | project2_config = tenant.layout.project_configs.get( |
| 60 | 'review.example.com/org/project2') |
| 61 | self.assertTrue('common-config-job' in |
| 62 | project2_config.pipelines['check'].job_list.jobs) |
| 63 | self.assertTrue('project2-job' in |
| 64 | project2_config.pipelines['check'].job_list.jobs) |
| 65 | |
| 66 | |
| 67 | class TestTenantOverride(TenantParserTestCase): |
| 68 | tenant_config_file = 'config/tenant-parser/override.yaml' |
| 69 | |
| 70 | def test_tenant_override(self): |
| 71 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 72 | self.assertEqual(['common-config'], |
| 73 | [x.name for x in tenant.config_projects]) |
| 74 | self.assertEqual(['org/project1', 'org/project2'], |
| 75 | [x.name for x in tenant.untrusted_projects]) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 76 | project = tenant.config_projects[0] |
| 77 | tpc = tenant.project_configs[project.canonical_name] |
| 78 | self.assertEqual(self.CONFIG_SET, tpc.load_classes) |
| 79 | project = tenant.untrusted_projects[0] |
| 80 | tpc = tenant.project_configs[project.canonical_name] |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 81 | self.assertEqual(self.UNTRUSTED_SET - set(['project']), |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 82 | tpc.load_classes) |
| 83 | project = tenant.untrusted_projects[1] |
| 84 | tpc = tenant.project_configs[project.canonical_name] |
| 85 | self.assertEqual(set(['job']), tpc.load_classes) |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 86 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 87 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 88 | self.assertTrue('project2-job' in tenant.layout.jobs) |
| 89 | project1_config = tenant.layout.project_configs.get( |
| 90 | 'review.example.com/org/project1') |
| 91 | self.assertTrue('common-config-job' in |
| 92 | project1_config.pipelines['check'].job_list.jobs) |
| 93 | self.assertFalse('project1-job' in |
| 94 | project1_config.pipelines['check'].job_list.jobs) |
| 95 | project2_config = tenant.layout.project_configs.get( |
| 96 | 'review.example.com/org/project2') |
| 97 | self.assertTrue('common-config-job' in |
| 98 | project2_config.pipelines['check'].job_list.jobs) |
| 99 | self.assertFalse('project2-job' in |
| 100 | project2_config.pipelines['check'].job_list.jobs) |
| 101 | |
| 102 | |
| 103 | class TestTenantGroups(TenantParserTestCase): |
| 104 | tenant_config_file = 'config/tenant-parser/groups.yaml' |
| 105 | |
| 106 | def test_tenant_groups(self): |
| 107 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 108 | self.assertEqual(['common-config'], |
| 109 | [x.name for x in tenant.config_projects]) |
| 110 | self.assertEqual(['org/project1', 'org/project2'], |
| 111 | [x.name for x in tenant.untrusted_projects]) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 112 | project = tenant.config_projects[0] |
| 113 | tpc = tenant.project_configs[project.canonical_name] |
| 114 | self.assertEqual(self.CONFIG_SET, tpc.load_classes) |
| 115 | project = tenant.untrusted_projects[0] |
| 116 | tpc = tenant.project_configs[project.canonical_name] |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 117 | self.assertEqual(self.UNTRUSTED_SET - set(['project']), |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 118 | tpc.load_classes) |
| 119 | project = tenant.untrusted_projects[1] |
| 120 | tpc = tenant.project_configs[project.canonical_name] |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 121 | self.assertEqual(self.UNTRUSTED_SET - set(['project']), |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 122 | tpc.load_classes) |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 123 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 124 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 125 | self.assertTrue('project2-job' in tenant.layout.jobs) |
| 126 | project1_config = tenant.layout.project_configs.get( |
| 127 | 'review.example.com/org/project1') |
| 128 | self.assertTrue('common-config-job' in |
| 129 | project1_config.pipelines['check'].job_list.jobs) |
| 130 | self.assertFalse('project1-job' in |
| 131 | project1_config.pipelines['check'].job_list.jobs) |
| 132 | project2_config = tenant.layout.project_configs.get( |
| 133 | 'review.example.com/org/project2') |
| 134 | self.assertTrue('common-config-job' in |
| 135 | project2_config.pipelines['check'].job_list.jobs) |
| 136 | self.assertFalse('project2-job' in |
| 137 | project2_config.pipelines['check'].job_list.jobs) |
| 138 | |
| 139 | |
| 140 | class TestTenantGroups2(TenantParserTestCase): |
| 141 | tenant_config_file = 'config/tenant-parser/groups2.yaml' |
| 142 | |
| 143 | def test_tenant_groups2(self): |
| 144 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 145 | self.assertEqual(['common-config'], |
| 146 | [x.name for x in tenant.config_projects]) |
| 147 | self.assertEqual(['org/project1', 'org/project2'], |
| 148 | [x.name for x in tenant.untrusted_projects]) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 149 | project = tenant.config_projects[0] |
| 150 | tpc = tenant.project_configs[project.canonical_name] |
| 151 | self.assertEqual(self.CONFIG_SET, tpc.load_classes) |
| 152 | project = tenant.untrusted_projects[0] |
| 153 | tpc = tenant.project_configs[project.canonical_name] |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 154 | self.assertEqual(self.UNTRUSTED_SET - set(['project']), |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 155 | tpc.load_classes) |
| 156 | project = tenant.untrusted_projects[1] |
| 157 | tpc = tenant.project_configs[project.canonical_name] |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 158 | self.assertEqual(self.UNTRUSTED_SET - set(['project', 'job']), |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 159 | tpc.load_classes) |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 160 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 161 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 162 | self.assertFalse('project2-job' in tenant.layout.jobs) |
| 163 | project1_config = tenant.layout.project_configs.get( |
| 164 | 'review.example.com/org/project1') |
| 165 | self.assertTrue('common-config-job' in |
| 166 | project1_config.pipelines['check'].job_list.jobs) |
| 167 | self.assertFalse('project1-job' in |
| 168 | project1_config.pipelines['check'].job_list.jobs) |
| 169 | project2_config = tenant.layout.project_configs.get( |
| 170 | 'review.example.com/org/project2') |
| 171 | self.assertTrue('common-config-job' in |
| 172 | project2_config.pipelines['check'].job_list.jobs) |
| 173 | self.assertFalse('project2-job' in |
| 174 | project2_config.pipelines['check'].job_list.jobs) |
| 175 | |
| 176 | |
| 177 | class TestTenantGroups3(TenantParserTestCase): |
| 178 | tenant_config_file = 'config/tenant-parser/groups3.yaml' |
| 179 | |
| 180 | def test_tenant_groups3(self): |
| 181 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 182 | self.assertEqual(['common-config'], |
| 183 | [x.name for x in tenant.config_projects]) |
| 184 | self.assertEqual(['org/project1', 'org/project2'], |
| 185 | [x.name for x in tenant.untrusted_projects]) |
James E. Blair | 08d9b78 | 2017-06-29 14:22:48 -0700 | [diff] [blame^] | 186 | project = tenant.config_projects[0] |
| 187 | tpc = tenant.project_configs[project.canonical_name] |
| 188 | self.assertEqual(self.CONFIG_SET, tpc.load_classes) |
| 189 | project = tenant.untrusted_projects[0] |
| 190 | tpc = tenant.project_configs[project.canonical_name] |
| 191 | self.assertEqual(set(['job']), tpc.load_classes) |
| 192 | project = tenant.untrusted_projects[1] |
| 193 | tpc = tenant.project_configs[project.canonical_name] |
| 194 | self.assertEqual(set(['project', 'job']), tpc.load_classes) |
James E. Blair | ac180ce | 2017-06-07 19:31:02 -0700 | [diff] [blame] | 195 | self.assertTrue('common-config-job' in tenant.layout.jobs) |
| 196 | self.assertTrue('project1-job' in tenant.layout.jobs) |
| 197 | self.assertTrue('project2-job' in tenant.layout.jobs) |
| 198 | project1_config = tenant.layout.project_configs.get( |
| 199 | 'review.example.com/org/project1') |
| 200 | self.assertTrue('common-config-job' in |
| 201 | project1_config.pipelines['check'].job_list.jobs) |
| 202 | self.assertFalse('project1-job' in |
| 203 | project1_config.pipelines['check'].job_list.jobs) |
| 204 | project2_config = tenant.layout.project_configs.get( |
| 205 | 'review.example.com/org/project2') |
| 206 | self.assertTrue('common-config-job' in |
| 207 | project2_config.pipelines['check'].job_list.jobs) |
| 208 | self.assertTrue('project2-job' in |
| 209 | project2_config.pipelines['check'].job_list.jobs) |