blob: 34bb33f21ee89b27fe7dd1bd2447a9447777f421 [file] [log] [blame]
Ryota MIBU08ff8672015-12-10 15:54:38 +09001# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from oslo_serialization import jsonutils as json
17from six.moves.urllib import parse as urllib
18
19from tempest import config
20from tempest.lib.common import rest_client
Nguyen Phuong Ana345c662016-08-25 14:40:16 +070021from tempest.lib.services.compute import flavors_client as flavor_cli
22from tempest.lib.services.compute import floating_ips_client as floatingip_cli
23from tempest.lib.services.compute import networks_client as network_cli
24from tempest.lib.services.compute import servers_client as server_cli
Ryota MIBU08ff8672015-12-10 15:54:38 +090025from tempest import manager
Nguyen Phuong Ana345c662016-08-25 14:40:16 +070026from tempest.services.object_storage import container_client as container_cli
27from tempest.services.object_storage import object_client as obj_cli
Ryota MIBU08ff8672015-12-10 15:54:38 +090028
Nguyen Phuong Ana345c662016-08-25 14:40:16 +070029from ceilometer.tests.tempest.service.images.v1 import images_client as \
30 img_cli_v1
31from ceilometer.tests.tempest.service.images.v2 import images_client as \
32 img_cli_v2
Ken'ichi Ohmichie8598fa2016-06-06 14:35:28 +090033
Ryota MIBU08ff8672015-12-10 15:54:38 +090034
35CONF = config.CONF
36
37
38class TelemetryClient(rest_client.RestClient):
39
40 version = '2'
41 uri_prefix = "v2"
42
43 def deserialize(self, body):
44 return json.loads(body.replace("\n", ""))
45
46 def serialize(self, body):
47 return json.dumps(body)
48
49 def create_sample(self, meter_name, sample_list):
50 uri = "%s/meters/%s" % (self.uri_prefix, meter_name)
51 body = self.serialize(sample_list)
52 resp, body = self.post(uri, body)
53 self.expected_success(200, resp.status)
54 body = self.deserialize(body)
55 return rest_client.ResponseBody(resp, body)
56
57 def _helper_list(self, uri, query=None, period=None):
58 uri_dict = {}
59 if query:
60 uri_dict = {'q.field': query[0],
61 'q.op': query[1],
62 'q.value': query[2]}
63 if period:
64 uri_dict['period'] = period
65 if uri_dict:
66 uri += "?%s" % urllib.urlencode(uri_dict)
67 resp, body = self.get(uri)
68 self.expected_success(200, resp.status)
69 body = self.deserialize(body)
70 return rest_client.ResponseBodyList(resp, body)
71
72 def list_resources(self, query=None):
73 uri = '%s/resources' % self.uri_prefix
74 return self._helper_list(uri, query)
75
76 def list_meters(self, query=None):
77 uri = '%s/meters' % self.uri_prefix
78 return self._helper_list(uri, query)
79
80 def list_statistics(self, meter, period=None, query=None):
81 uri = "%s/meters/%s/statistics" % (self.uri_prefix, meter)
82 return self._helper_list(uri, query, period)
83
84 def list_samples(self, meter_id, query=None):
85 uri = '%s/meters/%s' % (self.uri_prefix, meter_id)
86 return self._helper_list(uri, query)
87
88 def list_events(self, query=None):
89 uri = '%s/events' % self.uri_prefix
90 return self._helper_list(uri, query)
91
92 def show_resource(self, resource_id):
93 uri = '%s/resources/%s' % (self.uri_prefix, resource_id)
94 resp, body = self.get(uri)
95 self.expected_success(200, resp.status)
96 body = self.deserialize(body)
97 return rest_client.ResponseBody(resp, body)
98
99
100class Manager(manager.Manager):
101
102 load_clients = [
103 'servers_client',
104 'compute_networks_client',
105 'compute_floating_ips_client',
106 'flavors_client',
107 'image_client',
108 'image_client_v2',
109 'telemetry_client',
110 'container_client',
111 'object_client',
112 ]
113
114 default_params = {
115 'disable_ssl_certificate_validation':
116 CONF.identity.disable_ssl_certificate_validation,
117 'ca_certs': CONF.identity.ca_certificates_file,
118 'trace_requests': CONF.debug.trace_requests
119 }
120
121 compute_params = {
122 'service': CONF.compute.catalog_type,
123 'region': CONF.compute.region or CONF.identity.region,
124 'endpoint_type': CONF.compute.endpoint_type,
125 'build_interval': CONF.compute.build_interval,
126 'build_timeout': CONF.compute.build_timeout,
127 }
128 compute_params.update(default_params)
129
130 image_params = {
131 'catalog_type': CONF.image.catalog_type,
132 'region': CONF.image.region or CONF.identity.region,
133 'endpoint_type': CONF.image.endpoint_type,
134 'build_interval': CONF.image.build_interval,
135 'build_timeout': CONF.image.build_timeout,
136 }
137 image_params.update(default_params)
138
139 telemetry_params = {
ghanshyam905e0812016-04-14 11:45:56 +0900140 'service': CONF.telemetry.catalog_type,
Ryota MIBU08ff8672015-12-10 15:54:38 +0900141 'region': CONF.identity.region,
ghanshyam905e0812016-04-14 11:45:56 +0900142 'endpoint_type': CONF.telemetry.endpoint_type,
Ryota MIBU08ff8672015-12-10 15:54:38 +0900143 }
144 telemetry_params.update(default_params)
145
146 object_storage_params = {
147 'service': CONF.object_storage.catalog_type,
148 'region': CONF.object_storage.region or CONF.identity.region,
149 'endpoint_type': CONF.object_storage.endpoint_type
150 }
151 object_storage_params.update(default_params)
152
153 def __init__(self, credentials=None, service=None):
154 super(Manager, self).__init__(credentials)
155 for client in self.load_clients:
156 getattr(self, 'set_%s' % client)()
157
158 def set_servers_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700159 self.servers_client = server_cli.ServersClient(
160 self.auth_provider,
161 **self.compute_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900162
163 def set_compute_networks_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700164 self.compute_networks_client = network_cli.NetworksClient(
165 self.auth_provider,
166 **self.compute_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900167
168 def set_compute_floating_ips_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700169 self.compute_floating_ips_client = floatingip_cli.FloatingIPsClient(
Ryota MIBU08ff8672015-12-10 15:54:38 +0900170 self.auth_provider,
171 **self.compute_params)
172
173 def set_flavors_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700174 self.flavors_client = flavor_cli.FlavorsClient(
175 self.auth_provider,
176 **self.compute_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900177
178 def set_image_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700179 self.image_client = img_cli_v1.ImagesClient(
180 self.auth_provider,
181 **self.image_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900182
183 def set_image_client_v2(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700184 self.image_client_v2 = img_cli_v2.ImagesClient(
185 self.auth_provider,
186 **self.image_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900187
188 def set_telemetry_client(self):
189 self.telemetry_client = TelemetryClient(self.auth_provider,
190 **self.telemetry_params)
191
192 def set_container_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700193 self.container_client = container_cli.ContainerClient(
194 self.auth_provider,
195 **self.object_storage_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900196
197 def set_object_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700198 self.object_client = obj_cli.ObjectClient(
199 self.auth_provider,
200 **self.object_storage_params)