blob: 6fe637f3dce737c322e43304c133b15bca7bd2c8 [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.v2 import images_client as \
30 img_cli_v2
Ken'ichi Ohmichie8598fa2016-06-06 14:35:28 +090031
Ryota MIBU08ff8672015-12-10 15:54:38 +090032
33CONF = config.CONF
34
35
36class TelemetryClient(rest_client.RestClient):
37
38 version = '2'
39 uri_prefix = "v2"
40
41 def deserialize(self, body):
42 return json.loads(body.replace("\n", ""))
43
44 def serialize(self, body):
45 return json.dumps(body)
46
47 def create_sample(self, meter_name, sample_list):
48 uri = "%s/meters/%s" % (self.uri_prefix, meter_name)
49 body = self.serialize(sample_list)
50 resp, body = self.post(uri, body)
51 self.expected_success(200, resp.status)
52 body = self.deserialize(body)
53 return rest_client.ResponseBody(resp, body)
54
55 def _helper_list(self, uri, query=None, period=None):
56 uri_dict = {}
57 if query:
58 uri_dict = {'q.field': query[0],
59 'q.op': query[1],
60 'q.value': query[2]}
61 if period:
62 uri_dict['period'] = period
63 if uri_dict:
64 uri += "?%s" % urllib.urlencode(uri_dict)
65 resp, body = self.get(uri)
66 self.expected_success(200, resp.status)
67 body = self.deserialize(body)
68 return rest_client.ResponseBodyList(resp, body)
69
70 def list_resources(self, query=None):
71 uri = '%s/resources' % self.uri_prefix
72 return self._helper_list(uri, query)
73
74 def list_meters(self, query=None):
75 uri = '%s/meters' % self.uri_prefix
76 return self._helper_list(uri, query)
77
78 def list_statistics(self, meter, period=None, query=None):
79 uri = "%s/meters/%s/statistics" % (self.uri_prefix, meter)
80 return self._helper_list(uri, query, period)
81
82 def list_samples(self, meter_id, query=None):
83 uri = '%s/meters/%s' % (self.uri_prefix, meter_id)
84 return self._helper_list(uri, query)
85
Ryota MIBU08ff8672015-12-10 15:54:38 +090086 def show_resource(self, resource_id):
87 uri = '%s/resources/%s' % (self.uri_prefix, resource_id)
88 resp, body = self.get(uri)
89 self.expected_success(200, resp.status)
90 body = self.deserialize(body)
91 return rest_client.ResponseBody(resp, body)
92
93
94class Manager(manager.Manager):
95
96 load_clients = [
97 'servers_client',
98 'compute_networks_client',
99 'compute_floating_ips_client',
100 'flavors_client',
Ryota MIBU08ff8672015-12-10 15:54:38 +0900101 'image_client_v2',
102 'telemetry_client',
103 'container_client',
104 'object_client',
105 ]
106
107 default_params = {
108 'disable_ssl_certificate_validation':
109 CONF.identity.disable_ssl_certificate_validation,
110 'ca_certs': CONF.identity.ca_certificates_file,
111 'trace_requests': CONF.debug.trace_requests
112 }
113
114 compute_params = {
115 'service': CONF.compute.catalog_type,
116 'region': CONF.compute.region or CONF.identity.region,
117 'endpoint_type': CONF.compute.endpoint_type,
118 'build_interval': CONF.compute.build_interval,
119 'build_timeout': CONF.compute.build_timeout,
120 }
121 compute_params.update(default_params)
122
123 image_params = {
124 'catalog_type': CONF.image.catalog_type,
125 'region': CONF.image.region or CONF.identity.region,
126 'endpoint_type': CONF.image.endpoint_type,
127 'build_interval': CONF.image.build_interval,
128 'build_timeout': CONF.image.build_timeout,
129 }
130 image_params.update(default_params)
131
132 telemetry_params = {
ghanshyam905e0812016-04-14 11:45:56 +0900133 'service': CONF.telemetry.catalog_type,
Ryota MIBU08ff8672015-12-10 15:54:38 +0900134 'region': CONF.identity.region,
ghanshyam905e0812016-04-14 11:45:56 +0900135 'endpoint_type': CONF.telemetry.endpoint_type,
Ryota MIBU08ff8672015-12-10 15:54:38 +0900136 }
137 telemetry_params.update(default_params)
138
139 object_storage_params = {
140 'service': CONF.object_storage.catalog_type,
141 'region': CONF.object_storage.region or CONF.identity.region,
142 'endpoint_type': CONF.object_storage.endpoint_type
143 }
144 object_storage_params.update(default_params)
145
146 def __init__(self, credentials=None, service=None):
147 super(Manager, self).__init__(credentials)
148 for client in self.load_clients:
149 getattr(self, 'set_%s' % client)()
150
151 def set_servers_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700152 self.servers_client = server_cli.ServersClient(
153 self.auth_provider,
154 **self.compute_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900155
156 def set_compute_networks_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700157 self.compute_networks_client = network_cli.NetworksClient(
158 self.auth_provider,
159 **self.compute_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900160
161 def set_compute_floating_ips_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700162 self.compute_floating_ips_client = floatingip_cli.FloatingIPsClient(
Ryota MIBU08ff8672015-12-10 15:54:38 +0900163 self.auth_provider,
164 **self.compute_params)
165
166 def set_flavors_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700167 self.flavors_client = flavor_cli.FlavorsClient(
168 self.auth_provider,
169 **self.compute_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900170
Ryota MIBU08ff8672015-12-10 15:54:38 +0900171 def set_image_client_v2(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700172 self.image_client_v2 = img_cli_v2.ImagesClient(
173 self.auth_provider,
174 **self.image_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900175
176 def set_telemetry_client(self):
177 self.telemetry_client = TelemetryClient(self.auth_provider,
178 **self.telemetry_params)
179
180 def set_container_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700181 self.container_client = container_cli.ContainerClient(
182 self.auth_provider,
183 **self.object_storage_params)
Ryota MIBU08ff8672015-12-10 15:54:38 +0900184
185 def set_object_client(self):
Nguyen Phuong Ana345c662016-08-25 14:40:16 +0700186 self.object_client = obj_cli.ObjectClient(
187 self.auth_provider,
188 **self.object_storage_params)