blob: d1500cf5112e8c0a090501f48764f69fefcfeb33 [file] [log] [blame]
Xing Yang0ddf83e2015-11-17 22:15:25 -05001# 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
songwenping99d6e002021-01-05 03:07:46 +000016from urllib import parse as urllib
17
Xing Yang0ddf83e2015-11-17 22:15:25 -050018from oslo_serialization import jsonutils as json
Xing Yang0ddf83e2015-11-17 22:15:25 -050019
zhuflda8d2582018-09-29 15:58:04 +080020from tempest.lib.api_schema.response.volume import groups as schema
Xing Yang0ddf83e2015-11-17 22:15:25 -050021from tempest.lib.common import rest_client
22from tempest.lib import exceptions as lib_exc
zhufl02736522017-06-19 13:57:28 +080023from tempest.lib.services.volume import base_client
Xing Yang0ddf83e2015-11-17 22:15:25 -050024
25
26class GroupsClient(base_client.BaseClient):
27 """Client class to send CRUD Volume Group API requests"""
zhuflda8d2582018-09-29 15:58:04 +080028 api_version = 'v3'
Xing Yang0ddf83e2015-11-17 22:15:25 -050029
30 def create_group(self, **kwargs):
31 """Creates a group.
32
33 group_type and volume_types are required parameters in kwargs.
34 For a full list of available parameters, please refer to the official
35 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020036 https://docs.openstack.org/api-ref/block-storage/v3/#create-group
Xing Yang0ddf83e2015-11-17 22:15:25 -050037 """
38 post_body = json.dumps({'group': kwargs})
39 resp, body = self.post('groups', post_body)
40 body = json.loads(body)
zhuflda8d2582018-09-29 15:58:04 +080041 self.validate_response(schema.create_group, resp, body)
Xing Yang0ddf83e2015-11-17 22:15:25 -050042 return rest_client.ResponseBody(resp, body)
43
44 def delete_group(self, group_id, delete_volumes=True):
45 """Deletes a group.
46
47 For a full list of available parameters, please refer to the official
48 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020049 https://docs.openstack.org/api-ref/block-storage/v3/#delete-group
Xing Yang0ddf83e2015-11-17 22:15:25 -050050 """
51 post_body = {'delete-volumes': delete_volumes}
52 post_body = json.dumps({'delete': post_body})
53 resp, body = self.post('groups/%s/action' % group_id,
54 post_body)
zhuflda8d2582018-09-29 15:58:04 +080055 self.validate_response(schema.delete_group, resp, body)
Xing Yang0ddf83e2015-11-17 22:15:25 -050056 return rest_client.ResponseBody(resp, body)
57
58 def show_group(self, group_id):
59 """Returns the details of a single group.
60
61 For a full list of available parameters, please refer to the official
62 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020063 https://docs.openstack.org/api-ref/block-storage/v3/#show-group-details
Xing Yang0ddf83e2015-11-17 22:15:25 -050064 """
65 url = "groups/%s" % str(group_id)
66 resp, body = self.get(url)
67 body = json.loads(body)
zhuflda8d2582018-09-29 15:58:04 +080068 self.validate_response(schema.show_group, resp, body)
Xing Yang0ddf83e2015-11-17 22:15:25 -050069 return rest_client.ResponseBody(resp, body)
70
71 def list_groups(self, detail=False, **params):
72 """Lists information for all the tenant's groups.
73
74 For a full list of available parameters, please refer to the official
75 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020076 https://docs.openstack.org/api-ref/block-storage/v3/#list-groups
77 https://docs.openstack.org/api-ref/block-storage/v3/#list-groups-with-details
Xing Yang0ddf83e2015-11-17 22:15:25 -050078 """
79 url = "groups"
zhuflda8d2582018-09-29 15:58:04 +080080 schema_list_groups = schema.list_groups_no_detail
Xing Yang0ddf83e2015-11-17 22:15:25 -050081 if detail:
82 url += "/detail"
zhuflda8d2582018-09-29 15:58:04 +080083 schema_list_groups = schema.list_groups_with_detail
Xing Yang0ddf83e2015-11-17 22:15:25 -050084 if params:
85 url += '?%s' % urllib.urlencode(params)
86 resp, body = self.get(url)
87 body = json.loads(body)
zhuflda8d2582018-09-29 15:58:04 +080088 self.validate_response(schema_list_groups, resp, body)
Xing Yang0ddf83e2015-11-17 22:15:25 -050089 return rest_client.ResponseBody(resp, body)
90
xing-yangd56edc32017-07-01 14:00:06 -070091 def create_group_from_source(self, **kwargs):
92 """Creates a group from source.
93
94 For a full list of available parameters, please refer to the official
95 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020096 https://docs.openstack.org/api-ref/block-storage/v3/#create-group-from-source
xing-yangd56edc32017-07-01 14:00:06 -070097 """
98 post_body = json.dumps({'create-from-src': kwargs})
99 resp, body = self.post('groups/action', post_body)
100 body = json.loads(body)
zhuflda8d2582018-09-29 15:58:04 +0800101 self.validate_response(schema.create_group_from_source, resp, body)
xing-yangd56edc32017-07-01 14:00:06 -0700102 return rest_client.ResponseBody(resp, body)
103
xing-yang9ee98602017-07-01 14:12:54 -0700104 def update_group(self, group_id, **kwargs):
105 """Updates the specified group.
106
107 For a full list of available parameters, please refer to the official
108 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200109 https://docs.openstack.org/api-ref/block-storage/v3/#update-group
xing-yang9ee98602017-07-01 14:12:54 -0700110 """
111 put_body = json.dumps({'group': kwargs})
112 resp, body = self.put('groups/%s' % group_id, put_body)
zhuflda8d2582018-09-29 15:58:04 +0800113 self.validate_response(schema.update_group, resp, body)
xing-yang9ee98602017-07-01 14:12:54 -0700114 return rest_client.ResponseBody(resp, body)
115
jeremy.zhangcca99742017-08-20 01:08:24 +0800116 def reset_group_status(self, group_id, status_to_set):
117 """Resets group status.
118
119 For more information, please refer to the official API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200120 https://docs.openstack.org/api-ref/block-storage/v3/#reset-group-status
jeremy.zhangcca99742017-08-20 01:08:24 +0800121 """
122 post_body = json.dumps({'reset_status': {'status': status_to_set}})
123 resp, body = self.post('groups/%s/action' % group_id, post_body)
zhuflda8d2582018-09-29 15:58:04 +0800124 self.validate_response(schema.reset_group_status, resp, body)
jeremy.zhangcca99742017-08-20 01:08:24 +0800125 return rest_client.ResponseBody(resp, body)
126
Xing Yang0ddf83e2015-11-17 22:15:25 -0500127 def is_resource_deleted(self, id):
128 try:
129 self.show_group(id)
130 except lib_exc.NotFound:
131 return True
132 return False
133
134 @property
135 def resource_type(self):
136 """Returns the primary type of resource this client works with."""
137 return 'group'