1 # (c) 2014 Deutsche Telekom AG
2 # Copyright 2014 Red Hat, Inc.
3 # Copyright 2014 NEC Corporation
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
18 from neutron.tests.tempest.common import service_client
19 from neutron.tests.tempest import config
24 class NegativeRestClient(service_client.ServiceClient):
26 Version of RestClient that does not raise exceptions.
28 def __init__(self, auth_provider, service):
29 region = self._get_region(service)
30 super(NegativeRestClient, self).__init__(auth_provider,
33 def _get_region(self, service):
35 Returns the region for a specific service
38 for cfgname in dir(CONF._config):
39 # Find all config.FOO.catalog_type and assume FOO is a service.
40 cfg = getattr(CONF, cfgname)
41 catalog_type = getattr(cfg, 'catalog_type', None)
42 if catalog_type == service:
43 service_region = getattr(cfg, 'region', None)
44 if not service_region:
45 service_region = CONF.identity.region
48 def _error_checker(self, method, url,
49 headers, body, resp, resp_body):
52 def send_request(self, method, url_template, resources, body=None):
53 url = url_template % tuple(resources)
55 resp, body = self.get(url)
56 elif method == "POST":
57 resp, body = self.post(url, body)
59 resp, body = self.put(url, body)
60 elif method == "PATCH":
61 resp, body = self.patch(url, body)
62 elif method == "HEAD":
63 resp, body = self.head(url)
64 elif method == "DELETE":
65 resp, body = self.delete(url)
66 elif method == "COPY":
67 resp, body = self.copy(url)