@@ -122,4 +122,96 @@ def test_volume_qos_set_show_unset(self):
122122 cmd_output ['properties' ]
123123 )
124124
125- # TODO(qiangjiahui): Add tests for associate and disassociate volume type
125+ def test_volume_qos_asso_disasso (self ):
126+ """Tests associate and disassociate qos with volume type"""
127+ vol_type1 = uuid .uuid4 ().hex
128+ vol_type2 = uuid .uuid4 ().hex
129+ cmd_output = json .loads (self .openstack (
130+ 'volume type create -f json ' +
131+ vol_type1
132+ ))
133+ self .assertEqual (
134+ vol_type1 ,
135+ cmd_output ['name' ]
136+ )
137+ cmd_output = json .loads (self .openstack (
138+ 'volume type create -f json ' +
139+ vol_type2
140+ ))
141+ self .assertEqual (
142+ vol_type2 ,
143+ cmd_output ['name' ]
144+ )
145+ self .addCleanup (self .openstack , 'volume type delete ' + vol_type1 )
146+ self .addCleanup (self .openstack , 'volume type delete ' + vol_type2 )
147+
148+ name = uuid .uuid4 ().hex
149+ cmd_output = json .loads (self .openstack (
150+ 'volume qos create -f json ' +
151+ name
152+ ))
153+ self .assertEqual (
154+ name ,
155+ cmd_output ['name' ]
156+ )
157+ self .addCleanup (self .openstack , 'volume qos delete ' + name )
158+
159+ # Test associate
160+ raw_output = self .openstack (
161+ 'volume qos associate ' +
162+ name + ' ' + vol_type1
163+ )
164+ self .assertOutput ('' , raw_output )
165+ raw_output = self .openstack (
166+ 'volume qos associate ' +
167+ name + ' ' + vol_type2
168+ )
169+ self .assertOutput ('' , raw_output )
170+
171+ cmd_output = json .loads (self .openstack (
172+ 'volume qos show -f json ' +
173+ name
174+ ))
175+ types = cmd_output ["associations" ]
176+ self .assertIn (vol_type1 , types )
177+ self .assertIn (vol_type2 , types )
178+
179+ # Test disassociate
180+ raw_output = self .openstack (
181+ 'volume qos disassociate ' +
182+ '--volume-type ' + vol_type1 +
183+ ' ' + name
184+ )
185+ self .assertOutput ('' , raw_output )
186+ cmd_output = json .loads (self .openstack (
187+ 'volume qos show -f json ' +
188+ name
189+ ))
190+ types = cmd_output ["associations" ]
191+ self .assertNotIn (vol_type1 , types )
192+ self .assertIn (vol_type2 , types )
193+
194+ # Test disassociate --all
195+ raw_output = self .openstack (
196+ 'volume qos associate ' +
197+ name + ' ' + vol_type1
198+ )
199+ self .assertOutput ('' , raw_output )
200+ cmd_output = json .loads (self .openstack (
201+ 'volume qos show -f json ' +
202+ name
203+ ))
204+ types = cmd_output ["associations" ]
205+ self .assertIn (vol_type1 , types )
206+ self .assertIn (vol_type2 , types )
207+
208+ raw_output = self .openstack (
209+ 'volume qos disassociate ' +
210+ '--all ' + name
211+ )
212+ self .assertOutput ('' , raw_output )
213+ cmd_output = json .loads (self .openstack (
214+ 'volume qos show -f json ' +
215+ name
216+ ))
217+ self .assertNotIn ("associations" , cmd_output .keys ())
0 commit comments