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