blob: 9b0d34b8f1fc0668e22b4a116cfe5a5b3ae05fc6 [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
21from tempest.lib.services.compute.flavors_client import FlavorsClient
22from tempest.lib.services.compute.floating_ips_client import FloatingIPsClient
23from tempest.lib.services.compute.networks_client import NetworksClient
24from tempest.lib.services.compute.servers_client import ServersClient
25from tempest import manager
26from tempest.services.image.v1.json.images_client import ImagesClient
27from tempest.services.image.v2.json.images_client import ImagesClientV2
28from tempest.services.object_storage.container_client import ContainerClient
29from tempest.services.object_storage.object_client import ObjectClient
30
31
32CONF = config.CONF
33
34
35class TelemetryClient(rest_client.RestClient):
36
37 version = '2'
38 uri_prefix = "v2"
39
40 def deserialize(self, body):
41 return json.loads(body.replace("\n", ""))
42
43 def serialize(self, body):
44 return json.dumps(body)
45
46 def create_sample(self, meter_name, sample_list):
47 uri = "%s/meters/%s" % (self.uri_prefix, meter_name)
48 body = self.serialize(sample_list)
49 resp, body = self.post(uri, body)
50 self.expected_success(200, resp.status)
51 body = self.deserialize(body)
52 return rest_client.ResponseBody(resp, body)
53
54 def _helper_list(self, uri, query=None, period=None):
55 uri_dict = {}
56 if query:
57 uri_dict = {'q.field': query[0],
58 'q.op': query[1],
59 'q.value': query[2]}
60 if period:
61 uri_dict['period'] = period
62 if uri_dict:
63 uri += "?%s" % urllib.urlencode(uri_dict)
64 resp, body = self.get(uri)
65 self.expected_success(200, resp.status)
66 body = self.deserialize(body)
67 return rest_client.ResponseBodyList(resp, body)
68
69 def list_resources(self, query=None):
70 uri = '%s/resources' % self.uri_prefix
71 return self._helper_list(uri, query)
72
73 def list_meters(self, query=None):
74 uri = '%s/meters' % self.uri_prefix
75 return self._helper_list(uri, query)
76
77 def list_statistics(self, meter, period=None, query=None):
78 uri = "%s/meters/%s/statistics" % (self.uri_prefix, meter)
79 return self._helper_list(uri, query, period)
80
81 def list_samples(self, meter_id, query=None):
82 uri = '%s/meters/%s' % (self.uri_prefix, meter_id)
83 return self._helper_list(uri, query)
84
85 def list_events(self, query=None):
86 uri = '%s/events' % self.uri_prefix
87 return self._helper_list(uri, query)
88
89 def show_resource(self, resource_id):
90 uri = '%s/resources/%s' % (self.uri_prefix, resource_id)
91 resp, body = self.get(uri)
92 self.expected_success(200, resp.status)
93 body = self.deserialize(body)
94 return rest_client.ResponseBody(resp, body)
95
96
97class Manager(manager.Manager):
98
99 load_clients = [
100 'servers_client',
101 'compute_networks_client',
102 'compute_floating_ips_client',
103 'flavors_client',
104 'image_client',
105 'image_client_v2',
106 'telemetry_client',
107 'container_client',
108 'object_client',
109 ]
110
111 default_params = {
112 'disable_ssl_certificate_validation':
113 CONF.identity.disable_ssl_certificate_validation,
114 'ca_certs': CONF.identity.ca_certificates_file,
115 'trace_requests': CONF.debug.trace_requests
116 }
117
118 compute_params = {
119 'service': CONF.compute.catalog_type,
120 'region': CONF.compute.region or CONF.identity.region,
121 'endpoint_type': CONF.compute.endpoint_type,
122 'build_interval': CONF.compute.build_interval,
123 'build_timeout': CONF.compute.build_timeout,
124 }
125 compute_params.update(default_params)
126
127 image_params = {
128 'catalog_type': CONF.image.catalog_type,
129 'region': CONF.image.region or CONF.identity.region,
130 'endpoint_type': CONF.image.endpoint_type,
131 'build_interval': CONF.image.build_interval,
132 'build_timeout': CONF.image.build_timeout,
133 }
134 image_params.update(default_params)
135
136 telemetry_params = {
ghanshyam905e0812016-04-14 11:45:56 +0900137 'service': CONF.telemetry.catalog_type,
Ryota MIBU08ff8672015-12-10 15:54:38 +0900138 'region': CONF.identity.region,
ghanshyam905e0812016-04-14 11:45:56 +0900139 'endpoint_type': CONF.telemetry.endpoint_type,
Ryota MIBU08ff8672015-12-10 15:54:38 +0900140 }
141 telemetry_params.update(default_params)
142
143 object_storage_params = {
144 'service': CONF.object_storage.catalog_type,
145 'region': CONF.object_storage.region or CONF.identity.region,
146 'endpoint_type': CONF.object_storage.endpoint_type
147 }
148 object_storage_params.update(default_params)
149
150 def __init__(self, credentials=None, service=None):
151 super(Manager, self).__init__(credentials)
152 for client in self.load_clients:
153 getattr(self, 'set_%s' % client)()
154
155 def set_servers_client(self):
156 self.servers_client = ServersClient(self.auth_provider,
157 **self.compute_params)
158
159 def set_compute_networks_client(self):
160 self.compute_networks_client = NetworksClient(self.auth_provider,
161 **self.compute_params)
162
163 def set_compute_floating_ips_client(self):
164 self.compute_floating_ips_client = FloatingIPsClient(
165 self.auth_provider,
166 **self.compute_params)
167
168 def set_flavors_client(self):
169 self.flavors_client = FlavorsClient(self.auth_provider,
170 **self.compute_params)
171
172 def set_image_client(self):
173 self.image_client = ImagesClient(self.auth_provider,
174 **self.image_params)
175
176 def set_image_client_v2(self):
177 self.image_client_v2 = ImagesClientV2(self.auth_provider,
178 **self.image_params)
179
180 def set_telemetry_client(self):
181 self.telemetry_client = TelemetryClient(self.auth_provider,
182 **self.telemetry_params)
183
184 def set_container_client(self):
185 self.container_client = ContainerClient(self.auth_provider,
186 **self.object_storage_params)
187
188 def set_object_client(self):
189 self.object_client = ObjectClient(self.auth_provider,
190 **self.object_storage_params)