blob: c32a7d075bbad5f08b3c868ec3be7833df6dba8f [file] [log] [blame]
Ken'ichi Ohmichi0e836652015-01-08 04:38:56 +00001# Copyright 2015 NEC Corporation. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from tempest.common import rest_client
16from tempest import config
17
18CONF = config.CONF
19
20
21class ServiceClient(rest_client.RestClient):
22
23 def __init__(self, auth_provider, service, region,
24 endpoint_type=None, build_interval=None, build_timeout=None):
25 params = {
26 'disable_ssl_certificate_validation':
27 CONF.identity.disable_ssl_certificate_validation,
28 'ca_certs': CONF.identity.ca_certificates_file,
29 'trace_requests': CONF.debug.trace_requests
30 }
31 if endpoint_type is not None:
32 params.update({'endpoint_type': endpoint_type})
33 if build_interval is not None:
34 params.update({'build_interval': build_interval})
35 if build_timeout is not None:
36 params.update({'build_timeout': build_timeout})
37 super(ServiceClient, self).__init__(auth_provider, service, region,
38 **params)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000039
40
41class ResponseBody(dict):
42 """Class that wraps an http response and dict body into a single value.
43
44 Callers that receive this object will normally use it as a dict but
45 can extract the response if needed.
46 """
47
48 def __init__(self, response, body=None):
49 body_data = body or {}
50 self.update(body_data)
51 self.response = response
52
53 def __str__(self):
54 body = super.__str__(self)
55 return "response: %s\nBody: %s" % (self.response, body)
56
57
58class ResponseBodyList(list):
59 """Class that wraps an http response and list body into a single value.
60
61 Callers that receive this object will normally use it as a list but
62 can extract the response if needed.
63 """
64
65 def __init__(self, response, body=None):
66 body_data = body or []
67 self.extend(body_data)
68 self.response = response
69
70 def __str__(self):
71 body = super.__str__(self)
72 return "response: %s\nBody: %s" % (self.response, body)