1 # Copyright 2015 NEC Corporation. All rights reserved.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
15 from tempest_lib.common import rest_client
17 from neutron.tests.tempest import config
22 class ServiceClient(rest_client.RestClient):
24 def __init__(self, auth_provider, service, region,
25 endpoint_type=None, build_interval=None, build_timeout=None,
26 disable_ssl_certificate_validation=None, ca_certs=None,
29 # TODO(oomichi): This params setting should be removed after all
30 # service clients pass these values, and we can make ServiceClient
31 # free from CONF values.
32 dscv = (disable_ssl_certificate_validation or
33 CONF.identity.disable_ssl_certificate_validation)
35 'disable_ssl_certificate_validation': dscv,
36 'ca_certs': ca_certs or CONF.identity.ca_certificates_file,
37 'trace_requests': trace_requests or CONF.debug.trace_requests
40 if endpoint_type is not None:
41 params.update({'endpoint_type': endpoint_type})
42 if build_interval is not None:
43 params.update({'build_interval': build_interval})
44 if build_timeout is not None:
45 params.update({'build_timeout': build_timeout})
46 super(ServiceClient, self).__init__(auth_provider, service, region,
50 class ResponseBody(dict):
51 """Class that wraps an http response and dict body into a single value.
53 Callers that receive this object will normally use it as a dict but
54 can extract the response if needed.
57 def __init__(self, response, body=None):
58 body_data = body or {}
59 self.update(body_data)
60 self.response = response
63 body = super(ResponseBody, self).__str__()
64 return "response: %s\nBody: %s" % (self.response, body)
67 class ResponseBodyData(object):
68 """Class that wraps an http response and string data into a single value.
71 def __init__(self, response, data):
72 self.response = response
76 return "response: %s\nBody: %s" % (self.response, self.data)
79 class ResponseBodyList(list):
80 """Class that wraps an http response and list body into a single value.
82 Callers that receive this object will normally use it as a list but
83 can extract the response if needed.
86 def __init__(self, response, body=None):
87 body_data = body or []
88 self.extend(body_data)
89 self.response = response
92 body = super(ResponseBodyList, self).__str__()
93 return "response: %s\nBody: %s" % (self.response, body)