Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 1 | # 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 | |
| 16 | from oslo_serialization import jsonutils as json |
| 17 | from six.moves.urllib import parse as urllib |
| 18 | |
| 19 | from tempest import config |
| 20 | from tempest.lib.common import rest_client |
Nguyen Phuong An | a345c66 | 2016-08-25 14:40:16 +0700 | [diff] [blame] | 21 | from tempest.lib.services.compute import flavors_client as flavor_cli |
| 22 | from tempest.lib.services.compute import floating_ips_client as floatingip_cli |
| 23 | from tempest.lib.services.compute import networks_client as network_cli |
| 24 | from tempest.lib.services.compute import servers_client as server_cli |
Ken'ichi Ohmichi | 6f2d75f | 2017-01-27 15:19:57 -0800 | [diff] [blame] | 25 | from tempest.lib.services.image.v2 import images_client as img_cli_v2 |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 26 | from tempest import manager |
Nguyen Phuong An | a345c66 | 2016-08-25 14:40:16 +0700 | [diff] [blame] | 27 | from tempest.services.object_storage import container_client as container_cli |
| 28 | from tempest.services.object_storage import object_client as obj_cli |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 29 | |
| 30 | |
| 31 | CONF = config.CONF |
| 32 | |
| 33 | |
| 34 | class 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 MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 84 | 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 | |
| 92 | class Manager(manager.Manager): |
| 93 | |
| 94 | load_clients = [ |
| 95 | 'servers_client', |
| 96 | 'compute_networks_client', |
| 97 | 'compute_floating_ips_client', |
| 98 | 'flavors_client', |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 99 | '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 Ohmichi | 6f2d75f | 2017-01-27 15:19:57 -0800 | [diff] [blame] | 122 | 'service': CONF.image.catalog_type, |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 123 | '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 = { |
ghanshyam | 905e081 | 2016-04-14 11:45:56 +0900 | [diff] [blame] | 131 | 'service': CONF.telemetry.catalog_type, |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 132 | 'region': CONF.identity.region, |
ghanshyam | 905e081 | 2016-04-14 11:45:56 +0900 | [diff] [blame] | 133 | 'endpoint_type': CONF.telemetry.endpoint_type, |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 134 | } |
| 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 An | a345c66 | 2016-08-25 14:40:16 +0700 | [diff] [blame] | 150 | self.servers_client = server_cli.ServersClient( |
| 151 | self.auth_provider, |
| 152 | **self.compute_params) |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 153 | |
| 154 | def set_compute_networks_client(self): |
Nguyen Phuong An | a345c66 | 2016-08-25 14:40:16 +0700 | [diff] [blame] | 155 | self.compute_networks_client = network_cli.NetworksClient( |
| 156 | self.auth_provider, |
| 157 | **self.compute_params) |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 158 | |
| 159 | def set_compute_floating_ips_client(self): |
Nguyen Phuong An | a345c66 | 2016-08-25 14:40:16 +0700 | [diff] [blame] | 160 | self.compute_floating_ips_client = floatingip_cli.FloatingIPsClient( |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 161 | self.auth_provider, |
| 162 | **self.compute_params) |
| 163 | |
| 164 | def set_flavors_client(self): |
Nguyen Phuong An | a345c66 | 2016-08-25 14:40:16 +0700 | [diff] [blame] | 165 | self.flavors_client = flavor_cli.FlavorsClient( |
| 166 | self.auth_provider, |
| 167 | **self.compute_params) |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 168 | |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 169 | def set_image_client_v2(self): |
Nguyen Phuong An | a345c66 | 2016-08-25 14:40:16 +0700 | [diff] [blame] | 170 | self.image_client_v2 = img_cli_v2.ImagesClient( |
| 171 | self.auth_provider, |
| 172 | **self.image_params) |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 173 | |
| 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 An | a345c66 | 2016-08-25 14:40:16 +0700 | [diff] [blame] | 179 | self.container_client = container_cli.ContainerClient( |
| 180 | self.auth_provider, |
| 181 | **self.object_storage_params) |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 182 | |
| 183 | def set_object_client(self): |
Nguyen Phuong An | a345c66 | 2016-08-25 14:40:16 +0700 | [diff] [blame] | 184 | self.object_client = obj_cli.ObjectClient( |
| 185 | self.auth_provider, |
| 186 | **self.object_storage_params) |