blob: 287207e74605a64a23923d411eeae0cbe09d281b [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
Sławek Kapłoński153f3452017-03-24 22:04:53 +000020import testscenarios
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000021import testtools
22
23from neutron.services.qos import qos_consts
24from neutron.tests.tempest.api import base
25
26
Sławek Kapłoński153f3452017-03-24 22:04:53 +000027load_tests = testscenarios.load_tests_apply_scenarios
28
29
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000030class QosTestJSON(base.BaseAdminNetworkTest):
31 @classmethod
32 @test.requires_ext(extension="qos", service="network")
33 def resource_setup(cls):
34 super(QosTestJSON, cls).resource_setup()
35
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000036 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000037 def test_create_policy(self):
38 policy = self.create_qos_policy(name='test-policy',
39 description='test policy desc1',
40 shared=False)
41
42 # Test 'show policy'
43 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
44 retrieved_policy = retrieved_policy['policy']
45 self.assertEqual('test-policy', retrieved_policy['name'])
46 self.assertEqual('test policy desc1', retrieved_policy['description'])
47 self.assertFalse(retrieved_policy['shared'])
48
49 # Test 'list policies'
50 policies = self.admin_client.list_qos_policies()['policies']
51 policies_ids = [p['id'] for p in policies]
52 self.assertIn(policy['id'], policies_ids)
53
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000054 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Henry Gessaufa6c78d2016-10-09 19:56:09 -040055 @test.requires_ext(extension="project-id", service="network")
56 def test_show_policy_has_project_id(self):
57 policy = self.create_qos_policy(name='test-policy', shared=False)
58 body = self.admin_client.show_qos_policy(policy['id'])
59 show_policy = body['policy']
60 self.assertIn('project_id', show_policy)
61 self.assertIn('tenant_id', show_policy)
62 self.assertEqual(self.admin_client.tenant_id,
63 show_policy['project_id'])
64 self.assertEqual(self.admin_client.tenant_id,
65 show_policy['tenant_id'])
66
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000067 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000068 def test_list_policy_filter_by_name(self):
69 self.create_qos_policy(name='test', description='test policy',
70 shared=False)
71 self.create_qos_policy(name='test2', description='test policy',
72 shared=False)
73
74 policies = (self.admin_client.
75 list_qos_policies(name='test')['policies'])
76 self.assertEqual(1, len(policies))
77
78 retrieved_policy = policies[0]
79 self.assertEqual('test', retrieved_policy['name'])
80
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000081 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000082 def test_policy_update(self):
83 policy = self.create_qos_policy(name='test-policy',
84 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +000085 shared=False,
86 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000087 self.admin_client.update_qos_policy(policy['id'],
88 description='test policy desc2',
89 shared=True)
90
91 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
92 retrieved_policy = retrieved_policy['policy']
93 self.assertEqual('test policy desc2', retrieved_policy['description'])
94 self.assertTrue(retrieved_policy['shared'])
95 self.assertEqual([], retrieved_policy['rules'])
96
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000097 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +000098 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
99 policy = self.create_qos_policy(name='test-policy',
100 description='',
101 shared=False,
102 tenant_id=self.client.tenant_id)
103 self.assertRaises(
104 exceptions.Forbidden,
105 self.client.update_qos_policy,
106 policy['id'], description='test policy')
107
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000108 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000109 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
110 policy = self.create_qos_policy(name='test-policy',
111 description='',
112 shared=False,
113 tenant_id=self.admin_client.tenant_id)
114 self.assertRaises(
115 exceptions.NotFound,
116 self.client.update_qos_policy,
117 policy['id'], description='test policy')
118
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000119 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000120 def test_shared_policy_update(self):
121 policy = self.create_qos_policy(name='test-policy',
122 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000123 shared=True,
124 tenant_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000125
126 self.admin_client.update_qos_policy(policy['id'],
127 description='test policy desc2')
128 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
129 retrieved_policy = retrieved_policy['policy']
130 self.assertTrue(retrieved_policy['shared'])
131
132 self.admin_client.update_qos_policy(policy['id'],
133 shared=False)
134 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
135 retrieved_policy = retrieved_policy['policy']
136 self.assertFalse(retrieved_policy['shared'])
137
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000138 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000139 def test_delete_policy(self):
140 policy = self.admin_client.create_qos_policy(
141 'test-policy', 'desc', True)['policy']
142
143 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
144 retrieved_policy = retrieved_policy['policy']
145 self.assertEqual('test-policy', retrieved_policy['name'])
146
147 self.admin_client.delete_qos_policy(policy['id'])
148 self.assertRaises(exceptions.NotFound,
149 self.admin_client.show_qos_policy, policy['id'])
150
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000151 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000152 def test_list_admin_rule_types(self):
153 self._test_list_rule_types(self.admin_client)
154
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000155 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000156 def test_list_regular_rule_types(self):
157 self._test_list_rule_types(self.client)
158
159 def _test_list_rule_types(self, client):
160 # List supported rule types
161 # TODO(QoS): since in gate we run both ovs and linuxbridge ml2 drivers,
162 # and since Linux Bridge ml2 driver does not have QoS support yet, ml2
163 # plugin reports no rule types are supported. Once linuxbridge will
164 # receive support for QoS, the list of expected rule types will change.
165 #
166 # In theory, we could make the test conditional on which ml2 drivers
167 # are enabled in gate (or more specifically, on which supported qos
168 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200169 # available through tempest.lib framework
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000170 expected_rule_types = []
171 expected_rule_details = ['type']
172
173 rule_types = client.list_qos_rule_types()
174 actual_list_rule_types = rule_types['rule_types']
175 actual_rule_types = [rule['type'] for rule in actual_list_rule_types]
176
177 # Verify that only required fields present in rule details
178 for rule in actual_list_rule_types:
179 self.assertEqual(tuple(rule.keys()), tuple(expected_rule_details))
180
181 # Verify if expected rules are present in the actual rules list
182 for rule in expected_rule_types:
183 self.assertIn(rule, actual_rule_types)
184
185 def _disassociate_network(self, client, network_id):
Hong Hui Xiao25028302016-12-13 16:29:08 +0800186 updated_network = client.update_network(network_id,
187 qos_policy_id=None)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000188 self.assertIsNone(updated_network['network']['qos_policy_id'])
189
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000190 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000191 def test_policy_association_with_admin_network(self):
192 policy = self.create_qos_policy(name='test-policy',
193 description='test policy',
194 shared=False)
195 network = self.create_shared_network('test network',
196 qos_policy_id=policy['id'])
197
198 retrieved_network = self.admin_client.show_network(network['id'])
199 self.assertEqual(
200 policy['id'], retrieved_network['network']['qos_policy_id'])
201
202 self._disassociate_network(self.admin_client, network['id'])
203
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000204 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000205 def test_policy_association_with_tenant_network(self):
206 policy = self.create_qos_policy(name='test-policy',
207 description='test policy',
208 shared=True)
209 network = self.create_network('test network',
210 qos_policy_id=policy['id'])
211
212 retrieved_network = self.admin_client.show_network(network['id'])
213 self.assertEqual(
214 policy['id'], retrieved_network['network']['qos_policy_id'])
215
216 self._disassociate_network(self.client, network['id'])
217
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000218 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000219 def test_policy_association_with_network_nonexistent_policy(self):
220 self.assertRaises(
221 exceptions.NotFound,
222 self.create_network,
223 'test network',
224 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
225
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000226 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000227 def test_policy_association_with_network_non_shared_policy(self):
228 policy = self.create_qos_policy(name='test-policy',
229 description='test policy',
230 shared=False)
231 self.assertRaises(
232 exceptions.NotFound,
233 self.create_network,
234 'test network', qos_policy_id=policy['id'])
235
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000236 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000237 def test_policy_update_association_with_admin_network(self):
238 policy = self.create_qos_policy(name='test-policy',
239 description='test policy',
240 shared=False)
241 network = self.create_shared_network('test network')
242 retrieved_network = self.admin_client.show_network(network['id'])
243 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
244
245 self.admin_client.update_network(network['id'],
246 qos_policy_id=policy['id'])
247 retrieved_network = self.admin_client.show_network(network['id'])
248 self.assertEqual(
249 policy['id'], retrieved_network['network']['qos_policy_id'])
250
251 self._disassociate_network(self.admin_client, network['id'])
252
253 def _disassociate_port(self, port_id):
254 self.client.update_port(port_id, qos_policy_id=None)
255 updated_port = self.admin_client.show_port(port_id)
256 self.assertIsNone(updated_port['port']['qos_policy_id'])
257
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000258 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000259 def test_policy_association_with_port_shared_policy(self):
260 policy = self.create_qos_policy(name='test-policy',
261 description='test policy',
262 shared=True)
263 network = self.create_shared_network('test network')
264 port = self.create_port(network, qos_policy_id=policy['id'])
265
266 retrieved_port = self.admin_client.show_port(port['id'])
267 self.assertEqual(
268 policy['id'], retrieved_port['port']['qos_policy_id'])
269
270 self._disassociate_port(port['id'])
271
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000272 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000273 def test_policy_association_with_port_nonexistent_policy(self):
274 network = self.create_shared_network('test network')
275 self.assertRaises(
276 exceptions.NotFound,
277 self.create_port,
278 network,
279 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
280
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000281 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000282 def test_policy_association_with_port_non_shared_policy(self):
283 policy = self.create_qos_policy(name='test-policy',
284 description='test policy',
285 shared=False)
286 network = self.create_shared_network('test network')
287 self.assertRaises(
288 exceptions.NotFound,
289 self.create_port,
290 network, qos_policy_id=policy['id'])
291
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000292 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000293 def test_policy_update_association_with_port_shared_policy(self):
294 policy = self.create_qos_policy(name='test-policy',
295 description='test policy',
296 shared=True)
297 network = self.create_shared_network('test network')
298 port = self.create_port(network)
299 retrieved_port = self.admin_client.show_port(port['id'])
300 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
301
302 self.client.update_port(port['id'], qos_policy_id=policy['id'])
303 retrieved_port = self.admin_client.show_port(port['id'])
304 self.assertEqual(
305 policy['id'], retrieved_port['port']['qos_policy_id'])
306
307 self._disassociate_port(port['id'])
308
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000309 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000310 def test_delete_not_allowed_if_policy_in_use_by_network(self):
311 policy = self.create_qos_policy(name='test-policy',
312 description='test policy',
313 shared=True)
314 network = self.create_shared_network(
315 'test network', qos_policy_id=policy['id'])
316 self.assertRaises(
317 exceptions.Conflict,
318 self.admin_client.delete_qos_policy, policy['id'])
319
320 self._disassociate_network(self.admin_client, network['id'])
321 self.admin_client.delete_qos_policy(policy['id'])
322
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000323 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000324 def test_delete_not_allowed_if_policy_in_use_by_port(self):
325 policy = self.create_qos_policy(name='test-policy',
326 description='test policy',
327 shared=True)
328 network = self.create_shared_network('test network')
329 port = self.create_port(network, qos_policy_id=policy['id'])
330 self.assertRaises(
331 exceptions.Conflict,
332 self.admin_client.delete_qos_policy, policy['id'])
333
334 self._disassociate_port(port['id'])
335 self.admin_client.delete_qos_policy(policy['id'])
336
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000337 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000338 def test_qos_policy_delete_with_rules(self):
339 policy = self.create_qos_policy(name='test-policy',
340 description='test policy',
341 shared=False)
342 self.admin_client.create_bandwidth_limit_rule(
343 policy['id'], 200, 1337)['bandwidth_limit_rule']
344
345 self.admin_client.delete_qos_policy(policy['id'])
346
347 with testtools.ExpectedException(exceptions.NotFound):
348 self.admin_client.show_qos_policy(policy['id'])
349
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000350 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000351 def test_get_policy_that_is_shared(self):
352 policy = self.create_qos_policy(
353 name='test-policy-shared',
354 description='shared policy',
355 shared=True,
356 tenant_id=self.admin_client.tenant_id)
357 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
358 self.assertEqual(obtained_policy, policy)
359
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000360 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100361 def test_policy_create_forbidden_for_regular_tenants(self):
362 self.assertRaises(
363 exceptions.Forbidden,
364 self.client.create_qos_policy,
365 'test-policy', 'test policy', False)
366
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000367
368class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000369
370 direction = None
371
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000372 @classmethod
373 @test.requires_ext(extension="qos", service="network")
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900374 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000375 def resource_setup(cls):
376 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
377
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000378 @property
379 def opposite_direction(self):
380 if self.direction == "ingress":
381 return "egress"
382 elif self.direction == "egress":
383 return "ingress"
384 else:
385 return None
386
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000387 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000388 def test_rule_create(self):
389 policy = self.create_qos_policy(name='test-policy',
390 description='test policy',
391 shared=False)
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000392 rule = self.create_qos_bandwidth_limit_rule(
393 policy_id=policy['id'],
394 max_kbps=200,
395 max_burst_kbps=1337,
396 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000397
398 # Test 'show rule'
399 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
400 policy['id'], rule['id'])
401 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
402 self.assertEqual(rule['id'], retrieved_rule['id'])
403 self.assertEqual(200, retrieved_rule['max_kbps'])
404 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000405 if self.direction:
406 self.assertEqual(self.direction, retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000407
408 # Test 'list rules'
409 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
410 rules = rules['bandwidth_limit_rules']
411 rules_ids = [r['id'] for r in rules]
412 self.assertIn(rule['id'], rules_ids)
413
414 # Test 'show policy'
415 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
416 policy_rules = retrieved_policy['policy']['rules']
417 self.assertEqual(1, len(policy_rules))
418 self.assertEqual(rule['id'], policy_rules[0]['id'])
419 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
420 policy_rules[0]['type'])
421
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000422 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000423 def test_rule_create_fail_for_the_same_type(self):
424 policy = self.create_qos_policy(name='test-policy',
425 description='test policy',
426 shared=False)
427 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
428 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000429 max_burst_kbps=1337,
430 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000431
432 self.assertRaises(exceptions.Conflict,
433 self.create_qos_bandwidth_limit_rule,
434 policy_id=policy['id'],
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000435 max_kbps=201, max_burst_kbps=1338,
436 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000437
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000438 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000439 def test_rule_update(self):
440 policy = self.create_qos_policy(name='test-policy',
441 description='test policy',
442 shared=False)
443 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
444 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000445 max_burst_kbps=1,
446 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000447
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000448 self.admin_client.update_bandwidth_limit_rule(
449 policy['id'],
450 rule['id'],
451 max_kbps=200,
452 max_burst_kbps=1337,
453 direction=self.opposite_direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000454
455 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
456 policy['id'], rule['id'])
457 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
458 self.assertEqual(200, retrieved_policy['max_kbps'])
459 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000460 if self.opposite_direction:
461 self.assertEqual(self.opposite_direction,
462 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000463
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000464 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000465 def test_rule_delete(self):
466 policy = self.create_qos_policy(name='test-policy',
467 description='test policy',
468 shared=False)
469 rule = self.admin_client.create_bandwidth_limit_rule(
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000470 policy['id'], 200, 1337, self.direction)['bandwidth_limit_rule']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000471
472 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
473 policy['id'], rule['id'])
474 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
475 self.assertEqual(rule['id'], retrieved_policy['id'])
476
477 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
478 self.assertRaises(exceptions.NotFound,
479 self.admin_client.show_bandwidth_limit_rule,
480 policy['id'], rule['id'])
481
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000482 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000483 def test_rule_create_rule_nonexistent_policy(self):
484 self.assertRaises(
485 exceptions.NotFound,
486 self.create_qos_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000487 'policy', 200, 1337, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000488
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000489 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000490 def test_rule_create_forbidden_for_regular_tenants(self):
491 self.assertRaises(
492 exceptions.Forbidden,
493 self.client.create_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000494 'policy', 1, 2, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000495
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000496 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000497 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
498 policy = self.create_qos_policy(name='test-policy',
499 description='test policy',
500 shared=False,
501 tenant_id=self.client.tenant_id)
502 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
503 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000504 max_burst_kbps=1,
505 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000506 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400507 exceptions.Forbidden,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000508 self.client.update_bandwidth_limit_rule,
509 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
510
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000511 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000512 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
513 policy = self.create_qos_policy(name='test-policy',
514 description='test policy',
515 shared=False,
516 tenant_id=self.admin_client.tenant_id)
517 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
518 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000519 max_burst_kbps=1,
520 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000521 self.assertRaises(
522 exceptions.NotFound,
523 self.client.update_bandwidth_limit_rule,
524 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
525
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000526 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000527 def test_get_rules_by_policy(self):
528 policy1 = self.create_qos_policy(name='test-policy1',
529 description='test policy1',
530 shared=False)
531 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
532 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000533 max_burst_kbps=1337,
534 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000535
536 policy2 = self.create_qos_policy(name='test-policy2',
537 description='test policy2',
538 shared=False)
539 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
540 max_kbps=5000,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000541 max_burst_kbps=2523,
542 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000543
544 # Test 'list rules'
545 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
546 rules = rules['bandwidth_limit_rules']
547 rules_ids = [r['id'] for r in rules]
548 self.assertIn(rule1['id'], rules_ids)
549 self.assertNotIn(rule2['id'], rules_ids)
550
551
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000552class QosBandwidthLimitRuleWithDirectionTestJSON(
553 QosBandwidthLimitRuleTestJSON):
554
555 scenarios = [
556 ('ingress', {'direction': 'ingress'}),
557 ('egress', {'direction': 'egress'}),
558 ]
559
560 @classmethod
561 @test.requires_ext(extension="qos-bw-limit-direction", service="network")
562 def resource_setup(cls):
563 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
564
565
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000566class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
567
568 force_tenant_isolation = True
569 credentials = ['primary', 'alt', 'admin']
570
571 @classmethod
572 @test.requires_ext(extension="qos", service="network")
573 def resource_setup(cls):
574 super(RbacSharedQosPoliciesTest, cls).resource_setup()
575 cls.client2 = cls.alt_manager.network_client
576
577 def _create_qos_policy(self, tenant_id=None):
578 args = {'name': data_utils.rand_name('test-policy'),
579 'description': 'test policy',
580 'shared': False,
581 'tenant_id': tenant_id}
582 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
583 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
584
585 return qos_policy
586
587 def _make_admin_policy_shared_to_tenant_id(self, tenant_id):
588 policy = self._create_qos_policy()
589 rbac_policy = self.admin_client.create_rbac_policy(
590 object_type='qos_policy',
591 object_id=policy['id'],
592 action='access_as_shared',
593 target_tenant=tenant_id,
594 )['rbac_policy']
595
596 return {'policy': policy, 'rbac_policy': rbac_policy}
597
598 def _create_network(self, qos_policy_id, client, should_cleanup=True):
599 net = client.create_network(
600 name=data_utils.rand_name('test-network'),
601 qos_policy_id=qos_policy_id)['network']
602 if should_cleanup:
603 self.addCleanup(client.delete_network, net['id'])
604
605 return net
606
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000607 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000608 def test_policy_sharing_with_wildcard(self):
609 qos_pol = self.create_qos_policy(
610 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000611 description='test-shared-policy', shared=False,
612 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000613 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
614
615 # test update shared False -> True
616 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
617 qos_pol['shared'] = True
618 self.client2.show_qos_policy(qos_pol['id'])
619 rbac_pol = {'target_tenant': '*',
620 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000621 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000622 'object_type': 'qos_policy',
623 'object_id': qos_pol['id'],
624 'action': 'access_as_shared'}
625
626 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
627 rbac_policies = [r for r in rbac_policies if r.pop('id')]
628 self.assertIn(rbac_pol, rbac_policies)
629
630 # update shared True -> False should fail because the policy is bound
631 # to a network
632 net = self._create_network(qos_pol['id'], self.admin_client, False)
633 with testtools.ExpectedException(exceptions.Conflict):
634 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
635
636 # delete the network, and update shared True -> False should pass now
637 self.admin_client.delete_network(net['id'])
638 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
639 qos_pol['shared'] = False
640 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
641
642 def _create_net_bound_qos_rbacs(self):
643 res = self._make_admin_policy_shared_to_tenant_id(
644 self.client.tenant_id)
645 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
646
647 # add a wildcard rbac rule - now the policy globally shared
648 rbac_wildcard = self.admin_client.create_rbac_policy(
649 object_type='qos_policy',
650 object_id=qos_policy['id'],
651 action='access_as_shared',
652 target_tenant='*',
653 )['rbac_policy']
654
655 # tenant1 now uses qos policy for net
656 self._create_network(qos_policy['id'], self.client)
657
658 return rbac_for_client_tenant, rbac_wildcard
659
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000660 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000661 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self):
662 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
663 # globally unshare the qos-policy, the specific share should remain
664 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
665 self.client.list_rbac_policies(id=client_rbac['id'])
666
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000667 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000668 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self):
669 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
670 # remove client_rbac policy the wildcard share should remain
671 self.admin_client.delete_rbac_policy(client_rbac['id'])
672 self.client.list_rbac_policies(id=wildcard_rbac['id'])
673
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000674 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000675 def test_policy_sharing_with_wildcard_and_tenant_id(self):
676 res = self._make_admin_policy_shared_to_tenant_id(
677 self.client.tenant_id)
678 qos_policy, rbac = res['policy'], res['rbac_policy']
679 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
680 self.assertTrue(qos_pol['shared'])
681 with testtools.ExpectedException(exceptions.NotFound):
682 self.client2.show_qos_policy(qos_policy['id'])
683
684 # make the qos-policy globally shared
685 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
686 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
687 self.assertTrue(qos_pol['shared'])
688
689 # globally unshare the qos-policy, the specific share should remain
690 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
691 self.client.show_qos_policy(qos_policy['id'])
692 with testtools.ExpectedException(exceptions.NotFound):
693 self.client2.show_qos_policy(qos_policy['id'])
694 self.assertIn(rbac,
695 self.admin_client.list_rbac_policies()['rbac_policies'])
696
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000697 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000698 def test_policy_target_update(self):
699 res = self._make_admin_policy_shared_to_tenant_id(
700 self.client.tenant_id)
701 # change to client2
702 update_res = self.admin_client.update_rbac_policy(
703 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
704 self.assertEqual(self.client2.tenant_id,
705 update_res['rbac_policy']['target_tenant'])
706 # make sure everything else stayed the same
707 res['rbac_policy'].pop('target_tenant')
708 update_res['rbac_policy'].pop('target_tenant')
709 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
710
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000711 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000712 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
713 res = self._make_admin_policy_shared_to_tenant_id(
714 self.client2.tenant_id)
715 qos_policy_id = res['policy']['id']
716 self._create_network(qos_policy_id, self.client2)
717 # a network with shared qos-policy should prevent the deletion of an
718 # rbac-policy required for it to be shared
719 with testtools.ExpectedException(exceptions.Conflict):
720 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
721
722 # a wildcard policy should allow the specific policy to be deleted
723 # since it allows the remaining port
724 wild = self.admin_client.create_rbac_policy(
725 object_type='qos_policy', object_id=res['policy']['id'],
726 action='access_as_shared', target_tenant='*')['rbac_policy']
727 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
728
729 # now that wildcard is the only remaining, it should be subjected to
730 # the same restriction
731 with testtools.ExpectedException(exceptions.Conflict):
732 self.admin_client.delete_rbac_policy(wild['id'])
733
734 # we can't update the policy to a different tenant
735 with testtools.ExpectedException(exceptions.Conflict):
736 self.admin_client.update_rbac_policy(
737 wild['id'], target_tenant=self.client2.tenant_id)
738
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000739 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000740 def test_regular_client_shares_to_another_regular_client(self):
741 # owned by self.admin_client
742 policy = self._create_qos_policy()
743 with testtools.ExpectedException(exceptions.NotFound):
744 self.client.show_qos_policy(policy['id'])
745 rbac_policy = self.admin_client.create_rbac_policy(
746 object_type='qos_policy', object_id=policy['id'],
747 action='access_as_shared',
748 target_tenant=self.client.tenant_id)['rbac_policy']
749 self.client.show_qos_policy(policy['id'])
750
751 self.assertIn(rbac_policy,
752 self.admin_client.list_rbac_policies()['rbac_policies'])
753 # ensure that 'client2' can't see the rbac-policy sharing the
754 # qos-policy to it because the rbac-policy belongs to 'client'
755 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
756 self.client2.list_rbac_policies()['rbac_policies']])
757
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000758 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000759 def test_filter_fields(self):
760 policy = self._create_qos_policy()
761 self.admin_client.create_rbac_policy(
762 object_type='qos_policy', object_id=policy['id'],
763 action='access_as_shared', target_tenant=self.client2.tenant_id)
764 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
765 ('tenant_id', 'target_tenant'))
766 for fields in field_args:
767 res = self.admin_client.list_rbac_policies(fields=fields)
768 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
769
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000770 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000771 def test_rbac_policy_show(self):
772 res = self._make_admin_policy_shared_to_tenant_id(
773 self.client.tenant_id)
774 p1 = res['rbac_policy']
775 p2 = self.admin_client.create_rbac_policy(
776 object_type='qos_policy', object_id=res['policy']['id'],
777 action='access_as_shared',
778 target_tenant='*')['rbac_policy']
779
780 self.assertEqual(
781 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
782 self.assertEqual(
783 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
784
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000785 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000786 def test_filter_rbac_policies(self):
787 policy = self._create_qos_policy()
788 rbac_pol1 = self.admin_client.create_rbac_policy(
789 object_type='qos_policy', object_id=policy['id'],
790 action='access_as_shared',
791 target_tenant=self.client2.tenant_id)['rbac_policy']
792 rbac_pol2 = self.admin_client.create_rbac_policy(
793 object_type='qos_policy', object_id=policy['id'],
794 action='access_as_shared',
795 target_tenant=self.admin_client.tenant_id)['rbac_policy']
796 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
797 'rbac_policies']
798 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
799 'rbac_policies']
800 self.assertEqual(1, len(res1))
801 self.assertEqual(1, len(res2))
802 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
803 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
804
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000805 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000806 def test_regular_client_blocked_from_sharing_anothers_policy(self):
807 qos_policy = self._make_admin_policy_shared_to_tenant_id(
808 self.client.tenant_id)['policy']
809 with testtools.ExpectedException(exceptions.BadRequest):
810 self.client.create_rbac_policy(
811 object_type='qos_policy', object_id=qos_policy['id'],
812 action='access_as_shared',
813 target_tenant=self.client2.tenant_id)
814
815 # make sure the rbac-policy is invisible to the tenant for which it's
816 # being shared
817 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
818
819
820class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
821 VALID_DSCP_MARK1 = 56
822 VALID_DSCP_MARK2 = 48
823
824 @classmethod
825 @test.requires_ext(extension="qos", service="network")
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900826 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000827 def resource_setup(cls):
828 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
829
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000830 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000831 def test_rule_create(self):
832 policy = self.create_qos_policy(name='test-policy',
833 description='test policy',
834 shared=False)
835 rule = self.admin_client.create_dscp_marking_rule(
836 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
837
838 # Test 'show rule'
839 retrieved_rule = self.admin_client.show_dscp_marking_rule(
840 policy['id'], rule['id'])
841 retrieved_rule = retrieved_rule['dscp_marking_rule']
842 self.assertEqual(rule['id'], retrieved_rule['id'])
843 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
844
845 # Test 'list rules'
846 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
847 rules = rules['dscp_marking_rules']
848 rules_ids = [r['id'] for r in rules]
849 self.assertIn(rule['id'], rules_ids)
850
851 # Test 'show policy'
852 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
853 policy_rules = retrieved_policy['policy']['rules']
854 self.assertEqual(1, len(policy_rules))
855 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000856 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000857 policy_rules[0]['type'])
858
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000859 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000860 def test_rule_create_fail_for_the_same_type(self):
861 policy = self.create_qos_policy(name='test-policy',
862 description='test policy',
863 shared=False)
864 self.admin_client.create_dscp_marking_rule(
865 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
866
867 self.assertRaises(exceptions.Conflict,
868 self.admin_client.create_dscp_marking_rule,
869 policy_id=policy['id'],
870 dscp_mark=self.VALID_DSCP_MARK2)
871
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000872 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000873 def test_rule_update(self):
874 policy = self.create_qos_policy(name='test-policy',
875 description='test policy',
876 shared=False)
877 rule = self.admin_client.create_dscp_marking_rule(
878 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
879
880 self.admin_client.update_dscp_marking_rule(
881 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
882
883 retrieved_policy = self.admin_client.show_dscp_marking_rule(
884 policy['id'], rule['id'])
885 retrieved_policy = retrieved_policy['dscp_marking_rule']
886 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
887
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000888 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000889 def test_rule_delete(self):
890 policy = self.create_qos_policy(name='test-policy',
891 description='test policy',
892 shared=False)
893 rule = self.admin_client.create_dscp_marking_rule(
894 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
895
896 retrieved_policy = self.admin_client.show_dscp_marking_rule(
897 policy['id'], rule['id'])
898 retrieved_policy = retrieved_policy['dscp_marking_rule']
899 self.assertEqual(rule['id'], retrieved_policy['id'])
900
901 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
902 self.assertRaises(exceptions.NotFound,
903 self.admin_client.show_dscp_marking_rule,
904 policy['id'], rule['id'])
905
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000906 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000907 def test_rule_create_rule_nonexistent_policy(self):
908 self.assertRaises(
909 exceptions.NotFound,
910 self.admin_client.create_dscp_marking_rule,
911 'policy', self.VALID_DSCP_MARK1)
912
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000913 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000914 def test_rule_create_forbidden_for_regular_tenants(self):
915 self.assertRaises(
916 exceptions.Forbidden,
917 self.client.create_dscp_marking_rule,
918 'policy', self.VALID_DSCP_MARK1)
919
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000920 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000921 def test_invalid_rule_create(self):
922 policy = self.create_qos_policy(name='test-policy',
923 description='test policy',
924 shared=False)
925 self.assertRaises(
926 exceptions.BadRequest,
927 self.admin_client.create_dscp_marking_rule,
928 policy['id'], 58)
929
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000930 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000931 def test_get_rules_by_policy(self):
932 policy1 = self.create_qos_policy(name='test-policy1',
933 description='test policy1',
934 shared=False)
935 rule1 = self.admin_client.create_dscp_marking_rule(
936 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
937
938 policy2 = self.create_qos_policy(name='test-policy2',
939 description='test policy2',
940 shared=False)
941 rule2 = self.admin_client.create_dscp_marking_rule(
942 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
943
944 # Test 'list rules'
945 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
946 rules = rules['dscp_marking_rules']
947 rules_ids = [r['id'] for r in rules]
948 self.assertIn(rule1['id'], rules_ids)
949 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +0200950
951
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100952class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
953 DIRECTION_EGRESS = "egress"
954 DIRECTION_INGRESS = "ingress"
955 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
956 RULES_NAME = RULE_NAME + "s"
957
958 @classmethod
959 @test.requires_ext(extension="qos", service="network")
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900960 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100961 def resource_setup(cls):
962 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
963
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000964 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100965 def test_rule_create(self):
966 policy = self.create_qos_policy(name='test-policy',
967 description='test policy',
968 shared=False)
969 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000970 policy_id=policy['id'],
971 direction=self.DIRECTION_EGRESS,
972 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100973
974 # Test 'show rule'
975 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
976 policy['id'], rule['id'])
977 retrieved_rule = retrieved_rule[self.RULE_NAME]
978 self.assertEqual(rule['id'], retrieved_rule['id'])
979 self.assertEqual(1138, retrieved_rule['min_kbps'])
980 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
981
982 # Test 'list rules'
983 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
984 rules = rules[self.RULES_NAME]
985 rules_ids = [r['id'] for r in rules]
986 self.assertIn(rule['id'], rules_ids)
987
988 # Test 'show policy'
989 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
990 policy_rules = retrieved_policy['policy']['rules']
991 self.assertEqual(1, len(policy_rules))
992 self.assertEqual(rule['id'], policy_rules[0]['id'])
993 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
994 policy_rules[0]['type'])
995
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000996 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000997 def test_rule_create_fail_for_missing_min_kbps(self):
998 policy = self.create_qos_policy(name='test-policy',
999 description='test policy',
1000 shared=False)
1001 self.assertRaises(exceptions.BadRequest,
1002 self.admin_client.create_minimum_bandwidth_rule,
1003 policy_id=policy['id'],
1004 direction=self.DIRECTION_EGRESS)
1005
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001006 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001007 def test_rule_create_fail_for_the_same_type(self):
1008 policy = self.create_qos_policy(name='test-policy',
1009 description='test policy',
1010 shared=False)
1011 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001012 policy_id=policy['id'],
1013 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001014
1015 self.assertRaises(exceptions.Conflict,
1016 self.admin_client.create_minimum_bandwidth_rule,
1017 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001018 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001019
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001020 @decorators.idempotent_id('d6fce764-e511-4fa6-9f86-f4b41cf142cf')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001021 def test_rule_create_fail_for_direction_ingress(self):
1022 policy = self.create_qos_policy(name='test-policy',
1023 description='test policy',
1024 shared=False)
1025 self.assertRaises(exceptions.BadRequest,
1026 self.admin_client.create_minimum_bandwidth_rule,
1027 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001028 direction=self.DIRECTION_INGRESS,
1029 min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001030
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001031 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001032 def test_rule_update(self):
1033 policy = self.create_qos_policy(name='test-policy',
1034 description='test policy',
1035 shared=False)
1036 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001037 policy_id=policy['id'],
1038 direction=self.DIRECTION_EGRESS,
1039 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001040
1041 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
1042 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
1043
1044 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1045 policy['id'], rule['id'])
1046 retrieved_policy = retrieved_policy[self.RULE_NAME]
1047 self.assertEqual(350, retrieved_policy['min_kbps'])
1048 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1049
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001050 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001051 def test_rule_delete(self):
1052 policy = self.create_qos_policy(name='test-policy',
1053 description='test policy',
1054 shared=False)
1055 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001056 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001057
1058 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1059 policy['id'], rule['id'])
1060 retrieved_policy = retrieved_policy[self.RULE_NAME]
1061 self.assertEqual(rule['id'], retrieved_policy['id'])
1062
1063 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1064 rule['id'])
1065 self.assertRaises(exceptions.NotFound,
1066 self.admin_client.show_minimum_bandwidth_rule,
1067 policy['id'], rule['id'])
1068
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001069 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001070 def test_rule_create_rule_nonexistent_policy(self):
1071 self.assertRaises(
1072 exceptions.NotFound,
1073 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001074 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001075
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001076 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001077 def test_rule_create_forbidden_for_regular_tenants(self):
1078 self.assertRaises(
1079 exceptions.Forbidden,
1080 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001081 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001082
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001083 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001084 def test_get_rules_by_policy(self):
1085 policy1 = self.create_qos_policy(name='test-policy1',
1086 description='test policy1',
1087 shared=False)
1088 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001089 policy_id=policy1['id'],
1090 direction=self.DIRECTION_EGRESS,
1091 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001092
1093 policy2 = self.create_qos_policy(name='test-policy2',
1094 description='test policy2',
1095 shared=False)
1096 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001097 policy_id=policy2['id'],
1098 direction=self.DIRECTION_EGRESS,
1099 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001100
1101 # Test 'list rules'
1102 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1103 rules = rules[self.RULES_NAME]
1104 rules_ids = [r['id'] for r in rules]
1105 self.assertIn(rule1['id'], rules_ids)
1106 self.assertNotIn(rule2['id'], rules_ids)
1107
1108
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001109class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1110 base.BaseAdminNetworkTest):
1111
1112 resource = 'policy'
1113 plural_name = 'policies'
1114
1115 # Use unique description to isolate the tests from other QoS tests
1116 list_kwargs = {'description': 'search-criteria-test'}
1117 list_as_admin = True
1118
1119 @classmethod
1120 @test.requires_ext(extension="qos", service="network")
1121 def resource_setup(cls):
1122 super(QosSearchCriteriaTest, cls).resource_setup()
1123 for name in cls.resource_names:
1124 cls.create_qos_policy(
1125 name=name, description='search-criteria-test')
1126
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001127 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001128 def test_list_sorts_asc(self):
1129 self._test_list_sorts_asc()
1130
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001131 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001132 def test_list_sorts_desc(self):
1133 self._test_list_sorts_desc()
1134
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001135 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001136 def test_list_pagination(self):
1137 self._test_list_pagination()
1138
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001139 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001140 def test_list_pagination_with_marker(self):
1141 self._test_list_pagination_with_marker()
1142
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001143 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001144 def test_list_pagination_with_href_links(self):
1145 self._test_list_pagination_with_href_links()
1146
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001147 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001148 def test_list_pagination_page_reverse_asc(self):
1149 self._test_list_pagination_page_reverse_asc()
1150
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001151 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001152 def test_list_pagination_page_reverse_desc(self):
1153 self._test_list_pagination_page_reverse_desc()
1154
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001155 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001156 def test_list_pagination_page_reverse_with_href_links(self):
1157 self._test_list_pagination_page_reverse_with_href_links()
1158
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001159 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001160 def test_list_no_pagination_limit_0(self):
1161 self._test_list_no_pagination_limit_0()