blob: 7752f945b6b922b3f70e4e294ece2d7bffcc6dcc [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
Sławek Kapłońskiff294062016-12-04 15:00:54 +0000363 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000364 @test.requires_ext(extension="qos", service="network")
365 def resource_setup(cls):
366 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
367
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000368 @test.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
369 def test_rule_create(self):
370 policy = self.create_qos_policy(name='test-policy',
371 description='test policy',
372 shared=False)
373 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
374 max_kbps=200,
375 max_burst_kbps=1337)
376
377 # Test 'show rule'
378 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
379 policy['id'], rule['id'])
380 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
381 self.assertEqual(rule['id'], retrieved_rule['id'])
382 self.assertEqual(200, retrieved_rule['max_kbps'])
383 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
384
385 # Test 'list rules'
386 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
387 rules = rules['bandwidth_limit_rules']
388 rules_ids = [r['id'] for r in rules]
389 self.assertIn(rule['id'], rules_ids)
390
391 # Test 'show policy'
392 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
393 policy_rules = retrieved_policy['policy']['rules']
394 self.assertEqual(1, len(policy_rules))
395 self.assertEqual(rule['id'], policy_rules[0]['id'])
396 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
397 policy_rules[0]['type'])
398
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000399 @test.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
400 def test_rule_create_fail_for_the_same_type(self):
401 policy = self.create_qos_policy(name='test-policy',
402 description='test policy',
403 shared=False)
404 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
405 max_kbps=200,
406 max_burst_kbps=1337)
407
408 self.assertRaises(exceptions.Conflict,
409 self.create_qos_bandwidth_limit_rule,
410 policy_id=policy['id'],
411 max_kbps=201, max_burst_kbps=1338)
412
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000413 @test.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
414 def test_rule_update(self):
415 policy = self.create_qos_policy(name='test-policy',
416 description='test policy',
417 shared=False)
418 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
419 max_kbps=1,
420 max_burst_kbps=1)
421
422 self.admin_client.update_bandwidth_limit_rule(policy['id'],
423 rule['id'],
424 max_kbps=200,
425 max_burst_kbps=1337)
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(200, retrieved_policy['max_kbps'])
431 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
432
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000433 @test.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
434 def test_rule_delete(self):
435 policy = self.create_qos_policy(name='test-policy',
436 description='test policy',
437 shared=False)
438 rule = self.admin_client.create_bandwidth_limit_rule(
439 policy['id'], 200, 1337)['bandwidth_limit_rule']
440
441 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
442 policy['id'], rule['id'])
443 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
444 self.assertEqual(rule['id'], retrieved_policy['id'])
445
446 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
447 self.assertRaises(exceptions.NotFound,
448 self.admin_client.show_bandwidth_limit_rule,
449 policy['id'], rule['id'])
450
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000451 @test.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
452 def test_rule_create_rule_nonexistent_policy(self):
453 self.assertRaises(
454 exceptions.NotFound,
455 self.create_qos_bandwidth_limit_rule,
456 'policy', 200, 1337)
457
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000458 @test.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
459 def test_rule_create_forbidden_for_regular_tenants(self):
460 self.assertRaises(
461 exceptions.Forbidden,
462 self.client.create_bandwidth_limit_rule,
463 'policy', 1, 2)
464
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000465 @test.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
466 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
467 policy = self.create_qos_policy(name='test-policy',
468 description='test policy',
469 shared=False,
470 tenant_id=self.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
479 @test.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
480 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
481 policy = self.create_qos_policy(name='test-policy',
482 description='test policy',
483 shared=False,
484 tenant_id=self.admin_client.tenant_id)
485 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
486 max_kbps=1,
487 max_burst_kbps=1)
488 self.assertRaises(
489 exceptions.NotFound,
490 self.client.update_bandwidth_limit_rule,
491 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
492
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000493 @test.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
494 def test_get_rules_by_policy(self):
495 policy1 = self.create_qos_policy(name='test-policy1',
496 description='test policy1',
497 shared=False)
498 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
499 max_kbps=200,
500 max_burst_kbps=1337)
501
502 policy2 = self.create_qos_policy(name='test-policy2',
503 description='test policy2',
504 shared=False)
505 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
506 max_kbps=5000,
507 max_burst_kbps=2523)
508
509 # Test 'list rules'
510 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
511 rules = rules['bandwidth_limit_rules']
512 rules_ids = [r['id'] for r in rules]
513 self.assertIn(rule1['id'], rules_ids)
514 self.assertNotIn(rule2['id'], rules_ids)
515
516
517class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
518
519 force_tenant_isolation = True
520 credentials = ['primary', 'alt', 'admin']
521
522 @classmethod
523 @test.requires_ext(extension="qos", service="network")
524 def resource_setup(cls):
525 super(RbacSharedQosPoliciesTest, cls).resource_setup()
526 cls.client2 = cls.alt_manager.network_client
527
528 def _create_qos_policy(self, tenant_id=None):
529 args = {'name': data_utils.rand_name('test-policy'),
530 'description': 'test policy',
531 'shared': False,
532 'tenant_id': tenant_id}
533 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
534 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
535
536 return qos_policy
537
538 def _make_admin_policy_shared_to_tenant_id(self, tenant_id):
539 policy = self._create_qos_policy()
540 rbac_policy = self.admin_client.create_rbac_policy(
541 object_type='qos_policy',
542 object_id=policy['id'],
543 action='access_as_shared',
544 target_tenant=tenant_id,
545 )['rbac_policy']
546
547 return {'policy': policy, 'rbac_policy': rbac_policy}
548
549 def _create_network(self, qos_policy_id, client, should_cleanup=True):
550 net = client.create_network(
551 name=data_utils.rand_name('test-network'),
552 qos_policy_id=qos_policy_id)['network']
553 if should_cleanup:
554 self.addCleanup(client.delete_network, net['id'])
555
556 return net
557
558 @test.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
559 def test_policy_sharing_with_wildcard(self):
560 qos_pol = self.create_qos_policy(
561 name=data_utils.rand_name('test-policy'),
562 description='test-shared-policy', shared=False)
563 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
564
565 # test update shared False -> True
566 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
567 qos_pol['shared'] = True
568 self.client2.show_qos_policy(qos_pol['id'])
569 rbac_pol = {'target_tenant': '*',
570 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000571 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000572 'object_type': 'qos_policy',
573 'object_id': qos_pol['id'],
574 'action': 'access_as_shared'}
575
576 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
577 rbac_policies = [r for r in rbac_policies if r.pop('id')]
578 self.assertIn(rbac_pol, rbac_policies)
579
580 # update shared True -> False should fail because the policy is bound
581 # to a network
582 net = self._create_network(qos_pol['id'], self.admin_client, False)
583 with testtools.ExpectedException(exceptions.Conflict):
584 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
585
586 # delete the network, and update shared True -> False should pass now
587 self.admin_client.delete_network(net['id'])
588 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
589 qos_pol['shared'] = False
590 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
591
592 def _create_net_bound_qos_rbacs(self):
593 res = self._make_admin_policy_shared_to_tenant_id(
594 self.client.tenant_id)
595 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
596
597 # add a wildcard rbac rule - now the policy globally shared
598 rbac_wildcard = self.admin_client.create_rbac_policy(
599 object_type='qos_policy',
600 object_id=qos_policy['id'],
601 action='access_as_shared',
602 target_tenant='*',
603 )['rbac_policy']
604
605 # tenant1 now uses qos policy for net
606 self._create_network(qos_policy['id'], self.client)
607
608 return rbac_for_client_tenant, rbac_wildcard
609
610 @test.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
611 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self):
612 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
613 # globally unshare the qos-policy, the specific share should remain
614 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
615 self.client.list_rbac_policies(id=client_rbac['id'])
616
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200617 @test.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000618 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self):
619 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
620 # remove client_rbac policy the wildcard share should remain
621 self.admin_client.delete_rbac_policy(client_rbac['id'])
622 self.client.list_rbac_policies(id=wildcard_rbac['id'])
623
624 @test.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
625 def test_policy_sharing_with_wildcard_and_tenant_id(self):
626 res = self._make_admin_policy_shared_to_tenant_id(
627 self.client.tenant_id)
628 qos_policy, rbac = res['policy'], res['rbac_policy']
629 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
630 self.assertTrue(qos_pol['shared'])
631 with testtools.ExpectedException(exceptions.NotFound):
632 self.client2.show_qos_policy(qos_policy['id'])
633
634 # make the qos-policy globally shared
635 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
636 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
637 self.assertTrue(qos_pol['shared'])
638
639 # globally unshare the qos-policy, the specific share should remain
640 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
641 self.client.show_qos_policy(qos_policy['id'])
642 with testtools.ExpectedException(exceptions.NotFound):
643 self.client2.show_qos_policy(qos_policy['id'])
644 self.assertIn(rbac,
645 self.admin_client.list_rbac_policies()['rbac_policies'])
646
647 @test.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
648 def test_policy_target_update(self):
649 res = self._make_admin_policy_shared_to_tenant_id(
650 self.client.tenant_id)
651 # change to client2
652 update_res = self.admin_client.update_rbac_policy(
653 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
654 self.assertEqual(self.client2.tenant_id,
655 update_res['rbac_policy']['target_tenant'])
656 # make sure everything else stayed the same
657 res['rbac_policy'].pop('target_tenant')
658 update_res['rbac_policy'].pop('target_tenant')
659 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
660
661 @test.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
662 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
663 res = self._make_admin_policy_shared_to_tenant_id(
664 self.client2.tenant_id)
665 qos_policy_id = res['policy']['id']
666 self._create_network(qos_policy_id, self.client2)
667 # a network with shared qos-policy should prevent the deletion of an
668 # rbac-policy required for it to be shared
669 with testtools.ExpectedException(exceptions.Conflict):
670 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
671
672 # a wildcard policy should allow the specific policy to be deleted
673 # since it allows the remaining port
674 wild = self.admin_client.create_rbac_policy(
675 object_type='qos_policy', object_id=res['policy']['id'],
676 action='access_as_shared', target_tenant='*')['rbac_policy']
677 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
678
679 # now that wildcard is the only remaining, it should be subjected to
680 # the same restriction
681 with testtools.ExpectedException(exceptions.Conflict):
682 self.admin_client.delete_rbac_policy(wild['id'])
683
684 # we can't update the policy to a different tenant
685 with testtools.ExpectedException(exceptions.Conflict):
686 self.admin_client.update_rbac_policy(
687 wild['id'], target_tenant=self.client2.tenant_id)
688
689 @test.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
690 def test_regular_client_shares_to_another_regular_client(self):
691 # owned by self.admin_client
692 policy = self._create_qos_policy()
693 with testtools.ExpectedException(exceptions.NotFound):
694 self.client.show_qos_policy(policy['id'])
695 rbac_policy = self.admin_client.create_rbac_policy(
696 object_type='qos_policy', object_id=policy['id'],
697 action='access_as_shared',
698 target_tenant=self.client.tenant_id)['rbac_policy']
699 self.client.show_qos_policy(policy['id'])
700
701 self.assertIn(rbac_policy,
702 self.admin_client.list_rbac_policies()['rbac_policies'])
703 # ensure that 'client2' can't see the rbac-policy sharing the
704 # qos-policy to it because the rbac-policy belongs to 'client'
705 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
706 self.client2.list_rbac_policies()['rbac_policies']])
707
708 @test.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
709 def test_filter_fields(self):
710 policy = self._create_qos_policy()
711 self.admin_client.create_rbac_policy(
712 object_type='qos_policy', object_id=policy['id'],
713 action='access_as_shared', target_tenant=self.client2.tenant_id)
714 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
715 ('tenant_id', 'target_tenant'))
716 for fields in field_args:
717 res = self.admin_client.list_rbac_policies(fields=fields)
718 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
719
720 @test.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
721 def test_rbac_policy_show(self):
722 res = self._make_admin_policy_shared_to_tenant_id(
723 self.client.tenant_id)
724 p1 = res['rbac_policy']
725 p2 = self.admin_client.create_rbac_policy(
726 object_type='qos_policy', object_id=res['policy']['id'],
727 action='access_as_shared',
728 target_tenant='*')['rbac_policy']
729
730 self.assertEqual(
731 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
732 self.assertEqual(
733 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
734
735 @test.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
736 def test_filter_rbac_policies(self):
737 policy = self._create_qos_policy()
738 rbac_pol1 = self.admin_client.create_rbac_policy(
739 object_type='qos_policy', object_id=policy['id'],
740 action='access_as_shared',
741 target_tenant=self.client2.tenant_id)['rbac_policy']
742 rbac_pol2 = self.admin_client.create_rbac_policy(
743 object_type='qos_policy', object_id=policy['id'],
744 action='access_as_shared',
745 target_tenant=self.admin_client.tenant_id)['rbac_policy']
746 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
747 'rbac_policies']
748 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
749 'rbac_policies']
750 self.assertEqual(1, len(res1))
751 self.assertEqual(1, len(res2))
752 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
753 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
754
755 @test.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
756 def test_regular_client_blocked_from_sharing_anothers_policy(self):
757 qos_policy = self._make_admin_policy_shared_to_tenant_id(
758 self.client.tenant_id)['policy']
759 with testtools.ExpectedException(exceptions.BadRequest):
760 self.client.create_rbac_policy(
761 object_type='qos_policy', object_id=qos_policy['id'],
762 action='access_as_shared',
763 target_tenant=self.client2.tenant_id)
764
765 # make sure the rbac-policy is invisible to the tenant for which it's
766 # being shared
767 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
768
769
770class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
771 VALID_DSCP_MARK1 = 56
772 VALID_DSCP_MARK2 = 48
773
774 @classmethod
Sławek Kapłońskiff294062016-12-04 15:00:54 +0000775 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000776 @test.requires_ext(extension="qos", service="network")
777 def resource_setup(cls):
778 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
779
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200780 @test.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000781 def test_rule_create(self):
782 policy = self.create_qos_policy(name='test-policy',
783 description='test policy',
784 shared=False)
785 rule = self.admin_client.create_dscp_marking_rule(
786 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
787
788 # Test 'show rule'
789 retrieved_rule = self.admin_client.show_dscp_marking_rule(
790 policy['id'], rule['id'])
791 retrieved_rule = retrieved_rule['dscp_marking_rule']
792 self.assertEqual(rule['id'], retrieved_rule['id'])
793 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
794
795 # Test 'list rules'
796 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
797 rules = rules['dscp_marking_rules']
798 rules_ids = [r['id'] for r in rules]
799 self.assertIn(rule['id'], rules_ids)
800
801 # Test 'show policy'
802 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
803 policy_rules = retrieved_policy['policy']['rules']
804 self.assertEqual(1, len(policy_rules))
805 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000806 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000807 policy_rules[0]['type'])
808
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200809 @test.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000810 def test_rule_create_fail_for_the_same_type(self):
811 policy = self.create_qos_policy(name='test-policy',
812 description='test policy',
813 shared=False)
814 self.admin_client.create_dscp_marking_rule(
815 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
816
817 self.assertRaises(exceptions.Conflict,
818 self.admin_client.create_dscp_marking_rule,
819 policy_id=policy['id'],
820 dscp_mark=self.VALID_DSCP_MARK2)
821
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200822 @test.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000823 def test_rule_update(self):
824 policy = self.create_qos_policy(name='test-policy',
825 description='test policy',
826 shared=False)
827 rule = self.admin_client.create_dscp_marking_rule(
828 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
829
830 self.admin_client.update_dscp_marking_rule(
831 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
832
833 retrieved_policy = self.admin_client.show_dscp_marking_rule(
834 policy['id'], rule['id'])
835 retrieved_policy = retrieved_policy['dscp_marking_rule']
836 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
837
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200838 @test.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000839 def test_rule_delete(self):
840 policy = self.create_qos_policy(name='test-policy',
841 description='test policy',
842 shared=False)
843 rule = self.admin_client.create_dscp_marking_rule(
844 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
845
846 retrieved_policy = self.admin_client.show_dscp_marking_rule(
847 policy['id'], rule['id'])
848 retrieved_policy = retrieved_policy['dscp_marking_rule']
849 self.assertEqual(rule['id'], retrieved_policy['id'])
850
851 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
852 self.assertRaises(exceptions.NotFound,
853 self.admin_client.show_dscp_marking_rule,
854 policy['id'], rule['id'])
855
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200856 @test.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000857 def test_rule_create_rule_nonexistent_policy(self):
858 self.assertRaises(
859 exceptions.NotFound,
860 self.admin_client.create_dscp_marking_rule,
861 'policy', self.VALID_DSCP_MARK1)
862
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200863 @test.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000864 def test_rule_create_forbidden_for_regular_tenants(self):
865 self.assertRaises(
866 exceptions.Forbidden,
867 self.client.create_dscp_marking_rule,
868 'policy', self.VALID_DSCP_MARK1)
869
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000870 @test.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
871 def test_invalid_rule_create(self):
872 policy = self.create_qos_policy(name='test-policy',
873 description='test policy',
874 shared=False)
875 self.assertRaises(
876 exceptions.BadRequest,
877 self.admin_client.create_dscp_marking_rule,
878 policy['id'], 58)
879
Miguel Angel Ajocda3f072016-04-01 15:24:54 +0200880 @test.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000881 def test_get_rules_by_policy(self):
882 policy1 = self.create_qos_policy(name='test-policy1',
883 description='test policy1',
884 shared=False)
885 rule1 = self.admin_client.create_dscp_marking_rule(
886 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
887
888 policy2 = self.create_qos_policy(name='test-policy2',
889 description='test policy2',
890 shared=False)
891 rule2 = self.admin_client.create_dscp_marking_rule(
892 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
893
894 # Test 'list rules'
895 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
896 rules = rules['dscp_marking_rules']
897 rules_ids = [r['id'] for r in rules]
898 self.assertIn(rule1['id'], rules_ids)
899 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +0200900
901
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100902class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
903 DIRECTION_EGRESS = "egress"
904 DIRECTION_INGRESS = "ingress"
905 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
906 RULES_NAME = RULE_NAME + "s"
907
908 @classmethod
Sławek Kapłońskiff294062016-12-04 15:00:54 +0000909 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100910 @test.requires_ext(extension="qos", service="network")
911 def resource_setup(cls):
912 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
913
914 @test.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
915 def test_rule_create(self):
916 policy = self.create_qos_policy(name='test-policy',
917 description='test policy',
918 shared=False)
919 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000920 policy_id=policy['id'],
921 direction=self.DIRECTION_EGRESS,
922 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100923
924 # Test 'show rule'
925 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
926 policy['id'], rule['id'])
927 retrieved_rule = retrieved_rule[self.RULE_NAME]
928 self.assertEqual(rule['id'], retrieved_rule['id'])
929 self.assertEqual(1138, retrieved_rule['min_kbps'])
930 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
931
932 # Test 'list rules'
933 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
934 rules = rules[self.RULES_NAME]
935 rules_ids = [r['id'] for r in rules]
936 self.assertIn(rule['id'], rules_ids)
937
938 # Test 'show policy'
939 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
940 policy_rules = retrieved_policy['policy']['rules']
941 self.assertEqual(1, len(policy_rules))
942 self.assertEqual(rule['id'], policy_rules[0]['id'])
943 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
944 policy_rules[0]['type'])
945
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000946 @test.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
947 def test_rule_create_fail_for_missing_min_kbps(self):
948 policy = self.create_qos_policy(name='test-policy',
949 description='test policy',
950 shared=False)
951 self.assertRaises(exceptions.BadRequest,
952 self.admin_client.create_minimum_bandwidth_rule,
953 policy_id=policy['id'],
954 direction=self.DIRECTION_EGRESS)
955
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100956 @test.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
957 def test_rule_create_fail_for_the_same_type(self):
958 policy = self.create_qos_policy(name='test-policy',
959 description='test policy',
960 shared=False)
961 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000962 policy_id=policy['id'],
963 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100964
965 self.assertRaises(exceptions.Conflict,
966 self.admin_client.create_minimum_bandwidth_rule,
967 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000968 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100969
970 @test.idempotent_id('d6fce764-e511-4fa6-9f86-f4b41cf142cf')
971 def test_rule_create_fail_for_direction_ingress(self):
972 policy = self.create_qos_policy(name='test-policy',
973 description='test policy',
974 shared=False)
975 self.assertRaises(exceptions.BadRequest,
976 self.admin_client.create_minimum_bandwidth_rule,
977 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000978 direction=self.DIRECTION_INGRESS,
979 min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100980
981 @test.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
982 def test_rule_update(self):
983 policy = self.create_qos_policy(name='test-policy',
984 description='test policy',
985 shared=False)
986 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000987 policy_id=policy['id'],
988 direction=self.DIRECTION_EGRESS,
989 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100990
991 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
992 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
993
994 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
995 policy['id'], rule['id'])
996 retrieved_policy = retrieved_policy[self.RULE_NAME]
997 self.assertEqual(350, retrieved_policy['min_kbps'])
998 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
999
1000 @test.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
1001 def test_rule_delete(self):
1002 policy = self.create_qos_policy(name='test-policy',
1003 description='test policy',
1004 shared=False)
1005 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001006 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001007
1008 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1009 policy['id'], rule['id'])
1010 retrieved_policy = retrieved_policy[self.RULE_NAME]
1011 self.assertEqual(rule['id'], retrieved_policy['id'])
1012
1013 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1014 rule['id'])
1015 self.assertRaises(exceptions.NotFound,
1016 self.admin_client.show_minimum_bandwidth_rule,
1017 policy['id'], rule['id'])
1018
1019 @test.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
1020 def test_rule_create_rule_nonexistent_policy(self):
1021 self.assertRaises(
1022 exceptions.NotFound,
1023 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001024 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001025
1026 @test.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
1027 def test_rule_create_forbidden_for_regular_tenants(self):
1028 self.assertRaises(
1029 exceptions.Forbidden,
1030 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001031 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001032
1033 @test.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
1034 def test_get_rules_by_policy(self):
1035 policy1 = self.create_qos_policy(name='test-policy1',
1036 description='test policy1',
1037 shared=False)
1038 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001039 policy_id=policy1['id'],
1040 direction=self.DIRECTION_EGRESS,
1041 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001042
1043 policy2 = self.create_qos_policy(name='test-policy2',
1044 description='test policy2',
1045 shared=False)
1046 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001047 policy_id=policy2['id'],
1048 direction=self.DIRECTION_EGRESS,
1049 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001050
1051 # Test 'list rules'
1052 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1053 rules = rules[self.RULES_NAME]
1054 rules_ids = [r['id'] for r in rules]
1055 self.assertIn(rule1['id'], rules_ids)
1056 self.assertNotIn(rule2['id'], rules_ids)
1057
1058
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001059class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1060 base.BaseAdminNetworkTest):
1061
1062 resource = 'policy'
1063 plural_name = 'policies'
1064
1065 # Use unique description to isolate the tests from other QoS tests
1066 list_kwargs = {'description': 'search-criteria-test'}
1067 list_as_admin = True
1068
1069 @classmethod
1070 @test.requires_ext(extension="qos", service="network")
1071 def resource_setup(cls):
1072 super(QosSearchCriteriaTest, cls).resource_setup()
1073 for name in cls.resource_names:
1074 cls.create_qos_policy(
1075 name=name, description='search-criteria-test')
1076
1077 @test.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
1078 def test_list_sorts_asc(self):
1079 self._test_list_sorts_asc()
1080
1081 @test.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
1082 def test_list_sorts_desc(self):
1083 self._test_list_sorts_desc()
1084
1085 @test.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
1086 def test_list_pagination(self):
1087 self._test_list_pagination()
1088
1089 @test.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
1090 def test_list_pagination_with_marker(self):
1091 self._test_list_pagination_with_marker()
1092
1093 @test.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
1094 def test_list_pagination_with_href_links(self):
1095 self._test_list_pagination_with_href_links()
1096
1097 @test.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
1098 def test_list_pagination_page_reverse_asc(self):
1099 self._test_list_pagination_page_reverse_asc()
1100
1101 @test.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
1102 def test_list_pagination_page_reverse_desc(self):
1103 self._test_list_pagination_page_reverse_desc()
1104
1105 @test.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
1106 def test_list_pagination_page_reverse_with_href_links(self):
1107 self._test_list_pagination_page_reverse_with_href_links()
1108
1109 @test.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
1110 def test_list_no_pagination_limit_0(self):
1111 self._test_list_no_pagination_limit_0()