blob: 38cc153ce957889c0427e42e3b616e7c78cf2cf9 [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 Abaakouk25812742017-03-01 07:44:41 +010018
19from ceilometer.tests.tempest.scenario import manager
Mehdi Abaakouk49467202016-04-12 11:45:21 +020020
21
Mehdi Abaakouk7a61c672017-01-09 15:17:31 +010022class TestAutoscalingGabbi(manager.ScenarioTest):
23 credentials = ['admin', 'primary']
Mehdi Abaakouk49467202016-04-12 11:45:21 +020024
25 @classmethod
26 def skip_checks(cls):
27 super(TestAutoscalingGabbi, cls).skip_checks()
gord chung7014db62017-01-10 21:41:58 +000028 for name in ["aodh_plugin", "gnocchi", "nova", "heat", "panko",
Mehdi Abaakouk49467202016-04-12 11:45:21 +020029 "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 chung7014db62017-01-10 21:41:58 +000054 os.environ["PANKO_SERVICE_URL"] = cls._get_endpoint_for(
55 auth, "event")
Mehdi Abaakouk49467202016-04-12 11:45:21 +020056 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 Abaakouk49467202016-04-12 11:45:21 +020060
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 Abaakouk7a61c672017-01-09 15:17:31 +010071 os.environ["GLANCE_IMAGE_NAME"] = self.glance_image_create()
Mehdi Abaakouk49467202016-04-12 11:45:21 +020072 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 Abaakoukf79a0ae2016-12-15 16:44:30 +010082 is_keystone_v3 = 'catalog' in auth[1]
Mehdi Abaakouk49467202016-04-12 11:45:21 +020083
Mehdi Abaakoukf79a0ae2016-12-15 16:44:30 +010084 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 Abaakouk49467202016-04-12 11:45:21 +0200111
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