blob: f8b8c3cddb888ce7765f16774dce695db5848194 [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):
ghanshyam89c213f2017-12-14 07:22:12 +000022 """Volume QoS client.
David Paterson16c4cf22016-09-20 02:12:13 -070023
24 Client class to send CRUD QoS API requests
25 """
26
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000027 def is_resource_deleted(self, qos_id):
28 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000029 self.show_qos(qos_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +090030 except lib_exc.NotFound:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000031 return True
32 return False
33
Matt Riedemannd2b96512014-10-13 10:18:16 -070034 @property
35 def resource_type(self):
36 """Returns the primary type of resource this client works with."""
37 return 'qos'
38
Jordan Pittier0359c4d2015-12-09 14:34:58 +010039 def create_qos(self, **kwargs):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000040 """Create a QoS Specification.
41
Hanxi Liu3f3766b2016-09-28 17:43:35 +080042 For a full list of available parameters, please refer to the official
43 API reference:
zhufl32b2e302017-02-23 12:02:41 +080044 http://developer.openstack.org/api-ref/block-storage/v2/#create-qos-specification
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000045 """
Jordan Pittier0359c4d2015-12-09 14:34:58 +010046 post_body = json.dumps({'qos_specs': kwargs})
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000047 resp, body = self.post('qos-specs', post_body)
48 self.expected_success(200, resp.status)
49 body = json.loads(body)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080050 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000051
52 def delete_qos(self, qos_id, force=False):
53 """Delete the specified QoS specification."""
54 resp, body = self.delete(
guo yunxian6cdf0562016-08-17 16:21:52 +080055 "qos-specs/%s?force=%s" % (qos_id, force))
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000056 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080057 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000058
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 Ohmichi90d446a2016-03-02 10:17:38 -080065 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000066
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000067 def show_qos(self, qos_id):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000068 """Get the specified QoS specification."""
guo yunxian6cdf0562016-08-17 16:21:52 +080069 url = "qos-specs/%s" % qos_id
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000070 resp, body = self.get(url)
71 body = json.loads(body)
72 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080073 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000074
75 def set_qos_key(self, qos_id, **kwargs):
76 """Set the specified keys/values of QoS specification.
77
Hanxi Liu3f3766b2016-09-28 17:43:35 +080078 For a full list of available parameters, please refer to the official
79 API reference:
zhufl32b2e302017-02-23 12:02:41 +080080 http://developer.openstack.org/api-ref/block-storage/v2/#set-keys-in-qos-specification
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000081 """
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 Ohmichi90d446a2016-03-02 10:17:38 -080086 return rest_client.ResponseBody(resp, body)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000087
88 def unset_qos_key(self, qos_id, keys):
89 """Unset the specified keys of QoS specification.
90
Jordan Pittier0359c4d2015-12-09 14:34:58 +010091 :param keys: keys to delete from the QoS specification.
92
Hanxi Liu3f3766b2016-09-28 17:43:35 +080093 For a full list of available parameters, please refer to the official
94 API reference:
zhufl32b2e302017-02-23 12:02:41 +080095 http://developer.openstack.org/api-ref/block-storage/v2/#unset-keys-in-qos-specification
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)