zhufl | 0273652 | 2017-06-19 13:57:28 +0800 | [diff] [blame] | 1 | # Copyright 2016 Andrew Kerr |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | from tempest.lib.common import api_version_utils |
| 17 | from tempest.lib.common import rest_client |
| 18 | |
| 19 | VOLUME_MICROVERSION = None |
| 20 | |
| 21 | |
| 22 | class BaseClient(rest_client.RestClient): |
| 23 | """Base volume service clients class to support microversion.""" |
| 24 | api_microversion_header_name = 'Openstack-Api-Version' |
| 25 | |
| 26 | def get_headers(self, accept_type=None, send_type=None): |
| 27 | headers = super(BaseClient, self).get_headers( |
| 28 | accept_type=accept_type, send_type=send_type) |
| 29 | if VOLUME_MICROVERSION: |
| 30 | headers[self.api_microversion_header_name] = ('volume %s' % |
| 31 | VOLUME_MICROVERSION) |
| 32 | return headers |
| 33 | |
| 34 | def request(self, method, url, extra_headers=False, headers=None, |
| 35 | body=None, chunked=False): |
| 36 | |
| 37 | resp, resp_body = super(BaseClient, self).request( |
| 38 | method, url, extra_headers, headers, body, chunked) |
| 39 | if (VOLUME_MICROVERSION and |
| 40 | VOLUME_MICROVERSION != api_version_utils.LATEST_MICROVERSION): |
| 41 | api_version_utils.assert_version_header_matches_request( |
| 42 | self.api_microversion_header_name, |
| 43 | 'volume %s' % VOLUME_MICROVERSION, |
| 44 | resp) |
| 45 | return resp, resp_body |