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