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