blob: f6093631c484b07b27193ef2d99f5ea0c9d610a0 [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"]
69 if name.startswith("cirros") and name.endswith("-uec"):
70 os.environ["GLANCE_IMAGE_NAME"] = name
71 break
72 else:
73 cls.skipException("A cirros-.*-uec image is required")
74
75 @staticmethod
76 def clear_credentials():
77 # FIXME(sileht): We don't want the token to be invalided, but
78 # for some obcurs reason, clear_credentials is called before/during run
79 # So, make the one used by tearDropClass a dump, and call it manually
80 # in run()
81 pass
82
83 def run(self, result=None):
84 self.setUp()
85 try:
86 self.tests.run(result)
87 finally:
88 super(TestAutoscalingGabbi, self).clear_credentials()
89 self.tearDown()
90
91 @staticmethod
92 def _get_endpoint_for(auth, service):
93 opt_section = getattr(config.CONF, service)
94 endpoint_type = opt_section.endpoint_type
95 if not endpoint_type.endswith("URL"):
96 endpoint_type += "URL"
97
98 endpoints = [e for e in auth[1]['serviceCatalog']
99 if e['type'] == opt_section.catalog_type]
100 if not endpoints:
101 raise Exception("%s endpoint not found" %
102 config.CONF.metric.catalog_type)
103 return endpoints[0]['endpoints'][0][endpoint_type]
104
105 @staticmethod
106 def test_fake():
107 # NOTE(sileht): A fake test is needed to have the class loaded
108 # by the test runner
109 pass