Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | import os |
| 14 | import unittest |
| 15 | |
| 16 | from gabbi import driver |
| 17 | from tempest import config |
| 18 | from tempest import test |
| 19 | |
| 20 | from ceilometer.tests.tempest.service import client |
| 21 | |
| 22 | |
| 23 | class ClientManager(client.Manager): |
| 24 | load_clients = [ |
| 25 | 'image_client_v2', |
| 26 | ] |
| 27 | |
| 28 | |
| 29 | class TestAutoscalingGabbi(test.BaseTestCase): |
| 30 | credentials = ['admin'] |
| 31 | client_manager = ClientManager |
| 32 | |
| 33 | @classmethod |
| 34 | def skip_checks(cls): |
| 35 | super(TestAutoscalingGabbi, cls).skip_checks() |
| 36 | for name in ["aodh_plugin", "gnocchi", "nova", "heat", |
| 37 | "ceilometer", "glance"]: |
| 38 | cls._check_service(name) |
| 39 | |
| 40 | @classmethod |
| 41 | def _check_service(cls, name): |
| 42 | if not getattr(config.CONF.service_available, name, False): |
| 43 | raise cls.skipException("%s support is required" % |
| 44 | name.capitalize()) |
| 45 | |
| 46 | @classmethod |
| 47 | def resource_setup(cls): |
| 48 | super(TestAutoscalingGabbi, cls).resource_setup() |
| 49 | test_dir = os.path.join(os.path.dirname(__file__), '..', '..', |
| 50 | 'integration', 'gabbi', 'gabbits-live') |
| 51 | cls.tests = driver.build_tests( |
| 52 | test_dir, unittest.TestLoader(), |
| 53 | host='localhost', port='13245', |
| 54 | test_loader_name='tempest.scenario.telemetry-autoscaling.test') |
| 55 | |
| 56 | auth = cls.os_admin.auth_provider.get_auth() |
| 57 | os.environ["ADMIN_TOKEN"] = auth[0] |
| 58 | os.environ["AODH_SERVICE_URL"] = cls._get_endpoint_for( |
| 59 | auth, "alarming_plugin") |
| 60 | os.environ["GNOCCHI_SERVICE_URL"] = cls._get_endpoint_for( |
| 61 | auth, "metric") |
| 62 | os.environ["HEAT_SERVICE_URL"] = cls._get_endpoint_for( |
| 63 | auth, "orchestration") |
| 64 | os.environ["NOVA_SERVICE_URL"] = cls._get_endpoint_for(auth, "compute") |
| 65 | os.environ["GLANCE_SERVICE_URL"] = cls._get_endpoint_for(auth, "image") |
| 66 | images = cls.os_admin.image_client_v2.list_images()["images"] |
| 67 | for img in images: |
| 68 | name = img["name"] |
| 69 | if name.startswith("cirros") and name.endswith("-uec"): |
| 70 | os.environ["GLANCE_IMAGE_NAME"] = name |
| 71 | break |
| 72 | else: |
| 73 | cls.skipException("A cirros-.*-uec image is required") |
| 74 | |
| 75 | @staticmethod |
| 76 | def clear_credentials(): |
| 77 | # FIXME(sileht): We don't want the token to be invalided, but |
| 78 | # for some obcurs reason, clear_credentials is called before/during run |
| 79 | # So, make the one used by tearDropClass a dump, and call it manually |
| 80 | # in run() |
| 81 | pass |
| 82 | |
| 83 | def run(self, result=None): |
| 84 | self.setUp() |
| 85 | try: |
| 86 | self.tests.run(result) |
| 87 | finally: |
| 88 | super(TestAutoscalingGabbi, self).clear_credentials() |
| 89 | self.tearDown() |
| 90 | |
| 91 | @staticmethod |
| 92 | def _get_endpoint_for(auth, service): |
| 93 | opt_section = getattr(config.CONF, service) |
| 94 | endpoint_type = opt_section.endpoint_type |
Mehdi Abaakouk | f79a0ae | 2016-12-15 16:44:30 +0100 | [diff] [blame] | 95 | is_keystone_v3 = 'catalog' in auth[1] |
Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 96 | |
Mehdi Abaakouk | f79a0ae | 2016-12-15 16:44:30 +0100 | [diff] [blame] | 97 | if is_keystone_v3: |
| 98 | if endpoint_type.endswith("URL"): |
| 99 | endpoint_type = endpoint_type[:-3] |
| 100 | catalog = auth[1]['catalog'] |
| 101 | endpoints = [e['endpoints'] for e in catalog |
| 102 | if e['type'] == opt_section.catalog_type] |
| 103 | if not endpoints: |
| 104 | raise Exception("%s endpoint not found" % |
| 105 | config.CONF.metric.catalog_type) |
| 106 | endpoints = [e['url'] for e in endpoints[0] |
| 107 | if e['interface'] == endpoint_type] |
| 108 | if not endpoints: |
| 109 | raise Exception("%s interface not found for endpoint %s" % |
| 110 | (endpoint_type, |
| 111 | config.CONF.metric.catalog_type)) |
| 112 | return endpoints[0] |
| 113 | |
| 114 | else: |
| 115 | if not endpoint_type.endswith("URL"): |
| 116 | endpoint_type += "URL" |
| 117 | catalog = auth[1]['serviceCatalog'] |
| 118 | endpoints = [e for e in catalog |
| 119 | if e['type'] == opt_section.catalog_type] |
| 120 | if not endpoints: |
| 121 | raise Exception("%s endpoint not found" % |
| 122 | config.CONF.metric.catalog_type) |
| 123 | return endpoints[0]['endpoints'][0][endpoint_type] |
Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 124 | |
| 125 | @staticmethod |
| 126 | def test_fake(): |
| 127 | # NOTE(sileht): A fake test is needed to have the class loaded |
| 128 | # by the test runner |
| 129 | pass |