ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 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 | |
lkuchlan | 7bba16c | 2016-09-04 12:36:04 +0300 | [diff] [blame] | 16 | from debtcollector import removals |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 17 | from oslo_serialization import jsonutils as json |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 18 | import six |
Matthew Treinish | 8912814 | 2015-04-23 10:44:30 -0400 | [diff] [blame] | 19 | from six.moves.urllib import parse as urllib |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 20 | |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 21 | from tempest.lib.common import rest_client |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 22 | from tempest.lib import exceptions as lib_exc |
zhufl | 0273652 | 2017-06-19 13:57:28 +0800 | [diff] [blame] | 23 | from tempest.lib.services.volume import base_client |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 24 | |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 25 | |
zhufl | 0273652 | 2017-06-19 13:57:28 +0800 | [diff] [blame] | 26 | class VolumesClient(base_client.BaseClient): |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 27 | """Client class to send CRUD Volume V2 API requests""" |
| 28 | api_version = "v2" |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 29 | |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 30 | def _prepare_params(self, params): |
| 31 | """Prepares params for use in get or _ext_get methods. |
| 32 | |
| 33 | If params is a string it will be left as it is, but if it's not it will |
| 34 | be urlencoded. |
| 35 | """ |
| 36 | if isinstance(params, six.string_types): |
| 37 | return params |
| 38 | return urllib.urlencode(params) |
| 39 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 40 | def list_volumes(self, detail=False, params=None): |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 41 | """List all the volumes created. |
| 42 | |
| 43 | Params can be a string (must be urlencoded) or a dictionary. |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 44 | For a full list of available parameters, please refer to the official |
| 45 | API reference: |
| 46 | http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes-with-details |
| 47 | http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 48 | """ |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 49 | url = 'volumes' |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 50 | if detail: |
| 51 | url += '/detail' |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 52 | if params: |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 53 | url += '?%s' % self._prepare_params(params) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 54 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 55 | resp, body = self.get(url) |
| 56 | body = json.loads(body) |
| 57 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 58 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 59 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 60 | def show_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 61 | """Returns the details of a single volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 62 | url = "volumes/%s" % volume_id |
Attila Fazekas | b8aa759 | 2013-01-26 01:25:45 +0100 | [diff] [blame] | 63 | resp, body = self.get(url) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 64 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 65 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 66 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 67 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 68 | def create_volume(self, **kwargs): |
Ken'ichi Ohmichi | b279084 | 2015-11-17 11:46:13 +0000 | [diff] [blame] | 69 | """Creates a new Volume. |
| 70 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 71 | For a full list of available parameters, please refer to the official |
| 72 | API reference: |
Andrea Frittoli | 2715d22 | 2017-03-29 14:53:48 +0100 | [diff] [blame] | 73 | http://developer.openstack.org/api-ref/block-storage/v2/#create-volume |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 74 | """ |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 75 | post_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 76 | resp, body = self.post('volumes', post_body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 77 | body = json.loads(body) |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 78 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 79 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 80 | |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 81 | def update_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 82 | """Updates the Specified Volume. |
| 83 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 84 | For a full list of available parameters, please refer to the official |
| 85 | API reference: |
Andrea Frittoli | 2715d22 | 2017-03-29 14:53:48 +0100 | [diff] [blame] | 86 | http://developer.openstack.org/api-ref/block-storage/v2/#update-volume |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 87 | """ |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 88 | put_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 89 | resp, body = self.put('volumes/%s' % volume_id, put_body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 90 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 91 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 92 | return rest_client.ResponseBody(resp, body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 93 | |
Jordan Pittier | cb5f650 | 2017-04-10 14:27:39 +0200 | [diff] [blame] | 94 | def delete_volume(self, volume_id, **params): |
| 95 | """Deletes the Specified Volume. |
| 96 | |
| 97 | For a full list of available parameters, please refer to the official |
| 98 | API reference: |
| 99 | https://developer.openstack.org/api-ref/block-storage/v2/#delete-volume |
| 100 | """ |
lkuchlan | 0e3bbdf | 2016-07-11 12:06:51 +0300 | [diff] [blame] | 101 | url = 'volumes/%s' % volume_id |
Jordan Pittier | cb5f650 | 2017-04-10 14:27:39 +0200 | [diff] [blame] | 102 | if params: |
| 103 | url += '?%s' % urllib.urlencode(params) |
lkuchlan | 0e3bbdf | 2016-07-11 12:06:51 +0300 | [diff] [blame] | 104 | resp, body = self.delete(url) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 105 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 106 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 107 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 108 | def upload_volume(self, volume_id, **kwargs): |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 109 | """Uploads a volume in Glance.""" |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 110 | post_body = json.dumps({'os-volume_upload_image': kwargs}) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 111 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 112 | resp, body = self.post(url, post_body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 113 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 114 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 115 | return rest_client.ResponseBody(resp, body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 116 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 117 | def attach_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 118 | """Attaches a volume to a given instance on a given mountpoint. |
| 119 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 120 | For a full list of available parameters, please refer to the official |
| 121 | API reference: |
zhufl | ccd9d65 | 2017-03-30 15:01:49 +0800 | [diff] [blame] | 122 | http://developer.openstack.org/api-ref/block-storage/v2/#attach-volume-to-server |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 123 | """ |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 124 | post_body = json.dumps({'os-attach': kwargs}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 125 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 126 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 127 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 128 | return rest_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 129 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 130 | def set_bootable_volume(self, volume_id, **kwargs): |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 131 | """Set a bootable flag for a volume - true or false. |
| 132 | |
| 133 | For a full list of available parameters, please refer to the official |
| 134 | API reference: |
| 135 | http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-bootable-status |
| 136 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 137 | post_body = json.dumps({'os-set_bootable': kwargs}) |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 138 | url = 'volumes/%s/action' % (volume_id) |
| 139 | resp, body = self.post(url, post_body) |
| 140 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 141 | return rest_client.ResponseBody(resp, body) |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 142 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 143 | def detach_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 144 | """Detaches a volume from an instance.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 145 | post_body = json.dumps({'os-detach': {}}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 146 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 147 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 148 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 149 | return rest_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 150 | |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 151 | def reserve_volume(self, volume_id): |
| 152 | """Reserves a volume.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 153 | post_body = json.dumps({'os-reserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 154 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 155 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 156 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 157 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 158 | |
| 159 | def unreserve_volume(self, volume_id): |
| 160 | """Restore a reserved volume .""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 161 | post_body = json.dumps({'os-unreserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 162 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 163 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 164 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 165 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 166 | |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 167 | def is_resource_deleted(self, id): |
Ken'ichi Ohmichi | 4723fde | 2017-04-26 14:19:57 -0700 | [diff] [blame] | 168 | """Check the specified resource is deleted or not. |
| 169 | |
| 170 | :param id: A checked resource id |
| 171 | :raises lib_exc.DeleteErrorException: If the specified resource is on |
| 172 | the status the delete was failed. |
| 173 | """ |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 174 | try: |
Ken'ichi Ohmichi | 4723fde | 2017-04-26 14:19:57 -0700 | [diff] [blame] | 175 | volume = self.show_volume(id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 176 | except lib_exc.NotFound: |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 177 | return True |
Ken'ichi Ohmichi | 4723fde | 2017-04-26 14:19:57 -0700 | [diff] [blame] | 178 | if volume["volume"]["status"] == "error_deleting": |
| 179 | raise lib_exc.DeleteErrorException(resource_id=id) |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 180 | return False |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 181 | |
Matt Riedemann | d2b9651 | 2014-10-13 10:18:16 -0700 | [diff] [blame] | 182 | @property |
| 183 | def resource_type(self): |
| 184 | """Returns the primary type of resource this client works with.""" |
| 185 | return 'volume' |
| 186 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 187 | def extend_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 188 | """Extend a volume. |
| 189 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 190 | For a full list of available parameters, please refer to the official |
| 191 | API reference: |
zhufl | ccd9d65 | 2017-03-30 15:01:49 +0800 | [diff] [blame] | 192 | http://developer.openstack.org/api-ref/block-storage/v2/#extend-volume-size |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 193 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 194 | post_body = json.dumps({'os-extend': kwargs}) |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 195 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 196 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 197 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 198 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 199 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 200 | def reset_volume_status(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 201 | """Reset the Specified Volume's Status. |
| 202 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 203 | For a full list of available parameters, please refer to the official |
| 204 | API reference: |
zhufl | ccd9d65 | 2017-03-30 15:01:49 +0800 | [diff] [blame] | 205 | http://developer.openstack.org/api-ref/block-storage/v2/#reset-volume-statuses |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 206 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 207 | post_body = json.dumps({'os-reset_status': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 208 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 209 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 210 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 211 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 212 | def update_volume_readonly(self, volume_id, **kwargs): |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 213 | """Update the Specified Volume readonly.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 214 | post_body = json.dumps({'os-update_readonly_flag': kwargs}) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 215 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 216 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 217 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 218 | return rest_client.ResponseBody(resp, body) |
wanghao | 9d3d6cb | 2013-11-12 15:10:10 +0800 | [diff] [blame] | 219 | |
| 220 | def force_delete_volume(self, volume_id): |
| 221 | """Force Delete Volume.""" |
| 222 | post_body = json.dumps({'os-force_delete': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 223 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 224 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 225 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 226 | |
| 227 | def create_volume_metadata(self, volume_id, metadata): |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 228 | """Create metadata for the volume. |
| 229 | |
| 230 | For a full list of available parameters, please refer to the official |
| 231 | API reference: |
| 232 | http://developer.openstack.org/api-ref/block-storage/v2/#create-volume-metadata |
| 233 | """ |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 234 | put_body = json.dumps({'metadata': metadata}) |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 235 | url = "volumes/%s/metadata" % volume_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 236 | resp, body = self.post(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 237 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 238 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 239 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 240 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 241 | def show_volume_metadata(self, volume_id): |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 242 | """Get metadata of the volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 243 | url = "volumes/%s/metadata" % volume_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 244 | resp, body = self.get(url) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 245 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 246 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 247 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 248 | |
| 249 | def update_volume_metadata(self, volume_id, metadata): |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 250 | """Update metadata for the volume. |
| 251 | |
| 252 | For a full list of available parameters, please refer to the official |
| 253 | API reference: |
| 254 | http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-metadata |
| 255 | """ |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 256 | put_body = json.dumps({'metadata': metadata}) |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 257 | url = "volumes/%s/metadata" % volume_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 258 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 259 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 260 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 261 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 262 | |
jeremy.zhang | b40cb19 | 2017-07-04 12:56:59 +0800 | [diff] [blame] | 263 | def show_volume_metadata_item(self, volume_id, id): |
| 264 | """Show metadata item for the volume.""" |
| 265 | url = "volumes/%s/metadata/%s" % (volume_id, id) |
| 266 | resp, body = self.get(url) |
| 267 | body = json.loads(body) |
| 268 | self.expected_success(200, resp.status) |
| 269 | return rest_client.ResponseBody(resp, body) |
| 270 | |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 271 | def update_volume_metadata_item(self, volume_id, id, meta_item): |
| 272 | """Update metadata item for the volume.""" |
| 273 | put_body = json.dumps({'meta': meta_item}) |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 274 | url = "volumes/%s/metadata/%s" % (volume_id, id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 275 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 276 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 277 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 278 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 279 | |
| 280 | def delete_volume_metadata_item(self, volume_id, id): |
| 281 | """Delete metadata item for the volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 282 | url = "volumes/%s/metadata/%s" % (volume_id, id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 283 | resp, body = self.delete(url) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 284 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 285 | return rest_client.ResponseBody(resp, body) |
Zhi Kun Liu | 6e6cf83 | 2014-05-08 17:25:22 +0800 | [diff] [blame] | 286 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 287 | def retype_volume(self, volume_id, **kwargs): |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 288 | """Updates volume with new volume type. |
| 289 | |
| 290 | For a full list of available parameters, please refer to the official |
| 291 | API reference: |
| 292 | https://developer.openstack.org/api-ref/block-storage/v2/#retype-volume |
| 293 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 294 | post_body = json.dumps({'os-retype': kwargs}) |
nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 295 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| 296 | self.expected_success(202, resp.status) |
raigax9 | d850882 | 2017-07-12 18:31:39 -0400 | [diff] [blame] | 297 | return rest_client.ResponseBody(resp, body) |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 298 | |
jeremy.zhang | 7b0eaf8 | 2017-04-25 15:11:15 +0800 | [diff] [blame] | 299 | def force_detach_volume(self, volume_id, **kwargs): |
| 300 | """Force detach a volume. |
| 301 | |
| 302 | For a full list of available parameters, please refer to the official |
| 303 | API reference: |
| 304 | https://developer.openstack.org/api-ref/block-storage/v2/#force-detach-volume |
| 305 | """ |
| 306 | post_body = json.dumps({'os-force_detach': kwargs}) |
| 307 | url = 'volumes/%s/action' % volume_id |
| 308 | resp, body = self.post(url, post_body) |
| 309 | self.expected_success(202, resp.status) |
| 310 | return rest_client.ResponseBody(resp, body) |
| 311 | |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 312 | def update_volume_image_metadata(self, volume_id, **kwargs): |
| 313 | """Update image metadata for the volume. |
| 314 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 315 | For a full list of available parameters, please refer to the official |
| 316 | API reference: |
zhufl | ccd9d65 | 2017-03-30 15:01:49 +0800 | [diff] [blame] | 317 | http://developer.openstack.org/api-ref/block-storage/v2/#set-image-metadata-for-volume |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 318 | """ |
| 319 | post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}}) |
| 320 | url = "volumes/%s/action" % (volume_id) |
| 321 | resp, body = self.post(url, post_body) |
| 322 | body = json.loads(body) |
| 323 | self.expected_success(200, resp.status) |
| 324 | return rest_client.ResponseBody(resp, body) |
| 325 | |
| 326 | def delete_volume_image_metadata(self, volume_id, key_name): |
| 327 | """Delete image metadata item for the volume.""" |
| 328 | post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}}) |
| 329 | url = "volumes/%s/action" % (volume_id) |
| 330 | resp, body = self.post(url, post_body) |
| 331 | self.expected_success(200, resp.status) |
| 332 | return rest_client.ResponseBody(resp, body) |
| 333 | |
jeremy.zhang | f0599b1 | 2017-08-03 20:02:51 +0800 | [diff] [blame] | 334 | def show_volume_image_metadata(self, volume_id): |
| 335 | """Show image metadata for the volume.""" |
| 336 | post_body = json.dumps({'os-show_image_metadata': {}}) |
| 337 | url = "volumes/%s/action" % volume_id |
| 338 | resp, body = self.post(url, post_body) |
| 339 | body = json.loads(body) |
| 340 | self.expected_success(200, resp.status) |
| 341 | return rest_client.ResponseBody(resp, body) |
| 342 | |
Masayuki Igawa | 2b96098 | 2017-06-05 11:16:59 +0900 | [diff] [blame] | 343 | @removals.remove(message="use list_pools from tempest.lib.services." |
lkuchlan | 7bba16c | 2016-09-04 12:36:04 +0300 | [diff] [blame] | 344 | "volume.v2.scheduler_stats_client") |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 345 | def show_pools(self, detail=False): |
| 346 | # List all the volumes pools (hosts) |
| 347 | url = 'scheduler-stats/get_pools' |
| 348 | if detail: |
| 349 | url += '?detail=True' |
| 350 | |
| 351 | resp, body = self.get(url) |
| 352 | body = json.loads(body) |
| 353 | self.expected_success(200, resp.status) |
| 354 | return rest_client.ResponseBody(resp, body) |
| 355 | |
lkuchlan | 7bba16c | 2016-09-04 12:36:04 +0300 | [diff] [blame] | 356 | @removals.remove(message="use show_backend_capabilities from tempest.lib." |
| 357 | "services.volume.v2.capabilities_client") |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 358 | def show_backend_capabilities(self, host): |
| 359 | """Shows capabilities for a storage back end. |
| 360 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 361 | For a full list of available parameters, please refer to the official |
| 362 | API reference: |
zhufl | ccd9d65 | 2017-03-30 15:01:49 +0800 | [diff] [blame] | 363 | http://developer.openstack.org/api-ref/block-storage/v2/#show-back-end-capabilities |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 364 | """ |
| 365 | url = 'capabilities/%s' % host |
| 366 | resp, body = self.get(url) |
| 367 | body = json.loads(body) |
| 368 | self.expected_success(200, resp.status) |
| 369 | return rest_client.ResponseBody(resp, body) |
jeremy.zhang | f4fbf30 | 2017-03-22 11:25:53 +0800 | [diff] [blame] | 370 | |
| 371 | def unmanage_volume(self, volume_id): |
| 372 | """Unmanage volume. |
| 373 | |
| 374 | For a full list of available parameters, please refer to the official |
| 375 | API reference: |
| 376 | https://developer.openstack.org/api-ref/block-storage/v2/#unmanage-volume |
| 377 | """ |
| 378 | post_body = json.dumps({'os-unmanage': {}}) |
| 379 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| 380 | self.expected_success(202, resp.status) |
| 381 | return rest_client.ResponseBody(resp, body) |