blob: 9da14494fe31306d7d9ea0a9e52512933c354096 [file] [log] [blame]
Mehdi Abaakouk49467202016-04-12 11:45:21 +02001# 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
13import os
14import unittest
15
16from gabbi import driver
17from tempest import config
Mehdi Abaakouk7a61c672017-01-09 15:17:31 +010018from tempest.scenario import manager
Mehdi Abaakouk49467202016-04-12 11:45:21 +020019
20
Mehdi Abaakouk7a61c672017-01-09 15:17:31 +010021class TestAutoscalingGabbi(manager.ScenarioTest):
22 credentials = ['admin', 'primary']
Mehdi Abaakouk49467202016-04-12 11:45:21 +020023
24 @classmethod
25 def skip_checks(cls):
26 super(TestAutoscalingGabbi, cls).skip_checks()
gord chung7014db62017-01-10 21:41:58 +000027 for name in ["aodh_plugin", "gnocchi", "nova", "heat", "panko",
Mehdi Abaakouk49467202016-04-12 11:45:21 +020028 "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 chung7014db62017-01-10 21:41:58 +000053 os.environ["PANKO_SERVICE_URL"] = cls._get_endpoint_for(
54 auth, "event")
Mehdi Abaakouk49467202016-04-12 11:45:21 +020055 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 Abaakouk49467202016-04-12 11:45:21 +020059
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 Abaakouk7a61c672017-01-09 15:17:31 +010070 os.environ["GLANCE_IMAGE_NAME"] = self.glance_image_create()
Mehdi Abaakouk49467202016-04-12 11:45:21 +020071 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 Abaakoukf79a0ae2016-12-15 16:44:30 +010081 is_keystone_v3 = 'catalog' in auth[1]
Mehdi Abaakouk49467202016-04-12 11:45:21 +020082
Mehdi Abaakoukf79a0ae2016-12-15 16:44:30 +010083 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 Abaakouk49467202016-04-12 11:45:21 +0200110
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