blob: 104fb9b5e40435847ae6a2a4d339427ddab12eae [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
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000016from tempest.lib import decorators
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000017from tempest.lib import exceptions
18from tempest import test
19
20import testtools
21
22from neutron.services.qos import qos_consts
23from neutron.tests.tempest.api import base
24
25
26class QosTestJSON(base.BaseAdminNetworkTest):
27 @classmethod
28 @test.requires_ext(extension="qos", service="network")
29 def resource_setup(cls):
30 super(QosTestJSON, cls).resource_setup()
31
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000032 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000033 def test_create_policy(self):
34 policy = self.create_qos_policy(name='test-policy',
35 description='test policy desc1',
36 shared=False)
37
38 # Test 'show policy'
39 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
40 retrieved_policy = retrieved_policy['policy']
41 self.assertEqual('test-policy', retrieved_policy['name'])
42 self.assertEqual('test policy desc1', retrieved_policy['description'])
43 self.assertFalse(retrieved_policy['shared'])
44
45 # Test 'list policies'
46 policies = self.admin_client.list_qos_policies()['policies']
47 policies_ids = [p['id'] for p in policies]
48 self.assertIn(policy['id'], policies_ids)
49
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000050 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Henry Gessaufa6c78d2016-10-09 19:56:09 -040051 @test.requires_ext(extension="project-id", service="network")
52 def test_show_policy_has_project_id(self):
53 policy = self.create_qos_policy(name='test-policy', shared=False)
54 body = self.admin_client.show_qos_policy(policy['id'])
55 show_policy = body['policy']
56 self.assertIn('project_id', show_policy)
57 self.assertIn('tenant_id', show_policy)
58 self.assertEqual(self.admin_client.tenant_id,
59 show_policy['project_id'])
60 self.assertEqual(self.admin_client.tenant_id,
61 show_policy['tenant_id'])
62
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000063 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000064 def test_list_policy_filter_by_name(self):
65 self.create_qos_policy(name='test', description='test policy',
66 shared=False)
67 self.create_qos_policy(name='test2', description='test policy',
68 shared=False)
69
70 policies = (self.admin_client.
71 list_qos_policies(name='test')['policies'])
72 self.assertEqual(1, len(policies))
73
74 retrieved_policy = policies[0]
75 self.assertEqual('test', retrieved_policy['name'])
76
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000077 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000078 def test_policy_update(self):
79 policy = self.create_qos_policy(name='test-policy',
80 description='',
81 shared=False)
82 self.admin_client.update_qos_policy(policy['id'],
83 description='test policy desc2',
84 shared=True)
85
86 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
87 retrieved_policy = retrieved_policy['policy']
88 self.assertEqual('test policy desc2', retrieved_policy['description'])
89 self.assertTrue(retrieved_policy['shared'])
90 self.assertEqual([], retrieved_policy['rules'])
91
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000092 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +000093 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
94 policy = self.create_qos_policy(name='test-policy',
95 description='',
96 shared=False,
97 tenant_id=self.client.tenant_id)
98 self.assertRaises(
99 exceptions.Forbidden,
100 self.client.update_qos_policy,
101 policy['id'], description='test policy')
102
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000103 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000104 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
105 policy = self.create_qos_policy(name='test-policy',
106 description='',
107 shared=False,
108 tenant_id=self.admin_client.tenant_id)
109 self.assertRaises(
110 exceptions.NotFound,
111 self.client.update_qos_policy,
112 policy['id'], description='test policy')
113
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000114 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000115 def test_shared_policy_update(self):
116 policy = self.create_qos_policy(name='test-policy',
117 description='',
118 shared=True)
119
120 self.admin_client.update_qos_policy(policy['id'],
121 description='test policy desc2')
122 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
123 retrieved_policy = retrieved_policy['policy']
124 self.assertTrue(retrieved_policy['shared'])
125
126 self.admin_client.update_qos_policy(policy['id'],
127 shared=False)
128 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
129 retrieved_policy = retrieved_policy['policy']
130 self.assertFalse(retrieved_policy['shared'])
131
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000132 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000133 def test_delete_policy(self):
134 policy = self.admin_client.create_qos_policy(
135 'test-policy', 'desc', True)['policy']
136
137 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
138 retrieved_policy = retrieved_policy['policy']
139 self.assertEqual('test-policy', retrieved_policy['name'])
140
141 self.admin_client.delete_qos_policy(policy['id'])
142 self.assertRaises(exceptions.NotFound,
143 self.admin_client.show_qos_policy, policy['id'])
144
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000145 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000146 def test_list_admin_rule_types(self):
147 self._test_list_rule_types(self.admin_client)
148
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000149 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000150 def test_list_regular_rule_types(self):
151 self._test_list_rule_types(self.client)
152
153 def _test_list_rule_types(self, client):
154 # List supported rule types
155 # TODO(QoS): since in gate we run both ovs and linuxbridge ml2 drivers,
156 # and since Linux Bridge ml2 driver does not have QoS support yet, ml2
157 # plugin reports no rule types are supported. Once linuxbridge will
158 # receive support for QoS, the list of expected rule types will change.
159 #
160 # In theory, we could make the test conditional on which ml2 drivers
161 # are enabled in gate (or more specifically, on which supported qos
162 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200163 # available through tempest.lib framework
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000164 expected_rule_types = []
165 expected_rule_details = ['type']
166
167 rule_types = client.list_qos_rule_types()
168 actual_list_rule_types = rule_types['rule_types']
169 actual_rule_types = [rule['type'] for rule in actual_list_rule_types]
170
171 # Verify that only required fields present in rule details
172 for rule in actual_list_rule_types:
173 self.assertEqual(tuple(rule.keys()), tuple(expected_rule_details))
174
175 # Verify if expected rules are present in the actual rules list
176 for rule in expected_rule_types:
177 self.assertIn(rule, actual_rule_types)
178
179 def _disassociate_network(self, client, network_id):
Hong Hui Xiao25028302016-12-13 16:29:08 +0800180 updated_network = client.update_network(network_id,
181 qos_policy_id=None)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000182 self.assertIsNone(updated_network['network']['qos_policy_id'])
183
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000184 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000185 def test_policy_association_with_admin_network(self):
186 policy = self.create_qos_policy(name='test-policy',
187 description='test policy',
188 shared=False)
189 network = self.create_shared_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.admin_client, network['id'])
197
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000198 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000199 def test_policy_association_with_tenant_network(self):
200 policy = self.create_qos_policy(name='test-policy',
201 description='test policy',
202 shared=True)
203 network = self.create_network('test network',
204 qos_policy_id=policy['id'])
205
206 retrieved_network = self.admin_client.show_network(network['id'])
207 self.assertEqual(
208 policy['id'], retrieved_network['network']['qos_policy_id'])
209
210 self._disassociate_network(self.client, network['id'])
211
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000212 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000213 def test_policy_association_with_network_nonexistent_policy(self):
214 self.assertRaises(
215 exceptions.NotFound,
216 self.create_network,
217 'test network',
218 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
219
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000220 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000221 def test_policy_association_with_network_non_shared_policy(self):
222 policy = self.create_qos_policy(name='test-policy',
223 description='test policy',
224 shared=False)
225 self.assertRaises(
226 exceptions.NotFound,
227 self.create_network,
228 'test network', qos_policy_id=policy['id'])
229
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000230 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000231 def test_policy_update_association_with_admin_network(self):
232 policy = self.create_qos_policy(name='test-policy',
233 description='test policy',
234 shared=False)
235 network = self.create_shared_network('test network')
236 retrieved_network = self.admin_client.show_network(network['id'])
237 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
238
239 self.admin_client.update_network(network['id'],
240 qos_policy_id=policy['id'])
241 retrieved_network = self.admin_client.show_network(network['id'])
242 self.assertEqual(
243 policy['id'], retrieved_network['network']['qos_policy_id'])
244
245 self._disassociate_network(self.admin_client, network['id'])
246
247 def _disassociate_port(self, port_id):
248 self.client.update_port(port_id, qos_policy_id=None)
249 updated_port = self.admin_client.show_port(port_id)
250 self.assertIsNone(updated_port['port']['qos_policy_id'])
251
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000252 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000253 def test_policy_association_with_port_shared_policy(self):
254 policy = self.create_qos_policy(name='test-policy',
255 description='test policy',
256 shared=True)
257 network = self.create_shared_network('test network')
258 port = self.create_port(network, qos_policy_id=policy['id'])
259
260 retrieved_port = self.admin_client.show_port(port['id'])
261 self.assertEqual(
262 policy['id'], retrieved_port['port']['qos_policy_id'])
263
264 self._disassociate_port(port['id'])
265
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000266 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000267 def test_policy_association_with_port_nonexistent_policy(self):
268 network = self.create_shared_network('test network')
269 self.assertRaises(
270 exceptions.NotFound,
271 self.create_port,
272 network,
273 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
274
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000275 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000276 def test_policy_association_with_port_non_shared_policy(self):
277 policy = self.create_qos_policy(name='test-policy',
278 description='test policy',
279 shared=False)
280 network = self.create_shared_network('test network')
281 self.assertRaises(
282 exceptions.NotFound,
283 self.create_port,
284 network, qos_policy_id=policy['id'])
285
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000286 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000287 def test_policy_update_association_with_port_shared_policy(self):
288 policy = self.create_qos_policy(name='test-policy',
289 description='test policy',
290 shared=True)
291 network = self.create_shared_network('test network')
292 port = self.create_port(network)
293 retrieved_port = self.admin_client.show_port(port['id'])
294 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
295
296 self.client.update_port(port['id'], qos_policy_id=policy['id'])
297 retrieved_port = self.admin_client.show_port(port['id'])
298 self.assertEqual(
299 policy['id'], retrieved_port['port']['qos_policy_id'])
300
301 self._disassociate_port(port['id'])
302
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000303 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000304 def test_delete_not_allowed_if_policy_in_use_by_network(self):
305 policy = self.create_qos_policy(name='test-policy',
306 description='test policy',
307 shared=True)
308 network = self.create_shared_network(
309 'test 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_network(self.admin_client, network['id'])
315 self.admin_client.delete_qos_policy(policy['id'])
316
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000317 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000318 def test_delete_not_allowed_if_policy_in_use_by_port(self):
319 policy = self.create_qos_policy(name='test-policy',
320 description='test policy',
321 shared=True)
322 network = self.create_shared_network('test network')
323 port = self.create_port(network, qos_policy_id=policy['id'])
324 self.assertRaises(
325 exceptions.Conflict,
326 self.admin_client.delete_qos_policy, policy['id'])
327
328 self._disassociate_port(port['id'])
329 self.admin_client.delete_qos_policy(policy['id'])
330
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000331 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000332 def test_qos_policy_delete_with_rules(self):
333 policy = self.create_qos_policy(name='test-policy',
334 description='test policy',
335 shared=False)
336 self.admin_client.create_bandwidth_limit_rule(
337 policy['id'], 200, 1337)['bandwidth_limit_rule']
338
339 self.admin_client.delete_qos_policy(policy['id'])
340
341 with testtools.ExpectedException(exceptions.NotFound):
342 self.admin_client.show_qos_policy(policy['id'])
343
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000344 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000345 def test_get_policy_that_is_shared(self):
346 policy = self.create_qos_policy(
347 name='test-policy-shared',
348 description='shared policy',
349 shared=True,
350 tenant_id=self.admin_client.tenant_id)
351 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
352 self.assertEqual(obtained_policy, policy)
353
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000354 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100355 def test_policy_create_forbidden_for_regular_tenants(self):
356 self.assertRaises(
357 exceptions.Forbidden,
358 self.client.create_qos_policy,
359 'test-policy', 'test policy', False)
360
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000361
362class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
363 @classmethod
364 @test.requires_ext(extension="qos", service="network")
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900365 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000366 def resource_setup(cls):
367 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
368
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000369 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000370 def test_rule_create(self):
371 policy = self.create_qos_policy(name='test-policy',
372 description='test policy',
373 shared=False)
374 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
375 max_kbps=200,
376 max_burst_kbps=1337)
377
378 # Test 'show rule'
379 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
380 policy['id'], rule['id'])
381 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
382 self.assertEqual(rule['id'], retrieved_rule['id'])
383 self.assertEqual(200, retrieved_rule['max_kbps'])
384 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
385
386 # Test 'list rules'
387 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
388 rules = rules['bandwidth_limit_rules']
389 rules_ids = [r['id'] for r in rules]
390 self.assertIn(rule['id'], rules_ids)
391
392 # Test 'show policy'
393 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
394 policy_rules = retrieved_policy['policy']['rules']
395 self.assertEqual(1, len(policy_rules))
396 self.assertEqual(rule['id'], policy_rules[0]['id'])
397 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
398 policy_rules[0]['type'])
399
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000400 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000401 def test_rule_create_fail_for_the_same_type(self):
402 policy = self.create_qos_policy(name='test-policy',
403 description='test policy',
404 shared=False)
405 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
406 max_kbps=200,
407 max_burst_kbps=1337)
408
409 self.assertRaises(exceptions.Conflict,
410 self.create_qos_bandwidth_limit_rule,
411 policy_id=policy['id'],
412 max_kbps=201, max_burst_kbps=1338)
413
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000414 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000415 def test_rule_update(self):
416 policy = self.create_qos_policy(name='test-policy',
417 description='test policy',
418 shared=False)
419 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
420 max_kbps=1,
421 max_burst_kbps=1)
422
423 self.admin_client.update_bandwidth_limit_rule(policy['id'],
424 rule['id'],
425 max_kbps=200,
426 max_burst_kbps=1337)
427
428 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
429 policy['id'], rule['id'])
430 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
431 self.assertEqual(200, retrieved_policy['max_kbps'])
432 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
433
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000434 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000435 def test_rule_delete(self):
436 policy = self.create_qos_policy(name='test-policy',
437 description='test policy',
438 shared=False)
439 rule = self.admin_client.create_bandwidth_limit_rule(
440 policy['id'], 200, 1337)['bandwidth_limit_rule']
441
442 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
443 policy['id'], rule['id'])
444 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
445 self.assertEqual(rule['id'], retrieved_policy['id'])
446
447 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
448 self.assertRaises(exceptions.NotFound,
449 self.admin_client.show_bandwidth_limit_rule,
450 policy['id'], rule['id'])
451
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000452 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000453 def test_rule_create_rule_nonexistent_policy(self):
454 self.assertRaises(
455 exceptions.NotFound,
456 self.create_qos_bandwidth_limit_rule,
457 'policy', 200, 1337)
458
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000459 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000460 def test_rule_create_forbidden_for_regular_tenants(self):
461 self.assertRaises(
462 exceptions.Forbidden,
463 self.client.create_bandwidth_limit_rule,
464 'policy', 1, 2)
465
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000466 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000467 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
468 policy = self.create_qos_policy(name='test-policy',
469 description='test policy',
470 shared=False,
471 tenant_id=self.client.tenant_id)
472 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
473 max_kbps=1,
474 max_burst_kbps=1)
475 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400476 exceptions.Forbidden,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000477 self.client.update_bandwidth_limit_rule,
478 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
479
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000480 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000481 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
482 policy = self.create_qos_policy(name='test-policy',
483 description='test policy',
484 shared=False,
485 tenant_id=self.admin_client.tenant_id)
486 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
487 max_kbps=1,
488 max_burst_kbps=1)
489 self.assertRaises(
490 exceptions.NotFound,
491 self.client.update_bandwidth_limit_rule,
492 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
493
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000494 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000495 def test_get_rules_by_policy(self):
496 policy1 = self.create_qos_policy(name='test-policy1',
497 description='test policy1',
498 shared=False)
499 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
500 max_kbps=200,
501 max_burst_kbps=1337)
502
503 policy2 = self.create_qos_policy(name='test-policy2',
504 description='test policy2',
505 shared=False)
506 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
507 max_kbps=5000,
508 max_burst_kbps=2523)
509
510 # Test 'list rules'
511 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
512 rules = rules['bandwidth_limit_rules']
513 rules_ids = [r['id'] for r in rules]
514 self.assertIn(rule1['id'], rules_ids)
515 self.assertNotIn(rule2['id'], rules_ids)
516
517
518class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
519
520 force_tenant_isolation = True
521 credentials = ['primary', 'alt', 'admin']
522
523 @classmethod
524 @test.requires_ext(extension="qos", service="network")
525 def resource_setup(cls):
526 super(RbacSharedQosPoliciesTest, cls).resource_setup()
527 cls.client2 = cls.alt_manager.network_client
528
529 def _create_qos_policy(self, tenant_id=None):
530 args = {'name': data_utils.rand_name('test-policy'),
531 'description': 'test policy',
532 'shared': False,
533 'tenant_id': tenant_id}
534 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
535 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
536
537 return qos_policy
538
539 def _make_admin_policy_shared_to_tenant_id(self, tenant_id):
540 policy = self._create_qos_policy()
541 rbac_policy = self.admin_client.create_rbac_policy(
542 object_type='qos_policy',
543 object_id=policy['id'],
544 action='access_as_shared',
545 target_tenant=tenant_id,
546 )['rbac_policy']
547
548 return {'policy': policy, 'rbac_policy': rbac_policy}
549
550 def _create_network(self, qos_policy_id, client, should_cleanup=True):
551 net = client.create_network(
552 name=data_utils.rand_name('test-network'),
553 qos_policy_id=qos_policy_id)['network']
554 if should_cleanup:
555 self.addCleanup(client.delete_network, net['id'])
556
557 return net
558
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000559 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000560 def test_policy_sharing_with_wildcard(self):
561 qos_pol = self.create_qos_policy(
562 name=data_utils.rand_name('test-policy'),
563 description='test-shared-policy', shared=False)
564 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
565
566 # test update shared False -> True
567 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
568 qos_pol['shared'] = True
569 self.client2.show_qos_policy(qos_pol['id'])
570 rbac_pol = {'target_tenant': '*',
571 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000572 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000573 'object_type': 'qos_policy',
574 'object_id': qos_pol['id'],
575 'action': 'access_as_shared'}
576
577 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
578 rbac_policies = [r for r in rbac_policies if r.pop('id')]
579 self.assertIn(rbac_pol, rbac_policies)
580
581 # update shared True -> False should fail because the policy is bound
582 # to a network
583 net = self._create_network(qos_pol['id'], self.admin_client, False)
584 with testtools.ExpectedException(exceptions.Conflict):
585 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
586
587 # delete the network, and update shared True -> False should pass now
588 self.admin_client.delete_network(net['id'])
589 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
590 qos_pol['shared'] = False
591 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
592
593 def _create_net_bound_qos_rbacs(self):
594 res = self._make_admin_policy_shared_to_tenant_id(
595 self.client.tenant_id)
596 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
597
598 # add a wildcard rbac rule - now the policy globally shared
599 rbac_wildcard = self.admin_client.create_rbac_policy(
600 object_type='qos_policy',
601 object_id=qos_policy['id'],
602 action='access_as_shared',
603 target_tenant='*',
604 )['rbac_policy']
605
606 # tenant1 now uses qos policy for net
607 self._create_network(qos_policy['id'], self.client)
608
609 return rbac_for_client_tenant, rbac_wildcard
610
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000611 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000612 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self):
613 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
614 # globally unshare the qos-policy, the specific share should remain
615 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
616 self.client.list_rbac_policies(id=client_rbac['id'])
617
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000618 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000619 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self):
620 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
621 # remove client_rbac policy the wildcard share should remain
622 self.admin_client.delete_rbac_policy(client_rbac['id'])
623 self.client.list_rbac_policies(id=wildcard_rbac['id'])
624
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000625 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000626 def test_policy_sharing_with_wildcard_and_tenant_id(self):
627 res = self._make_admin_policy_shared_to_tenant_id(
628 self.client.tenant_id)
629 qos_policy, rbac = res['policy'], res['rbac_policy']
630 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
631 self.assertTrue(qos_pol['shared'])
632 with testtools.ExpectedException(exceptions.NotFound):
633 self.client2.show_qos_policy(qos_policy['id'])
634
635 # make the qos-policy globally shared
636 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
637 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
638 self.assertTrue(qos_pol['shared'])
639
640 # globally unshare the qos-policy, the specific share should remain
641 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
642 self.client.show_qos_policy(qos_policy['id'])
643 with testtools.ExpectedException(exceptions.NotFound):
644 self.client2.show_qos_policy(qos_policy['id'])
645 self.assertIn(rbac,
646 self.admin_client.list_rbac_policies()['rbac_policies'])
647
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000648 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000649 def test_policy_target_update(self):
650 res = self._make_admin_policy_shared_to_tenant_id(
651 self.client.tenant_id)
652 # change to client2
653 update_res = self.admin_client.update_rbac_policy(
654 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
655 self.assertEqual(self.client2.tenant_id,
656 update_res['rbac_policy']['target_tenant'])
657 # make sure everything else stayed the same
658 res['rbac_policy'].pop('target_tenant')
659 update_res['rbac_policy'].pop('target_tenant')
660 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
661
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000662 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000663 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
664 res = self._make_admin_policy_shared_to_tenant_id(
665 self.client2.tenant_id)
666 qos_policy_id = res['policy']['id']
667 self._create_network(qos_policy_id, self.client2)
668 # a network with shared qos-policy should prevent the deletion of an
669 # rbac-policy required for it to be shared
670 with testtools.ExpectedException(exceptions.Conflict):
671 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
672
673 # a wildcard policy should allow the specific policy to be deleted
674 # since it allows the remaining port
675 wild = self.admin_client.create_rbac_policy(
676 object_type='qos_policy', object_id=res['policy']['id'],
677 action='access_as_shared', target_tenant='*')['rbac_policy']
678 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
679
680 # now that wildcard is the only remaining, it should be subjected to
681 # the same restriction
682 with testtools.ExpectedException(exceptions.Conflict):
683 self.admin_client.delete_rbac_policy(wild['id'])
684
685 # we can't update the policy to a different tenant
686 with testtools.ExpectedException(exceptions.Conflict):
687 self.admin_client.update_rbac_policy(
688 wild['id'], target_tenant=self.client2.tenant_id)
689
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000690 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000691 def test_regular_client_shares_to_another_regular_client(self):
692 # owned by self.admin_client
693 policy = self._create_qos_policy()
694 with testtools.ExpectedException(exceptions.NotFound):
695 self.client.show_qos_policy(policy['id'])
696 rbac_policy = self.admin_client.create_rbac_policy(
697 object_type='qos_policy', object_id=policy['id'],
698 action='access_as_shared',
699 target_tenant=self.client.tenant_id)['rbac_policy']
700 self.client.show_qos_policy(policy['id'])
701
702 self.assertIn(rbac_policy,
703 self.admin_client.list_rbac_policies()['rbac_policies'])
704 # ensure that 'client2' can't see the rbac-policy sharing the
705 # qos-policy to it because the rbac-policy belongs to 'client'
706 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
707 self.client2.list_rbac_policies()['rbac_policies']])
708
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000709 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000710 def test_filter_fields(self):
711 policy = self._create_qos_policy()
712 self.admin_client.create_rbac_policy(
713 object_type='qos_policy', object_id=policy['id'],
714 action='access_as_shared', target_tenant=self.client2.tenant_id)
715 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
716 ('tenant_id', 'target_tenant'))
717 for fields in field_args:
718 res = self.admin_client.list_rbac_policies(fields=fields)
719 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
720
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000721 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000722 def test_rbac_policy_show(self):
723 res = self._make_admin_policy_shared_to_tenant_id(
724 self.client.tenant_id)
725 p1 = res['rbac_policy']
726 p2 = self.admin_client.create_rbac_policy(
727 object_type='qos_policy', object_id=res['policy']['id'],
728 action='access_as_shared',
729 target_tenant='*')['rbac_policy']
730
731 self.assertEqual(
732 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
733 self.assertEqual(
734 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
735
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000736 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000737 def test_filter_rbac_policies(self):
738 policy = self._create_qos_policy()
739 rbac_pol1 = self.admin_client.create_rbac_policy(
740 object_type='qos_policy', object_id=policy['id'],
741 action='access_as_shared',
742 target_tenant=self.client2.tenant_id)['rbac_policy']
743 rbac_pol2 = self.admin_client.create_rbac_policy(
744 object_type='qos_policy', object_id=policy['id'],
745 action='access_as_shared',
746 target_tenant=self.admin_client.tenant_id)['rbac_policy']
747 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
748 'rbac_policies']
749 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
750 'rbac_policies']
751 self.assertEqual(1, len(res1))
752 self.assertEqual(1, len(res2))
753 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
754 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
755
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000756 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000757 def test_regular_client_blocked_from_sharing_anothers_policy(self):
758 qos_policy = self._make_admin_policy_shared_to_tenant_id(
759 self.client.tenant_id)['policy']
760 with testtools.ExpectedException(exceptions.BadRequest):
761 self.client.create_rbac_policy(
762 object_type='qos_policy', object_id=qos_policy['id'],
763 action='access_as_shared',
764 target_tenant=self.client2.tenant_id)
765
766 # make sure the rbac-policy is invisible to the tenant for which it's
767 # being shared
768 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
769
770
771class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
772 VALID_DSCP_MARK1 = 56
773 VALID_DSCP_MARK2 = 48
774
775 @classmethod
776 @test.requires_ext(extension="qos", service="network")
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900777 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000778 def resource_setup(cls):
779 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
780
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000781 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000782 def test_rule_create(self):
783 policy = self.create_qos_policy(name='test-policy',
784 description='test policy',
785 shared=False)
786 rule = self.admin_client.create_dscp_marking_rule(
787 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
788
789 # Test 'show rule'
790 retrieved_rule = self.admin_client.show_dscp_marking_rule(
791 policy['id'], rule['id'])
792 retrieved_rule = retrieved_rule['dscp_marking_rule']
793 self.assertEqual(rule['id'], retrieved_rule['id'])
794 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
795
796 # Test 'list rules'
797 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
798 rules = rules['dscp_marking_rules']
799 rules_ids = [r['id'] for r in rules]
800 self.assertIn(rule['id'], rules_ids)
801
802 # Test 'show policy'
803 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
804 policy_rules = retrieved_policy['policy']['rules']
805 self.assertEqual(1, len(policy_rules))
806 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000807 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000808 policy_rules[0]['type'])
809
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000810 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000811 def test_rule_create_fail_for_the_same_type(self):
812 policy = self.create_qos_policy(name='test-policy',
813 description='test policy',
814 shared=False)
815 self.admin_client.create_dscp_marking_rule(
816 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
817
818 self.assertRaises(exceptions.Conflict,
819 self.admin_client.create_dscp_marking_rule,
820 policy_id=policy['id'],
821 dscp_mark=self.VALID_DSCP_MARK2)
822
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000823 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000824 def test_rule_update(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 self.admin_client.update_dscp_marking_rule(
832 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
833
834 retrieved_policy = self.admin_client.show_dscp_marking_rule(
835 policy['id'], rule['id'])
836 retrieved_policy = retrieved_policy['dscp_marking_rule']
837 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
838
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000839 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000840 def test_rule_delete(self):
841 policy = self.create_qos_policy(name='test-policy',
842 description='test policy',
843 shared=False)
844 rule = self.admin_client.create_dscp_marking_rule(
845 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
846
847 retrieved_policy = self.admin_client.show_dscp_marking_rule(
848 policy['id'], rule['id'])
849 retrieved_policy = retrieved_policy['dscp_marking_rule']
850 self.assertEqual(rule['id'], retrieved_policy['id'])
851
852 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
853 self.assertRaises(exceptions.NotFound,
854 self.admin_client.show_dscp_marking_rule,
855 policy['id'], rule['id'])
856
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000857 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000858 def test_rule_create_rule_nonexistent_policy(self):
859 self.assertRaises(
860 exceptions.NotFound,
861 self.admin_client.create_dscp_marking_rule,
862 'policy', self.VALID_DSCP_MARK1)
863
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000864 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000865 def test_rule_create_forbidden_for_regular_tenants(self):
866 self.assertRaises(
867 exceptions.Forbidden,
868 self.client.create_dscp_marking_rule,
869 'policy', self.VALID_DSCP_MARK1)
870
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000871 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000872 def test_invalid_rule_create(self):
873 policy = self.create_qos_policy(name='test-policy',
874 description='test policy',
875 shared=False)
876 self.assertRaises(
877 exceptions.BadRequest,
878 self.admin_client.create_dscp_marking_rule,
879 policy['id'], 58)
880
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000881 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000882 def test_get_rules_by_policy(self):
883 policy1 = self.create_qos_policy(name='test-policy1',
884 description='test policy1',
885 shared=False)
886 rule1 = self.admin_client.create_dscp_marking_rule(
887 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
888
889 policy2 = self.create_qos_policy(name='test-policy2',
890 description='test policy2',
891 shared=False)
892 rule2 = self.admin_client.create_dscp_marking_rule(
893 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
894
895 # Test 'list rules'
896 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
897 rules = rules['dscp_marking_rules']
898 rules_ids = [r['id'] for r in rules]
899 self.assertIn(rule1['id'], rules_ids)
900 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +0200901
902
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100903class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
904 DIRECTION_EGRESS = "egress"
905 DIRECTION_INGRESS = "ingress"
906 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
907 RULES_NAME = RULE_NAME + "s"
908
909 @classmethod
910 @test.requires_ext(extension="qos", service="network")
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900911 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100912 def resource_setup(cls):
913 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
914
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000915 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100916 def test_rule_create(self):
917 policy = self.create_qos_policy(name='test-policy',
918 description='test policy',
919 shared=False)
920 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000921 policy_id=policy['id'],
922 direction=self.DIRECTION_EGRESS,
923 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100924
925 # Test 'show rule'
926 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
927 policy['id'], rule['id'])
928 retrieved_rule = retrieved_rule[self.RULE_NAME]
929 self.assertEqual(rule['id'], retrieved_rule['id'])
930 self.assertEqual(1138, retrieved_rule['min_kbps'])
931 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
932
933 # Test 'list rules'
934 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
935 rules = rules[self.RULES_NAME]
936 rules_ids = [r['id'] for r in rules]
937 self.assertIn(rule['id'], rules_ids)
938
939 # Test 'show policy'
940 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
941 policy_rules = retrieved_policy['policy']['rules']
942 self.assertEqual(1, len(policy_rules))
943 self.assertEqual(rule['id'], policy_rules[0]['id'])
944 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
945 policy_rules[0]['type'])
946
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000947 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000948 def test_rule_create_fail_for_missing_min_kbps(self):
949 policy = self.create_qos_policy(name='test-policy',
950 description='test policy',
951 shared=False)
952 self.assertRaises(exceptions.BadRequest,
953 self.admin_client.create_minimum_bandwidth_rule,
954 policy_id=policy['id'],
955 direction=self.DIRECTION_EGRESS)
956
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000957 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100958 def test_rule_create_fail_for_the_same_type(self):
959 policy = self.create_qos_policy(name='test-policy',
960 description='test policy',
961 shared=False)
962 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000963 policy_id=policy['id'],
964 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100965
966 self.assertRaises(exceptions.Conflict,
967 self.admin_client.create_minimum_bandwidth_rule,
968 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000969 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100970
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000971 @decorators.idempotent_id('d6fce764-e511-4fa6-9f86-f4b41cf142cf')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100972 def test_rule_create_fail_for_direction_ingress(self):
973 policy = self.create_qos_policy(name='test-policy',
974 description='test policy',
975 shared=False)
976 self.assertRaises(exceptions.BadRequest,
977 self.admin_client.create_minimum_bandwidth_rule,
978 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000979 direction=self.DIRECTION_INGRESS,
980 min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100981
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000982 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100983 def test_rule_update(self):
984 policy = self.create_qos_policy(name='test-policy',
985 description='test policy',
986 shared=False)
987 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000988 policy_id=policy['id'],
989 direction=self.DIRECTION_EGRESS,
990 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100991
992 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
993 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
994
995 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
996 policy['id'], rule['id'])
997 retrieved_policy = retrieved_policy[self.RULE_NAME]
998 self.assertEqual(350, retrieved_policy['min_kbps'])
999 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1000
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001001 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001002 def test_rule_delete(self):
1003 policy = self.create_qos_policy(name='test-policy',
1004 description='test policy',
1005 shared=False)
1006 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001007 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001008
1009 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1010 policy['id'], rule['id'])
1011 retrieved_policy = retrieved_policy[self.RULE_NAME]
1012 self.assertEqual(rule['id'], retrieved_policy['id'])
1013
1014 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1015 rule['id'])
1016 self.assertRaises(exceptions.NotFound,
1017 self.admin_client.show_minimum_bandwidth_rule,
1018 policy['id'], rule['id'])
1019
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001020 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001021 def test_rule_create_rule_nonexistent_policy(self):
1022 self.assertRaises(
1023 exceptions.NotFound,
1024 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001025 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001026
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001027 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001028 def test_rule_create_forbidden_for_regular_tenants(self):
1029 self.assertRaises(
1030 exceptions.Forbidden,
1031 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001032 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001033
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001034 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001035 def test_get_rules_by_policy(self):
1036 policy1 = self.create_qos_policy(name='test-policy1',
1037 description='test policy1',
1038 shared=False)
1039 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001040 policy_id=policy1['id'],
1041 direction=self.DIRECTION_EGRESS,
1042 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001043
1044 policy2 = self.create_qos_policy(name='test-policy2',
1045 description='test policy2',
1046 shared=False)
1047 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001048 policy_id=policy2['id'],
1049 direction=self.DIRECTION_EGRESS,
1050 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001051
1052 # Test 'list rules'
1053 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1054 rules = rules[self.RULES_NAME]
1055 rules_ids = [r['id'] for r in rules]
1056 self.assertIn(rule1['id'], rules_ids)
1057 self.assertNotIn(rule2['id'], rules_ids)
1058
1059
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001060class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1061 base.BaseAdminNetworkTest):
1062
1063 resource = 'policy'
1064 plural_name = 'policies'
1065
1066 # Use unique description to isolate the tests from other QoS tests
1067 list_kwargs = {'description': 'search-criteria-test'}
1068 list_as_admin = True
1069
1070 @classmethod
1071 @test.requires_ext(extension="qos", service="network")
1072 def resource_setup(cls):
1073 super(QosSearchCriteriaTest, cls).resource_setup()
1074 for name in cls.resource_names:
1075 cls.create_qos_policy(
1076 name=name, description='search-criteria-test')
1077
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001078 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001079 def test_list_sorts_asc(self):
1080 self._test_list_sorts_asc()
1081
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001082 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001083 def test_list_sorts_desc(self):
1084 self._test_list_sorts_desc()
1085
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001086 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001087 def test_list_pagination(self):
1088 self._test_list_pagination()
1089
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001090 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001091 def test_list_pagination_with_marker(self):
1092 self._test_list_pagination_with_marker()
1093
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001094 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001095 def test_list_pagination_with_href_links(self):
1096 self._test_list_pagination_with_href_links()
1097
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001098 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001099 def test_list_pagination_page_reverse_asc(self):
1100 self._test_list_pagination_page_reverse_asc()
1101
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001102 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001103 def test_list_pagination_page_reverse_desc(self):
1104 self._test_list_pagination_page_reverse_desc()
1105
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001106 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001107 def test_list_pagination_page_reverse_with_href_links(self):
1108 self._test_list_pagination_page_reverse_with_href_links()
1109
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001110 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001111 def test_list_no_pagination_limit_0(self):
1112 self._test_list_no_pagination_limit_0()