Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / tests / tempest / common / negative_rest_client.py
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
18 from neutron.tests.tempest.common import service_client
19 from neutron.tests.tempest import config
20
21 CONF = config.CONF
22
23
24 class NegativeRestClient(service_client.ServiceClient):
25     """
26     Version of RestClient that does not raise exceptions.
27     """
28     def __init__(self, auth_provider, service):
29         region = self._get_region(service)
30         super(NegativeRestClient, self).__init__(auth_provider,
31                                                  service, region)
32
33     def _get_region(self, service):
34         """
35         Returns the region for a specific service
36         """
37         service_region = None
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
46         return service_region
47
48     def _error_checker(self, method, url,
49                        headers, body, resp, resp_body):
50         pass
51
52     def send_request(self, method, url_template, resources, body=None):
53         url = url_template % tuple(resources)
54         if method == "GET":
55             resp, body = self.get(url)
56         elif method == "POST":
57             resp, body = self.post(url, body)
58         elif method == "PUT":
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)
68         else:
69             assert False
70
71         return resp, body