Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 1 | # All Rights Reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 15 | from oslo_serialization import jsonutils as json |
Masayuki Igawa | dd75908 | 2015-01-20 14:35:20 +0900 | [diff] [blame] | 16 | |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 17 | from tempest.lib.common import rest_client |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 18 | from tempest.lib import exceptions as lib_exc |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 19 | |
| 20 | |
David Paterson | 16c4cf2 | 2016-09-20 02:12:13 -0700 | [diff] [blame] | 21 | class QosSpecsClient(rest_client.RestClient): |
ghanshyam | 89c213f | 2017-12-14 07:22:12 +0000 | [diff] [blame] | 22 | """Volume QoS client. |
David Paterson | 16c4cf2 | 2016-09-20 02:12:13 -0700 | [diff] [blame] | 23 | |
| 24 | Client class to send CRUD QoS API requests |
| 25 | """ |
| 26 | |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 27 | def is_resource_deleted(self, qos_id): |
| 28 | try: |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 29 | self.show_qos(qos_id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 30 | except lib_exc.NotFound: |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 31 | return True |
| 32 | return False |
| 33 | |
Matt Riedemann | d2b9651 | 2014-10-13 10:18:16 -0700 | [diff] [blame] | 34 | @property |
| 35 | def resource_type(self): |
| 36 | """Returns the primary type of resource this client works with.""" |
| 37 | return 'qos' |
| 38 | |
Jordan Pittier | 0359c4d | 2015-12-09 14:34:58 +0100 | [diff] [blame] | 39 | def create_qos(self, **kwargs): |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 40 | """Create a QoS Specification. |
| 41 | |
Hanxi Liu | 3f3766b | 2016-09-28 17:43:35 +0800 | [diff] [blame] | 42 | For a full list of available parameters, please refer to the official |
| 43 | API reference: |
zhufl | 32b2e30 | 2017-02-23 12:02:41 +0800 | [diff] [blame] | 44 | http://developer.openstack.org/api-ref/block-storage/v2/#create-qos-specification |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 45 | """ |
Jordan Pittier | 0359c4d | 2015-12-09 14:34:58 +0100 | [diff] [blame] | 46 | post_body = json.dumps({'qos_specs': kwargs}) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 47 | resp, body = self.post('qos-specs', post_body) |
| 48 | self.expected_success(200, resp.status) |
| 49 | body = json.loads(body) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 50 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 51 | |
| 52 | def delete_qos(self, qos_id, force=False): |
| 53 | """Delete the specified QoS specification.""" |
| 54 | resp, body = self.delete( |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 55 | "qos-specs/%s?force=%s" % (qos_id, force)) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 56 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 57 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 58 | |
| 59 | def list_qos(self): |
| 60 | """List all the QoS specifications created.""" |
| 61 | url = 'qos-specs' |
| 62 | resp, body = self.get(url) |
| 63 | body = json.loads(body) |
| 64 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 65 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 66 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 67 | def show_qos(self, qos_id): |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 68 | """Get the specified QoS specification.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 69 | url = "qos-specs/%s" % qos_id |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 70 | resp, body = self.get(url) |
| 71 | body = json.loads(body) |
| 72 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 73 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 74 | |
| 75 | def set_qos_key(self, qos_id, **kwargs): |
| 76 | """Set the specified keys/values of QoS specification. |
| 77 | |
Hanxi Liu | 3f3766b | 2016-09-28 17:43:35 +0800 | [diff] [blame] | 78 | For a full list of available parameters, please refer to the official |
| 79 | API reference: |
zhufl | 32b2e30 | 2017-02-23 12:02:41 +0800 | [diff] [blame] | 80 | http://developer.openstack.org/api-ref/block-storage/v2/#set-keys-in-qos-specification |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 81 | """ |
| 82 | put_body = json.dumps({"qos_specs": kwargs}) |
| 83 | resp, body = self.put('qos-specs/%s' % qos_id, put_body) |
| 84 | body = json.loads(body) |
| 85 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 86 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 87 | |
| 88 | def unset_qos_key(self, qos_id, keys): |
| 89 | """Unset the specified keys of QoS specification. |
| 90 | |
Jordan Pittier | 0359c4d | 2015-12-09 14:34:58 +0100 | [diff] [blame] | 91 | :param keys: keys to delete from the QoS specification. |
| 92 | |
Hanxi Liu | 3f3766b | 2016-09-28 17:43:35 +0800 | [diff] [blame] | 93 | For a full list of available parameters, please refer to the official |
| 94 | API reference: |
zhufl | 32b2e30 | 2017-02-23 12:02:41 +0800 | [diff] [blame] | 95 | http://developer.openstack.org/api-ref/block-storage/v2/#unset-keys-in-qos-specification |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 96 | """ |
| 97 | put_body = json.dumps({'keys': keys}) |
Joseph Lanoux | 2cdd550 | 2015-01-16 14:46:51 +0000 | [diff] [blame] | 98 | resp, body = self.put('qos-specs/%s/delete_keys' % qos_id, put_body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 99 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 100 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 101 | |
| 102 | def associate_qos(self, qos_id, vol_type_id): |
| 103 | """Associate the specified QoS with specified volume-type.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 104 | url = "qos-specs/%s/associate" % qos_id |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 105 | url += "?vol_type_id=%s" % vol_type_id |
Joseph Lanoux | 2cdd550 | 2015-01-16 14:46:51 +0000 | [diff] [blame] | 106 | resp, body = self.get(url) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 107 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 108 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 109 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 110 | def show_association_qos(self, qos_id): |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 111 | """Get the association of the specified QoS specification.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 112 | url = "qos-specs/%s/associations" % qos_id |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 113 | resp, body = self.get(url) |
| 114 | body = json.loads(body) |
| 115 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 116 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 117 | |
| 118 | def disassociate_qos(self, qos_id, vol_type_id): |
| 119 | """Disassociate the specified QoS with specified volume-type.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 120 | url = "qos-specs/%s/disassociate" % qos_id |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 121 | url += "?vol_type_id=%s" % vol_type_id |
Joseph Lanoux | 2cdd550 | 2015-01-16 14:46:51 +0000 | [diff] [blame] | 122 | resp, body = self.get(url) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 123 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 124 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 125 | |
| 126 | def disassociate_all_qos(self, qos_id): |
| 127 | """Disassociate the specified QoS with all associations.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 128 | url = "qos-specs/%s/disassociate_all" % qos_id |
Joseph Lanoux | 2cdd550 | 2015-01-16 14:46:51 +0000 | [diff] [blame] | 129 | resp, body = self.get(url) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +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) |