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): |
| 22 | """Volume V1 QoS client. |
| 23 | |
| 24 | Client class to send CRUD QoS API requests |
| 25 | """ |
| 26 | |
| 27 | api_version = "v1" |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 28 | |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 29 | def is_resource_deleted(self, qos_id): |
| 30 | try: |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 31 | self.show_qos(qos_id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 32 | except lib_exc.NotFound: |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 33 | return True |
| 34 | return False |
| 35 | |
Matt Riedemann | d2b9651 | 2014-10-13 10:18:16 -0700 | [diff] [blame] | 36 | @property |
| 37 | def resource_type(self): |
| 38 | """Returns the primary type of resource this client works with.""" |
| 39 | return 'qos' |
| 40 | |
Jordan Pittier | 0359c4d | 2015-12-09 14:34:58 +0100 | [diff] [blame] | 41 | def create_qos(self, **kwargs): |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 42 | """Create a QoS Specification. |
| 43 | |
dharmendra | e139b23 | 2016-11-16 15:19:42 +0900 | [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/#create-qos-specification |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 47 | """ |
Jordan Pittier | 0359c4d | 2015-12-09 14:34:58 +0100 | [diff] [blame] | 48 | post_body = json.dumps({'qos_specs': kwargs}) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 49 | resp, body = self.post('qos-specs', post_body) |
| 50 | self.expected_success(200, resp.status) |
| 51 | body = json.loads(body) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 52 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 53 | |
| 54 | def delete_qos(self, qos_id, force=False): |
| 55 | """Delete the specified QoS specification.""" |
| 56 | resp, body = self.delete( |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 57 | "qos-specs/%s?force=%s" % (qos_id, force)) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 58 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 59 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 60 | |
| 61 | def list_qos(self): |
| 62 | """List all the QoS specifications created.""" |
| 63 | url = 'qos-specs' |
| 64 | resp, body = self.get(url) |
| 65 | body = json.loads(body) |
| 66 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 67 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 68 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 69 | def show_qos(self, qos_id): |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 70 | """Get the specified QoS specification.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 71 | url = "qos-specs/%s" % qos_id |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 72 | resp, body = self.get(url) |
| 73 | body = json.loads(body) |
| 74 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 75 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 76 | |
| 77 | def set_qos_key(self, qos_id, **kwargs): |
| 78 | """Set the specified keys/values of QoS specification. |
| 79 | |
dharmendra | e139b23 | 2016-11-16 15:19:42 +0900 | [diff] [blame] | 80 | For a full list of available parameters, please refer to the official |
| 81 | API reference: |
| 82 | 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] | 83 | """ |
| 84 | put_body = json.dumps({"qos_specs": kwargs}) |
| 85 | resp, body = self.put('qos-specs/%s' % qos_id, put_body) |
| 86 | body = json.loads(body) |
| 87 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 88 | return rest_client.ResponseBody(resp, body) |
Swapnil Kulkarni | 7dba3e6 | 2014-08-14 09:05:07 +0000 | [diff] [blame] | 89 | |
| 90 | def unset_qos_key(self, qos_id, keys): |
| 91 | """Unset the specified keys of QoS specification. |
| 92 | |
Jordan Pittier | 0359c4d | 2015-12-09 14:34:58 +0100 | [diff] [blame] | 93 | :param keys: keys to delete from the QoS specification. |
| 94 | |
| 95 | TODO(jordanP): Add a link once LP #1524877 is fixed. |
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) |