blob: bed56c38ed73304285a15a1484705a01d5e3566a [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
18from tempest import test
19
20from ceilometer.tests.tempest.service import client
21
22
23class ClientManager(client.Manager):
24 load_clients = [
25 'image_client_v2',
26 ]
27
28
29class TestAutoscalingGabbi(test.BaseTestCase):
30 credentials = ['admin']
31 client_manager = ClientManager
32
33 @classmethod
34 def skip_checks(cls):
35 super(TestAutoscalingGabbi, cls).skip_checks()
36 for name in ["aodh_plugin", "gnocchi", "nova", "heat",
37 "ceilometer", "glance"]:
38 cls._check_service(name)
39
40 @classmethod
41 def _check_service(cls, name):
42 if not getattr(config.CONF.service_available, name, False):
43 raise cls.skipException("%s support is required" %
44 name.capitalize())
45
46 @classmethod
47 def resource_setup(cls):
48 super(TestAutoscalingGabbi, cls).resource_setup()
49 test_dir = os.path.join(os.path.dirname(__file__), '..', '..',
50 'integration', 'gabbi', 'gabbits-live')
51 cls.tests = driver.build_tests(
52 test_dir, unittest.TestLoader(),
53 host='localhost', port='13245',
54 test_loader_name='tempest.scenario.telemetry-autoscaling.test')
55
56 auth = cls.os_admin.auth_provider.get_auth()
57 os.environ["ADMIN_TOKEN"] = auth[0]
58 os.environ["AODH_SERVICE_URL"] = cls._get_endpoint_for(
59 auth, "alarming_plugin")
60 os.environ["GNOCCHI_SERVICE_URL"] = cls._get_endpoint_for(
61 auth, "metric")
62 os.environ["HEAT_SERVICE_URL"] = cls._get_endpoint_for(
63 auth, "orchestration")
64 os.environ["NOVA_SERVICE_URL"] = cls._get_endpoint_for(auth, "compute")
65 os.environ["GLANCE_SERVICE_URL"] = cls._get_endpoint_for(auth, "image")
66 images = cls.os_admin.image_client_v2.list_images()["images"]
67 for img in images:
68 name = img["name"]
Mehdi Abaakoukd48779e2017-01-03 17:05:53 +010069 # devstack or tempest format
70 if ((name.startswith("cirros") and name.endswith("-uec")) or
71 name == 'scenario-img'):
Mehdi Abaakouk49467202016-04-12 11:45:21 +020072 os.environ["GLANCE_IMAGE_NAME"] = name
73 break
Mehdi Abaakoukd48779e2017-01-03 17:05:53 +010074
Mehdi Abaakouk49467202016-04-12 11:45:21 +020075 else:
Mehdi Abaakoukd48779e2017-01-03 17:05:53 +010076 cls.skipException("A cirros-.*-uec/cirros image is required")
Mehdi Abaakouk49467202016-04-12 11:45:21 +020077
78 @staticmethod
79 def clear_credentials():
80 # FIXME(sileht): We don't want the token to be invalided, but
81 # for some obcurs reason, clear_credentials is called before/during run
82 # So, make the one used by tearDropClass a dump, and call it manually
83 # in run()
84 pass
85
86 def run(self, result=None):
87 self.setUp()
88 try:
89 self.tests.run(result)
90 finally:
91 super(TestAutoscalingGabbi, self).clear_credentials()
92 self.tearDown()
93
94 @staticmethod
95 def _get_endpoint_for(auth, service):
96 opt_section = getattr(config.CONF, service)
97 endpoint_type = opt_section.endpoint_type
Mehdi Abaakoukf79a0ae2016-12-15 16:44:30 +010098 is_keystone_v3 = 'catalog' in auth[1]
Mehdi Abaakouk49467202016-04-12 11:45:21 +020099
Mehdi Abaakoukf79a0ae2016-12-15 16:44:30 +0100100 if is_keystone_v3:
101 if endpoint_type.endswith("URL"):
102 endpoint_type = endpoint_type[:-3]
103 catalog = auth[1]['catalog']
104 endpoints = [e['endpoints'] 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 endpoints = [e['url'] for e in endpoints[0]
110 if e['interface'] == endpoint_type]
111 if not endpoints:
112 raise Exception("%s interface not found for endpoint %s" %
113 (endpoint_type,
114 config.CONF.metric.catalog_type))
115 return endpoints[0]
116
117 else:
118 if not endpoint_type.endswith("URL"):
119 endpoint_type += "URL"
120 catalog = auth[1]['serviceCatalog']
121 endpoints = [e for e in catalog
122 if e['type'] == opt_section.catalog_type]
123 if not endpoints:
124 raise Exception("%s endpoint not found" %
125 config.CONF.metric.catalog_type)
126 return endpoints[0]['endpoints'][0][endpoint_type]
Mehdi Abaakouk49467202016-04-12 11:45:21 +0200127
128 @staticmethod
129 def test_fake():
130 # NOTE(sileht): A fake test is needed to have the class loaded
131 # by the test runner
132 pass