blob: 5239fb967cdd1e4cf60345be31c8751f1638296b [file] [log] [blame]
Ryota MIBUf0832d52015-12-10 15:32:13 +09001# 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 time
14
15from oslo_utils import timeutils
Ryota MIBUf0832d52015-12-10 15:32:13 +090016from tempest.common import compute
17from tempest.common.utils import data_utils
18from tempest import config
Ryota MIBU08ff8672015-12-10 15:54:38 +090019from tempest.lib import exceptions as lib_exc
Ryota MIBUf0832d52015-12-10 15:32:13 +090020import tempest.test
21
Ryota MIBU08ff8672015-12-10 15:54:38 +090022from ceilometer.tests.tempest.service import client
23
24
Ryota MIBUf0832d52015-12-10 15:32:13 +090025CONF = config.CONF
26
27
Ryota MIBU08ff8672015-12-10 15:54:38 +090028class ClientManager(client.Manager):
29
30 load_clients = [
31 'servers_client',
32 'compute_networks_client',
33 'compute_floating_ips_client',
34 'flavors_client',
Ryota MIBU08ff8672015-12-10 15:54:38 +090035 'image_client_v2',
36 'telemetry_client',
37 ]
38
39
Ryota MIBUf0832d52015-12-10 15:32:13 +090040class BaseTelemetryTest(tempest.test.BaseTestCase):
41
42 """Base test case class for all Telemetry API tests."""
43
44 credentials = ['primary']
Ryota MIBU08ff8672015-12-10 15:54:38 +090045 client_manager = ClientManager
Ryota MIBUf0832d52015-12-10 15:32:13 +090046
47 @classmethod
48 def skip_checks(cls):
49 super(BaseTelemetryTest, cls).skip_checks()
Mehdi Abaakoukbe636172017-01-09 13:45:19 +010050 if (not CONF.service_available.ceilometer or
51 not CONF.telemetry.deprecated_api_enabled):
52 raise cls.skipException("Ceilometer API support is required")
Ryota MIBUf0832d52015-12-10 15:32:13 +090053
54 @classmethod
55 def setup_credentials(cls):
56 cls.set_network_resources()
57 super(BaseTelemetryTest, cls).setup_credentials()
58
59 @classmethod
60 def setup_clients(cls):
61 super(BaseTelemetryTest, cls).setup_clients()
Ryota MIBU08ff8672015-12-10 15:54:38 +090062 cls.telemetry_client = cls.os_primary.telemetry_client
63 cls.servers_client = cls.os_primary.servers_client
64 cls.flavors_client = cls.os_primary.flavors_client
Ryota MIBU08ff8672015-12-10 15:54:38 +090065 cls.image_client_v2 = cls.os_primary.image_client_v2
Ryota MIBUf0832d52015-12-10 15:32:13 +090066
67 @classmethod
68 def resource_setup(cls):
69 super(BaseTelemetryTest, cls).resource_setup()
70 cls.nova_notifications = ['memory', 'vcpus', 'disk.root.size',
71 'disk.ephemeral.size']
72
Ryota MIBUf0832d52015-12-10 15:32:13 +090073 cls.glance_v2_notifications = ['image.download', 'image.serve']
74
75 cls.server_ids = []
76 cls.image_ids = []
77
78 @classmethod
79 def create_server(cls):
80 tenant_network = cls.get_tenant_network()
81 body, server = compute.create_test_server(
Ryota MIBU08ff8672015-12-10 15:54:38 +090082 cls.os_primary,
Ryota MIBUf0832d52015-12-10 15:32:13 +090083 tenant_network=tenant_network,
84 name=data_utils.rand_name('ceilometer-instance'),
85 wait_until='ACTIVE')
86 cls.server_ids.append(body['id'])
87 return body
88
89 @classmethod
Ryota MIBU08ff8672015-12-10 15:54:38 +090090 def create_image(cls, client, **kwargs):
91 body = client.create_image(name=data_utils.rand_name('image'),
92 container_format='bare',
93 disk_format='raw',
94 **kwargs)
Ryota MIBUf0832d52015-12-10 15:32:13 +090095 # TODO(jswarren) Move ['image'] up to initial body value assignment
96 # once both v1 and v2 glance clients include the full response
97 # object.
98 if 'image' in body:
99 body = body['image']
100 cls.image_ids.append(body['id'])
101 return body
102
103 @staticmethod
104 def cleanup_resources(method, list_of_ids):
105 for resource_id in list_of_ids:
106 try:
107 method(resource_id)
108 except lib_exc.NotFound:
109 pass
110
111 @classmethod
112 def resource_cleanup(cls):
113 cls.cleanup_resources(cls.servers_client.delete_server, cls.server_ids)
liushenge65b3912016-11-17 15:22:39 +0800114 cls.cleanup_resources(cls.image_client_v2.delete_image, cls.image_ids)
Ryota MIBUf0832d52015-12-10 15:32:13 +0900115 super(BaseTelemetryTest, cls).resource_cleanup()
116
117 def await_samples(self, metric, query):
118 """This method is to wait for sample to add it to database.
119
120 There are long time delays when using Postgresql (or Mysql)
121 database as ceilometer backend
122 """
123 timeout = CONF.compute.build_timeout
124 start = timeutils.utcnow()
125 while timeutils.delta_seconds(start, timeutils.utcnow()) < timeout:
126 body = self.telemetry_client.list_samples(metric, query)
127 if body:
128 return body
129 time.sleep(CONF.compute.build_interval)
130
Hanxi Liu3146cd92016-12-22 17:08:48 +0800131 raise lib_exc.TimeoutException(
Ryota MIBUf0832d52015-12-10 15:32:13 +0900132 'Sample for metric:%s with query:%s has not been added to the '
133 'database within %d seconds' % (metric, query,
134 CONF.compute.build_timeout))
135
136
137class BaseTelemetryAdminTest(BaseTelemetryTest):
138 """Base test case class for admin Telemetry API tests."""
139
140 credentials = ['primary', 'admin']
141
142 @classmethod
143 def setup_clients(cls):
144 super(BaseTelemetryAdminTest, cls).setup_clients()
145 cls.telemetry_admin_client = cls.os_adm.telemetry_client