| #!/usr/bin/env python |
| |
| # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| # not use this file except in compliance with the License. You may obtain |
| # a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations |
| # under the License. |
| |
| import os |
| import textwrap |
| |
| from tests.base import AnsibleZuulTestCase |
| |
| |
| class TestMultipleTenants(AnsibleZuulTestCase): |
| # A temporary class to hold new tests while others are disabled |
| |
| tenant_config_file = 'config/multi-tenant/main.yaml' |
| |
| def test_multiple_tenants(self): |
| A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| A.addApproval('code-review', 2) |
| self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| self.waitUntilSettled() |
| self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 'SUCCESS') |
| self.assertEqual(self.getJobFromHistory('python27').result, |
| 'SUCCESS') |
| self.assertEqual(A.data['status'], 'MERGED') |
| self.assertEqual(A.reported, 2, |
| "A should report start and success") |
| self.assertIn('tenant-one-gate', A.messages[1], |
| "A should transit tenant-one gate") |
| self.assertNotIn('tenant-two-gate', A.messages[1], |
| "A should *not* transit tenant-two gate") |
| |
| B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| B.addApproval('code-review', 2) |
| self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| self.waitUntilSettled() |
| self.assertEqual(self.getJobFromHistory('python27', |
| 'org/project2').result, |
| 'SUCCESS') |
| self.assertEqual(self.getJobFromHistory('project2-test1').result, |
| 'SUCCESS') |
| self.assertEqual(B.data['status'], 'MERGED') |
| self.assertEqual(B.reported, 2, |
| "B should report start and success") |
| self.assertIn('tenant-two-gate', B.messages[1], |
| "B should transit tenant-two gate") |
| self.assertNotIn('tenant-one-gate', B.messages[1], |
| "B should *not* transit tenant-one gate") |
| |
| self.assertEqual(A.reported, 2, "Activity in tenant two should" |
| "not affect tenant one") |
| |
| |
| class TestInRepoConfig(AnsibleZuulTestCase): |
| # A temporary class to hold new tests while others are disabled |
| |
| tenant_config_file = 'config/in-repo/main.yaml' |
| |
| def test_in_repo_config(self): |
| A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| A.addApproval('code-review', 2) |
| self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| self.waitUntilSettled() |
| self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 'SUCCESS') |
| self.assertEqual(A.data['status'], 'MERGED') |
| self.assertEqual(A.reported, 2, |
| "A should report start and success") |
| self.assertIn('tenant-one-gate', A.messages[1], |
| "A should transit tenant-one gate") |
| |
| def test_dynamic_config(self): |
| in_repo_conf = textwrap.dedent( |
| """ |
| - job: |
| name: project-test2 |
| |
| - project: |
| name: org/project |
| tenant-one-gate: |
| jobs: |
| - project-test2 |
| """) |
| |
| in_repo_playbook = textwrap.dedent( |
| """ |
| - hosts: all |
| tasks: [] |
| """) |
| |
| file_dict = {'.zuul.yaml': in_repo_conf, |
| 'playbooks/project-test2.yaml': in_repo_playbook} |
| A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| files=file_dict) |
| A.addApproval('code-review', 2) |
| self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| self.waitUntilSettled() |
| self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 'SUCCESS') |
| self.assertEqual(A.data['status'], 'MERGED') |
| self.assertEqual(A.reported, 2, |
| "A should report start and success") |
| self.assertIn('tenant-one-gate', A.messages[1], |
| "A should transit tenant-one gate") |
| |
| |
| class TestAnsible(AnsibleZuulTestCase): |
| # A temporary class to hold new tests while others are disabled |
| |
| tenant_config_file = 'config/ansible/main.yaml' |
| |
| def test_playbook(self): |
| A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| self.waitUntilSettled() |
| build = self.getJobFromHistory('python27') |
| self.assertEqual(build.result, 'SUCCESS') |
| flag_path = os.path.join(self.test_root, build.uuid + '.flag') |
| self.assertTrue(os.path.exists(flag_path)) |