blob: e247b7b7cf38bb5225f9a8fc22edd066c528fa10 [file] [log] [blame]
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +00001# 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 Treinish21905512015-07-13 10:33:35 -040015from oslo_serialization import jsonutils as json
Masayuki Igawadd759082015-01-20 14:35:20 +090016
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080017from tempest.lib.common import rest_client
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050018from tempest.lib import exceptions as lib_exc
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000019
20
David Paterson16c4cf22016-09-20 02:12:13 -070021class 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 Kulkarni7dba3e62014-08-14 09:05:07 +000028
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000029 def is_resource_deleted(self, qos_id):
30 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000031 self.show_qos(qos_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +090032 except lib_exc.NotFound:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000033 return True
34 return False
35
Matt Riedemannd2b96512014-10-13 10:18:16 -070036 @property
37 def resource_type(self):
38 """Returns the primary type of resource this client works with."""
39 return 'qos'
40
Jordan Pittier0359c4d2015-12-09 14:34:58 +010041 def create_qos(self, **kwargs):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000042 """Create a QoS Specification.
43
dharmendrae139b232016-11-16 15:19:42 +090044 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 Kulkarni7dba3e62014-08-14 09:05:07 +000047 """
Jordan Pittier0359c4d2015-12-09 14:34:58 +010048 post_body = json.dumps({'qos_specs': kwargs})
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000049 resp, body = self.post('qos-specs', post_body)
50 self.expected_success(200, resp.status)
51 body = json.loads(body)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080052 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000053
54 def delete_qos(self, qos_id, force=False):
55 """Delete the specified QoS specification."""
56 resp, body = self.delete(
guo yunxian6cdf0562016-08-17 16:21:52 +080057 "qos-specs/%s?force=%s" % (qos_id, force))
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000058 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080059 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000060
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 Ohmichi90d446a2016-03-02 10:17:38 -080067 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000068
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000069 def show_qos(self, qos_id):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000070 """Get the specified QoS specification."""
guo yunxian6cdf0562016-08-17 16:21:52 +080071 url = "qos-specs/%s" % qos_id
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000072 resp, body = self.get(url)
73 body = json.loads(body)
74 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080075 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000076
77 def set_qos_key(self, qos_id, **kwargs):
78 """Set the specified keys/values of QoS specification.
79
dharmendrae139b232016-11-16 15:19:42 +090080 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 Kulkarni7dba3e62014-08-14 09:05:07 +000083 """
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 Ohmichi90d446a2016-03-02 10:17:38 -080088 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000089
90 def unset_qos_key(self, qos_id, keys):
91 """Unset the specified keys of QoS specification.
92
Jordan Pittier0359c4d2015-12-09 14:34:58 +010093 :param keys: keys to delete from the QoS specification.
94
95 TODO(jordanP): Add a link once LP #1524877 is fixed.
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000096 """
97 put_body = json.dumps({'keys': keys})
Joseph Lanoux2cdd5502015-01-16 14:46:51 +000098 resp, body = self.put('qos-specs/%s/delete_keys' % qos_id, put_body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000099 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800100 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000101
102 def associate_qos(self, qos_id, vol_type_id):
103 """Associate the specified QoS with specified volume-type."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800104 url = "qos-specs/%s/associate" % qos_id
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000105 url += "?vol_type_id=%s" % vol_type_id
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000106 resp, body = self.get(url)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000107 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800108 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000109
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000110 def show_association_qos(self, qos_id):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000111 """Get the association of the specified QoS specification."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800112 url = "qos-specs/%s/associations" % qos_id
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000113 resp, body = self.get(url)
114 body = json.loads(body)
115 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800116 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000117
118 def disassociate_qos(self, qos_id, vol_type_id):
119 """Disassociate the specified QoS with specified volume-type."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800120 url = "qos-specs/%s/disassociate" % qos_id
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000121 url += "?vol_type_id=%s" % vol_type_id
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000122 resp, body = self.get(url)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000123 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800124 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000125
126 def disassociate_all_qos(self, qos_id):
127 """Disassociate the specified QoS with all associations."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800128 url = "qos-specs/%s/disassociate_all" % qos_id
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000129 resp, body = self.get(url)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000130 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800131 return rest_client.ResponseBody(resp, body)