blob: a719b7964bac00cadb97cfdd7f53d7cf2e5e2f74 [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
16from tempest.common.utils import data_utils as utils
17from 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
46 self.volume_qos_client.delete_qos(body['id'])
47 self.volume_qos_client.wait_for_resource_deletion(body['id'])
48
49 # validate the deletion
50 _, list_qos = self.volume_qos_client.list_qos()
51 self.assertNotIn(body, list_qos)
52
53 def _create_test_volume_type(self):
54 vol_type_name = utils.rand_name("volume-type")
55 _, vol_type = self.volume_types_client.create_volume_type(
56 vol_type_name)
57 self.addCleanup(self.volume_types_client.delete_volume_type,
58 vol_type['id'])
59 return vol_type
60
61 def _test_associate_qos(self, vol_type_id):
62 self.volume_qos_client.associate_qos(
63 self.created_qos['id'], vol_type_id)
64
65 def _test_get_association_qos(self):
66 _, body = self.volume_qos_client.get_association_qos(
67 self.created_qos['id'])
68
69 associations = []
70 for association in body:
71 associations.append(association['id'])
72
73 return associations
74
75 def test_create_delete_qos_with_front_end_consumer(self):
76 """Tests the creation and deletion of QoS specs
77
78 With consumer as front end
79 """
80 self._create_delete_test_qos_with_given_consumer('front-end')
81
82 def test_create_delete_qos_with_back_end_consumer(self):
83 """Tests the creation and deletion of QoS specs
84
85 With consumer as back-end
86 """
87 self._create_delete_test_qos_with_given_consumer('back-end')
88
89 @test.attr(type='smoke')
90 def test_create_delete_qos_with_both_consumer(self):
91 """Tests the creation and deletion of QoS specs
92
93 With consumer as both front end and back end
94 """
95 self._create_delete_test_qos_with_given_consumer('both')
96
97 @test.attr(type='smoke')
98 def test_get_qos(self):
99 """Tests the detail of a given qos-specs"""
100 _, body = self.volume_qos_client.get_qos(self.created_qos['id'])
101 self.assertEqual(self.qos_name, body['name'])
102 self.assertEqual(self.qos_consumer, body['consumer'])
103
104 @test.attr(type='smoke')
105 def test_list_qos(self):
106 """Tests the list of all qos-specs"""
107 _, body = self.volume_qos_client.list_qos()
108 self.assertIn(self.created_qos, body)
109
110 @test.attr(type='smoke')
111 def test_set_unset_qos_key(self):
112 """Test the addition of a specs key to qos-specs"""
113 args = {'iops_bytes': '500'}
114 _, body = self.volume_qos_client.set_qos_key(self.created_qos['id'],
115 iops_bytes='500')
116 self.assertEqual(args, body)
117 _, body = self.volume_qos_client.get_qos(self.created_qos['id'])
118 self.assertEqual(args['iops_bytes'], body['specs']['iops_bytes'])
119
120 # test the deletion of a specs key from qos-specs
121 keys = ['iops_bytes']
122 self.volume_qos_client.unset_qos_key(self.created_qos['id'], keys)
123 operation = 'qos-key-unset'
124 self.volume_qos_client.wait_for_qos_operations(self.created_qos['id'],
125 operation, keys)
126 _, body = self.volume_qos_client.get_qos(self.created_qos['id'])
127 self.assertNotIn(keys[0], body['specs'])
128
129 @test.attr(type='smoke')
130 def test_associate_disassociate_qos(self):
131 """Test the following operations :
132
133 1. associate_qos
134 2. get_association_qos
135 3. disassociate_qos
136 4. disassociate_all_qos
137 """
138
139 # create a test volume-type
140 vol_type = []
141 for _ in range(0, 3):
142 vol_type.append(self._create_test_volume_type())
143
144 # associate the qos-specs with volume-types
145 for i in range(0, 3):
146 self._test_associate_qos(vol_type[i]['id'])
147
148 # get the association of the qos-specs
149 associations = self._test_get_association_qos()
150
151 for i in range(0, 3):
152 self.assertIn(vol_type[i]['id'], associations)
153
154 # disassociate a volume-type with qos-specs
155 self.volume_qos_client.disassociate_qos(
156 self.created_qos['id'], vol_type[0]['id'])
157 operation = 'disassociate'
158 self.volume_qos_client.wait_for_qos_operations(self.created_qos['id'],
159 operation,
160 vol_type[0]['id'])
161 associations = self._test_get_association_qos()
162 self.assertNotIn(vol_type[0]['id'], associations)
163
164 # disassociate all volume-types from qos-specs
165 self.volume_qos_client.disassociate_all_qos(
166 self.created_qos['id'])
167 operation = 'disassociate-all'
168 self.volume_qos_client.wait_for_qos_operations(self.created_qos['id'],
169 operation)
170 associations = self._test_get_association_qos()
171 self.assertEmpty(associations)
172
173
174class QosSpecsV1TestJSON(QosSpecsV2TestJSON):
175 _api_version = 1