blob: a9ae1c3ec6054a47d60dd20a64b426477ad84e2c [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
18from tempest.common import rest_client
19from tempest import config
20
21CONF = config.CONF
22
23
24class NegativeRestClient(rest_client.RestClient):
25 """
26 Version of RestClient that does not raise exceptions.
27 """
28
29 def __init__(self, auth_provider, service):
30 region = self._get_region(service)
31 super(NegativeRestClient, self).__init__(auth_provider,
32 service, region)
33
34 def _get_region(self, service):
35 """
36 Returns the region for a specific service
37 """
38 service_region = None
39 for cfgname in dir(CONF._config):
40 # Find all config.FOO.catalog_type and assume FOO is a service.
41 cfg = getattr(CONF, cfgname)
42 catalog_type = getattr(cfg, 'catalog_type', None)
43 if catalog_type == service:
44 service_region = getattr(cfg, 'region', None)
45 if not service_region:
46 service_region = CONF.identity.region
47 return service_region
48
49 def _error_checker(self, method, url,
50 headers, body, resp, resp_body):
51 pass
52
53 def send_request(self, method, url_template, resources, body=None):
54 url = url_template % tuple(resources)
55 if method == "GET":
56 resp, body = self.get(url)
57 elif method == "POST":
58 resp, body = self.post(url, body)
59 elif method == "PUT":
60 resp, body = self.put(url, body)
61 elif method == "PATCH":
62 resp, body = self.patch(url, body)
63 elif method == "HEAD":
64 resp, body = self.head(url)
65 elif method == "DELETE":
66 resp, body = self.delete(url)
67 elif method == "COPY":
68 resp, body = self.copy(url)
69 else:
70 assert False
71
72 return resp, body