blob: 2f1c75a648d7812554443f3188248f7b098dc96d [file] [log] [blame]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001# Copyright 2015 Red Hat, Inc.
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.lib.common.utils import data_utils
16from tempest.lib import exceptions
17from tempest import test
18
19import testtools
20
21from neutron.services.qos import qos_consts
22from neutron.tests.tempest.api import base
23
24
25class QosTestJSON(base.BaseAdminNetworkTest):
26 @classmethod
27 @test.requires_ext(extension="qos", service="network")
28 def resource_setup(cls):
29 super(QosTestJSON, cls).resource_setup()
30
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000031 @test.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
32 def test_create_policy(self):
33 policy = self.create_qos_policy(name='test-policy',
34 description='test policy desc1',
35 shared=False)
36
37 # Test 'show policy'
38 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
39 retrieved_policy = retrieved_policy['policy']
40 self.assertEqual('test-policy', retrieved_policy['name'])
41 self.assertEqual('test policy desc1', retrieved_policy['description'])
42 self.assertFalse(retrieved_policy['shared'])
43
44 # Test 'list policies'
45 policies = self.admin_client.list_qos_policies()['policies']
46 policies_ids = [p['id'] for p in policies]
47 self.assertIn(policy['id'], policies_ids)
48
Henry Gessaufa6c78d2016-10-09 19:56:09 -040049 @test.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
50 @test.requires_ext(extension="project-id", service="network")
51 def test_show_policy_has_project_id(self):
52 policy = self.create_qos_policy(name='test-policy', shared=False)
53 body = self.admin_client.show_qos_policy(policy['id'])
54 show_policy = body['policy']
55 self.assertIn('project_id', show_policy)
56 self.assertIn('tenant_id', show_policy)
57 self.assertEqual(self.admin_client.tenant_id,
58 show_policy['project_id'])
59 self.assertEqual(self.admin_client.tenant_id,
60 show_policy['tenant_id'])
61
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000062 @test.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
63 def test_list_policy_filter_by_name(self):
64 self.create_qos_policy(name='test', description='test policy',
65 shared=False)
66 self.create_qos_policy(name='test2', description='test policy',
67 shared=False)
68
69 policies = (self.admin_client.
70 list_qos_policies(name='test')['policies'])
71 self.assertEqual(1, len(policies))
72
73 retrieved_policy = policies[0]
74 self.assertEqual('test', retrieved_policy['name'])
75
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000076 @test.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
77 def test_policy_update(self):
78 policy = self.create_qos_policy(name='test-policy',
79 description='',
80 shared=False)
81 self.admin_client.update_qos_policy(policy['id'],
82 description='test policy desc2',
83 shared=True)
84
85 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
86 retrieved_policy = retrieved_policy['policy']
87 self.assertEqual('test policy desc2', retrieved_policy['description'])
88 self.assertTrue(retrieved_policy['shared'])
89 self.assertEqual([], retrieved_policy['rules'])
90
Sławek Kapłoński0acecc62016-08-20 21:00:51 +000091 @test.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
92 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
93 policy = self.create_qos_policy(name='test-policy',
94 description='',
95 shared=False,
96 tenant_id=self.client.tenant_id)
97 self.assertRaises(
98 exceptions.Forbidden,
99 self.client.update_qos_policy,
100 policy['id'], description='test policy')
101
102 @test.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
103 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
104 policy = self.create_qos_policy(name='test-policy',
105 description='',
106 shared=False,
107 tenant_id=self.admin_client.tenant_id)
108 self.assertRaises(
109 exceptions.NotFound,
110 self.client.update_qos_policy,
111 policy['id'], description='test policy')
112
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000113 @test.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
114 def test_shared_policy_update(self):
115 policy = self.create_qos_policy(name='test-policy',
116 description='',
117 shared=True)
118
119 self.admin_client.update_qos_policy(policy['id'],
120 description='test policy desc2')
121 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
122 retrieved_policy = retrieved_policy['policy']
123 self.assertTrue(retrieved_policy['shared'])
124
125 self.admin_client.update_qos_policy(policy['id'],
126 shared=False)
127 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
128 retrieved_policy = retrieved_policy['policy']
129 self.assertFalse(retrieved_policy['shared'])
130
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000131 @test.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
132 def test_delete_policy(self):
133 policy = self.admin_client.create_qos_policy(
134 'test-policy', 'desc', True)['policy']
135
136 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
137 retrieved_policy = retrieved_policy['policy']
138 self.assertEqual('test-policy', retrieved_policy['name'])
139
140 self.admin_client.delete_qos_policy(policy['id'])
141 self.assertRaises(exceptions.NotFound,
142 self.admin_client.show_qos_policy, policy['id'])
143
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000144 @test.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
145 def test_list_admin_rule_types(self):
146 self._test_list_rule_types(self.admin_client)
147
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000148 @test.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
149 def test_list_regular_rule_types(self):
150 self._test_list_rule_types(self.client)
151
152 def _test_list_rule_types(self, client):
153 # List supported rule types
154 # TODO(QoS): since in gate we run both ovs and linuxbridge ml2 drivers,
155 # and since Linux Bridge ml2 driver does not have QoS support yet, ml2
156 # plugin reports no rule types are supported. Once linuxbridge will
157 # receive support for QoS, the list of expected rule types will change.
158 #
159 # In theory, we could make the test conditional on which ml2 drivers
160 # are enabled in gate (or more specifically, on which supported qos
161 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200162 # available through tempest.lib framework
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000163 expected_rule_types = []
164 expected_rule_details = ['type']
165
166 rule_types = client.list_qos_rule_types()
167 actual_list_rule_types = rule_types['rule_types']
168 actual_rule_types = [rule['type'] for rule in actual_list_rule_types]
169
170 # Verify that only required fields present in rule details
171 for rule in actual_list_rule_types:
172 self.assertEqual(tuple(rule.keys()), tuple(expected_rule_details))
173
174 # Verify if expected rules are present in the actual rules list
175 for rule in expected_rule_types:
176 self.assertIn(rule, actual_rule_types)
177
178 def _disassociate_network(self, client, network_id):
179 client.update_network(network_id, qos_policy_id=None)
180 updated_network = self.admin_client.show_network(network_id)
181 self.assertIsNone(updated_network['network']['qos_policy_id'])
182
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000183 @test.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
184 def test_policy_association_with_admin_network(self):
185 policy = self.create_qos_policy(name='test-policy',
186 description='test policy',
187 shared=False)
188 network = self.create_shared_network('test network',
189 qos_policy_id=policy['id'])
190
191 retrieved_network = self.admin_client.show_network(network['id'])
192 self.assertEqual(
193 policy['id'], retrieved_network['network']['qos_policy_id'])
194
195 self._disassociate_network(self.admin_client, network['id'])
196
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000197 @test.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
198 def test_policy_association_with_tenant_network(self):
199 policy = self.create_qos_policy(name='test-policy',
200 description='test policy',
201 shared=True)
202 network = self.create_network('test network',
203 qos_policy_id=policy['id'])
204
205 retrieved_network = self.admin_client.show_network(network['id'])
206 self.assertEqual(
207 policy['id'], retrieved_network['network']['qos_policy_id'])
208
209 self._disassociate_network(self.client, network['id'])
210
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000211 @test.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
212 def test_policy_association_with_network_nonexistent_policy(self):
213 self.assertRaises(
214 exceptions.NotFound,
215 self.create_network,
216 'test network',
217 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
218
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000219 @test.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
220 def test_policy_association_with_network_non_shared_policy(self):
221 policy = self.create_qos_policy(name='test-policy',
222 description='test policy',
223 shared=False)
224 self.assertRaises(
225 exceptions.NotFound,
226 self.create_network,
227 'test network', qos_policy_id=policy['id'])
228
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000229 @test.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
230 def test_policy_update_association_with_admin_network(self):
231 policy = self.create_qos_policy(name='test-policy',
232 description='test policy',
233 shared=False)
234 network = self.create_shared_network('test network')
235 retrieved_network = self.admin_client.show_network(network['id'])
236 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
237
238 self.admin_client.update_network(network['id'],
239 qos_policy_id=policy['id'])
240 retrieved_network = self.admin_client.show_network(network['id'])
241 self.assertEqual(
242 policy['id'], retrieved_network['network']['qos_policy_id'])
243
244 self._disassociate_network(self.admin_client, network['id'])
245
246 def _disassociate_port(self, port_id):
247 self.client.update_port(port_id, qos_policy_id=None)
248 updated_port = self.admin_client.show_port(port_id)
249 self.assertIsNone(updated_port['port']['qos_policy_id'])
250
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000251 @test.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
252 def test_policy_association_with_port_shared_policy(self):
253 policy = self.create_qos_policy(name='test-policy',
254 description='test policy',
255 shared=True)
256 network = self.create_shared_network('test network')
257 port = self.create_port(network, qos_policy_id=policy['id'])
258
259 retrieved_port = self.admin_client.show_port(port['id'])
260 self.assertEqual(
261 policy['id'], retrieved_port['port']['qos_policy_id'])
262
263 self._disassociate_port(port['id'])
264
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000265 @test.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
266 def test_policy_association_with_port_nonexistent_policy(self):
267 network = self.create_shared_network('test network')
268 self.assertRaises(
269 exceptions.NotFound,
270 self.create_port,
271 network,
272 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
273
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000274 @test.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
275 def test_policy_association_with_port_non_shared_policy(self):
276 policy = self.create_qos_policy(name='test-policy',
277 description='test policy',
278 shared=False)
279 network = self.create_shared_network('test network')
280 self.assertRaises(
281 exceptions.NotFound,
282 self.create_port,
283 network, qos_policy_id=policy['id'])
284
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000285 @test.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
286 def test_policy_update_association_with_port_shared_policy(self):
287 policy = self.create_qos_policy(name='test-policy',
288 description='test policy',
289 shared=True)
290 network = self.create_shared_network('test network')
291 port = self.create_port(network)
292 retrieved_port = self.admin_client.show_port(port['id'])
293 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
294
295 self.client.update_port(port['id'], qos_policy_id=policy['id'])
296 retrieved_port = self.admin_client.show_port(port['id'])
297 self.assertEqual(
298 policy['id'], retrieved_port['port']['qos_policy_id'])
299
300 self._disassociate_port(port['id'])
301
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000302 @test.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
303 def test_delete_not_allowed_if_policy_in_use_by_network(self):
304 policy = self.create_qos_policy(name='test-policy',
305 description='test policy',
306 shared=True)
307 network = self.create_shared_network(
308 'test network', qos_policy_id=policy['id'])
309 self.assertRaises(
310 exceptions.Conflict,
311 self.admin_client.delete_qos_policy, policy['id'])
312
313 self._disassociate_network(self.admin_client, network['id'])
314 self.admin_client.delete_qos_policy(policy['id'])
315
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000316 @test.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
317 def test_delete_not_allowed_if_policy_in_use_by_port(self):
318 policy = self.create_qos_policy(name='test-policy',
319 description='test policy',
320 shared=True)
321 network = self.create_shared_network('test network')
322 port = self.create_port(network, qos_policy_id=policy['id'])
323 self.assertRaises(
324 exceptions.Conflict,
325 self.admin_client.delete_qos_policy, policy['id'])
326
327 self._disassociate_port(port['id'])
328 self.admin_client.delete_qos_policy(policy['id'])
329
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000330 @test.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
331 def test_qos_policy_delete_with_rules(self):
332 policy = self.create_qos_policy(name='test-policy',
333 description='test policy',
334 shared=False)
335 self.admin_client.create_bandwidth_limit_rule(
336 policy['id'], 200, 1337)['bandwidth_limit_rule']
337
338 self.admin_client.delete_qos_policy(policy['id'])
339
340 with testtools.ExpectedException(exceptions.NotFound):
341 self.admin_client.show_qos_policy(policy['id'])
342
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000343 @test.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
344 def test_get_policy_that_is_shared(self):
345 policy = self.create_qos_policy(
346 name='test-policy-shared',
347 description='shared policy',
348 shared=True,
349 tenant_id=self.admin_client.tenant_id)
350 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
351 self.assertEqual(obtained_policy, policy)
352
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100353 @test.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
354 def test_policy_create_forbidden_for_regular_tenants(self):
355 self.assertRaises(
356 exceptions.Forbidden,
357 self.client.create_qos_policy,
358 'test-policy', 'test policy', False)
359
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000360
361class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
362 @classmethod
363 @test.requires_ext(extension="qos", service="network")
364 def resource_setup(cls):
365 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
366
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000367 @test.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
368 def test_rule_create(self):
369 policy = self.create_qos_policy(name='test-policy',
370 description='test policy',
371 shared=False)
372 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
373 max_kbps=200,
374 max_burst_kbps=1337)
375
376 # Test 'show rule'
377 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
378 policy['id'], rule['id'])
379 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
380 self.assertEqual(rule['id'], retrieved_rule['id'])
381 self.assertEqual(200, retrieved_rule['max_kbps'])
382 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
383
384 # Test 'list rules'
385 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
386 rules = rules['bandwidth_limit_rules']
387 rules_ids = [r['id'] for r in rules]
388 self.assertIn(rule['id'], rules_ids)
389
390 # Test 'show policy'
391 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
392 policy_rules = retrieved_policy['policy']['rules']
393 self.assertEqual(1, len(policy_rules))
394 self.assertEqual(rule['id'], policy_rules[0]['id'])
395 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
396 policy_rules[0]['type'])
397
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000398 @test.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
399 def test_rule_create_fail_for_the_same_type(self):
400 policy = self.create_qos_policy(name='test-policy',
401 description='test policy',
402 shared=False)
403 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
404 max_kbps=200,
405 max_burst_kbps=1337)
406
407 self.assertRaises(exceptions.Conflict,
408 self.create_qos_bandwidth_limit_rule,
409 policy_id=policy['id'],
410 max_kbps=201, max_burst_kbps=1338)
411
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000412 @test.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
413 def test_rule_update(self):
414 policy = self.create_qos_policy(name='test-policy',
415 description='test policy',
416 shared=False)
417 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
418 max_kbps=1,
419 max_burst_kbps=1)
420
421 self.admin_client.update_bandwidth_limit_rule(policy['id'],
422 rule['id'],
423 max_kbps=200,
424 max_burst_kbps=1337)
425
426 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
427 policy['id'], rule['id'])
428 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
429 self.assertEqual(200, retrieved_policy['max_kbps'])
430 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
431
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000432 @test.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
433 def test_rule_delete(self):
434 policy = self.create_qos_policy(name='test-policy',
435 description='test policy',
436 shared=False)
437 rule = self.admin_client.create_bandwidth_limit_rule(
438 policy['id'], 200, 1337)['bandwidth_limit_rule']
439
440 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
441 policy['id'], rule['id'])
442 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
443 self.assertEqual(rule['id'], retrieved_policy['id'])
444
445 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
446 self.assertRaises(exceptions.NotFound,
447 self.admin_client.show_bandwidth_limit_rule,
448 policy['id'], rule['id'])
449
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000450 @test.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
451 def test_rule_create_rule_nonexistent_policy(self):
452 self.assertRaises(
453 exceptions.NotFound,
454 self.create_qos_bandwidth_limit_rule,
455 'policy', 200, 1337)
456
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000457 @test.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
458 def test_rule_create_forbidden_for_regular_tenants(self):
459 self.assertRaises(
460 exceptions.Forbidden,
461 self.client.create_bandwidth_limit_rule,
462 'policy', 1, 2)
463
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000464 @test.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
465 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
466 policy = self.create_qos_policy(name='test-policy',
467 description='test policy',
468 shared=False,
469 tenant_id=self.client.tenant_id)
470 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
471 max_kbps=1,
472 max_burst_kbps=1)
473 self.assertRaises(
474 exceptions.NotFound,
475 self.client.update_bandwidth_limit_rule,
476 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
477
478 @test.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
479 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
480 policy = self.create_qos_policy(name='test-policy',
481 description='test policy',
482 shared=False,
483 tenant_id=self.admin_client.tenant_id)
484 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
485 max_kbps=1,
486 max_burst_kbps=1)
487 self.assertRaises(
488 exceptions.NotFound,
489 self.client.update_bandwidth_limit_rule,
490 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
491
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000492 @test.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
493 def test_get_rules_by_policy(self):
494 policy1 = self.create_qos_policy(name='test-policy1',
495 description='test policy1',
496 shared=False)
497 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
498 max_kbps=200,
499 max_burst_kbps=1337)
500
501 policy2 = self.create_qos_policy(name='test-policy2',
502 description='test policy2',
503 shared=False)
504 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
505 max_kbps=5000,
506 max_burst_kbps=2523)
507
508 # Test 'list rules'
509 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
510 rules = rules['bandwidth_limit_rules']
511 rules_ids = [r['id'] for r in rules]
512 self.assertIn(rule1['id'], rules_ids)
513 self.assertNotIn(rule2['id'], rules_ids)
514
515
516class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
517
518 force_tenant_isolation = True
519 credentials = ['primary', 'alt', 'admin']
520
521 @classmethod
522 @test.requires_ext(extension="qos", service="network")
523 def resource_setup(cls):
524 super(RbacSharedQosPoliciesTest, cls).resource_setup()
525 cls.client2 = cls.alt_manager.network_client
526
527 def _create_qos_policy(self, tenant_id=None):
528 args = {'name': data_utils.rand_name('test-policy'),
529 'description': 'test policy',
530 'shared': False,
531 'tenant_id': tenant_id}
532 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
533 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
534
535 return qos_policy
536
537 def _make_admin_policy_shared_to_tenant_id(self, tenant_id):
538 policy = self._create_qos_policy()
539 rbac_policy = self.admin_client.create_rbac_policy(
540 object_type='qos_policy',
541 object_id=policy['id'],
542 action='access_as_shared',
543 target_tenant=tenant_id,
544 )['rbac_policy']
545
546 return {'policy': policy, 'rbac_policy': rbac_policy}
547
548 def _create_network(self, qos_policy_id, client, should_cleanup=True):
549 net = client.create_network(
550 name=data_utils.rand_name('test-network'),
551 qos_policy_id=qos_policy_id)['network']
552 if should_cleanup:
553 self.addCleanup(client.delete_network, net['id'])
554
555 return net
556
557 @test.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
558 def test_policy_sharing_with_wildcard(self):
559 qos_pol = self.create_qos_policy(
560 name=data_utils.rand_name('test-policy'),
561 description='test-shared-policy', shared=False)
562 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
563
564 # test update shared False -> True
565 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
566 qos_pol['shared'] = True
567 self.client2.show_qos_policy(qos_pol['id'])
568 rbac_pol = {'target_tenant': '*',
569 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000570 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000571 'object_type': 'qos_policy',
572 'object_id': qos_pol['id'],
573 'action': 'access_as_shared'}
574
575 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
576 rbac_policies = [r for r in rbac_policies if r.pop('id')]
577 self.assertIn(rbac_pol, rbac_policies)
578
579 # update shared True -> False should fail because the policy is bound
580 # to a network
581 net = self._create_network(qos_pol['id'], self.admin_client, False)
582 with testtools.ExpectedException(exceptions.Conflict):
583 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
584
585 # delete the network, and update shared True -> False should pass now
586 self.admin_client.delete_network(net['id'])
587 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
588 qos_pol['shared'] = False
589 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
590
591 def _create_net_bound_qos_rbacs(self):
592 res = self._make_admin_policy_shared_to_tenant_id(
593 self.client.tenant_id)
594 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
595
596 # add a wildcard rbac rule - now the policy globally shared
597 rbac_wildcard = self.admin_client.create_rbac_policy(
598 object_type='qos_policy',
599 object_id=qos_policy['id'],
600 action='access_as_shared',
601 target_tenant='*',
602 )['rbac_policy']
603
604 # tenant1 now uses qos policy for net
605 self._create_network(qos_policy['id'], self.client)
606
607 return rbac_for_client_tenant, rbac_wildcard
608
609 @test.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
610 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self):
611 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
612 # globally unshare the qos-policy, the specific share should remain
613 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
614 self.client.list_rbac_policies(id=client_rbac['id'])
615
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200616 @test.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000617 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self):
618 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
619 # remove client_rbac policy the wildcard share should remain
620 self.admin_client.delete_rbac_policy(client_rbac['id'])
621 self.client.list_rbac_policies(id=wildcard_rbac['id'])
622
623 @test.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
624 def test_policy_sharing_with_wildcard_and_tenant_id(self):
625 res = self._make_admin_policy_shared_to_tenant_id(
626 self.client.tenant_id)
627 qos_policy, rbac = res['policy'], res['rbac_policy']
628 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
629 self.assertTrue(qos_pol['shared'])
630 with testtools.ExpectedException(exceptions.NotFound):
631 self.client2.show_qos_policy(qos_policy['id'])
632
633 # make the qos-policy globally shared
634 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
635 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
636 self.assertTrue(qos_pol['shared'])
637
638 # globally unshare the qos-policy, the specific share should remain
639 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
640 self.client.show_qos_policy(qos_policy['id'])
641 with testtools.ExpectedException(exceptions.NotFound):
642 self.client2.show_qos_policy(qos_policy['id'])
643 self.assertIn(rbac,
644 self.admin_client.list_rbac_policies()['rbac_policies'])
645
646 @test.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
647 def test_policy_target_update(self):
648 res = self._make_admin_policy_shared_to_tenant_id(
649 self.client.tenant_id)
650 # change to client2
651 update_res = self.admin_client.update_rbac_policy(
652 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
653 self.assertEqual(self.client2.tenant_id,
654 update_res['rbac_policy']['target_tenant'])
655 # make sure everything else stayed the same
656 res['rbac_policy'].pop('target_tenant')
657 update_res['rbac_policy'].pop('target_tenant')
658 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
659
660 @test.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
661 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
662 res = self._make_admin_policy_shared_to_tenant_id(
663 self.client2.tenant_id)
664 qos_policy_id = res['policy']['id']
665 self._create_network(qos_policy_id, self.client2)
666 # a network with shared qos-policy should prevent the deletion of an
667 # rbac-policy required for it to be shared
668 with testtools.ExpectedException(exceptions.Conflict):
669 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
670
671 # a wildcard policy should allow the specific policy to be deleted
672 # since it allows the remaining port
673 wild = self.admin_client.create_rbac_policy(
674 object_type='qos_policy', object_id=res['policy']['id'],
675 action='access_as_shared', target_tenant='*')['rbac_policy']
676 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
677
678 # now that wildcard is the only remaining, it should be subjected to
679 # the same restriction
680 with testtools.ExpectedException(exceptions.Conflict):
681 self.admin_client.delete_rbac_policy(wild['id'])
682
683 # we can't update the policy to a different tenant
684 with testtools.ExpectedException(exceptions.Conflict):
685 self.admin_client.update_rbac_policy(
686 wild['id'], target_tenant=self.client2.tenant_id)
687
688 @test.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
689 def test_regular_client_shares_to_another_regular_client(self):
690 # owned by self.admin_client
691 policy = self._create_qos_policy()
692 with testtools.ExpectedException(exceptions.NotFound):
693 self.client.show_qos_policy(policy['id'])
694 rbac_policy = self.admin_client.create_rbac_policy(
695 object_type='qos_policy', object_id=policy['id'],
696 action='access_as_shared',
697 target_tenant=self.client.tenant_id)['rbac_policy']
698 self.client.show_qos_policy(policy['id'])
699
700 self.assertIn(rbac_policy,
701 self.admin_client.list_rbac_policies()['rbac_policies'])
702 # ensure that 'client2' can't see the rbac-policy sharing the
703 # qos-policy to it because the rbac-policy belongs to 'client'
704 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
705 self.client2.list_rbac_policies()['rbac_policies']])
706
707 @test.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
708 def test_filter_fields(self):
709 policy = self._create_qos_policy()
710 self.admin_client.create_rbac_policy(
711 object_type='qos_policy', object_id=policy['id'],
712 action='access_as_shared', target_tenant=self.client2.tenant_id)
713 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
714 ('tenant_id', 'target_tenant'))
715 for fields in field_args:
716 res = self.admin_client.list_rbac_policies(fields=fields)
717 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
718
719 @test.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
720 def test_rbac_policy_show(self):
721 res = self._make_admin_policy_shared_to_tenant_id(
722 self.client.tenant_id)
723 p1 = res['rbac_policy']
724 p2 = self.admin_client.create_rbac_policy(
725 object_type='qos_policy', object_id=res['policy']['id'],
726 action='access_as_shared',
727 target_tenant='*')['rbac_policy']
728
729 self.assertEqual(
730 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
731 self.assertEqual(
732 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
733
734 @test.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
735 def test_filter_rbac_policies(self):
736 policy = self._create_qos_policy()
737 rbac_pol1 = self.admin_client.create_rbac_policy(
738 object_type='qos_policy', object_id=policy['id'],
739 action='access_as_shared',
740 target_tenant=self.client2.tenant_id)['rbac_policy']
741 rbac_pol2 = self.admin_client.create_rbac_policy(
742 object_type='qos_policy', object_id=policy['id'],
743 action='access_as_shared',
744 target_tenant=self.admin_client.tenant_id)['rbac_policy']
745 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
746 'rbac_policies']
747 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
748 'rbac_policies']
749 self.assertEqual(1, len(res1))
750 self.assertEqual(1, len(res2))
751 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
752 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
753
754 @test.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
755 def test_regular_client_blocked_from_sharing_anothers_policy(self):
756 qos_policy = self._make_admin_policy_shared_to_tenant_id(
757 self.client.tenant_id)['policy']
758 with testtools.ExpectedException(exceptions.BadRequest):
759 self.client.create_rbac_policy(
760 object_type='qos_policy', object_id=qos_policy['id'],
761 action='access_as_shared',
762 target_tenant=self.client2.tenant_id)
763
764 # make sure the rbac-policy is invisible to the tenant for which it's
765 # being shared
766 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
767
768
769class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
770 VALID_DSCP_MARK1 = 56
771 VALID_DSCP_MARK2 = 48
772
773 @classmethod
774 @test.requires_ext(extension="qos", service="network")
775 def resource_setup(cls):
776 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
777
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200778 @test.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000779 def test_rule_create(self):
780 policy = self.create_qos_policy(name='test-policy',
781 description='test policy',
782 shared=False)
783 rule = self.admin_client.create_dscp_marking_rule(
784 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
785
786 # Test 'show rule'
787 retrieved_rule = self.admin_client.show_dscp_marking_rule(
788 policy['id'], rule['id'])
789 retrieved_rule = retrieved_rule['dscp_marking_rule']
790 self.assertEqual(rule['id'], retrieved_rule['id'])
791 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
792
793 # Test 'list rules'
794 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
795 rules = rules['dscp_marking_rules']
796 rules_ids = [r['id'] for r in rules]
797 self.assertIn(rule['id'], rules_ids)
798
799 # Test 'show policy'
800 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
801 policy_rules = retrieved_policy['policy']['rules']
802 self.assertEqual(1, len(policy_rules))
803 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000804 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000805 policy_rules[0]['type'])
806
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200807 @test.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000808 def test_rule_create_fail_for_the_same_type(self):
809 policy = self.create_qos_policy(name='test-policy',
810 description='test policy',
811 shared=False)
812 self.admin_client.create_dscp_marking_rule(
813 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
814
815 self.assertRaises(exceptions.Conflict,
816 self.admin_client.create_dscp_marking_rule,
817 policy_id=policy['id'],
818 dscp_mark=self.VALID_DSCP_MARK2)
819
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200820 @test.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000821 def test_rule_update(self):
822 policy = self.create_qos_policy(name='test-policy',
823 description='test policy',
824 shared=False)
825 rule = self.admin_client.create_dscp_marking_rule(
826 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
827
828 self.admin_client.update_dscp_marking_rule(
829 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
830
831 retrieved_policy = self.admin_client.show_dscp_marking_rule(
832 policy['id'], rule['id'])
833 retrieved_policy = retrieved_policy['dscp_marking_rule']
834 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
835
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200836 @test.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000837 def test_rule_delete(self):
838 policy = self.create_qos_policy(name='test-policy',
839 description='test policy',
840 shared=False)
841 rule = self.admin_client.create_dscp_marking_rule(
842 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
843
844 retrieved_policy = self.admin_client.show_dscp_marking_rule(
845 policy['id'], rule['id'])
846 retrieved_policy = retrieved_policy['dscp_marking_rule']
847 self.assertEqual(rule['id'], retrieved_policy['id'])
848
849 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
850 self.assertRaises(exceptions.NotFound,
851 self.admin_client.show_dscp_marking_rule,
852 policy['id'], rule['id'])
853
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200854 @test.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000855 def test_rule_create_rule_nonexistent_policy(self):
856 self.assertRaises(
857 exceptions.NotFound,
858 self.admin_client.create_dscp_marking_rule,
859 'policy', self.VALID_DSCP_MARK1)
860
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200861 @test.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000862 def test_rule_create_forbidden_for_regular_tenants(self):
863 self.assertRaises(
864 exceptions.Forbidden,
865 self.client.create_dscp_marking_rule,
866 'policy', self.VALID_DSCP_MARK1)
867
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000868 @test.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
869 def test_invalid_rule_create(self):
870 policy = self.create_qos_policy(name='test-policy',
871 description='test policy',
872 shared=False)
873 self.assertRaises(
874 exceptions.BadRequest,
875 self.admin_client.create_dscp_marking_rule,
876 policy['id'], 58)
877
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200878 @test.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000879 def test_get_rules_by_policy(self):
880 policy1 = self.create_qos_policy(name='test-policy1',
881 description='test policy1',
882 shared=False)
883 rule1 = self.admin_client.create_dscp_marking_rule(
884 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
885
886 policy2 = self.create_qos_policy(name='test-policy2',
887 description='test policy2',
888 shared=False)
889 rule2 = self.admin_client.create_dscp_marking_rule(
890 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
891
892 # Test 'list rules'
893 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
894 rules = rules['dscp_marking_rules']
895 rules_ids = [r['id'] for r in rules]
896 self.assertIn(rule1['id'], rules_ids)
897 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +0200898
899
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100900class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
901 DIRECTION_EGRESS = "egress"
902 DIRECTION_INGRESS = "ingress"
903 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
904 RULES_NAME = RULE_NAME + "s"
905
906 @classmethod
907 @test.requires_ext(extension="qos", service="network")
908 def resource_setup(cls):
909 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
910
911 @test.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
912 def test_rule_create(self):
913 policy = self.create_qos_policy(name='test-policy',
914 description='test policy',
915 shared=False)
916 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000917 policy_id=policy['id'],
918 direction=self.DIRECTION_EGRESS,
919 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100920
921 # Test 'show rule'
922 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
923 policy['id'], rule['id'])
924 retrieved_rule = retrieved_rule[self.RULE_NAME]
925 self.assertEqual(rule['id'], retrieved_rule['id'])
926 self.assertEqual(1138, retrieved_rule['min_kbps'])
927 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
928
929 # Test 'list rules'
930 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
931 rules = rules[self.RULES_NAME]
932 rules_ids = [r['id'] for r in rules]
933 self.assertIn(rule['id'], rules_ids)
934
935 # Test 'show policy'
936 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
937 policy_rules = retrieved_policy['policy']['rules']
938 self.assertEqual(1, len(policy_rules))
939 self.assertEqual(rule['id'], policy_rules[0]['id'])
940 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
941 policy_rules[0]['type'])
942
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000943 @test.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
944 def test_rule_create_fail_for_missing_min_kbps(self):
945 policy = self.create_qos_policy(name='test-policy',
946 description='test policy',
947 shared=False)
948 self.assertRaises(exceptions.BadRequest,
949 self.admin_client.create_minimum_bandwidth_rule,
950 policy_id=policy['id'],
951 direction=self.DIRECTION_EGRESS)
952
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100953 @test.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
954 def test_rule_create_fail_for_the_same_type(self):
955 policy = self.create_qos_policy(name='test-policy',
956 description='test policy',
957 shared=False)
958 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000959 policy_id=policy['id'],
960 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100961
962 self.assertRaises(exceptions.Conflict,
963 self.admin_client.create_minimum_bandwidth_rule,
964 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000965 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100966
967 @test.idempotent_id('d6fce764-e511-4fa6-9f86-f4b41cf142cf')
968 def test_rule_create_fail_for_direction_ingress(self):
969 policy = self.create_qos_policy(name='test-policy',
970 description='test policy',
971 shared=False)
972 self.assertRaises(exceptions.BadRequest,
973 self.admin_client.create_minimum_bandwidth_rule,
974 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000975 direction=self.DIRECTION_INGRESS,
976 min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100977
978 @test.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
979 def test_rule_update(self):
980 policy = self.create_qos_policy(name='test-policy',
981 description='test policy',
982 shared=False)
983 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000984 policy_id=policy['id'],
985 direction=self.DIRECTION_EGRESS,
986 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100987
988 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
989 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
990
991 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
992 policy['id'], rule['id'])
993 retrieved_policy = retrieved_policy[self.RULE_NAME]
994 self.assertEqual(350, retrieved_policy['min_kbps'])
995 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
996
997 @test.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
998 def test_rule_delete(self):
999 policy = self.create_qos_policy(name='test-policy',
1000 description='test policy',
1001 shared=False)
1002 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001003 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001004
1005 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1006 policy['id'], rule['id'])
1007 retrieved_policy = retrieved_policy[self.RULE_NAME]
1008 self.assertEqual(rule['id'], retrieved_policy['id'])
1009
1010 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1011 rule['id'])
1012 self.assertRaises(exceptions.NotFound,
1013 self.admin_client.show_minimum_bandwidth_rule,
1014 policy['id'], rule['id'])
1015
1016 @test.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
1017 def test_rule_create_rule_nonexistent_policy(self):
1018 self.assertRaises(
1019 exceptions.NotFound,
1020 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001021 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001022
1023 @test.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
1024 def test_rule_create_forbidden_for_regular_tenants(self):
1025 self.assertRaises(
1026 exceptions.Forbidden,
1027 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001028 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001029
1030 @test.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
1031 def test_get_rules_by_policy(self):
1032 policy1 = self.create_qos_policy(name='test-policy1',
1033 description='test policy1',
1034 shared=False)
1035 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001036 policy_id=policy1['id'],
1037 direction=self.DIRECTION_EGRESS,
1038 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001039
1040 policy2 = self.create_qos_policy(name='test-policy2',
1041 description='test policy2',
1042 shared=False)
1043 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001044 policy_id=policy2['id'],
1045 direction=self.DIRECTION_EGRESS,
1046 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001047
1048 # Test 'list rules'
1049 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1050 rules = rules[self.RULES_NAME]
1051 rules_ids = [r['id'] for r in rules]
1052 self.assertIn(rule1['id'], rules_ids)
1053 self.assertNotIn(rule2['id'], rules_ids)
1054
1055
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001056class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1057 base.BaseAdminNetworkTest):
1058
1059 resource = 'policy'
1060 plural_name = 'policies'
1061
1062 # Use unique description to isolate the tests from other QoS tests
1063 list_kwargs = {'description': 'search-criteria-test'}
1064 list_as_admin = True
1065
1066 @classmethod
1067 @test.requires_ext(extension="qos", service="network")
1068 def resource_setup(cls):
1069 super(QosSearchCriteriaTest, cls).resource_setup()
1070 for name in cls.resource_names:
1071 cls.create_qos_policy(
1072 name=name, description='search-criteria-test')
1073
1074 @test.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
1075 def test_list_sorts_asc(self):
1076 self._test_list_sorts_asc()
1077
1078 @test.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
1079 def test_list_sorts_desc(self):
1080 self._test_list_sorts_desc()
1081
1082 @test.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
1083 def test_list_pagination(self):
1084 self._test_list_pagination()
1085
1086 @test.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
1087 def test_list_pagination_with_marker(self):
1088 self._test_list_pagination_with_marker()
1089
1090 @test.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
1091 def test_list_pagination_with_href_links(self):
1092 self._test_list_pagination_with_href_links()
1093
1094 @test.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
1095 def test_list_pagination_page_reverse_asc(self):
1096 self._test_list_pagination_page_reverse_asc()
1097
1098 @test.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
1099 def test_list_pagination_page_reverse_desc(self):
1100 self._test_list_pagination_page_reverse_desc()
1101
1102 @test.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
1103 def test_list_pagination_page_reverse_with_href_links(self):
1104 self._test_list_pagination_page_reverse_with_href_links()
1105
1106 @test.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
1107 def test_list_no_pagination_limit_0(self):
1108 self._test_list_no_pagination_limit_0()