blob: f35abd8e08409390aaca6f0ec9107f27cab04830 [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):
Jakub Libosvar1982aa12017-05-30 11:15:33 +000031
32 required_extensions = ['qos']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000033
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000034 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000035 def test_create_policy(self):
36 policy = self.create_qos_policy(name='test-policy',
37 description='test policy desc1',
38 shared=False)
39
40 # Test 'show policy'
41 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
42 retrieved_policy = retrieved_policy['policy']
43 self.assertEqual('test-policy', retrieved_policy['name'])
44 self.assertEqual('test policy desc1', retrieved_policy['description'])
45 self.assertFalse(retrieved_policy['shared'])
46
47 # Test 'list policies'
48 policies = self.admin_client.list_qos_policies()['policies']
49 policies_ids = [p['id'] for p in policies]
50 self.assertIn(policy['id'], policies_ids)
51
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000052 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Henry Gessaufa6c78d2016-10-09 19:56:09 -040053 @test.requires_ext(extension="project-id", service="network")
54 def test_show_policy_has_project_id(self):
55 policy = self.create_qos_policy(name='test-policy', shared=False)
56 body = self.admin_client.show_qos_policy(policy['id'])
57 show_policy = body['policy']
58 self.assertIn('project_id', show_policy)
59 self.assertIn('tenant_id', show_policy)
60 self.assertEqual(self.admin_client.tenant_id,
61 show_policy['project_id'])
62 self.assertEqual(self.admin_client.tenant_id,
63 show_policy['tenant_id'])
64
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000065 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000066 def test_list_policy_filter_by_name(self):
67 self.create_qos_policy(name='test', description='test policy',
68 shared=False)
69 self.create_qos_policy(name='test2', description='test policy',
70 shared=False)
71
72 policies = (self.admin_client.
73 list_qos_policies(name='test')['policies'])
74 self.assertEqual(1, len(policies))
75
76 retrieved_policy = policies[0]
77 self.assertEqual('test', retrieved_policy['name'])
78
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000079 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000080 def test_policy_update(self):
81 policy = self.create_qos_policy(name='test-policy',
82 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +000083 shared=False,
84 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000085 self.admin_client.update_qos_policy(policy['id'],
86 description='test policy desc2',
87 shared=True)
88
89 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
90 retrieved_policy = retrieved_policy['policy']
91 self.assertEqual('test policy desc2', retrieved_policy['description'])
92 self.assertTrue(retrieved_policy['shared'])
93 self.assertEqual([], retrieved_policy['rules'])
94
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000095 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +000096 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
97 policy = self.create_qos_policy(name='test-policy',
98 description='',
99 shared=False,
100 tenant_id=self.client.tenant_id)
101 self.assertRaises(
102 exceptions.Forbidden,
103 self.client.update_qos_policy,
104 policy['id'], description='test policy')
105
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000106 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000107 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
108 policy = self.create_qos_policy(name='test-policy',
109 description='',
110 shared=False,
111 tenant_id=self.admin_client.tenant_id)
112 self.assertRaises(
113 exceptions.NotFound,
114 self.client.update_qos_policy,
115 policy['id'], description='test policy')
116
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000117 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000118 def test_shared_policy_update(self):
119 policy = self.create_qos_policy(name='test-policy',
120 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000121 shared=True,
122 tenant_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000123
124 self.admin_client.update_qos_policy(policy['id'],
125 description='test policy desc2')
126 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
127 retrieved_policy = retrieved_policy['policy']
128 self.assertTrue(retrieved_policy['shared'])
129
130 self.admin_client.update_qos_policy(policy['id'],
131 shared=False)
132 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
133 retrieved_policy = retrieved_policy['policy']
134 self.assertFalse(retrieved_policy['shared'])
135
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000136 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000137 def test_delete_policy(self):
138 policy = self.admin_client.create_qos_policy(
139 'test-policy', 'desc', True)['policy']
140
141 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
142 retrieved_policy = retrieved_policy['policy']
143 self.assertEqual('test-policy', retrieved_policy['name'])
144
145 self.admin_client.delete_qos_policy(policy['id'])
146 self.assertRaises(exceptions.NotFound,
147 self.admin_client.show_qos_policy, policy['id'])
148
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000149 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000150 def test_list_admin_rule_types(self):
151 self._test_list_rule_types(self.admin_client)
152
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000153 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000154 def test_list_regular_rule_types(self):
155 self._test_list_rule_types(self.client)
156
157 def _test_list_rule_types(self, client):
158 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000159 # Since returned rule types depends on loaded backend drivers this test
160 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000161 #
162 # In theory, we could make the test conditional on which ml2 drivers
163 # are enabled in gate (or more specifically, on which supported qos
164 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200165 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000166 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000167
168 rule_types = client.list_qos_rule_types()
169 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000170
171 # Verify that only required fields present in rule details
172 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000173 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000174
175 def _disassociate_network(self, client, network_id):
Hong Hui Xiao25028302016-12-13 16:29:08 +0800176 updated_network = client.update_network(network_id,
177 qos_policy_id=None)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000178 self.assertIsNone(updated_network['network']['qos_policy_id'])
179
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000180 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000181 def test_policy_association_with_admin_network(self):
182 policy = self.create_qos_policy(name='test-policy',
183 description='test policy',
184 shared=False)
185 network = self.create_shared_network('test network',
186 qos_policy_id=policy['id'])
187
188 retrieved_network = self.admin_client.show_network(network['id'])
189 self.assertEqual(
190 policy['id'], retrieved_network['network']['qos_policy_id'])
191
192 self._disassociate_network(self.admin_client, network['id'])
193
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000194 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000195 def test_policy_association_with_tenant_network(self):
196 policy = self.create_qos_policy(name='test-policy',
197 description='test policy',
198 shared=True)
199 network = self.create_network('test network',
200 qos_policy_id=policy['id'])
201
202 retrieved_network = self.admin_client.show_network(network['id'])
203 self.assertEqual(
204 policy['id'], retrieved_network['network']['qos_policy_id'])
205
206 self._disassociate_network(self.client, network['id'])
207
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000208 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000209 def test_policy_association_with_network_nonexistent_policy(self):
210 self.assertRaises(
211 exceptions.NotFound,
212 self.create_network,
213 'test network',
214 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
215
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000216 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000217 def test_policy_association_with_network_non_shared_policy(self):
218 policy = self.create_qos_policy(name='test-policy',
219 description='test policy',
220 shared=False)
221 self.assertRaises(
222 exceptions.NotFound,
223 self.create_network,
224 'test network', qos_policy_id=policy['id'])
225
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000226 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000227 def test_policy_update_association_with_admin_network(self):
228 policy = self.create_qos_policy(name='test-policy',
229 description='test policy',
230 shared=False)
231 network = self.create_shared_network('test network')
232 retrieved_network = self.admin_client.show_network(network['id'])
233 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
234
235 self.admin_client.update_network(network['id'],
236 qos_policy_id=policy['id'])
237 retrieved_network = self.admin_client.show_network(network['id'])
238 self.assertEqual(
239 policy['id'], retrieved_network['network']['qos_policy_id'])
240
241 self._disassociate_network(self.admin_client, network['id'])
242
243 def _disassociate_port(self, port_id):
244 self.client.update_port(port_id, qos_policy_id=None)
245 updated_port = self.admin_client.show_port(port_id)
246 self.assertIsNone(updated_port['port']['qos_policy_id'])
247
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000248 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000249 def test_policy_association_with_port_shared_policy(self):
250 policy = self.create_qos_policy(name='test-policy',
251 description='test policy',
252 shared=True)
253 network = self.create_shared_network('test network')
254 port = self.create_port(network, qos_policy_id=policy['id'])
255
256 retrieved_port = self.admin_client.show_port(port['id'])
257 self.assertEqual(
258 policy['id'], retrieved_port['port']['qos_policy_id'])
259
260 self._disassociate_port(port['id'])
261
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000262 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000263 def test_policy_association_with_port_nonexistent_policy(self):
264 network = self.create_shared_network('test network')
265 self.assertRaises(
266 exceptions.NotFound,
267 self.create_port,
268 network,
269 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
270
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000271 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000272 def test_policy_association_with_port_non_shared_policy(self):
273 policy = self.create_qos_policy(name='test-policy',
274 description='test policy',
275 shared=False)
276 network = self.create_shared_network('test network')
277 self.assertRaises(
278 exceptions.NotFound,
279 self.create_port,
280 network, qos_policy_id=policy['id'])
281
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000282 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000283 def test_policy_update_association_with_port_shared_policy(self):
284 policy = self.create_qos_policy(name='test-policy',
285 description='test policy',
286 shared=True)
287 network = self.create_shared_network('test network')
288 port = self.create_port(network)
289 retrieved_port = self.admin_client.show_port(port['id'])
290 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
291
292 self.client.update_port(port['id'], qos_policy_id=policy['id'])
293 retrieved_port = self.admin_client.show_port(port['id'])
294 self.assertEqual(
295 policy['id'], retrieved_port['port']['qos_policy_id'])
296
297 self._disassociate_port(port['id'])
298
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000299 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000300 def test_delete_not_allowed_if_policy_in_use_by_network(self):
301 policy = self.create_qos_policy(name='test-policy',
302 description='test policy',
303 shared=True)
304 network = self.create_shared_network(
305 'test network', qos_policy_id=policy['id'])
306 self.assertRaises(
307 exceptions.Conflict,
308 self.admin_client.delete_qos_policy, policy['id'])
309
310 self._disassociate_network(self.admin_client, network['id'])
311 self.admin_client.delete_qos_policy(policy['id'])
312
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000313 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000314 def test_delete_not_allowed_if_policy_in_use_by_port(self):
315 policy = self.create_qos_policy(name='test-policy',
316 description='test policy',
317 shared=True)
318 network = self.create_shared_network('test network')
319 port = self.create_port(network, qos_policy_id=policy['id'])
320 self.assertRaises(
321 exceptions.Conflict,
322 self.admin_client.delete_qos_policy, policy['id'])
323
324 self._disassociate_port(port['id'])
325 self.admin_client.delete_qos_policy(policy['id'])
326
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000327 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000328 def test_qos_policy_delete_with_rules(self):
329 policy = self.create_qos_policy(name='test-policy',
330 description='test policy',
331 shared=False)
332 self.admin_client.create_bandwidth_limit_rule(
333 policy['id'], 200, 1337)['bandwidth_limit_rule']
334
335 self.admin_client.delete_qos_policy(policy['id'])
336
337 with testtools.ExpectedException(exceptions.NotFound):
338 self.admin_client.show_qos_policy(policy['id'])
339
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000340 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000341 def test_get_policy_that_is_shared(self):
342 policy = self.create_qos_policy(
343 name='test-policy-shared',
344 description='shared policy',
345 shared=True,
346 tenant_id=self.admin_client.tenant_id)
347 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
348 self.assertEqual(obtained_policy, policy)
349
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000350 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100351 def test_policy_create_forbidden_for_regular_tenants(self):
352 self.assertRaises(
353 exceptions.Forbidden,
354 self.client.create_qos_policy,
355 'test-policy', 'test policy', False)
356
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000357
358class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000359
360 direction = None
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000361 required_extensions = ['qos']
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000362
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000363 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900364 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000365 def resource_setup(cls):
366 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
367
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000368 @property
369 def opposite_direction(self):
370 if self.direction == "ingress":
371 return "egress"
372 elif self.direction == "egress":
373 return "ingress"
374 else:
375 return None
376
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000377 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000378 def test_rule_create(self):
379 policy = self.create_qos_policy(name='test-policy',
380 description='test policy',
381 shared=False)
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000382 rule = self.create_qos_bandwidth_limit_rule(
383 policy_id=policy['id'],
384 max_kbps=200,
385 max_burst_kbps=1337,
386 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000387
388 # Test 'show rule'
389 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
390 policy['id'], rule['id'])
391 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
392 self.assertEqual(rule['id'], retrieved_rule['id'])
393 self.assertEqual(200, retrieved_rule['max_kbps'])
394 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000395 if self.direction:
396 self.assertEqual(self.direction, retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000397
398 # Test 'list rules'
399 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
400 rules = rules['bandwidth_limit_rules']
401 rules_ids = [r['id'] for r in rules]
402 self.assertIn(rule['id'], rules_ids)
403
404 # Test 'show policy'
405 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
406 policy_rules = retrieved_policy['policy']['rules']
407 self.assertEqual(1, len(policy_rules))
408 self.assertEqual(rule['id'], policy_rules[0]['id'])
409 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
410 policy_rules[0]['type'])
411
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000412 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000413 def test_rule_create_fail_for_the_same_type(self):
414 policy = self.create_qos_policy(name='test-policy',
415 description='test policy',
416 shared=False)
417 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
418 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000419 max_burst_kbps=1337,
420 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000421
422 self.assertRaises(exceptions.Conflict,
423 self.create_qos_bandwidth_limit_rule,
424 policy_id=policy['id'],
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000425 max_kbps=201, max_burst_kbps=1338,
426 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000427
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000428 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000429 def test_rule_update(self):
430 policy = self.create_qos_policy(name='test-policy',
431 description='test policy',
432 shared=False)
433 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
434 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000435 max_burst_kbps=1,
436 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000437
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000438 self.admin_client.update_bandwidth_limit_rule(
439 policy['id'],
440 rule['id'],
441 max_kbps=200,
442 max_burst_kbps=1337,
443 direction=self.opposite_direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000444
445 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
446 policy['id'], rule['id'])
447 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
448 self.assertEqual(200, retrieved_policy['max_kbps'])
449 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000450 if self.opposite_direction:
451 self.assertEqual(self.opposite_direction,
452 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000453
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000454 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000455 def test_rule_delete(self):
456 policy = self.create_qos_policy(name='test-policy',
457 description='test policy',
458 shared=False)
459 rule = self.admin_client.create_bandwidth_limit_rule(
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000460 policy['id'], 200, 1337, self.direction)['bandwidth_limit_rule']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000461
462 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
463 policy['id'], rule['id'])
464 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
465 self.assertEqual(rule['id'], retrieved_policy['id'])
466
467 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
468 self.assertRaises(exceptions.NotFound,
469 self.admin_client.show_bandwidth_limit_rule,
470 policy['id'], rule['id'])
471
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000472 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000473 def test_rule_create_rule_nonexistent_policy(self):
474 self.assertRaises(
475 exceptions.NotFound,
476 self.create_qos_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000477 'policy', 200, 1337, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000478
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000479 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000480 def test_rule_create_forbidden_for_regular_tenants(self):
481 self.assertRaises(
482 exceptions.Forbidden,
483 self.client.create_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000484 'policy', 1, 2, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000485
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000486 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000487 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
488 policy = self.create_qos_policy(name='test-policy',
489 description='test policy',
490 shared=False,
491 tenant_id=self.client.tenant_id)
492 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
493 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000494 max_burst_kbps=1,
495 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000496 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400497 exceptions.Forbidden,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000498 self.client.update_bandwidth_limit_rule,
499 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
500
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000501 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000502 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
503 policy = self.create_qos_policy(name='test-policy',
504 description='test policy',
505 shared=False,
506 tenant_id=self.admin_client.tenant_id)
507 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
508 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000509 max_burst_kbps=1,
510 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000511 self.assertRaises(
512 exceptions.NotFound,
513 self.client.update_bandwidth_limit_rule,
514 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
515
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000516 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000517 def test_get_rules_by_policy(self):
518 policy1 = self.create_qos_policy(name='test-policy1',
519 description='test policy1',
520 shared=False)
521 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
522 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000523 max_burst_kbps=1337,
524 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000525
526 policy2 = self.create_qos_policy(name='test-policy2',
527 description='test policy2',
528 shared=False)
529 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
530 max_kbps=5000,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000531 max_burst_kbps=2523,
532 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000533
534 # Test 'list rules'
535 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
536 rules = rules['bandwidth_limit_rules']
537 rules_ids = [r['id'] for r in rules]
538 self.assertIn(rule1['id'], rules_ids)
539 self.assertNotIn(rule2['id'], rules_ids)
540
541
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000542class QosBandwidthLimitRuleWithDirectionTestJSON(
543 QosBandwidthLimitRuleTestJSON):
544
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000545 required_extensions = (
546 QosBandwidthLimitRuleTestJSON.required_extensions +
547 ['qos-bw-limit-direction']
548 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000549 scenarios = [
550 ('ingress', {'direction': 'ingress'}),
551 ('egress', {'direction': 'egress'}),
552 ]
553
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000554
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000555class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
556
557 force_tenant_isolation = True
558 credentials = ['primary', 'alt', 'admin']
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000559 required_extensions = ['qos']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000560
561 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000562 def resource_setup(cls):
563 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530564 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000565
566 def _create_qos_policy(self, tenant_id=None):
567 args = {'name': data_utils.rand_name('test-policy'),
568 'description': 'test policy',
569 'shared': False,
570 'tenant_id': tenant_id}
571 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
572 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
573
574 return qos_policy
575
576 def _make_admin_policy_shared_to_tenant_id(self, tenant_id):
577 policy = self._create_qos_policy()
578 rbac_policy = self.admin_client.create_rbac_policy(
579 object_type='qos_policy',
580 object_id=policy['id'],
581 action='access_as_shared',
582 target_tenant=tenant_id,
583 )['rbac_policy']
584
585 return {'policy': policy, 'rbac_policy': rbac_policy}
586
587 def _create_network(self, qos_policy_id, client, should_cleanup=True):
588 net = client.create_network(
589 name=data_utils.rand_name('test-network'),
590 qos_policy_id=qos_policy_id)['network']
591 if should_cleanup:
592 self.addCleanup(client.delete_network, net['id'])
593
594 return net
595
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000596 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000597 def test_policy_sharing_with_wildcard(self):
598 qos_pol = self.create_qos_policy(
599 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000600 description='test-shared-policy', shared=False,
601 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000602 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
603
604 # test update shared False -> True
605 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
606 qos_pol['shared'] = True
607 self.client2.show_qos_policy(qos_pol['id'])
608 rbac_pol = {'target_tenant': '*',
609 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000610 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000611 'object_type': 'qos_policy',
612 'object_id': qos_pol['id'],
613 'action': 'access_as_shared'}
614
615 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
616 rbac_policies = [r for r in rbac_policies if r.pop('id')]
617 self.assertIn(rbac_pol, rbac_policies)
618
619 # update shared True -> False should fail because the policy is bound
620 # to a network
621 net = self._create_network(qos_pol['id'], self.admin_client, False)
622 with testtools.ExpectedException(exceptions.Conflict):
623 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
624
625 # delete the network, and update shared True -> False should pass now
626 self.admin_client.delete_network(net['id'])
627 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
628 qos_pol['shared'] = False
629 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
630
631 def _create_net_bound_qos_rbacs(self):
632 res = self._make_admin_policy_shared_to_tenant_id(
633 self.client.tenant_id)
634 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
635
636 # add a wildcard rbac rule - now the policy globally shared
637 rbac_wildcard = self.admin_client.create_rbac_policy(
638 object_type='qos_policy',
639 object_id=qos_policy['id'],
640 action='access_as_shared',
641 target_tenant='*',
642 )['rbac_policy']
643
644 # tenant1 now uses qos policy for net
645 self._create_network(qos_policy['id'], self.client)
646
647 return rbac_for_client_tenant, rbac_wildcard
648
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000649 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000650 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self):
651 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
652 # globally unshare the qos-policy, the specific share should remain
653 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
654 self.client.list_rbac_policies(id=client_rbac['id'])
655
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000656 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000657 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self):
658 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
659 # remove client_rbac policy the wildcard share should remain
660 self.admin_client.delete_rbac_policy(client_rbac['id'])
661 self.client.list_rbac_policies(id=wildcard_rbac['id'])
662
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000663 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000664 def test_policy_sharing_with_wildcard_and_tenant_id(self):
665 res = self._make_admin_policy_shared_to_tenant_id(
666 self.client.tenant_id)
667 qos_policy, rbac = res['policy'], res['rbac_policy']
668 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
669 self.assertTrue(qos_pol['shared'])
670 with testtools.ExpectedException(exceptions.NotFound):
671 self.client2.show_qos_policy(qos_policy['id'])
672
673 # make the qos-policy globally shared
674 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
675 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
676 self.assertTrue(qos_pol['shared'])
677
678 # globally unshare the qos-policy, the specific share should remain
679 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
680 self.client.show_qos_policy(qos_policy['id'])
681 with testtools.ExpectedException(exceptions.NotFound):
682 self.client2.show_qos_policy(qos_policy['id'])
683 self.assertIn(rbac,
684 self.admin_client.list_rbac_policies()['rbac_policies'])
685
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000686 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000687 def test_policy_target_update(self):
688 res = self._make_admin_policy_shared_to_tenant_id(
689 self.client.tenant_id)
690 # change to client2
691 update_res = self.admin_client.update_rbac_policy(
692 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
693 self.assertEqual(self.client2.tenant_id,
694 update_res['rbac_policy']['target_tenant'])
695 # make sure everything else stayed the same
696 res['rbac_policy'].pop('target_tenant')
697 update_res['rbac_policy'].pop('target_tenant')
698 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
699
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000700 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000701 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
702 res = self._make_admin_policy_shared_to_tenant_id(
703 self.client2.tenant_id)
704 qos_policy_id = res['policy']['id']
705 self._create_network(qos_policy_id, self.client2)
706 # a network with shared qos-policy should prevent the deletion of an
707 # rbac-policy required for it to be shared
708 with testtools.ExpectedException(exceptions.Conflict):
709 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
710
711 # a wildcard policy should allow the specific policy to be deleted
712 # since it allows the remaining port
713 wild = self.admin_client.create_rbac_policy(
714 object_type='qos_policy', object_id=res['policy']['id'],
715 action='access_as_shared', target_tenant='*')['rbac_policy']
716 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
717
718 # now that wildcard is the only remaining, it should be subjected to
719 # the same restriction
720 with testtools.ExpectedException(exceptions.Conflict):
721 self.admin_client.delete_rbac_policy(wild['id'])
722
723 # we can't update the policy to a different tenant
724 with testtools.ExpectedException(exceptions.Conflict):
725 self.admin_client.update_rbac_policy(
726 wild['id'], target_tenant=self.client2.tenant_id)
727
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000728 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000729 def test_regular_client_shares_to_another_regular_client(self):
730 # owned by self.admin_client
731 policy = self._create_qos_policy()
732 with testtools.ExpectedException(exceptions.NotFound):
733 self.client.show_qos_policy(policy['id'])
734 rbac_policy = self.admin_client.create_rbac_policy(
735 object_type='qos_policy', object_id=policy['id'],
736 action='access_as_shared',
737 target_tenant=self.client.tenant_id)['rbac_policy']
738 self.client.show_qos_policy(policy['id'])
739
740 self.assertIn(rbac_policy,
741 self.admin_client.list_rbac_policies()['rbac_policies'])
742 # ensure that 'client2' can't see the rbac-policy sharing the
743 # qos-policy to it because the rbac-policy belongs to 'client'
744 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
745 self.client2.list_rbac_policies()['rbac_policies']])
746
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000747 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000748 def test_filter_fields(self):
749 policy = self._create_qos_policy()
750 self.admin_client.create_rbac_policy(
751 object_type='qos_policy', object_id=policy['id'],
752 action='access_as_shared', target_tenant=self.client2.tenant_id)
753 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
754 ('tenant_id', 'target_tenant'))
755 for fields in field_args:
756 res = self.admin_client.list_rbac_policies(fields=fields)
757 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
758
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000759 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000760 def test_rbac_policy_show(self):
761 res = self._make_admin_policy_shared_to_tenant_id(
762 self.client.tenant_id)
763 p1 = res['rbac_policy']
764 p2 = self.admin_client.create_rbac_policy(
765 object_type='qos_policy', object_id=res['policy']['id'],
766 action='access_as_shared',
767 target_tenant='*')['rbac_policy']
768
769 self.assertEqual(
770 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
771 self.assertEqual(
772 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
773
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000774 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000775 def test_filter_rbac_policies(self):
776 policy = self._create_qos_policy()
777 rbac_pol1 = self.admin_client.create_rbac_policy(
778 object_type='qos_policy', object_id=policy['id'],
779 action='access_as_shared',
780 target_tenant=self.client2.tenant_id)['rbac_policy']
781 rbac_pol2 = self.admin_client.create_rbac_policy(
782 object_type='qos_policy', object_id=policy['id'],
783 action='access_as_shared',
784 target_tenant=self.admin_client.tenant_id)['rbac_policy']
785 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
786 'rbac_policies']
787 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
788 'rbac_policies']
789 self.assertEqual(1, len(res1))
790 self.assertEqual(1, len(res2))
791 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
792 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
793
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000794 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000795 def test_regular_client_blocked_from_sharing_anothers_policy(self):
796 qos_policy = self._make_admin_policy_shared_to_tenant_id(
797 self.client.tenant_id)['policy']
798 with testtools.ExpectedException(exceptions.BadRequest):
799 self.client.create_rbac_policy(
800 object_type='qos_policy', object_id=qos_policy['id'],
801 action='access_as_shared',
802 target_tenant=self.client2.tenant_id)
803
804 # make sure the rbac-policy is invisible to the tenant for which it's
805 # being shared
806 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
807
808
809class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
810 VALID_DSCP_MARK1 = 56
811 VALID_DSCP_MARK2 = 48
812
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000813 required_extensions = ['qos']
814
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000815 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900816 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000817 def resource_setup(cls):
818 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
819
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000820 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000821 def test_rule_create(self):
822 policy = self.create_qos_policy(name='test-policy',
823 description='test policy',
824 shared=False)
825 rule = self.admin_client.create_dscp_marking_rule(
826 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
827
828 # Test 'show rule'
829 retrieved_rule = self.admin_client.show_dscp_marking_rule(
830 policy['id'], rule['id'])
831 retrieved_rule = retrieved_rule['dscp_marking_rule']
832 self.assertEqual(rule['id'], retrieved_rule['id'])
833 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
834
835 # Test 'list rules'
836 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
837 rules = rules['dscp_marking_rules']
838 rules_ids = [r['id'] for r in rules]
839 self.assertIn(rule['id'], rules_ids)
840
841 # Test 'show policy'
842 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
843 policy_rules = retrieved_policy['policy']['rules']
844 self.assertEqual(1, len(policy_rules))
845 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000846 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000847 policy_rules[0]['type'])
848
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000849 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000850 def test_rule_create_fail_for_the_same_type(self):
851 policy = self.create_qos_policy(name='test-policy',
852 description='test policy',
853 shared=False)
854 self.admin_client.create_dscp_marking_rule(
855 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
856
857 self.assertRaises(exceptions.Conflict,
858 self.admin_client.create_dscp_marking_rule,
859 policy_id=policy['id'],
860 dscp_mark=self.VALID_DSCP_MARK2)
861
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000862 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000863 def test_rule_update(self):
864 policy = self.create_qos_policy(name='test-policy',
865 description='test policy',
866 shared=False)
867 rule = self.admin_client.create_dscp_marking_rule(
868 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
869
870 self.admin_client.update_dscp_marking_rule(
871 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
872
873 retrieved_policy = self.admin_client.show_dscp_marking_rule(
874 policy['id'], rule['id'])
875 retrieved_policy = retrieved_policy['dscp_marking_rule']
876 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
877
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000878 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000879 def test_rule_delete(self):
880 policy = self.create_qos_policy(name='test-policy',
881 description='test policy',
882 shared=False)
883 rule = self.admin_client.create_dscp_marking_rule(
884 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
885
886 retrieved_policy = self.admin_client.show_dscp_marking_rule(
887 policy['id'], rule['id'])
888 retrieved_policy = retrieved_policy['dscp_marking_rule']
889 self.assertEqual(rule['id'], retrieved_policy['id'])
890
891 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
892 self.assertRaises(exceptions.NotFound,
893 self.admin_client.show_dscp_marking_rule,
894 policy['id'], rule['id'])
895
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000896 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000897 def test_rule_create_rule_nonexistent_policy(self):
898 self.assertRaises(
899 exceptions.NotFound,
900 self.admin_client.create_dscp_marking_rule,
901 'policy', self.VALID_DSCP_MARK1)
902
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000903 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000904 def test_rule_create_forbidden_for_regular_tenants(self):
905 self.assertRaises(
906 exceptions.Forbidden,
907 self.client.create_dscp_marking_rule,
908 'policy', self.VALID_DSCP_MARK1)
909
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000910 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000911 def test_invalid_rule_create(self):
912 policy = self.create_qos_policy(name='test-policy',
913 description='test policy',
914 shared=False)
915 self.assertRaises(
916 exceptions.BadRequest,
917 self.admin_client.create_dscp_marking_rule,
918 policy['id'], 58)
919
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000920 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000921 def test_get_rules_by_policy(self):
922 policy1 = self.create_qos_policy(name='test-policy1',
923 description='test policy1',
924 shared=False)
925 rule1 = self.admin_client.create_dscp_marking_rule(
926 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
927
928 policy2 = self.create_qos_policy(name='test-policy2',
929 description='test policy2',
930 shared=False)
931 rule2 = self.admin_client.create_dscp_marking_rule(
932 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
933
934 # Test 'list rules'
935 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
936 rules = rules['dscp_marking_rules']
937 rules_ids = [r['id'] for r in rules]
938 self.assertIn(rule1['id'], rules_ids)
939 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +0200940
941
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100942class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
943 DIRECTION_EGRESS = "egress"
944 DIRECTION_INGRESS = "ingress"
945 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
946 RULES_NAME = RULE_NAME + "s"
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000947 required_extensions = ['qos']
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100948
949 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900950 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100951 def resource_setup(cls):
952 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
953
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000954 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100955 def test_rule_create(self):
956 policy = self.create_qos_policy(name='test-policy',
957 description='test policy',
958 shared=False)
959 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000960 policy_id=policy['id'],
961 direction=self.DIRECTION_EGRESS,
962 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100963
964 # Test 'show rule'
965 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
966 policy['id'], rule['id'])
967 retrieved_rule = retrieved_rule[self.RULE_NAME]
968 self.assertEqual(rule['id'], retrieved_rule['id'])
969 self.assertEqual(1138, retrieved_rule['min_kbps'])
970 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
971
972 # Test 'list rules'
973 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
974 rules = rules[self.RULES_NAME]
975 rules_ids = [r['id'] for r in rules]
976 self.assertIn(rule['id'], rules_ids)
977
978 # Test 'show policy'
979 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
980 policy_rules = retrieved_policy['policy']['rules']
981 self.assertEqual(1, len(policy_rules))
982 self.assertEqual(rule['id'], policy_rules[0]['id'])
983 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
984 policy_rules[0]['type'])
985
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000986 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000987 def test_rule_create_fail_for_missing_min_kbps(self):
988 policy = self.create_qos_policy(name='test-policy',
989 description='test policy',
990 shared=False)
991 self.assertRaises(exceptions.BadRequest,
992 self.admin_client.create_minimum_bandwidth_rule,
993 policy_id=policy['id'],
994 direction=self.DIRECTION_EGRESS)
995
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000996 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100997 def test_rule_create_fail_for_the_same_type(self):
998 policy = self.create_qos_policy(name='test-policy',
999 description='test policy',
1000 shared=False)
1001 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001002 policy_id=policy['id'],
1003 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001004
1005 self.assertRaises(exceptions.Conflict,
1006 self.admin_client.create_minimum_bandwidth_rule,
1007 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001008 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001009
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001010 @decorators.idempotent_id('d6fce764-e511-4fa6-9f86-f4b41cf142cf')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001011 def test_rule_create_fail_for_direction_ingress(self):
1012 policy = self.create_qos_policy(name='test-policy',
1013 description='test policy',
1014 shared=False)
1015 self.assertRaises(exceptions.BadRequest,
1016 self.admin_client.create_minimum_bandwidth_rule,
1017 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001018 direction=self.DIRECTION_INGRESS,
1019 min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001020
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001021 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001022 def test_rule_update(self):
1023 policy = self.create_qos_policy(name='test-policy',
1024 description='test policy',
1025 shared=False)
1026 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001027 policy_id=policy['id'],
1028 direction=self.DIRECTION_EGRESS,
1029 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001030
1031 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
1032 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
1033
1034 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1035 policy['id'], rule['id'])
1036 retrieved_policy = retrieved_policy[self.RULE_NAME]
1037 self.assertEqual(350, retrieved_policy['min_kbps'])
1038 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1039
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001040 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001041 def test_rule_delete(self):
1042 policy = self.create_qos_policy(name='test-policy',
1043 description='test policy',
1044 shared=False)
1045 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001046 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001047
1048 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1049 policy['id'], rule['id'])
1050 retrieved_policy = retrieved_policy[self.RULE_NAME]
1051 self.assertEqual(rule['id'], retrieved_policy['id'])
1052
1053 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1054 rule['id'])
1055 self.assertRaises(exceptions.NotFound,
1056 self.admin_client.show_minimum_bandwidth_rule,
1057 policy['id'], rule['id'])
1058
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001059 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001060 def test_rule_create_rule_nonexistent_policy(self):
1061 self.assertRaises(
1062 exceptions.NotFound,
1063 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001064 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001065
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001066 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001067 def test_rule_create_forbidden_for_regular_tenants(self):
1068 self.assertRaises(
1069 exceptions.Forbidden,
1070 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001071 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001072
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001073 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001074 def test_get_rules_by_policy(self):
1075 policy1 = self.create_qos_policy(name='test-policy1',
1076 description='test policy1',
1077 shared=False)
1078 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001079 policy_id=policy1['id'],
1080 direction=self.DIRECTION_EGRESS,
1081 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001082
1083 policy2 = self.create_qos_policy(name='test-policy2',
1084 description='test policy2',
1085 shared=False)
1086 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001087 policy_id=policy2['id'],
1088 direction=self.DIRECTION_EGRESS,
1089 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001090
1091 # Test 'list rules'
1092 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1093 rules = rules[self.RULES_NAME]
1094 rules_ids = [r['id'] for r in rules]
1095 self.assertIn(rule1['id'], rules_ids)
1096 self.assertNotIn(rule2['id'], rules_ids)
1097
1098
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001099class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1100 base.BaseAdminNetworkTest):
1101
1102 resource = 'policy'
1103 plural_name = 'policies'
1104
1105 # Use unique description to isolate the tests from other QoS tests
1106 list_kwargs = {'description': 'search-criteria-test'}
1107 list_as_admin = True
1108
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001109 required_extensions = ['qos']
1110
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001111 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001112 def resource_setup(cls):
1113 super(QosSearchCriteriaTest, cls).resource_setup()
1114 for name in cls.resource_names:
1115 cls.create_qos_policy(
1116 name=name, description='search-criteria-test')
1117
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001118 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001119 def test_list_sorts_asc(self):
1120 self._test_list_sorts_asc()
1121
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001122 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001123 def test_list_sorts_desc(self):
1124 self._test_list_sorts_desc()
1125
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001126 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001127 def test_list_pagination(self):
1128 self._test_list_pagination()
1129
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001130 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001131 def test_list_pagination_with_marker(self):
1132 self._test_list_pagination_with_marker()
1133
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001134 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001135 def test_list_pagination_with_href_links(self):
1136 self._test_list_pagination_with_href_links()
1137
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001138 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001139 def test_list_pagination_page_reverse_asc(self):
1140 self._test_list_pagination_page_reverse_asc()
1141
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001142 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001143 def test_list_pagination_page_reverse_desc(self):
1144 self._test_list_pagination_page_reverse_desc()
1145
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001146 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001147 def test_list_pagination_page_reverse_with_href_links(self):
1148 self._test_list_pagination_page_reverse_with_href_links()
1149
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001150 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001151 def test_list_no_pagination_limit_0(self):
1152 self._test_list_no_pagination_limit_0()