blob: 7735710484b8f9b5347c474dacd402eaa0b734fb [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ński7aa3a352017-06-19 06:35:25 +000034 @staticmethod
35 def _get_driver_details(rule_type_details, driver_name):
36 for driver in rule_type_details['drivers']:
37 if driver['name'] == driver_name:
38 return driver
39
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000040 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000041 def test_create_policy(self):
42 policy = self.create_qos_policy(name='test-policy',
43 description='test policy desc1',
44 shared=False)
45
46 # Test 'show policy'
47 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
48 retrieved_policy = retrieved_policy['policy']
49 self.assertEqual('test-policy', retrieved_policy['name'])
50 self.assertEqual('test policy desc1', retrieved_policy['description'])
51 self.assertFalse(retrieved_policy['shared'])
52
53 # Test 'list policies'
54 policies = self.admin_client.list_qos_policies()['policies']
55 policies_ids = [p['id'] for p in policies]
56 self.assertIn(policy['id'], policies_ids)
57
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000058 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Henry Gessaufa6c78d2016-10-09 19:56:09 -040059 @test.requires_ext(extension="project-id", service="network")
60 def test_show_policy_has_project_id(self):
61 policy = self.create_qos_policy(name='test-policy', shared=False)
62 body = self.admin_client.show_qos_policy(policy['id'])
63 show_policy = body['policy']
64 self.assertIn('project_id', show_policy)
65 self.assertIn('tenant_id', show_policy)
66 self.assertEqual(self.admin_client.tenant_id,
67 show_policy['project_id'])
68 self.assertEqual(self.admin_client.tenant_id,
69 show_policy['tenant_id'])
70
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000071 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000072 def test_list_policy_filter_by_name(self):
73 self.create_qos_policy(name='test', description='test policy',
74 shared=False)
75 self.create_qos_policy(name='test2', description='test policy',
76 shared=False)
77
78 policies = (self.admin_client.
79 list_qos_policies(name='test')['policies'])
80 self.assertEqual(1, len(policies))
81
82 retrieved_policy = policies[0]
83 self.assertEqual('test', retrieved_policy['name'])
84
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000085 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000086 def test_policy_update(self):
87 policy = self.create_qos_policy(name='test-policy',
88 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +000089 shared=False,
90 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000091 self.admin_client.update_qos_policy(policy['id'],
92 description='test policy desc2',
93 shared=True)
94
95 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
96 retrieved_policy = retrieved_policy['policy']
97 self.assertEqual('test policy desc2', retrieved_policy['description'])
98 self.assertTrue(retrieved_policy['shared'])
99 self.assertEqual([], retrieved_policy['rules'])
100
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000101 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000102 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
103 policy = self.create_qos_policy(name='test-policy',
104 description='',
105 shared=False,
106 tenant_id=self.client.tenant_id)
107 self.assertRaises(
108 exceptions.Forbidden,
109 self.client.update_qos_policy,
110 policy['id'], description='test policy')
111
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000112 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000113 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
114 policy = self.create_qos_policy(name='test-policy',
115 description='',
116 shared=False,
117 tenant_id=self.admin_client.tenant_id)
118 self.assertRaises(
119 exceptions.NotFound,
120 self.client.update_qos_policy,
121 policy['id'], description='test policy')
122
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000123 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000124 def test_shared_policy_update(self):
125 policy = self.create_qos_policy(name='test-policy',
126 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000127 shared=True,
128 tenant_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000129
130 self.admin_client.update_qos_policy(policy['id'],
131 description='test policy desc2')
132 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
133 retrieved_policy = retrieved_policy['policy']
134 self.assertTrue(retrieved_policy['shared'])
135
136 self.admin_client.update_qos_policy(policy['id'],
137 shared=False)
138 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
139 retrieved_policy = retrieved_policy['policy']
140 self.assertFalse(retrieved_policy['shared'])
141
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000142 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000143 def test_delete_policy(self):
144 policy = self.admin_client.create_qos_policy(
145 'test-policy', 'desc', True)['policy']
146
147 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
148 retrieved_policy = retrieved_policy['policy']
149 self.assertEqual('test-policy', retrieved_policy['name'])
150
151 self.admin_client.delete_qos_policy(policy['id'])
152 self.assertRaises(exceptions.NotFound,
153 self.admin_client.show_qos_policy, policy['id'])
154
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000155 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000156 def test_list_admin_rule_types(self):
157 self._test_list_rule_types(self.admin_client)
158
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000159 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000160 def test_list_regular_rule_types(self):
161 self._test_list_rule_types(self.client)
162
163 def _test_list_rule_types(self, client):
164 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000165 # Since returned rule types depends on loaded backend drivers this test
166 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000167 #
168 # In theory, we could make the test conditional on which ml2 drivers
169 # are enabled in gate (or more specifically, on which supported qos
170 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200171 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000172 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000173
174 rule_types = client.list_qos_rule_types()
175 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000176
177 # Verify that only required fields present in rule details
178 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000179 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000180
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000181 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
182 def test_show_rule_type_details_as_user(self):
183 self.assertRaises(
184 exceptions.Forbidden,
185 self.client.show_qos_rule_type,
186 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
187
188 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
189 def test_show_rule_type_details_as_admin(self):
190 # Since returned rule types depend on loaded backend drivers this test
191 # is checking only if returned keys are same as expected keys
192
193 # In theory, we could make the test conditional on which ml2 drivers
194 # are enabled in gate, but that option doesn't seem to be
195 # available through tempest.lib framework
196 expected_rule_type_details_keys = ['type', 'drivers']
197
198 rule_type_details = self.admin_client.show_qos_rule_type(
199 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
200
201 # Verify that only required fields present in rule details
202 self.assertEqual(
203 sorted(tuple(expected_rule_type_details_keys)),
204 sorted(tuple(rule_type_details.keys())))
205
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000206 def _disassociate_network(self, client, network_id):
Hong Hui Xiao25028302016-12-13 16:29:08 +0800207 updated_network = client.update_network(network_id,
208 qos_policy_id=None)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000209 self.assertIsNone(updated_network['network']['qos_policy_id'])
210
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000211 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000212 def test_policy_association_with_admin_network(self):
213 policy = self.create_qos_policy(name='test-policy',
214 description='test policy',
215 shared=False)
216 network = self.create_shared_network('test network',
217 qos_policy_id=policy['id'])
218
219 retrieved_network = self.admin_client.show_network(network['id'])
220 self.assertEqual(
221 policy['id'], retrieved_network['network']['qos_policy_id'])
222
223 self._disassociate_network(self.admin_client, network['id'])
224
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000225 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000226 def test_policy_association_with_tenant_network(self):
227 policy = self.create_qos_policy(name='test-policy',
228 description='test policy',
229 shared=True)
230 network = self.create_network('test network',
231 qos_policy_id=policy['id'])
232
233 retrieved_network = self.admin_client.show_network(network['id'])
234 self.assertEqual(
235 policy['id'], retrieved_network['network']['qos_policy_id'])
236
237 self._disassociate_network(self.client, network['id'])
238
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000239 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000240 def test_policy_association_with_network_nonexistent_policy(self):
241 self.assertRaises(
242 exceptions.NotFound,
243 self.create_network,
244 'test network',
245 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
246
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000247 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000248 def test_policy_association_with_network_non_shared_policy(self):
249 policy = self.create_qos_policy(name='test-policy',
250 description='test policy',
251 shared=False)
252 self.assertRaises(
253 exceptions.NotFound,
254 self.create_network,
255 'test network', qos_policy_id=policy['id'])
256
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000257 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000258 def test_policy_update_association_with_admin_network(self):
259 policy = self.create_qos_policy(name='test-policy',
260 description='test policy',
261 shared=False)
262 network = self.create_shared_network('test network')
263 retrieved_network = self.admin_client.show_network(network['id'])
264 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
265
266 self.admin_client.update_network(network['id'],
267 qos_policy_id=policy['id'])
268 retrieved_network = self.admin_client.show_network(network['id'])
269 self.assertEqual(
270 policy['id'], retrieved_network['network']['qos_policy_id'])
271
272 self._disassociate_network(self.admin_client, network['id'])
273
274 def _disassociate_port(self, port_id):
275 self.client.update_port(port_id, qos_policy_id=None)
276 updated_port = self.admin_client.show_port(port_id)
277 self.assertIsNone(updated_port['port']['qos_policy_id'])
278
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000279 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000280 def test_policy_association_with_port_shared_policy(self):
281 policy = self.create_qos_policy(name='test-policy',
282 description='test policy',
283 shared=True)
284 network = self.create_shared_network('test network')
285 port = self.create_port(network, qos_policy_id=policy['id'])
286
287 retrieved_port = self.admin_client.show_port(port['id'])
288 self.assertEqual(
289 policy['id'], retrieved_port['port']['qos_policy_id'])
290
291 self._disassociate_port(port['id'])
292
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000293 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000294 def test_policy_association_with_port_nonexistent_policy(self):
295 network = self.create_shared_network('test network')
296 self.assertRaises(
297 exceptions.NotFound,
298 self.create_port,
299 network,
300 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
301
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000302 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000303 def test_policy_association_with_port_non_shared_policy(self):
304 policy = self.create_qos_policy(name='test-policy',
305 description='test policy',
306 shared=False)
307 network = self.create_shared_network('test network')
308 self.assertRaises(
309 exceptions.NotFound,
310 self.create_port,
311 network, qos_policy_id=policy['id'])
312
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000313 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000314 def test_policy_update_association_with_port_shared_policy(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)
320 retrieved_port = self.admin_client.show_port(port['id'])
321 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
322
323 self.client.update_port(port['id'], qos_policy_id=policy['id'])
324 retrieved_port = self.admin_client.show_port(port['id'])
325 self.assertEqual(
326 policy['id'], retrieved_port['port']['qos_policy_id'])
327
328 self._disassociate_port(port['id'])
329
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000330 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000331 def test_delete_not_allowed_if_policy_in_use_by_network(self):
332 policy = self.create_qos_policy(name='test-policy',
333 description='test policy',
334 shared=True)
335 network = self.create_shared_network(
336 'test network', qos_policy_id=policy['id'])
337 self.assertRaises(
338 exceptions.Conflict,
339 self.admin_client.delete_qos_policy, policy['id'])
340
341 self._disassociate_network(self.admin_client, network['id'])
342 self.admin_client.delete_qos_policy(policy['id'])
343
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000344 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000345 def test_delete_not_allowed_if_policy_in_use_by_port(self):
346 policy = self.create_qos_policy(name='test-policy',
347 description='test policy',
348 shared=True)
349 network = self.create_shared_network('test network')
350 port = self.create_port(network, qos_policy_id=policy['id'])
351 self.assertRaises(
352 exceptions.Conflict,
353 self.admin_client.delete_qos_policy, policy['id'])
354
355 self._disassociate_port(port['id'])
356 self.admin_client.delete_qos_policy(policy['id'])
357
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000358 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000359 def test_qos_policy_delete_with_rules(self):
360 policy = self.create_qos_policy(name='test-policy',
361 description='test policy',
362 shared=False)
363 self.admin_client.create_bandwidth_limit_rule(
364 policy['id'], 200, 1337)['bandwidth_limit_rule']
365
366 self.admin_client.delete_qos_policy(policy['id'])
367
368 with testtools.ExpectedException(exceptions.NotFound):
369 self.admin_client.show_qos_policy(policy['id'])
370
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000371 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000372 def test_get_policy_that_is_shared(self):
373 policy = self.create_qos_policy(
374 name='test-policy-shared',
375 description='shared policy',
376 shared=True,
377 tenant_id=self.admin_client.tenant_id)
378 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
379 self.assertEqual(obtained_policy, policy)
380
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000381 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100382 def test_policy_create_forbidden_for_regular_tenants(self):
383 self.assertRaises(
384 exceptions.Forbidden,
385 self.client.create_qos_policy,
386 'test-policy', 'test policy', False)
387
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000388
389class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000390
391 direction = None
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000392 required_extensions = ['qos']
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000393
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000394 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900395 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000396 def resource_setup(cls):
397 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
398
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000399 @property
400 def opposite_direction(self):
401 if self.direction == "ingress":
402 return "egress"
403 elif self.direction == "egress":
404 return "ingress"
405 else:
406 return None
407
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000408 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000409 def test_rule_create(self):
410 policy = self.create_qos_policy(name='test-policy',
411 description='test policy',
412 shared=False)
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000413 rule = self.create_qos_bandwidth_limit_rule(
414 policy_id=policy['id'],
415 max_kbps=200,
416 max_burst_kbps=1337,
417 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000418
419 # Test 'show rule'
420 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
421 policy['id'], rule['id'])
422 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
423 self.assertEqual(rule['id'], retrieved_rule['id'])
424 self.assertEqual(200, retrieved_rule['max_kbps'])
425 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000426 if self.direction:
427 self.assertEqual(self.direction, retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000428
429 # Test 'list rules'
430 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
431 rules = rules['bandwidth_limit_rules']
432 rules_ids = [r['id'] for r in rules]
433 self.assertIn(rule['id'], rules_ids)
434
435 # Test 'show policy'
436 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
437 policy_rules = retrieved_policy['policy']['rules']
438 self.assertEqual(1, len(policy_rules))
439 self.assertEqual(rule['id'], policy_rules[0]['id'])
440 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
441 policy_rules[0]['type'])
442
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000443 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000444 def test_rule_create_fail_for_the_same_type(self):
445 policy = self.create_qos_policy(name='test-policy',
446 description='test policy',
447 shared=False)
448 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
449 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000450 max_burst_kbps=1337,
451 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000452
453 self.assertRaises(exceptions.Conflict,
454 self.create_qos_bandwidth_limit_rule,
455 policy_id=policy['id'],
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000456 max_kbps=201, max_burst_kbps=1338,
457 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000458
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000459 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000460 def test_rule_update(self):
461 policy = self.create_qos_policy(name='test-policy',
462 description='test policy',
463 shared=False)
464 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
465 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000466 max_burst_kbps=1,
467 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000468
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000469 self.admin_client.update_bandwidth_limit_rule(
470 policy['id'],
471 rule['id'],
472 max_kbps=200,
473 max_burst_kbps=1337,
474 direction=self.opposite_direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000475
476 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
477 policy['id'], rule['id'])
478 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
479 self.assertEqual(200, retrieved_policy['max_kbps'])
480 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000481 if self.opposite_direction:
482 self.assertEqual(self.opposite_direction,
483 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000484
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000485 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000486 def test_rule_delete(self):
487 policy = self.create_qos_policy(name='test-policy',
488 description='test policy',
489 shared=False)
490 rule = self.admin_client.create_bandwidth_limit_rule(
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000491 policy['id'], 200, 1337, self.direction)['bandwidth_limit_rule']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000492
493 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
494 policy['id'], rule['id'])
495 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
496 self.assertEqual(rule['id'], retrieved_policy['id'])
497
498 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
499 self.assertRaises(exceptions.NotFound,
500 self.admin_client.show_bandwidth_limit_rule,
501 policy['id'], rule['id'])
502
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000503 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000504 def test_rule_create_rule_nonexistent_policy(self):
505 self.assertRaises(
506 exceptions.NotFound,
507 self.create_qos_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000508 'policy', 200, 1337, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000509
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000510 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000511 def test_rule_create_forbidden_for_regular_tenants(self):
512 self.assertRaises(
513 exceptions.Forbidden,
514 self.client.create_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000515 'policy', 1, 2, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000516
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000517 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000518 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
519 policy = self.create_qos_policy(name='test-policy',
520 description='test policy',
521 shared=False,
522 tenant_id=self.client.tenant_id)
523 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
524 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000525 max_burst_kbps=1,
526 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000527 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400528 exceptions.Forbidden,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000529 self.client.update_bandwidth_limit_rule,
530 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
531
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000532 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000533 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
534 policy = self.create_qos_policy(name='test-policy',
535 description='test policy',
536 shared=False,
537 tenant_id=self.admin_client.tenant_id)
538 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
539 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000540 max_burst_kbps=1,
541 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000542 self.assertRaises(
543 exceptions.NotFound,
544 self.client.update_bandwidth_limit_rule,
545 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
546
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000547 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000548 def test_get_rules_by_policy(self):
549 policy1 = self.create_qos_policy(name='test-policy1',
550 description='test policy1',
551 shared=False)
552 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
553 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000554 max_burst_kbps=1337,
555 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000556
557 policy2 = self.create_qos_policy(name='test-policy2',
558 description='test policy2',
559 shared=False)
560 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
561 max_kbps=5000,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000562 max_burst_kbps=2523,
563 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000564
565 # Test 'list rules'
566 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
567 rules = rules['bandwidth_limit_rules']
568 rules_ids = [r['id'] for r in rules]
569 self.assertIn(rule1['id'], rules_ids)
570 self.assertNotIn(rule2['id'], rules_ids)
571
572
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000573class QosBandwidthLimitRuleWithDirectionTestJSON(
574 QosBandwidthLimitRuleTestJSON):
575
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000576 required_extensions = (
577 QosBandwidthLimitRuleTestJSON.required_extensions +
578 ['qos-bw-limit-direction']
579 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000580 scenarios = [
581 ('ingress', {'direction': 'ingress'}),
582 ('egress', {'direction': 'egress'}),
583 ]
584
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000585
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000586class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
587
588 force_tenant_isolation = True
589 credentials = ['primary', 'alt', 'admin']
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000590 required_extensions = ['qos']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000591
592 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000593 def resource_setup(cls):
594 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530595 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000596
597 def _create_qos_policy(self, tenant_id=None):
598 args = {'name': data_utils.rand_name('test-policy'),
599 'description': 'test policy',
600 'shared': False,
601 'tenant_id': tenant_id}
602 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
603 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
604
605 return qos_policy
606
607 def _make_admin_policy_shared_to_tenant_id(self, tenant_id):
608 policy = self._create_qos_policy()
609 rbac_policy = self.admin_client.create_rbac_policy(
610 object_type='qos_policy',
611 object_id=policy['id'],
612 action='access_as_shared',
613 target_tenant=tenant_id,
614 )['rbac_policy']
615
616 return {'policy': policy, 'rbac_policy': rbac_policy}
617
618 def _create_network(self, qos_policy_id, client, should_cleanup=True):
619 net = client.create_network(
620 name=data_utils.rand_name('test-network'),
621 qos_policy_id=qos_policy_id)['network']
622 if should_cleanup:
623 self.addCleanup(client.delete_network, net['id'])
624
625 return net
626
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000627 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000628 def test_policy_sharing_with_wildcard(self):
629 qos_pol = self.create_qos_policy(
630 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000631 description='test-shared-policy', shared=False,
632 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000633 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
634
635 # test update shared False -> True
636 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
637 qos_pol['shared'] = True
638 self.client2.show_qos_policy(qos_pol['id'])
639 rbac_pol = {'target_tenant': '*',
640 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000641 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000642 'object_type': 'qos_policy',
643 'object_id': qos_pol['id'],
644 'action': 'access_as_shared'}
645
646 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
647 rbac_policies = [r for r in rbac_policies if r.pop('id')]
648 self.assertIn(rbac_pol, rbac_policies)
649
650 # update shared True -> False should fail because the policy is bound
651 # to a network
652 net = self._create_network(qos_pol['id'], self.admin_client, False)
653 with testtools.ExpectedException(exceptions.Conflict):
654 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
655
656 # delete the network, and update shared True -> False should pass now
657 self.admin_client.delete_network(net['id'])
658 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
659 qos_pol['shared'] = False
660 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
661
662 def _create_net_bound_qos_rbacs(self):
663 res = self._make_admin_policy_shared_to_tenant_id(
664 self.client.tenant_id)
665 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
666
667 # add a wildcard rbac rule - now the policy globally shared
668 rbac_wildcard = self.admin_client.create_rbac_policy(
669 object_type='qos_policy',
670 object_id=qos_policy['id'],
671 action='access_as_shared',
672 target_tenant='*',
673 )['rbac_policy']
674
675 # tenant1 now uses qos policy for net
676 self._create_network(qos_policy['id'], self.client)
677
678 return rbac_for_client_tenant, rbac_wildcard
679
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000680 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000681 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self):
682 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
683 # globally unshare the qos-policy, the specific share should remain
684 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
685 self.client.list_rbac_policies(id=client_rbac['id'])
686
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000687 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000688 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self):
689 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
690 # remove client_rbac policy the wildcard share should remain
691 self.admin_client.delete_rbac_policy(client_rbac['id'])
692 self.client.list_rbac_policies(id=wildcard_rbac['id'])
693
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000694 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000695 def test_policy_sharing_with_wildcard_and_tenant_id(self):
696 res = self._make_admin_policy_shared_to_tenant_id(
697 self.client.tenant_id)
698 qos_policy, rbac = res['policy'], res['rbac_policy']
699 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
700 self.assertTrue(qos_pol['shared'])
701 with testtools.ExpectedException(exceptions.NotFound):
702 self.client2.show_qos_policy(qos_policy['id'])
703
704 # make the qos-policy globally shared
705 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
706 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
707 self.assertTrue(qos_pol['shared'])
708
709 # globally unshare the qos-policy, the specific share should remain
710 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
711 self.client.show_qos_policy(qos_policy['id'])
712 with testtools.ExpectedException(exceptions.NotFound):
713 self.client2.show_qos_policy(qos_policy['id'])
714 self.assertIn(rbac,
715 self.admin_client.list_rbac_policies()['rbac_policies'])
716
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000717 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000718 def test_policy_target_update(self):
719 res = self._make_admin_policy_shared_to_tenant_id(
720 self.client.tenant_id)
721 # change to client2
722 update_res = self.admin_client.update_rbac_policy(
723 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
724 self.assertEqual(self.client2.tenant_id,
725 update_res['rbac_policy']['target_tenant'])
726 # make sure everything else stayed the same
727 res['rbac_policy'].pop('target_tenant')
728 update_res['rbac_policy'].pop('target_tenant')
729 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
730
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000731 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000732 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
733 res = self._make_admin_policy_shared_to_tenant_id(
734 self.client2.tenant_id)
735 qos_policy_id = res['policy']['id']
736 self._create_network(qos_policy_id, self.client2)
737 # a network with shared qos-policy should prevent the deletion of an
738 # rbac-policy required for it to be shared
739 with testtools.ExpectedException(exceptions.Conflict):
740 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
741
742 # a wildcard policy should allow the specific policy to be deleted
743 # since it allows the remaining port
744 wild = self.admin_client.create_rbac_policy(
745 object_type='qos_policy', object_id=res['policy']['id'],
746 action='access_as_shared', target_tenant='*')['rbac_policy']
747 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
748
749 # now that wildcard is the only remaining, it should be subjected to
750 # the same restriction
751 with testtools.ExpectedException(exceptions.Conflict):
752 self.admin_client.delete_rbac_policy(wild['id'])
753
754 # we can't update the policy to a different tenant
755 with testtools.ExpectedException(exceptions.Conflict):
756 self.admin_client.update_rbac_policy(
757 wild['id'], target_tenant=self.client2.tenant_id)
758
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000759 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000760 def test_regular_client_shares_to_another_regular_client(self):
761 # owned by self.admin_client
762 policy = self._create_qos_policy()
763 with testtools.ExpectedException(exceptions.NotFound):
764 self.client.show_qos_policy(policy['id'])
765 rbac_policy = self.admin_client.create_rbac_policy(
766 object_type='qos_policy', object_id=policy['id'],
767 action='access_as_shared',
768 target_tenant=self.client.tenant_id)['rbac_policy']
769 self.client.show_qos_policy(policy['id'])
770
771 self.assertIn(rbac_policy,
772 self.admin_client.list_rbac_policies()['rbac_policies'])
773 # ensure that 'client2' can't see the rbac-policy sharing the
774 # qos-policy to it because the rbac-policy belongs to 'client'
775 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
776 self.client2.list_rbac_policies()['rbac_policies']])
777
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000778 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000779 def test_filter_fields(self):
780 policy = self._create_qos_policy()
781 self.admin_client.create_rbac_policy(
782 object_type='qos_policy', object_id=policy['id'],
783 action='access_as_shared', target_tenant=self.client2.tenant_id)
784 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
785 ('tenant_id', 'target_tenant'))
786 for fields in field_args:
787 res = self.admin_client.list_rbac_policies(fields=fields)
788 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
789
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000790 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000791 def test_rbac_policy_show(self):
792 res = self._make_admin_policy_shared_to_tenant_id(
793 self.client.tenant_id)
794 p1 = res['rbac_policy']
795 p2 = self.admin_client.create_rbac_policy(
796 object_type='qos_policy', object_id=res['policy']['id'],
797 action='access_as_shared',
798 target_tenant='*')['rbac_policy']
799
800 self.assertEqual(
801 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
802 self.assertEqual(
803 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
804
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000805 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000806 def test_filter_rbac_policies(self):
807 policy = self._create_qos_policy()
808 rbac_pol1 = self.admin_client.create_rbac_policy(
809 object_type='qos_policy', object_id=policy['id'],
810 action='access_as_shared',
811 target_tenant=self.client2.tenant_id)['rbac_policy']
812 rbac_pol2 = self.admin_client.create_rbac_policy(
813 object_type='qos_policy', object_id=policy['id'],
814 action='access_as_shared',
815 target_tenant=self.admin_client.tenant_id)['rbac_policy']
816 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
817 'rbac_policies']
818 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
819 'rbac_policies']
820 self.assertEqual(1, len(res1))
821 self.assertEqual(1, len(res2))
822 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
823 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
824
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000825 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000826 def test_regular_client_blocked_from_sharing_anothers_policy(self):
827 qos_policy = self._make_admin_policy_shared_to_tenant_id(
828 self.client.tenant_id)['policy']
829 with testtools.ExpectedException(exceptions.BadRequest):
830 self.client.create_rbac_policy(
831 object_type='qos_policy', object_id=qos_policy['id'],
832 action='access_as_shared',
833 target_tenant=self.client2.tenant_id)
834
835 # make sure the rbac-policy is invisible to the tenant for which it's
836 # being shared
837 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
838
839
840class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
841 VALID_DSCP_MARK1 = 56
842 VALID_DSCP_MARK2 = 48
843
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000844 required_extensions = ['qos']
845
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000846 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900847 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000848 def resource_setup(cls):
849 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
850
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000851 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000852 def test_rule_create(self):
853 policy = self.create_qos_policy(name='test-policy',
854 description='test policy',
855 shared=False)
856 rule = self.admin_client.create_dscp_marking_rule(
857 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
858
859 # Test 'show rule'
860 retrieved_rule = self.admin_client.show_dscp_marking_rule(
861 policy['id'], rule['id'])
862 retrieved_rule = retrieved_rule['dscp_marking_rule']
863 self.assertEqual(rule['id'], retrieved_rule['id'])
864 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
865
866 # Test 'list rules'
867 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
868 rules = rules['dscp_marking_rules']
869 rules_ids = [r['id'] for r in rules]
870 self.assertIn(rule['id'], rules_ids)
871
872 # Test 'show policy'
873 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
874 policy_rules = retrieved_policy['policy']['rules']
875 self.assertEqual(1, len(policy_rules))
876 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000877 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000878 policy_rules[0]['type'])
879
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000880 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000881 def test_rule_create_fail_for_the_same_type(self):
882 policy = self.create_qos_policy(name='test-policy',
883 description='test policy',
884 shared=False)
885 self.admin_client.create_dscp_marking_rule(
886 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
887
888 self.assertRaises(exceptions.Conflict,
889 self.admin_client.create_dscp_marking_rule,
890 policy_id=policy['id'],
891 dscp_mark=self.VALID_DSCP_MARK2)
892
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000893 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000894 def test_rule_update(self):
895 policy = self.create_qos_policy(name='test-policy',
896 description='test policy',
897 shared=False)
898 rule = self.admin_client.create_dscp_marking_rule(
899 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
900
901 self.admin_client.update_dscp_marking_rule(
902 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
903
904 retrieved_policy = self.admin_client.show_dscp_marking_rule(
905 policy['id'], rule['id'])
906 retrieved_policy = retrieved_policy['dscp_marking_rule']
907 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
908
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000909 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000910 def test_rule_delete(self):
911 policy = self.create_qos_policy(name='test-policy',
912 description='test policy',
913 shared=False)
914 rule = self.admin_client.create_dscp_marking_rule(
915 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
916
917 retrieved_policy = self.admin_client.show_dscp_marking_rule(
918 policy['id'], rule['id'])
919 retrieved_policy = retrieved_policy['dscp_marking_rule']
920 self.assertEqual(rule['id'], retrieved_policy['id'])
921
922 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
923 self.assertRaises(exceptions.NotFound,
924 self.admin_client.show_dscp_marking_rule,
925 policy['id'], rule['id'])
926
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000927 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000928 def test_rule_create_rule_nonexistent_policy(self):
929 self.assertRaises(
930 exceptions.NotFound,
931 self.admin_client.create_dscp_marking_rule,
932 'policy', self.VALID_DSCP_MARK1)
933
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000934 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000935 def test_rule_create_forbidden_for_regular_tenants(self):
936 self.assertRaises(
937 exceptions.Forbidden,
938 self.client.create_dscp_marking_rule,
939 'policy', self.VALID_DSCP_MARK1)
940
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000941 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000942 def test_invalid_rule_create(self):
943 policy = self.create_qos_policy(name='test-policy',
944 description='test policy',
945 shared=False)
946 self.assertRaises(
947 exceptions.BadRequest,
948 self.admin_client.create_dscp_marking_rule,
949 policy['id'], 58)
950
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000951 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000952 def test_get_rules_by_policy(self):
953 policy1 = self.create_qos_policy(name='test-policy1',
954 description='test policy1',
955 shared=False)
956 rule1 = self.admin_client.create_dscp_marking_rule(
957 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
958
959 policy2 = self.create_qos_policy(name='test-policy2',
960 description='test policy2',
961 shared=False)
962 rule2 = self.admin_client.create_dscp_marking_rule(
963 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
964
965 # Test 'list rules'
966 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
967 rules = rules['dscp_marking_rules']
968 rules_ids = [r['id'] for r in rules]
969 self.assertIn(rule1['id'], rules_ids)
970 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +0200971
972
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100973class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
974 DIRECTION_EGRESS = "egress"
975 DIRECTION_INGRESS = "ingress"
976 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
977 RULES_NAME = RULE_NAME + "s"
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000978 required_extensions = ['qos']
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100979
980 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900981 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100982 def resource_setup(cls):
983 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
984
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000985 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100986 def test_rule_create(self):
987 policy = self.create_qos_policy(name='test-policy',
988 description='test policy',
989 shared=False)
990 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000991 policy_id=policy['id'],
992 direction=self.DIRECTION_EGRESS,
993 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100994
995 # Test 'show rule'
996 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
997 policy['id'], rule['id'])
998 retrieved_rule = retrieved_rule[self.RULE_NAME]
999 self.assertEqual(rule['id'], retrieved_rule['id'])
1000 self.assertEqual(1138, retrieved_rule['min_kbps'])
1001 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1002
1003 # Test 'list rules'
1004 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
1005 rules = rules[self.RULES_NAME]
1006 rules_ids = [r['id'] for r in rules]
1007 self.assertIn(rule['id'], rules_ids)
1008
1009 # Test 'show policy'
1010 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1011 policy_rules = retrieved_policy['policy']['rules']
1012 self.assertEqual(1, len(policy_rules))
1013 self.assertEqual(rule['id'], policy_rules[0]['id'])
1014 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1015 policy_rules[0]['type'])
1016
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001017 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001018 def test_rule_create_fail_for_missing_min_kbps(self):
1019 policy = self.create_qos_policy(name='test-policy',
1020 description='test policy',
1021 shared=False)
1022 self.assertRaises(exceptions.BadRequest,
1023 self.admin_client.create_minimum_bandwidth_rule,
1024 policy_id=policy['id'],
1025 direction=self.DIRECTION_EGRESS)
1026
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001027 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001028 def test_rule_create_fail_for_the_same_type(self):
1029 policy = self.create_qos_policy(name='test-policy',
1030 description='test policy',
1031 shared=False)
1032 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001033 policy_id=policy['id'],
1034 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001035
1036 self.assertRaises(exceptions.Conflict,
1037 self.admin_client.create_minimum_bandwidth_rule,
1038 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001039 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001040
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001041 @decorators.idempotent_id('d6fce764-e511-4fa6-9f86-f4b41cf142cf')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001042 def test_rule_create_fail_for_direction_ingress(self):
1043 policy = self.create_qos_policy(name='test-policy',
1044 description='test policy',
1045 shared=False)
1046 self.assertRaises(exceptions.BadRequest,
1047 self.admin_client.create_minimum_bandwidth_rule,
1048 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001049 direction=self.DIRECTION_INGRESS,
1050 min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001051
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001052 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001053 def test_rule_update(self):
1054 policy = self.create_qos_policy(name='test-policy',
1055 description='test policy',
1056 shared=False)
1057 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001058 policy_id=policy['id'],
1059 direction=self.DIRECTION_EGRESS,
1060 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001061
1062 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
1063 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
1064
1065 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1066 policy['id'], rule['id'])
1067 retrieved_policy = retrieved_policy[self.RULE_NAME]
1068 self.assertEqual(350, retrieved_policy['min_kbps'])
1069 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1070
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001071 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001072 def test_rule_delete(self):
1073 policy = self.create_qos_policy(name='test-policy',
1074 description='test policy',
1075 shared=False)
1076 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001077 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001078
1079 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1080 policy['id'], rule['id'])
1081 retrieved_policy = retrieved_policy[self.RULE_NAME]
1082 self.assertEqual(rule['id'], retrieved_policy['id'])
1083
1084 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1085 rule['id'])
1086 self.assertRaises(exceptions.NotFound,
1087 self.admin_client.show_minimum_bandwidth_rule,
1088 policy['id'], rule['id'])
1089
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001090 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001091 def test_rule_create_rule_nonexistent_policy(self):
1092 self.assertRaises(
1093 exceptions.NotFound,
1094 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001095 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001096
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001097 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001098 def test_rule_create_forbidden_for_regular_tenants(self):
1099 self.assertRaises(
1100 exceptions.Forbidden,
1101 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001102 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001103
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001104 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001105 def test_get_rules_by_policy(self):
1106 policy1 = self.create_qos_policy(name='test-policy1',
1107 description='test policy1',
1108 shared=False)
1109 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001110 policy_id=policy1['id'],
1111 direction=self.DIRECTION_EGRESS,
1112 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001113
1114 policy2 = self.create_qos_policy(name='test-policy2',
1115 description='test policy2',
1116 shared=False)
1117 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001118 policy_id=policy2['id'],
1119 direction=self.DIRECTION_EGRESS,
1120 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001121
1122 # Test 'list rules'
1123 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1124 rules = rules[self.RULES_NAME]
1125 rules_ids = [r['id'] for r in rules]
1126 self.assertIn(rule1['id'], rules_ids)
1127 self.assertNotIn(rule2['id'], rules_ids)
1128
1129
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001130class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1131 base.BaseAdminNetworkTest):
1132
1133 resource = 'policy'
1134 plural_name = 'policies'
1135
1136 # Use unique description to isolate the tests from other QoS tests
1137 list_kwargs = {'description': 'search-criteria-test'}
1138 list_as_admin = True
1139
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001140 required_extensions = ['qos']
1141
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001142 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001143 def resource_setup(cls):
1144 super(QosSearchCriteriaTest, cls).resource_setup()
1145 for name in cls.resource_names:
1146 cls.create_qos_policy(
1147 name=name, description='search-criteria-test')
1148
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001149 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001150 def test_list_sorts_asc(self):
1151 self._test_list_sorts_asc()
1152
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001153 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001154 def test_list_sorts_desc(self):
1155 self._test_list_sorts_desc()
1156
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001157 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001158 def test_list_pagination(self):
1159 self._test_list_pagination()
1160
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001161 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001162 def test_list_pagination_with_marker(self):
1163 self._test_list_pagination_with_marker()
1164
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001165 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001166 def test_list_pagination_with_href_links(self):
1167 self._test_list_pagination_with_href_links()
1168
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001169 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001170 def test_list_pagination_page_reverse_asc(self):
1171 self._test_list_pagination_page_reverse_asc()
1172
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001173 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001174 def test_list_pagination_page_reverse_desc(self):
1175 self._test_list_pagination_page_reverse_desc()
1176
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001177 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001178 def test_list_pagination_page_reverse_with_href_links(self):
1179 self._test_list_pagination_page_reverse_with_href_links()
1180
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001181 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001182 def test_list_no_pagination_limit_0(self):
1183 self._test_list_no_pagination_limit_0()