blob: 332b4503b513ee99e340a764104e34c61c096a2e [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
Ken'ichi Ohmichi6f2d75f2017-01-27 15:19:57 -080025from tempest.lib.services.image.v2 import images_client as img_cli_v2
Ryota MIBU08ff8672015-12-10 15:54:38 +090026from tempest import manager
Nguyen Phuong Ana345c662016-08-25 14:40:16 +070027from tempest.services.object_storage import container_client as container_cli
28from tempest.services.object_storage import object_client as obj_cli
Ryota MIBU08ff8672015-12-10 15:54:38 +090029
30
31CONF = config.CONF
32
33
34class TelemetryClient(rest_client.RestClient):
35
36 version = '2'
37 uri_prefix = "v2"
38
39 def deserialize(self, body):
40 return json.loads(body.replace("\n", ""))
41
42 def serialize(self, body):
43 return json.dumps(body)
44
45 def create_sample(self, meter_name, sample_list):
46 uri = "%s/meters/%s" % (self.uri_prefix, meter_name)
47 body = self.serialize(sample_list)
48 resp, body = self.post(uri, body)
49 self.expected_success(200, resp.status)
50 body = self.deserialize(body)
51 return rest_client.ResponseBody(resp, body)
52
53 def _helper_list(self, uri, query=None, period=None):
54 uri_dict = {}
55 if query:
56 uri_dict = {'q.field': query[0],
57 'q.op': query[1],
58 'q.value': query[2]}
59 if period:
60 uri_dict['period'] = period
61 if uri_dict:
62 uri += "?%s" % urllib.urlencode(uri_dict)
63 resp, body = self.get(uri)
64 self.expected_success(200, resp.status)
65 body = self.deserialize(body)
66 return rest_client.ResponseBodyList(resp, body)
67
68 def list_resources(self, query=None):
69 uri = '%s/resources' % self.uri_prefix
70 return self._helper_list(uri, query)
71
72 def list_meters(self, query=None):
73 uri = '%s/meters' % self.uri_prefix
74 return self._helper_list(uri, query)
75
76 def list_statistics(self, meter, period=None, query=None):
77 uri = "%s/meters/%s/statistics" % (self.uri_prefix, meter)
78 return self._helper_list(uri, query, period)
79
80 def list_samples(self, meter_id, query=None):
81 uri = '%s/meters/%s' % (self.uri_prefix, meter_id)
82 return self._helper_list(uri, query)
83
Ryota MIBU08ff8672015-12-10 15:54:38 +090084 def show_resource(self, resource_id):
85 uri = '%s/resources/%s' % (self.uri_prefix, resource_id)
86 resp, body = self.get(uri)
87 self.expected_success(200, resp.status)
88 body = self.deserialize(body)
89 return rest_client.ResponseBody(resp, body)
90
91
92class Manager(manager.Manager):
93
94 load_clients = [
95 'servers_client',
96 'compute_networks_client',
97 'compute_floating_ips_client',
98 'flavors_client',
Ryota MIBU08ff8672015-12-10 15:54:38 +090099 'image_client_v2',
100 'telemetry_client',
101 'container_client',
102 'object_client',
103 ]
104
105 default_params = {
106 'disable_ssl_certificate_validation':
107 CONF.identity.disable_ssl_certificate_validation,
108 'ca_certs': CONF.identity.ca_certificates_file,
109 'trace_requests': CONF.debug.trace_requests
110 }
111
112 compute_params = {
113 'service': CONF.compute.catalog_type,
114 'region': CONF.compute.region or CONF.identity.region,
115 'endpoint_type': CONF.compute.endpoint_type,
116 'build_interval': CONF.compute.build_interval,
117 'build_timeout': CONF.compute.build_timeout,
118 }
119 compute_params.update(default_params)
120
121 image_params = {
Ken'ichi Ohmichi6f2d75f2017-01-27 15:19:57 -0800122 'service': CONF.image.catalog_type,
Ryota MIBU08ff8672015-12-10 15:54:38 +0900123 'region': CONF.image.region or CONF.identity.region,
124 'endpoint_type': CONF.image.endpoint_type,
125 'build_interval': CONF.image.build_interval,
126 'build_timeout': CONF.image.build_timeout,
127 }
128 image_params.update(default_params)
129
130 telemetry_params = {
ghanshyam905e0812016-04-14 11:45:56 +0900131 'service': CONF.telemetry.catalog_type,
Ryota MIBU08ff8672015-12-10 15:54:38 +0900132 'region': CONF.identity.region,
ghanshyam905e0812016-04-14 11:45:56 +0900133 'endpoint_type': CONF.telemetry.endpoint_type,
Ryota MIBU08ff8672015-12-10 15:54:38 +0900134 }
135 telemetry_params.update(default_params)
136
137 object_storage_params = {
138 'service': CONF.object_storage.catalog_type,
139 'region': CONF.object_storage.region or CONF.identity.region,
140 'endpoint_type': CONF.object_storage.endpoint_type
141 }
142 object_storage_params.update(default_params)
143
144 def __init__(self, credentials=None, service=None):
145 super(Manager, self).__init__(credentials)
146 for client in self.load_clients:
147 getattr(self, 'set_%s' % client)()
148
149 def set_servers_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700150 self.servers_client = server_cli.ServersClient(
151 self.auth_provider,
152 **self.compute_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900153
154 def set_compute_networks_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700155 self.compute_networks_client = network_cli.NetworksClient(
156 self.auth_provider,
157 **self.compute_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900158
159 def set_compute_floating_ips_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700160 self.compute_floating_ips_client = floatingip_cli.FloatingIPsClient(
Ryota MIBU08ff8672015-12-10 15:54:38 +0900161 self.auth_provider,
162 **self.compute_params)
163
164 def set_flavors_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700165 self.flavors_client = flavor_cli.FlavorsClient(
166 self.auth_provider,
167 **self.compute_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900168
Ryota MIBU08ff8672015-12-10 15:54:38 +0900169 def set_image_client_v2(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700170 self.image_client_v2 = img_cli_v2.ImagesClient(
171 self.auth_provider,
172 **self.image_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900173
174 def set_telemetry_client(self):
175 self.telemetry_client = TelemetryClient(self.auth_provider,
176 **self.telemetry_params)
177
178 def set_container_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700179 self.container_client = container_cli.ContainerClient(
180 self.auth_provider,
181 **self.object_storage_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900182
183 def set_object_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700184 self.object_client = obj_cli.ObjectClient(
185 self.auth_provider,
186 **self.object_storage_params)