Ken'ichi Ohmichi | 4266268 | 2015-01-05 05:00:04 +0000 | [diff] [blame] | 1 | # (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 Lanoux | 9b59767 | 2015-01-21 16:38:08 +0000 | [diff] [blame] | 18 | from tempest.common import service_client |
Ken'ichi Ohmichi | 4266268 | 2015-01-05 05:00:04 +0000 | [diff] [blame] | 19 | from tempest import config |
| 20 | |
| 21 | CONF = config.CONF |
| 22 | |
| 23 | |
Joseph Lanoux | 9b59767 | 2015-01-21 16:38:08 +0000 | [diff] [blame] | 24 | class NegativeRestClient(service_client.ServiceClient): |
Ken'ichi Ohmichi | cb67d2d | 2015-11-19 08:23:22 +0000 | [diff] [blame] | 25 | """Version of RestClient that does not raise exceptions.""" |
David Kranz | 1e33e37 | 2015-03-20 09:42:56 -0400 | [diff] [blame] | 26 | 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 Ohmichi | 4266268 | 2015-01-05 05:00:04 +0000 | [diff] [blame] | 42 | |
David Kranz | 1e33e37 | 2015-03-20 09:42:56 -0400 | [diff] [blame] | 43 | def _get_region_and_endpoint_type(self, service): |
Ken'ichi Ohmichi | cb67d2d | 2015-11-19 08:23:22 +0000 | [diff] [blame] | 44 | """Returns the region for a specific service""" |
Ken'ichi Ohmichi | 4266268 | 2015-01-05 05:00:04 +0000 | [diff] [blame] | 45 | service_region = None |
David Kranz | 1e33e37 | 2015-03-20 09:42:56 -0400 | [diff] [blame] | 46 | service_endpoint_type = None |
Ken'ichi Ohmichi | 4266268 | 2015-01-05 05:00:04 +0000 | [diff] [blame] | 47 | 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 Kranz | 1e33e37 | 2015-03-20 09:42:56 -0400 | [diff] [blame] | 53 | service_endpoint_type = getattr(cfg, 'endpoint_type', None) |
Ken'ichi Ohmichi | 4266268 | 2015-01-05 05:00:04 +0000 | [diff] [blame] | 54 | if not service_region: |
| 55 | service_region = CONF.identity.region |
David Kranz | 1e33e37 | 2015-03-20 09:42:56 -0400 | [diff] [blame] | 56 | return service_region, service_endpoint_type |
Ken'ichi Ohmichi | 4266268 | 2015-01-05 05:00:04 +0000 | [diff] [blame] | 57 | |
| 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 |