Ken'ichi Ohmichi | 0e83665 | 2015-01-08 04:38:56 +0000 | [diff] [blame] | 1 | # 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 | |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 15 | from tempest.lib.common import rest_client |
Ken'ichi Ohmichi | 79aede1 | 2015-01-17 08:19:47 +0000 | [diff] [blame] | 16 | |
Ken'ichi Ohmichi | 0e83665 | 2015-01-08 04:38:56 +0000 | [diff] [blame] | 17 | |
| 18 | class ServiceClient(rest_client.RestClient): |
| 19 | |
| 20 | def __init__(self, auth_provider, service, region, |
Ken'ichi Ohmichi | c2b11ce | 2015-01-16 07:17:29 +0000 | [diff] [blame] | 21 | endpoint_type=None, build_interval=None, build_timeout=None, |
| 22 | disable_ssl_certificate_validation=None, ca_certs=None, |
| 23 | trace_requests=None): |
| 24 | |
David Kranz | 1e33e37 | 2015-03-20 09:42:56 -0400 | [diff] [blame] | 25 | dscv = disable_ssl_certificate_validation |
Ken'ichi Ohmichi | 0e83665 | 2015-01-08 04:38:56 +0000 | [diff] [blame] | 26 | params = { |
Ken'ichi Ohmichi | c2b11ce | 2015-01-16 07:17:29 +0000 | [diff] [blame] | 27 | 'disable_ssl_certificate_validation': dscv, |
David Kranz | 1e33e37 | 2015-03-20 09:42:56 -0400 | [diff] [blame] | 28 | 'ca_certs': ca_certs, |
| 29 | 'trace_requests': trace_requests |
Ken'ichi Ohmichi | 0e83665 | 2015-01-08 04:38:56 +0000 | [diff] [blame] | 30 | } |
Ken'ichi Ohmichi | c2b11ce | 2015-01-16 07:17:29 +0000 | [diff] [blame] | 31 | |
Ken'ichi Ohmichi | 0e83665 | 2015-01-08 04:38:56 +0000 | [diff] [blame] | 32 | if endpoint_type is not None: |
| 33 | params.update({'endpoint_type': endpoint_type}) |
| 34 | if build_interval is not None: |
| 35 | params.update({'build_interval': build_interval}) |
| 36 | if build_timeout is not None: |
| 37 | params.update({'build_timeout': build_timeout}) |
| 38 | super(ServiceClient, self).__init__(auth_provider, service, region, |
| 39 | **params) |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 40 | |
| 41 | |
| 42 | class ResponseBody(dict): |
| 43 | """Class that wraps an http response and dict body into a single value. |
| 44 | |
| 45 | Callers that receive this object will normally use it as a dict but |
| 46 | can extract the response if needed. |
| 47 | """ |
| 48 | |
| 49 | def __init__(self, response, body=None): |
| 50 | body_data = body or {} |
| 51 | self.update(body_data) |
| 52 | self.response = response |
| 53 | |
| 54 | def __str__(self): |
David Kranz | 01fa7e4 | 2015-02-10 15:51:51 -0500 | [diff] [blame] | 55 | body = super(ResponseBody, self).__str__() |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 56 | return "response: %s\nBody: %s" % (self.response, body) |
| 57 | |
| 58 | |
David Kranz | e4e3b41 | 2015-02-10 10:50:42 -0500 | [diff] [blame] | 59 | class ResponseBodyData(object): |
Ken'ichi Ohmichi | cb67d2d | 2015-11-19 08:23:22 +0000 | [diff] [blame] | 60 | """Class that wraps an http response and string data into a single value""" |
David Kranz | e4e3b41 | 2015-02-10 10:50:42 -0500 | [diff] [blame] | 61 | |
| 62 | def __init__(self, response, data): |
| 63 | self.response = response |
| 64 | self.data = data |
| 65 | |
| 66 | def __str__(self): |
| 67 | return "response: %s\nBody: %s" % (self.response, self.data) |
| 68 | |
| 69 | |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 70 | class ResponseBodyList(list): |
| 71 | """Class that wraps an http response and list body into a single value. |
| 72 | |
| 73 | Callers that receive this object will normally use it as a list but |
| 74 | can extract the response if needed. |
| 75 | """ |
| 76 | |
| 77 | def __init__(self, response, body=None): |
| 78 | body_data = body or [] |
| 79 | self.extend(body_data) |
| 80 | self.response = response |
| 81 | |
| 82 | def __str__(self): |
David Kranz | 01fa7e4 | 2015-02-10 15:51:51 -0500 | [diff] [blame] | 83 | body = super(ResponseBodyList, self).__str__() |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 84 | return "response: %s\nBody: %s" % (self.response, body) |