blob: f8067900067739430fe38952d51eff76674fd3a6 [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 Treinish01472ff2015-02-20 17:26:52 -050015from tempest_lib.common.utils import data_utils as utils
16
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000017from tempest.api.volume import base
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000018from tempest import test
19
20
21class QosSpecsV2TestJSON(base.BaseVolumeAdminTest):
22 """Test the Cinder QoS-specs.
23
24 Tests for create, list, delete, show, associate,
25 disassociate, set/unset key V2 APIs.
26 """
27
28 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010029 def resource_setup(cls):
30 super(QosSpecsV2TestJSON, cls).resource_setup()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000031 # Create admin qos client
32 # Create a test shared qos-specs for tests
33 cls.qos_name = utils.rand_name(cls.__name__ + '-QoS')
34 cls.qos_consumer = 'front-end'
35
36 cls.created_qos = cls.create_test_qos_specs(cls.qos_name,
37 cls.qos_consumer,
38 read_iops_sec='2000')
39
40 def _create_delete_test_qos_with_given_consumer(self, consumer):
41 name = utils.rand_name('qos')
42 qos = {'name': name, 'consumer': consumer}
43 body = self.create_test_qos_specs(name, consumer)
44 for key in ['name', 'consumer']:
45 self.assertEqual(qos[key], body[key])
46
47 self.volume_qos_client.delete_qos(body['id'])
48 self.volume_qos_client.wait_for_resource_deletion(body['id'])
49
50 # validate the deletion
Joseph Lanoux6809bab2014-12-18 14:57:18 +000051 list_qos = self.volume_qos_client.list_qos()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000052 self.assertNotIn(body, list_qos)
53
54 def _create_test_volume_type(self):
55 vol_type_name = utils.rand_name("volume-type")
Joseph Lanoux6809bab2014-12-18 14:57:18 +000056 vol_type = self.volume_types_client.create_volume_type(
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000057 vol_type_name)
58 self.addCleanup(self.volume_types_client.delete_volume_type,
59 vol_type['id'])
60 return vol_type
61
62 def _test_associate_qos(self, vol_type_id):
63 self.volume_qos_client.associate_qos(
64 self.created_qos['id'], vol_type_id)
65
66 def _test_get_association_qos(self):
Joseph Lanoux6809bab2014-12-18 14:57:18 +000067 body = self.volume_qos_client.get_association_qos(
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000068 self.created_qos['id'])
69
70 associations = []
71 for association in body:
72 associations.append(association['id'])
73
74 return associations
75
Chris Hoge7579c1a2015-02-26 14:12:15 -080076 @test.idempotent_id('7e15f883-4bef-49a9-95eb-f94209a1ced1')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000077 def test_create_delete_qos_with_front_end_consumer(self):
78 """Tests the creation and deletion of QoS specs
79
80 With consumer as front end
81 """
82 self._create_delete_test_qos_with_given_consumer('front-end')
83
Chris Hoge7579c1a2015-02-26 14:12:15 -080084 @test.idempotent_id('b115cded-8f58-4ee4-aab5-9192cfada08f')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000085 def test_create_delete_qos_with_back_end_consumer(self):
86 """Tests the creation and deletion of QoS specs
87
88 With consumer as back-end
89 """
90 self._create_delete_test_qos_with_given_consumer('back-end')
91
92 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080093 @test.idempotent_id('f88d65eb-ea0d-487d-af8d-71f4011575a4')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000094 def test_create_delete_qos_with_both_consumer(self):
95 """Tests the creation and deletion of QoS specs
96
97 With consumer as both front end and back end
98 """
99 self._create_delete_test_qos_with_given_consumer('both')
100
101 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800102 @test.idempotent_id('7aa214cc-ac1a-4397-931f-3bb2e83bb0fd')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000103 def test_get_qos(self):
104 """Tests the detail of a given qos-specs"""
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000105 body = self.volume_qos_client.get_qos(self.created_qos['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000106 self.assertEqual(self.qos_name, body['name'])
107 self.assertEqual(self.qos_consumer, body['consumer'])
108
109 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800110 @test.idempotent_id('75e04226-bcf7-4595-a34b-fdf0736f38fc')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000111 def test_list_qos(self):
112 """Tests the list of all qos-specs"""
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000113 body = self.volume_qos_client.list_qos()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000114 self.assertIn(self.created_qos, body)
115
116 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800117 @test.idempotent_id('ed00fd85-4494-45f2-8ceb-9e2048919aed')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000118 def test_set_unset_qos_key(self):
119 """Test the addition of a specs key to qos-specs"""
120 args = {'iops_bytes': '500'}
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000121 body = self.volume_qos_client.set_qos_key(self.created_qos['id'],
122 iops_bytes='500')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000123 self.assertEqual(args, body)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000124 body = self.volume_qos_client.get_qos(self.created_qos['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000125 self.assertEqual(args['iops_bytes'], body['specs']['iops_bytes'])
126
127 # test the deletion of a specs key from qos-specs
128 keys = ['iops_bytes']
129 self.volume_qos_client.unset_qos_key(self.created_qos['id'], keys)
130 operation = 'qos-key-unset'
131 self.volume_qos_client.wait_for_qos_operations(self.created_qos['id'],
132 operation, keys)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000133 body = self.volume_qos_client.get_qos(self.created_qos['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000134 self.assertNotIn(keys[0], body['specs'])
135
136 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800137 @test.idempotent_id('1dd93c76-6420-485d-a771-874044c416ac')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000138 def test_associate_disassociate_qos(self):
139 """Test the following operations :
140
141 1. associate_qos
142 2. get_association_qos
143 3. disassociate_qos
144 4. disassociate_all_qos
145 """
146
147 # create a test volume-type
148 vol_type = []
149 for _ in range(0, 3):
150 vol_type.append(self._create_test_volume_type())
151
152 # associate the qos-specs with volume-types
153 for i in range(0, 3):
154 self._test_associate_qos(vol_type[i]['id'])
155
156 # get the association of the qos-specs
157 associations = self._test_get_association_qos()
158
159 for i in range(0, 3):
160 self.assertIn(vol_type[i]['id'], associations)
161
162 # disassociate a volume-type with qos-specs
163 self.volume_qos_client.disassociate_qos(
164 self.created_qos['id'], vol_type[0]['id'])
165 operation = 'disassociate'
166 self.volume_qos_client.wait_for_qos_operations(self.created_qos['id'],
167 operation,
168 vol_type[0]['id'])
169 associations = self._test_get_association_qos()
170 self.assertNotIn(vol_type[0]['id'], associations)
171
172 # disassociate all volume-types from qos-specs
173 self.volume_qos_client.disassociate_all_qos(
174 self.created_qos['id'])
175 operation = 'disassociate-all'
176 self.volume_qos_client.wait_for_qos_operations(self.created_qos['id'],
177 operation)
178 associations = self._test_get_association_qos()
179 self.assertEmpty(associations)
180
181
182class QosSpecsV1TestJSON(QosSpecsV2TestJSON):
183 _api_version = 1