| 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 | 
| Mehdi Abaakouk | 7a61c67 | 2017-01-09 15:17:31 +0100 | [diff] [blame] | 18 | from tempest.scenario import manager | 
| Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 19 |  | 
|  | 20 |  | 
| Mehdi Abaakouk | 7a61c67 | 2017-01-09 15:17:31 +0100 | [diff] [blame] | 21 | class TestAutoscalingGabbi(manager.ScenarioTest): | 
|  | 22 | credentials = ['admin', 'primary'] | 
| Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 23 |  | 
|  | 24 | @classmethod | 
|  | 25 | def skip_checks(cls): | 
|  | 26 | super(TestAutoscalingGabbi, cls).skip_checks() | 
| gord chung | 7014db6 | 2017-01-10 21:41:58 +0000 | [diff] [blame^] | 27 | for name in ["aodh_plugin", "gnocchi", "nova", "heat", "panko", | 
| Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 28 | "ceilometer", "glance"]: | 
|  | 29 | cls._check_service(name) | 
|  | 30 |  | 
|  | 31 | @classmethod | 
|  | 32 | def _check_service(cls, name): | 
|  | 33 | if not getattr(config.CONF.service_available, name, False): | 
|  | 34 | raise cls.skipException("%s support is required" % | 
|  | 35 | name.capitalize()) | 
|  | 36 |  | 
|  | 37 | @classmethod | 
|  | 38 | def resource_setup(cls): | 
|  | 39 | super(TestAutoscalingGabbi, cls).resource_setup() | 
|  | 40 | test_dir = os.path.join(os.path.dirname(__file__), '..', '..', | 
|  | 41 | 'integration', 'gabbi', 'gabbits-live') | 
|  | 42 | cls.tests = driver.build_tests( | 
|  | 43 | test_dir, unittest.TestLoader(), | 
|  | 44 | host='localhost', port='13245', | 
|  | 45 | test_loader_name='tempest.scenario.telemetry-autoscaling.test') | 
|  | 46 |  | 
|  | 47 | auth = cls.os_admin.auth_provider.get_auth() | 
|  | 48 | os.environ["ADMIN_TOKEN"] = auth[0] | 
|  | 49 | os.environ["AODH_SERVICE_URL"] = cls._get_endpoint_for( | 
|  | 50 | auth, "alarming_plugin") | 
|  | 51 | os.environ["GNOCCHI_SERVICE_URL"] = cls._get_endpoint_for( | 
|  | 52 | auth, "metric") | 
| gord chung | 7014db6 | 2017-01-10 21:41:58 +0000 | [diff] [blame^] | 53 | os.environ["PANKO_SERVICE_URL"] = cls._get_endpoint_for( | 
|  | 54 | auth, "event") | 
| Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 55 | os.environ["HEAT_SERVICE_URL"] = cls._get_endpoint_for( | 
|  | 56 | auth, "orchestration") | 
|  | 57 | os.environ["NOVA_SERVICE_URL"] = cls._get_endpoint_for(auth, "compute") | 
|  | 58 | os.environ["GLANCE_SERVICE_URL"] = cls._get_endpoint_for(auth, "image") | 
| Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 59 |  | 
|  | 60 | @staticmethod | 
|  | 61 | def clear_credentials(): | 
|  | 62 | # FIXME(sileht): We don't want the token to be invalided, but | 
|  | 63 | # for some obcurs reason, clear_credentials is called before/during run | 
|  | 64 | # So, make the one used by tearDropClass a dump, and call it manually | 
|  | 65 | # in run() | 
|  | 66 | pass | 
|  | 67 |  | 
|  | 68 | def run(self, result=None): | 
|  | 69 | self.setUp() | 
| Mehdi Abaakouk | 7a61c67 | 2017-01-09 15:17:31 +0100 | [diff] [blame] | 70 | os.environ["GLANCE_IMAGE_NAME"] = self.glance_image_create() | 
| Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 71 | try: | 
|  | 72 | self.tests.run(result) | 
|  | 73 | finally: | 
|  | 74 | super(TestAutoscalingGabbi, self).clear_credentials() | 
|  | 75 | self.tearDown() | 
|  | 76 |  | 
|  | 77 | @staticmethod | 
|  | 78 | def _get_endpoint_for(auth, service): | 
|  | 79 | opt_section = getattr(config.CONF, service) | 
|  | 80 | endpoint_type = opt_section.endpoint_type | 
| Mehdi Abaakouk | f79a0ae | 2016-12-15 16:44:30 +0100 | [diff] [blame] | 81 | is_keystone_v3 = 'catalog' in auth[1] | 
| Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 82 |  | 
| Mehdi Abaakouk | f79a0ae | 2016-12-15 16:44:30 +0100 | [diff] [blame] | 83 | if is_keystone_v3: | 
|  | 84 | if endpoint_type.endswith("URL"): | 
|  | 85 | endpoint_type = endpoint_type[:-3] | 
|  | 86 | catalog = auth[1]['catalog'] | 
|  | 87 | endpoints = [e['endpoints'] for e in catalog | 
|  | 88 | if e['type'] == opt_section.catalog_type] | 
|  | 89 | if not endpoints: | 
|  | 90 | raise Exception("%s endpoint not found" % | 
|  | 91 | config.CONF.metric.catalog_type) | 
|  | 92 | endpoints = [e['url'] for e in endpoints[0] | 
|  | 93 | if e['interface'] == endpoint_type] | 
|  | 94 | if not endpoints: | 
|  | 95 | raise Exception("%s interface not found for endpoint %s" % | 
|  | 96 | (endpoint_type, | 
|  | 97 | config.CONF.metric.catalog_type)) | 
|  | 98 | return endpoints[0] | 
|  | 99 |  | 
|  | 100 | else: | 
|  | 101 | if not endpoint_type.endswith("URL"): | 
|  | 102 | endpoint_type += "URL" | 
|  | 103 | catalog = auth[1]['serviceCatalog'] | 
|  | 104 | endpoints = [e for e in catalog | 
|  | 105 | if e['type'] == opt_section.catalog_type] | 
|  | 106 | if not endpoints: | 
|  | 107 | raise Exception("%s endpoint not found" % | 
|  | 108 | config.CONF.metric.catalog_type) | 
|  | 109 | return endpoints[0]['endpoints'][0][endpoint_type] | 
| Mehdi Abaakouk | 4946720 | 2016-04-12 11:45:21 +0200 | [diff] [blame] | 110 |  | 
|  | 111 | @staticmethod | 
|  | 112 | def test_fake(): | 
|  | 113 | # NOTE(sileht): A fake test is needed to have the class loaded | 
|  | 114 | # by the test runner | 
|  | 115 | pass |