blob: d97411c47b989182df7460466865d37c6833d56c [file] [log] [blame]
Ken'ichi Ohmichi42662682015-01-05 05:00:04 +00001# (c) 2014 Deutsche Telekom AG
2# Copyright 2014 Red Hat, Inc.
3# Copyright 2014 NEC Corporation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Joseph Lanoux9b597672015-01-21 16:38:08 +000018from tempest.common import service_client
Ken'ichi Ohmichi42662682015-01-05 05:00:04 +000019from tempest import config
20
21CONF = config.CONF
22
23
Joseph Lanoux9b597672015-01-21 16:38:08 +000024class NegativeRestClient(service_client.ServiceClient):
Ken'ichi Ohmichicb67d2d2015-11-19 08:23:22 +000025 """Version of RestClient that does not raise exceptions."""
David Kranz1e33e372015-03-20 09:42:56 -040026 def __init__(self, auth_provider, service,
27 build_interval=None, build_timeout=None,
28 disable_ssl_certificate_validation=None,
29 ca_certs=None, trace_requests=None):
30 region, endpoint_type = self._get_region_and_endpoint_type(service)
31 super(NegativeRestClient, self).__init__(
32 auth_provider,
33 service,
34 region,
35 endpoint_type=endpoint_type,
36 build_interval=build_interval,
37 build_timeout=build_timeout,
38 disable_ssl_certificate_validation=(
39 disable_ssl_certificate_validation),
40 ca_certs=ca_certs,
41 trace_requests=trace_requests)
Ken'ichi Ohmichi42662682015-01-05 05:00:04 +000042
David Kranz1e33e372015-03-20 09:42:56 -040043 def _get_region_and_endpoint_type(self, service):
Ken'ichi Ohmichicb67d2d2015-11-19 08:23:22 +000044 """Returns the region for a specific service"""
Ken'ichi Ohmichi42662682015-01-05 05:00:04 +000045 service_region = None
David Kranz1e33e372015-03-20 09:42:56 -040046 service_endpoint_type = None
Ken'ichi Ohmichi42662682015-01-05 05:00:04 +000047 for cfgname in dir(CONF._config):
48 # Find all config.FOO.catalog_type and assume FOO is a service.
49 cfg = getattr(CONF, cfgname)
50 catalog_type = getattr(cfg, 'catalog_type', None)
51 if catalog_type == service:
52 service_region = getattr(cfg, 'region', None)
David Kranz1e33e372015-03-20 09:42:56 -040053 service_endpoint_type = getattr(cfg, 'endpoint_type', None)
Ken'ichi Ohmichi42662682015-01-05 05:00:04 +000054 if not service_region:
55 service_region = CONF.identity.region
David Kranz1e33e372015-03-20 09:42:56 -040056 return service_region, service_endpoint_type
Ken'ichi Ohmichi42662682015-01-05 05:00:04 +000057
58 def _error_checker(self, method, url,
59 headers, body, resp, resp_body):
60 pass
61
62 def send_request(self, method, url_template, resources, body=None):
63 url = url_template % tuple(resources)
64 if method == "GET":
65 resp, body = self.get(url)
66 elif method == "POST":
67 resp, body = self.post(url, body)
68 elif method == "PUT":
69 resp, body = self.put(url, body)
70 elif method == "PATCH":
71 resp, body = self.patch(url, body)
72 elif method == "HEAD":
73 resp, body = self.head(url)
74 elif method == "DELETE":
75 resp, body = self.delete(url)
76 elif method == "COPY":
77 resp, body = self.copy(url)
78 else:
79 assert False
80
81 return resp, body