Monty Taylor | 0d92612 | 2017-05-24 08:07:56 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2017 Red Hat, Inc. |
| 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 | |
| 17 | import os |
| 18 | |
| 19 | import yaml |
| 20 | |
| 21 | from tests.base import ZuulTestCase |
| 22 | |
| 23 | |
| 24 | class TestInventory(ZuulTestCase): |
| 25 | |
| 26 | tenant_config_file = 'config/inventory/main.yaml' |
| 27 | |
| 28 | def setUp(self): |
| 29 | super(TestInventory, self).setUp() |
| 30 | self.executor_server.hold_jobs_in_build = True |
| 31 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 32 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 33 | self.waitUntilSettled() |
| 34 | |
| 35 | def _get_build_inventory(self, name): |
| 36 | build = self.getBuildByName(name) |
| 37 | inv_path = os.path.join(build.jobdir.root, 'ansible', 'inventory.yaml') |
| 38 | return yaml.safe_load(open(inv_path, 'r')) |
| 39 | |
| 40 | def test_single_inventory(self): |
| 41 | |
| 42 | inventory = self._get_build_inventory('single-inventory') |
| 43 | |
| 44 | all_nodes = ('ubuntu-xenial',) |
| 45 | self.assertIn('all', inventory) |
| 46 | self.assertIn('hosts', inventory['all']) |
| 47 | for node_name in all_nodes: |
| 48 | self.assertIn(node_name, inventory['all']['hosts']) |
| 49 | |
| 50 | self.executor_server.release() |
| 51 | self.waitUntilSettled() |
| 52 | |
| 53 | def test_group_inventory(self): |
| 54 | |
| 55 | inventory = self._get_build_inventory('group-inventory') |
| 56 | |
| 57 | all_nodes = ('controller', 'compute1', 'compute2') |
| 58 | self.assertIn('all', inventory) |
| 59 | self.assertIn('hosts', inventory['all']) |
| 60 | for group_name in ('ceph-osd', 'ceph-monitor'): |
| 61 | self.assertIn(group_name, inventory) |
| 62 | for node_name in all_nodes: |
| 63 | self.assertIn(node_name, inventory['all']['hosts']) |
| 64 | self.assertIn(node_name, |
| 65 | inventory['ceph-monitor']['hosts']) |
| 66 | self.executor_server.release() |
| 67 | self.waitUntilSettled() |