blob: 83f7e21a62082f8564fed1bbc186959176c224e0 [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
lkuchlanec1ba4f2016-09-06 10:28:18 +030016from tempest.common import waiters
Martin Kopec213d0a42023-11-30 10:28:14 +010017from tempest import config
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080018from tempest.lib.common.utils import data_utils as utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080019from tempest.lib import decorators
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000020
Martin Kopec213d0a42023-11-30 10:28:14 +010021CONF = config.CONF
22
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000023
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070024class QosSpecsTestJSON(base.BaseVolumeAdminTest):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000025 """Test the Cinder QoS-specs.
26
27 Tests for create, list, delete, show, associate,
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070028 disassociate, set/unset key APIs.
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000029 """
30
31 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010032 def resource_setup(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070033 super(QosSpecsTestJSON, cls).resource_setup()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000034 # Create admin qos client
35 # Create a test shared qos-specs for tests
Martin Kopec213d0a42023-11-30 10:28:14 +010036 cls.qos_name = utils.rand_name(
37 cls.__name__ + '-QoS', prefix=CONF.resource_name_prefix)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000038 cls.qos_consumer = 'front-end'
39
40 cls.created_qos = cls.create_test_qos_specs(cls.qos_name,
41 cls.qos_consumer,
42 read_iops_sec='2000')
43
44 def _create_delete_test_qos_with_given_consumer(self, consumer):
Martin Kopec213d0a42023-11-30 10:28:14 +010045 name = utils.rand_name(
46 self.__class__.__name__ + '-qos', prefix=CONF.resource_name_prefix)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000047 qos = {'name': name, 'consumer': consumer}
48 body = self.create_test_qos_specs(name, consumer)
49 for key in ['name', 'consumer']:
50 self.assertEqual(qos[key], body[key])
51
bkopilov62d21752016-06-08 10:16:11 +030052 self.admin_volume_qos_client.delete_qos(body['id'])
53 self.admin_volume_qos_client.wait_for_resource_deletion(body['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000054
55 # validate the deletion
bkopilov62d21752016-06-08 10:16:11 +030056 list_qos = self.admin_volume_qos_client.list_qos()['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000057 self.assertNotIn(body, list_qos)
58
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000059 def _test_associate_qos(self, vol_type_id):
bkopilov62d21752016-06-08 10:16:11 +030060 self.admin_volume_qos_client.associate_qos(
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000061 self.created_qos['id'], vol_type_id)
62
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080063 @decorators.idempotent_id('7e15f883-4bef-49a9-95eb-f94209a1ced1')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000064 def test_create_delete_qos_with_front_end_consumer(self):
65 """Tests the creation and deletion of QoS specs
66
67 With consumer as front end
68 """
69 self._create_delete_test_qos_with_given_consumer('front-end')
70
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080071 @decorators.idempotent_id('b115cded-8f58-4ee4-aab5-9192cfada08f')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000072 def test_create_delete_qos_with_back_end_consumer(self):
73 """Tests the creation and deletion of QoS specs
74
75 With consumer as back-end
76 """
77 self._create_delete_test_qos_with_given_consumer('back-end')
78
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080079 @decorators.idempotent_id('f88d65eb-ea0d-487d-af8d-71f4011575a4')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000080 def test_create_delete_qos_with_both_consumer(self):
81 """Tests the creation and deletion of QoS specs
82
83 With consumer as both front end and back end
84 """
85 self._create_delete_test_qos_with_given_consumer('both')
86
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080087 @decorators.idempotent_id('7aa214cc-ac1a-4397-931f-3bb2e83bb0fd')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000088 def test_get_qos(self):
89 """Tests the detail of a given qos-specs"""
bkopilov62d21752016-06-08 10:16:11 +030090 body = self.admin_volume_qos_client.show_qos(
John Warren3836f3d2015-08-13 18:08:52 +000091 self.created_qos['id'])['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000092 self.assertEqual(self.qos_name, body['name'])
93 self.assertEqual(self.qos_consumer, body['consumer'])
94
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080095 @decorators.idempotent_id('75e04226-bcf7-4595-a34b-fdf0736f38fc')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000096 def test_list_qos(self):
97 """Tests the list of all qos-specs"""
bkopilov62d21752016-06-08 10:16:11 +030098 body = self.admin_volume_qos_client.list_qos()['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +000099 self.assertIn(self.created_qos, body)
100
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800101 @decorators.idempotent_id('ed00fd85-4494-45f2-8ceb-9e2048919aed')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000102 def test_set_unset_qos_key(self):
103 """Test the addition of a specs key to qos-specs"""
104 args = {'iops_bytes': '500'}
bkopilov62d21752016-06-08 10:16:11 +0300105 body = self.admin_volume_qos_client.set_qos_key(
John Warren3836f3d2015-08-13 18:08:52 +0000106 self.created_qos['id'],
107 iops_bytes='500')['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000108 self.assertEqual(args, body)
bkopilov62d21752016-06-08 10:16:11 +0300109 body = self.admin_volume_qos_client.show_qos(
John Warren3836f3d2015-08-13 18:08:52 +0000110 self.created_qos['id'])['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000111 self.assertEqual(args['iops_bytes'], body['specs']['iops_bytes'])
112
113 # test the deletion of a specs key from qos-specs
114 keys = ['iops_bytes']
bkopilov62d21752016-06-08 10:16:11 +0300115 self.admin_volume_qos_client.unset_qos_key(self.created_qos['id'],
116 keys)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000117 operation = 'qos-key-unset'
lkuchlanec1ba4f2016-09-06 10:28:18 +0300118 waiters.wait_for_qos_operations(self.admin_volume_qos_client,
119 self.created_qos['id'],
120 operation, keys)
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.assertNotIn(keys[0], body['specs'])
124
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800125 @decorators.idempotent_id('1dd93c76-6420-485d-a771-874044c416ac')
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000126 def test_associate_disassociate_qos(self):
127 """Test the following operations :
128
129 1. associate_qos
130 2. get_association_qos
131 3. disassociate_qos
132 4. disassociate_all_qos
133 """
134
135 # create a test volume-type
136 vol_type = []
137 for _ in range(0, 3):
lkuchlan76650572016-05-23 12:30:10 +0300138 vol_type.append(self.create_volume_type())
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000139
140 # associate the qos-specs with volume-types
141 for i in range(0, 3):
142 self._test_associate_qos(vol_type[i]['id'])
143
144 # get the association of the qos-specs
zhufl5d1ceb32016-10-09 14:51:45 +0800145 body = self.admin_volume_qos_client.show_association_qos(
146 self.created_qos['id'])['qos_associations']
147 associations = [association['id'] for association in body]
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000148 for i in range(0, 3):
149 self.assertIn(vol_type[i]['id'], associations)
150
151 # disassociate a volume-type with qos-specs
bkopilov62d21752016-06-08 10:16:11 +0300152 self.admin_volume_qos_client.disassociate_qos(
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000153 self.created_qos['id'], vol_type[0]['id'])
154 operation = 'disassociate'
lkuchlanec1ba4f2016-09-06 10:28:18 +0300155 waiters.wait_for_qos_operations(self.admin_volume_qos_client,
156 self.created_qos['id'], operation,
157 vol_type[0]['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000158
159 # disassociate all volume-types from qos-specs
bkopilov62d21752016-06-08 10:16:11 +0300160 self.admin_volume_qos_client.disassociate_all_qos(
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000161 self.created_qos['id'])
162 operation = 'disassociate-all'
lkuchlanec1ba4f2016-09-06 10:28:18 +0300163 waiters.wait_for_qos_operations(self.admin_volume_qos_client,
164 self.created_qos['id'], operation)