blob: e9b5ba0f40c8090db4a32d3438319199e52baee0 [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()
27 for name in ["aodh_plugin", "gnocchi", "nova", "heat",
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")
53 os.environ["HEAT_SERVICE_URL"] = cls._get_endpoint_for(
54 auth, "orchestration")
55 os.environ["NOVA_SERVICE_URL"] = cls._get_endpoint_for(auth, "compute")
56 os.environ["GLANCE_SERVICE_URL"] = cls._get_endpoint_for(auth, "image")
Mehdi Abaakouk49467202016-04-12 11:45:21 +020057
58 @staticmethod
59 def clear_credentials():
60 # FIXME(sileht): We don't want the token to be invalided, but
61 # for some obcurs reason, clear_credentials is called before/during run
62 # So, make the one used by tearDropClass a dump, and call it manually
63 # in run()
64 pass
65
66 def run(self, result=None):
67 self.setUp()
Mehdi Abaakouk7a61c672017-01-09 15:17:31 +010068 os.environ["GLANCE_IMAGE_NAME"] = self.glance_image_create()
Mehdi Abaakouk49467202016-04-12 11:45:21 +020069 try:
70 self.tests.run(result)
71 finally:
72 super(TestAutoscalingGabbi, self).clear_credentials()
73 self.tearDown()
74
75 @staticmethod
76 def _get_endpoint_for(auth, service):
77 opt_section = getattr(config.CONF, service)
78 endpoint_type = opt_section.endpoint_type
Mehdi Abaakoukf79a0ae2016-12-15 16:44:30 +010079 is_keystone_v3 = 'catalog' in auth[1]
Mehdi Abaakouk49467202016-04-12 11:45:21 +020080
Mehdi Abaakoukf79a0ae2016-12-15 16:44:30 +010081 if is_keystone_v3:
82 if endpoint_type.endswith("URL"):
83 endpoint_type = endpoint_type[:-3]
84 catalog = auth[1]['catalog']
85 endpoints = [e['endpoints'] for e in catalog
86 if e['type'] == opt_section.catalog_type]
87 if not endpoints:
88 raise Exception("%s endpoint not found" %
89 config.CONF.metric.catalog_type)
90 endpoints = [e['url'] for e in endpoints[0]
91 if e['interface'] == endpoint_type]
92 if not endpoints:
93 raise Exception("%s interface not found for endpoint %s" %
94 (endpoint_type,
95 config.CONF.metric.catalog_type))
96 return endpoints[0]
97
98 else:
99 if not endpoint_type.endswith("URL"):
100 endpoint_type += "URL"
101 catalog = auth[1]['serviceCatalog']
102 endpoints = [e for e in catalog
103 if e['type'] == opt_section.catalog_type]
104 if not endpoints:
105 raise Exception("%s endpoint not found" %
106 config.CONF.metric.catalog_type)
107 return endpoints[0]['endpoints'][0][endpoint_type]
Mehdi Abaakouk49467202016-04-12 11:45:21 +0200108
109 @staticmethod
110 def test_fake():
111 # NOTE(sileht): A fake test is needed to have the class loaded
112 # by the test runner
113 pass