Xing Yang | 0ddf83e | 2015-11-17 22:15:25 -0500 | [diff] [blame] | 1 | # Copyright (C) 2017 Dell Inc. or its subsidiaries. |
| 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 oslo_serialization import jsonutils as json |
| 17 | from six.moves.urllib import parse as urllib |
| 18 | |
| 19 | from tempest.lib.common import rest_client |
| 20 | from tempest.lib import exceptions as lib_exc |
zhufl | 0273652 | 2017-06-19 13:57:28 +0800 | [diff] [blame] | 21 | from tempest.lib.services.volume import base_client |
Xing Yang | 0ddf83e | 2015-11-17 22:15:25 -0500 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class GroupsClient(base_client.BaseClient): |
| 25 | """Client class to send CRUD Volume Group API requests""" |
zhufl | 0273652 | 2017-06-19 13:57:28 +0800 | [diff] [blame] | 26 | api_version = 'v3' |
Xing Yang | 0ddf83e | 2015-11-17 22:15:25 -0500 | [diff] [blame] | 27 | |
| 28 | def create_group(self, **kwargs): |
| 29 | """Creates a group. |
| 30 | |
| 31 | group_type and volume_types are required parameters in kwargs. |
| 32 | For a full list of available parameters, please refer to the official |
| 33 | API reference: |
| 34 | https://developer.openstack.org/api-ref/block-storage/v3/#create-group |
| 35 | """ |
| 36 | post_body = json.dumps({'group': kwargs}) |
| 37 | resp, body = self.post('groups', post_body) |
| 38 | body = json.loads(body) |
| 39 | self.expected_success(202, resp.status) |
| 40 | return rest_client.ResponseBody(resp, body) |
| 41 | |
| 42 | def delete_group(self, group_id, delete_volumes=True): |
| 43 | """Deletes a group. |
| 44 | |
| 45 | For a full list of available parameters, please refer to the official |
| 46 | API reference: |
| 47 | https://developer.openstack.org/api-ref/block-storage/v3/#delete-group |
| 48 | """ |
| 49 | post_body = {'delete-volumes': delete_volumes} |
| 50 | post_body = json.dumps({'delete': post_body}) |
| 51 | resp, body = self.post('groups/%s/action' % group_id, |
| 52 | post_body) |
| 53 | self.expected_success(202, resp.status) |
| 54 | return rest_client.ResponseBody(resp, body) |
| 55 | |
| 56 | def show_group(self, group_id): |
| 57 | """Returns the details of a single group. |
| 58 | |
| 59 | For a full list of available parameters, please refer to the official |
| 60 | API reference: |
| 61 | https://developer.openstack.org/api-ref/block-storage/v3/#show-group-details |
| 62 | """ |
| 63 | url = "groups/%s" % str(group_id) |
| 64 | resp, body = self.get(url) |
| 65 | body = json.loads(body) |
| 66 | self.expected_success(200, resp.status) |
| 67 | return rest_client.ResponseBody(resp, body) |
| 68 | |
| 69 | def list_groups(self, detail=False, **params): |
| 70 | """Lists information for all the tenant's groups. |
| 71 | |
| 72 | For a full list of available parameters, please refer to the official |
| 73 | API reference: |
| 74 | https://developer.openstack.org/api-ref/block-storage/v3/#list-groups |
| 75 | https://developer.openstack.org/api-ref/block-storage/v3/#list-groups-with-details |
| 76 | """ |
| 77 | url = "groups" |
| 78 | if detail: |
| 79 | url += "/detail" |
| 80 | if params: |
| 81 | url += '?%s' % urllib.urlencode(params) |
| 82 | resp, body = self.get(url) |
| 83 | body = json.loads(body) |
| 84 | self.expected_success(200, resp.status) |
| 85 | return rest_client.ResponseBody(resp, body) |
| 86 | |
xing-yang | d56edc3 | 2017-07-01 14:00:06 -0700 | [diff] [blame] | 87 | def create_group_from_source(self, **kwargs): |
| 88 | """Creates a group from source. |
| 89 | |
| 90 | For a full list of available parameters, please refer to the official |
| 91 | API reference: |
| 92 | https://developer.openstack.org/api-ref/block-storage/v3/#create-group-from-source |
| 93 | """ |
| 94 | post_body = json.dumps({'create-from-src': kwargs}) |
| 95 | resp, body = self.post('groups/action', post_body) |
| 96 | body = json.loads(body) |
| 97 | self.expected_success(202, resp.status) |
| 98 | return rest_client.ResponseBody(resp, body) |
| 99 | |
xing-yang | 9ee9860 | 2017-07-01 14:12:54 -0700 | [diff] [blame] | 100 | def update_group(self, group_id, **kwargs): |
| 101 | """Updates the specified group. |
| 102 | |
| 103 | For a full list of available parameters, please refer to the official |
| 104 | API reference: |
| 105 | https://developer.openstack.org/api-ref/block-storage/v3/#update-group |
| 106 | """ |
| 107 | put_body = json.dumps({'group': kwargs}) |
| 108 | resp, body = self.put('groups/%s' % group_id, put_body) |
| 109 | self.expected_success(202, resp.status) |
| 110 | return rest_client.ResponseBody(resp, body) |
| 111 | |
jeremy.zhang | cca9974 | 2017-08-20 01:08:24 +0800 | [diff] [blame] | 112 | def reset_group_status(self, group_id, status_to_set): |
| 113 | """Resets group status. |
| 114 | |
| 115 | For more information, please refer to the official API reference: |
| 116 | https://developer.openstack.org/api-ref/block-storage/v3/#reset-group-status |
| 117 | """ |
| 118 | post_body = json.dumps({'reset_status': {'status': status_to_set}}) |
| 119 | resp, body = self.post('groups/%s/action' % group_id, post_body) |
| 120 | self.expected_success(202, resp.status) |
| 121 | return rest_client.ResponseBody(resp, body) |
| 122 | |
Xing Yang | 0ddf83e | 2015-11-17 22:15:25 -0500 | [diff] [blame] | 123 | def is_resource_deleted(self, id): |
| 124 | try: |
| 125 | self.show_group(id) |
| 126 | except lib_exc.NotFound: |
| 127 | return True |
| 128 | return False |
| 129 | |
| 130 | @property |
| 131 | def resource_type(self): |
| 132 | """Returns the primary type of resource this client works with.""" |
| 133 | return 'group' |