blob: 68e57f5a08cfe643ec7d196eb05efdf5f729cefb [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
15from tempest.api.volume import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120016from tempest.common.utils import data_utils as utils
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000017from tempest import test
18
19
20class QosSpecsV2TestJSON(base.BaseVolumeAdminTest):
21 """Test the Cinder QoS-specs.
22
23 Tests for create, list, delete, show, associate,
24 disassociate, set/unset key V2 APIs.
25 """
26
27 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010028 def resource_setup(cls):
29 super(QosSpecsV2TestJSON, cls).resource_setup()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000030 # Create admin qos client
31 # Create a test shared qos-specs for tests
32 cls.qos_name = utils.rand_name(cls.__name__ + '-QoS')
33 cls.qos_consumer = 'front-end'
34
35 cls.created_qos = cls.create_test_qos_specs(cls.qos_name,
36 cls.qos_consumer,
37 read_iops_sec='2000')
38
39 def _create_delete_test_qos_with_given_consumer(self, consumer):
40 name = utils.rand_name('qos')
41 qos = {'name': name, 'consumer': consumer}
42 body = self.create_test_qos_specs(name, consumer)
43 for key in ['name', 'consumer']:
44 self.assertEqual(qos[key], body[key])
45
bkopilov62d21752016-06-08 10:16:11 +030046 self.admin_volume_qos_client.delete_qos(body['id'])
47 self.admin_volume_qos_client.wait_for_resource_deletion(body['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000048
49 # validate the deletion
bkopilov62d21752016-06-08 10:16:11 +030050 list_qos = self.admin_volume_qos_client.list_qos()['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000051 self.assertNotIn(body, list_qos)
52
53 def _create_test_volume_type(self):
54 vol_type_name = utils.rand_name("volume-type")
bkopilov62d21752016-06-08 10:16:11 +030055 vol_type = self.admin_volume_types_client.create_volume_type(
lei zhang83c4bbd2015-11-27 00:35:21 +080056 name=vol_type_name)['volume_type']
bkopilov62d21752016-06-08 10:16:11 +030057 self.addCleanup(self.admin_volume_types_client.delete_volume_type,
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000058 vol_type['id'])
59 return vol_type
60
61 def _test_associate_qos(self, vol_type_id):
bkopilov62d21752016-06-08 10:16:11 +030062 self.admin_volume_qos_client.associate_qos(
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000063 self.created_qos['id'], vol_type_id)
64
65 def _test_get_association_qos(self):
bkopilov62d21752016-06-08 10:16:11 +030066 body = self.admin_volume_qos_client.show_association_qos(
John Warren3836f3d2015-08-13 18:08:52 +000067 self.created_qos['id'])['qos_associations']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000068
69 associations = []
70 for association in body:
71 associations.append(association['id'])
72
73 return associations
74
Chris Hoge7579c1a2015-02-26 14:12:15 -080075 @test.idempotent_id('7e15f883-4bef-49a9-95eb-f94209a1ced1')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000076 def test_create_delete_qos_with_front_end_consumer(self):
77 """Tests the creation and deletion of QoS specs
78
79 With consumer as front end
80 """
81 self._create_delete_test_qos_with_given_consumer('front-end')
82
Chris Hoge7579c1a2015-02-26 14:12:15 -080083 @test.idempotent_id('b115cded-8f58-4ee4-aab5-9192cfada08f')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000084 def test_create_delete_qos_with_back_end_consumer(self):
85 """Tests the creation and deletion of QoS specs
86
87 With consumer as back-end
88 """
89 self._create_delete_test_qos_with_given_consumer('back-end')
90
Chris Hoge7579c1a2015-02-26 14:12:15 -080091 @test.idempotent_id('f88d65eb-ea0d-487d-af8d-71f4011575a4')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000092 def test_create_delete_qos_with_both_consumer(self):
93 """Tests the creation and deletion of QoS specs
94
95 With consumer as both front end and back end
96 """
97 self._create_delete_test_qos_with_given_consumer('both')
98
Chris Hoge7579c1a2015-02-26 14:12:15 -080099 @test.idempotent_id('7aa214cc-ac1a-4397-931f-3bb2e83bb0fd')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000100 def test_get_qos(self):
101 """Tests the detail of a given qos-specs"""
bkopilov62d21752016-06-08 10:16:11 +0300102 body = self.admin_volume_qos_client.show_qos(
John Warren3836f3d2015-08-13 18:08:52 +0000103 self.created_qos['id'])['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000104 self.assertEqual(self.qos_name, body['name'])
105 self.assertEqual(self.qos_consumer, body['consumer'])
106
Chris Hoge7579c1a2015-02-26 14:12:15 -0800107 @test.idempotent_id('75e04226-bcf7-4595-a34b-fdf0736f38fc')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000108 def test_list_qos(self):
109 """Tests the list of all qos-specs"""
bkopilov62d21752016-06-08 10:16:11 +0300110 body = self.admin_volume_qos_client.list_qos()['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000111 self.assertIn(self.created_qos, body)
112
Chris Hoge7579c1a2015-02-26 14:12:15 -0800113 @test.idempotent_id('ed00fd85-4494-45f2-8ceb-9e2048919aed')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000114 def test_set_unset_qos_key(self):
115 """Test the addition of a specs key to qos-specs"""
116 args = {'iops_bytes': '500'}
bkopilov62d21752016-06-08 10:16:11 +0300117 body = self.admin_volume_qos_client.set_qos_key(
John Warren3836f3d2015-08-13 18:08:52 +0000118 self.created_qos['id'],
119 iops_bytes='500')['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000120 self.assertEqual(args, body)
bkopilov62d21752016-06-08 10:16:11 +0300121 body = self.admin_volume_qos_client.show_qos(
John Warren3836f3d2015-08-13 18:08:52 +0000122 self.created_qos['id'])['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000123 self.assertEqual(args['iops_bytes'], body['specs']['iops_bytes'])
124
125 # test the deletion of a specs key from qos-specs
126 keys = ['iops_bytes']
bkopilov62d21752016-06-08 10:16:11 +0300127 self.admin_volume_qos_client.unset_qos_key(self.created_qos['id'],
128 keys)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000129 operation = 'qos-key-unset'
bkopilov62d21752016-06-08 10:16:11 +0300130 self.admin_volume_qos_client.wait_for_qos_operations(
131 self.created_qos['id'], operation, keys)
132 body = self.admin_volume_qos_client.show_qos(
John Warren3836f3d2015-08-13 18:08:52 +0000133 self.created_qos['id'])['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000134 self.assertNotIn(keys[0], body['specs'])
135
Chris Hoge7579c1a2015-02-26 14:12:15 -0800136 @test.idempotent_id('1dd93c76-6420-485d-a771-874044c416ac')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000137 def test_associate_disassociate_qos(self):
138 """Test the following operations :
139
140 1. associate_qos
141 2. get_association_qos
142 3. disassociate_qos
143 4. disassociate_all_qos
144 """
145
146 # create a test volume-type
147 vol_type = []
148 for _ in range(0, 3):
149 vol_type.append(self._create_test_volume_type())
150
151 # associate the qos-specs with volume-types
152 for i in range(0, 3):
153 self._test_associate_qos(vol_type[i]['id'])
154
155 # get the association of the qos-specs
156 associations = self._test_get_association_qos()
157
158 for i in range(0, 3):
159 self.assertIn(vol_type[i]['id'], associations)
160
161 # disassociate a volume-type with qos-specs
bkopilov62d21752016-06-08 10:16:11 +0300162 self.admin_volume_qos_client.disassociate_qos(
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000163 self.created_qos['id'], vol_type[0]['id'])
164 operation = 'disassociate'
bkopilov62d21752016-06-08 10:16:11 +0300165 self.admin_volume_qos_client.wait_for_qos_operations(
166 self.created_qos['id'], operation, vol_type[0]['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000167 associations = self._test_get_association_qos()
168 self.assertNotIn(vol_type[0]['id'], associations)
169
170 # disassociate all volume-types from qos-specs
bkopilov62d21752016-06-08 10:16:11 +0300171 self.admin_volume_qos_client.disassociate_all_qos(
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000172 self.created_qos['id'])
173 operation = 'disassociate-all'
bkopilov62d21752016-06-08 10:16:11 +0300174 self.admin_volume_qos_client.wait_for_qos_operations(
175 self.created_qos['id'], operation)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000176 associations = self._test_get_association_qos()
177 self.assertEmpty(associations)
178
179
180class QosSpecsV1TestJSON(QosSpecsV2TestJSON):
181 _api_version = 1