Ken'ichi Ohmichi | 4adae2f | 2017-03-15 15:47:44 -0700 | [diff] [blame] | 1 | # Copyright 2017 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 | |
Doug Schveninger | 152f105 | 2019-09-06 19:53:02 -0500 | [diff] [blame] | 15 | from six.moves.urllib.parse import urljoin |
| 16 | |
Ken'ichi Ohmichi | 4adae2f | 2017-03-15 15:47:44 -0700 | [diff] [blame] | 17 | from oslo_serialization import jsonutils as json |
| 18 | |
| 19 | from tempest.lib.api_schema.response.volume import versions as schema |
| 20 | from tempest.lib.common import rest_client |
zhufl | 0273652 | 2017-06-19 13:57:28 +0800 | [diff] [blame] | 21 | from tempest.lib.services.volume import base_client |
Ken'ichi Ohmichi | 4adae2f | 2017-03-15 15:47:44 -0700 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class VersionsClient(base_client.BaseClient): |
Ken'ichi Ohmichi | 4adae2f | 2017-03-15 15:47:44 -0700 | [diff] [blame] | 25 | |
| 26 | def list_versions(self): |
| 27 | """List API versions |
| 28 | |
| 29 | For a full list of available parameters, please refer to the official |
| 30 | API reference: |
Andreas Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 31 | https://docs.openstack.org/api-ref/block-storage/v3/#list-all-api-versions |
Ken'ichi Ohmichi | 4adae2f | 2017-03-15 15:47:44 -0700 | [diff] [blame] | 32 | """ |
| 33 | version_url = self._get_base_version_url() |
| 34 | |
Ken'ichi Ohmichi | 4adae2f | 2017-03-15 15:47:44 -0700 | [diff] [blame] | 35 | resp, body = self.raw_request(version_url, 'GET') |
Ken'ichi Ohmichi | 4adae2f | 2017-03-15 15:47:44 -0700 | [diff] [blame] | 36 | # NOTE: We need a raw_request() here instead of request() call because |
| 37 | # "list API versions" API doesn't require an authentication and we can |
| 38 | # skip it with raw_request() call. |
Ken'ichi Ohmichi | 4adae2f | 2017-03-15 15:47:44 -0700 | [diff] [blame] | 39 | self._error_checker(resp, body) |
| 40 | |
| 41 | body = json.loads(body) |
| 42 | self.validate_response(schema.list_versions, resp, body) |
| 43 | return rest_client.ResponseBody(resp, body) |
wangzhiguang | db10fb0 | 2019-07-29 18:05:10 +0800 | [diff] [blame] | 44 | |
| 45 | def show_version(self, version): |
| 46 | """Show API version details |
| 47 | |
Doug Schveninger | 152f105 | 2019-09-06 19:53:02 -0500 | [diff] [blame] | 48 | Use raw_request in order to have access to the endpoints minus |
| 49 | version and project in order to add version only back. |
| 50 | |
wangzhiguang | db10fb0 | 2019-07-29 18:05:10 +0800 | [diff] [blame] | 51 | For a full list of available parameters, please refer to the official |
| 52 | API reference: |
| 53 | https://docs.openstack.org/api-ref/block-storage/v3/#show-api-v3-details |
| 54 | """ |
| 55 | |
Doug Schveninger | 152f105 | 2019-09-06 19:53:02 -0500 | [diff] [blame] | 56 | version_url = urljoin(self._get_base_version_url(), version + '/') |
Gayathri Devi Kathiri | fe7a983 | 2020-07-13 15:22:13 +0000 | [diff] [blame] | 57 | headers = self.get_headers() |
| 58 | headers['X-Auth-Token'] = self.token |
| 59 | resp, body = self.raw_request(version_url, 'GET', headers=headers) |
Doug Schveninger | 152f105 | 2019-09-06 19:53:02 -0500 | [diff] [blame] | 60 | self._error_checker(resp, body) |
wangzhiguang | db10fb0 | 2019-07-29 18:05:10 +0800 | [diff] [blame] | 61 | body = json.loads(body) |
| 62 | self.validate_response(schema.volume_api_version_details, resp, body) |
| 63 | return rest_client.ResponseBody(resp, body) |