blob: 179f8a1ab4e8968b4001e8128c2981ca032d64cd [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
Ryota MIBU08ff8672015-12-10 15:54:38 +090026from tempest.services.object_storage.container_client import ContainerClient
27from tempest.services.object_storage.object_client import ObjectClient
28
Ken'ichi Ohmichie8598fa2016-06-06 14:35:28 +090029from ceilometer.tests.tempest.service.images.v1.images_client import \
30 ImagesClient
31from ceilometer.tests.tempest.service.images.v2.images_client import \
32 ImagesClient as ImagesClientV2
33
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):
159 self.servers_client = ServersClient(self.auth_provider,
160 **self.compute_params)
161
162 def set_compute_networks_client(self):
163 self.compute_networks_client = NetworksClient(self.auth_provider,
164 **self.compute_params)
165
166 def set_compute_floating_ips_client(self):
167 self.compute_floating_ips_client = FloatingIPsClient(
168 self.auth_provider,
169 **self.compute_params)
170
171 def set_flavors_client(self):
172 self.flavors_client = FlavorsClient(self.auth_provider,
173 **self.compute_params)
174
175 def set_image_client(self):
176 self.image_client = ImagesClient(self.auth_provider,
177 **self.image_params)
178
179 def set_image_client_v2(self):
180 self.image_client_v2 = ImagesClientV2(self.auth_provider,
181 **self.image_params)
182
183 def set_telemetry_client(self):
184 self.telemetry_client = TelemetryClient(self.auth_provider,
185 **self.telemetry_params)
186
187 def set_container_client(self):
188 self.container_client = ContainerClient(self.auth_provider,
189 **self.object_storage_params)
190
191 def set_object_client(self):
192 self.object_client = ObjectClient(self.auth_provider,
193 **self.object_storage_params)