blob: a82291a74efd91226913031a340ab0ce1456ee49 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07002# 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
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053016import json
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053017import time
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050018import urllib
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053019
Masayuki Igawabfa07602015-01-20 18:47:17 +090020from tempest_lib import exceptions as lib_exc
21
Joseph Lanoux6809bab2014-12-18 14:57:18 +000022from tempest.common import service_client
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070023from tempest import exceptions
24
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053025
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +000026class BaseVolumesClientJSON(service_client.ServiceClient):
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070027 """
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080028 Base client class to send CRUD Volume API requests to a Cinder endpoint
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070029 """
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053030
Ken'ichi Ohmichia39d0be2014-12-17 08:46:11 +000031 create_resp = 200
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053032
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000033 def __init__(self, auth_provider, service, region,
34 default_volume_size=1, **kwargs):
35 super(BaseVolumesClientJSON, self).__init__(
36 auth_provider, service, region, **kwargs)
37 self.default_volume_size = default_volume_size
38
anju tiwari789449a2013-08-29 16:56:17 +053039 def get_attachment_from_volume(self, volume):
40 """Return the element 'attachment' from input volumes."""
41 return volume['attachments'][0]
42
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000043 def list_volumes(self, detail=False, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -050044 """List all the volumes created."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070045 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000046 if detail:
47 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050048 if params:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000049 url += '?%s' % urllib.urlencode(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053050
chris fattarsi5098fa22012-04-17 13:27:00 -070051 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053052 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000053 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000054 return service_client.ResponseBodyList(resp, body['volumes'])
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053055
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000056 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050057 """Returns the details of a single volume."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070058 url = "volumes/%s" % str(volume_id)
Attila Fazekasb8aa7592013-01-26 01:25:45 +010059 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053060 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000061 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000062 return service_client.ResponseBody(resp, body['volume'])
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053063
Jerry Cai9733d0e2014-03-19 15:50:49 +080064 def create_volume(self, size=None, **kwargs):
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053065 """
66 Creates a new Volume.
Jerry Cai9733d0e2014-03-19 15:50:49 +080067 size: Size of volume in GB.
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053068 Following optional keyword arguments are accepted:
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080069 display_name: Optional Volume Name(only for V1).
70 name: Optional Volume Name(only for V2).
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053071 metadata: A dictionary of values to be used as metadata.
Rohan Rhishikesh Kanadec316f0a2012-12-04 05:44:39 -080072 volume_type: Optional Name of volume_type for the volume
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010073 snapshot_id: When specified the volume is created from this snapshot
Giulio Fidente36836c42013-04-05 15:43:51 +020074 imageRef: When specified the volume is created from this image
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053075 """
Jerry Cai9733d0e2014-03-19 15:50:49 +080076 if size is None:
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000077 size = self.default_volume_size
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010078 post_body = {'size': size}
79 post_body.update(kwargs)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053080 post_body = json.dumps({'volume': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020081 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053082 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000083 self.expected_success(self.create_resp, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000084 return service_client.ResponseBody(resp, body['volume'])
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053085
QingXin Meng611768a2013-09-18 00:51:33 -070086 def update_volume(self, volume_id, **kwargs):
87 """Updates the Specified Volume."""
88 put_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020089 resp, body = self.put('volumes/%s' % volume_id, put_body)
QingXin Meng611768a2013-09-18 00:51:33 -070090 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000091 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000092 return service_client.ResponseBody(resp, body['volume'])
QingXin Meng611768a2013-09-18 00:51:33 -070093
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053094 def delete_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050095 """Deletes the Specified Volume."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000096 resp, body = self.delete("volumes/%s" % str(volume_id))
97 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +000098 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053099
Ryan Hsua67f4632013-08-29 16:03:06 -0700100 def upload_volume(self, volume_id, image_name, disk_format):
Giulio Fidente884e9da2013-06-21 17:25:42 +0200101 """Uploads a volume in Glance."""
102 post_body = {
103 'image_name': image_name,
Ryan Hsua67f4632013-08-29 16:03:06 -0700104 'disk_format': disk_format
Giulio Fidente884e9da2013-06-21 17:25:42 +0200105 }
106 post_body = json.dumps({'os-volume_upload_image': post_body})
107 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200108 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200109 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000110 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000111 return service_client.ResponseBody(resp,
112 body['os-volume_upload_image'])
Giulio Fidente884e9da2013-06-21 17:25:42 +0200113
Rohit Karajgia42fe442012-09-21 03:08:33 -0700114 def attach_volume(self, volume_id, instance_uuid, mountpoint):
Sean Daguef237ccb2013-01-04 15:19:14 -0500115 """Attaches a volume to a given instance on a given mountpoint."""
Rohit Karajgia42fe442012-09-21 03:08:33 -0700116 post_body = {
Zhongyue Luo30a563f2012-09-30 23:43:50 +0900117 'instance_uuid': instance_uuid,
118 'mountpoint': mountpoint,
119 }
Rohit Karajgia42fe442012-09-21 03:08:33 -0700120 post_body = json.dumps({'os-attach': post_body})
121 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200122 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000123 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000124 return service_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700125
126 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500127 """Detaches a volume from an instance."""
Rohit Karajgia42fe442012-09-21 03:08:33 -0700128 post_body = {}
129 post_body = json.dumps({'os-detach': post_body})
130 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200131 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000132 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000133 return service_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700134
zhangyanzi6b632432013-10-24 19:08:50 +0800135 def reserve_volume(self, volume_id):
136 """Reserves a volume."""
137 post_body = {}
138 post_body = json.dumps({'os-reserve': post_body})
139 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200140 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000141 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000142 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800143
144 def unreserve_volume(self, volume_id):
145 """Restore a reserved volume ."""
146 post_body = {}
147 post_body = json.dumps({'os-unreserve': post_body})
148 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200149 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000150 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000151 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800152
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530153 def wait_for_volume_status(self, volume_id, status):
Sean Daguef237ccb2013-01-04 15:19:14 -0500154 """Waits for a Volume to reach a given status."""
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000155 body = self.show_volume(volume_id)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530156 volume_status = body['status']
157 start = int(time.time())
158
159 while volume_status != status:
160 time.sleep(self.build_interval)
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000161 body = self.show_volume(volume_id)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530162 volume_status = body['status']
163 if volume_status == 'error':
rajalakshmi-ganesane3bb58f2012-05-16 12:01:15 +0530164 raise exceptions.VolumeBuildErrorException(volume_id=volume_id)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530165
166 if int(time.time()) - start >= self.build_timeout:
Martin Pavlasek1102c3a2014-10-20 17:17:55 +0200167 message = ('Volume %s failed to reach %s status (current: %s) '
168 'within the required time '
169 '(%s s).' % (volume_id,
170 status,
171 volume_status,
172 self.build_timeout))
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530173 raise exceptions.TimeoutException(message)
David Kranz6aceb4a2012-06-05 14:05:45 -0400174
175 def is_resource_deleted(self, id):
176 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000177 self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900178 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400179 return True
180 return False
wanghao5b981752013-10-22 11:41:41 +0800181
Matt Riedemannd2b96512014-10-13 10:18:16 -0700182 @property
183 def resource_type(self):
184 """Returns the primary type of resource this client works with."""
185 return 'volume'
186
wanghao5b981752013-10-22 11:41:41 +0800187 def extend_volume(self, volume_id, extend_size):
188 """Extend a volume."""
189 post_body = {
190 'new_size': extend_size
191 }
192 post_body = json.dumps({'os-extend': post_body})
193 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200194 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000195 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000196 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800197
198 def reset_volume_status(self, volume_id, status):
199 """Reset the Specified Volume's Status."""
200 post_body = json.dumps({'os-reset_status': {"status": status}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200201 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000202 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000203 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800204
205 def volume_begin_detaching(self, volume_id):
206 """Volume Begin Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000207 # ref cinder/api/contrib/volume_actions.py#L158
wanghaoaa1f2f92013-10-10 11:30:37 +0800208 post_body = json.dumps({'os-begin_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200209 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000210 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000211 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800212
213 def volume_roll_detaching(self, volume_id):
214 """Volume Roll Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000215 # cinder/api/contrib/volume_actions.py#L170
wanghaoaa1f2f92013-10-10 11:30:37 +0800216 post_body = json.dumps({'os-roll_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200217 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000218 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000219 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800220
221 def create_volume_transfer(self, vol_id, display_name=None):
222 """Create a volume transfer."""
223 post_body = {
224 'volume_id': vol_id
225 }
226 if display_name:
227 post_body['name'] = display_name
228 post_body = json.dumps({'transfer': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200229 resp, body = self.post('os-volume-transfer', post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800230 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000231 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000232 return service_client.ResponseBody(resp, body['transfer'])
wingwjcbd82dc2013-10-22 16:38:39 +0800233
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000234 def show_volume_transfer(self, transfer_id):
wingwjcbd82dc2013-10-22 16:38:39 +0800235 """Returns the details of a volume transfer."""
236 url = "os-volume-transfer/%s" % str(transfer_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200237 resp, body = self.get(url)
wingwjcbd82dc2013-10-22 16:38:39 +0800238 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000239 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000240 return service_client.ResponseBody(resp, body['transfer'])
wingwjcbd82dc2013-10-22 16:38:39 +0800241
242 def list_volume_transfers(self, params=None):
243 """List all the volume transfers created."""
244 url = 'os-volume-transfer'
245 if params:
246 url += '?%s' % urllib.urlencode(params)
247 resp, body = self.get(url)
248 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000249 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000250 return service_client.ResponseBodyList(resp, body['transfers'])
wingwjcbd82dc2013-10-22 16:38:39 +0800251
252 def delete_volume_transfer(self, transfer_id):
253 """Delete a volume transfer."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000254 resp, body = self.delete("os-volume-transfer/%s" % str(transfer_id))
255 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000256 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800257
258 def accept_volume_transfer(self, transfer_id, transfer_auth_key):
259 """Accept a volume transfer."""
260 post_body = {
261 'auth_key': transfer_auth_key,
262 }
263 url = 'os-volume-transfer/%s/accept' % transfer_id
264 post_body = json.dumps({'accept': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200265 resp, body = self.post(url, post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800266 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000267 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000268 return service_client.ResponseBody(resp, body['transfer'])
zhangyanziaa180072013-11-21 12:31:26 +0800269
270 def update_volume_readonly(self, volume_id, readonly):
271 """Update the Specified Volume readonly."""
272 post_body = {
273 'readonly': readonly
274 }
275 post_body = json.dumps({'os-update_readonly_flag': post_body})
276 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200277 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000278 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000279 return service_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800280
281 def force_delete_volume(self, volume_id):
282 """Force Delete Volume."""
283 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200284 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000285 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000286 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800287
288 def create_volume_metadata(self, volume_id, metadata):
289 """Create metadata for the volume."""
290 put_body = json.dumps({'metadata': metadata})
291 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200292 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800293 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000294 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000295 return service_client.ResponseBody(resp, body['metadata'])
huangtianhua0ff41682013-12-16 14:49:31 +0800296
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000297 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800298 """Get metadata of the volume."""
299 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200300 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800301 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000302 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000303 return service_client.ResponseBody(resp, body['metadata'])
huangtianhua0ff41682013-12-16 14:49:31 +0800304
305 def update_volume_metadata(self, volume_id, metadata):
306 """Update metadata for the volume."""
307 put_body = json.dumps({'metadata': metadata})
308 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200309 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800310 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000311 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000312 return service_client.ResponseBody(resp, body['metadata'])
huangtianhua0ff41682013-12-16 14:49:31 +0800313
314 def update_volume_metadata_item(self, volume_id, id, meta_item):
315 """Update metadata item for the volume."""
316 put_body = json.dumps({'meta': meta_item})
317 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200318 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800319 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000320 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000321 return service_client.ResponseBody(resp, body['meta'])
huangtianhua0ff41682013-12-16 14:49:31 +0800322
323 def delete_volume_metadata_item(self, volume_id, id):
324 """Delete metadata item for the volume."""
325 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200326 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000327 self.expected_success(200, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000328 return service_client.ResponseBody(resp, body)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800329
nayna-patel78f743e2015-01-09 10:52:51 +0000330 def retype_volume(self, volume_id, volume_type, **kwargs):
331 """Updates volume with new volume type."""
332 post_body = {'new_type': volume_type}
333 post_body.update(kwargs)
334 post_body = json.dumps({'os-retype': post_body})
335 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
336 self.expected_success(202, resp.status)
337
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800338
339class VolumesClientJSON(BaseVolumesClientJSON):
340 """
341 Client class to send CRUD Volume V1 API requests to a Cinder endpoint
342 """