blob: 728029786f7eb9b66b8f3d11877bc523e10db9a8 [file] [log] [blame]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001# Copyright 2015 Red Hat, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000016from tempest.lib import decorators
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000017from tempest.lib import exceptions
18from tempest import test
19
Sławek Kapłoński153f3452017-03-24 22:04:53 +000020import testscenarios
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000021import testtools
22
23from neutron.services.qos import qos_consts
24from neutron.tests.tempest.api import base
25
26
Sławek Kapłoński153f3452017-03-24 22:04:53 +000027load_tests = testscenarios.load_tests_apply_scenarios
28
29
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000030class QosTestJSON(base.BaseAdminNetworkTest):
31 @classmethod
32 @test.requires_ext(extension="qos", service="network")
33 def resource_setup(cls):
34 super(QosTestJSON, cls).resource_setup()
35
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000036 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000037 def test_create_policy(self):
38 policy = self.create_qos_policy(name='test-policy',
39 description='test policy desc1',
40 shared=False)
41
42 # Test 'show policy'
43 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
44 retrieved_policy = retrieved_policy['policy']
45 self.assertEqual('test-policy', retrieved_policy['name'])
46 self.assertEqual('test policy desc1', retrieved_policy['description'])
47 self.assertFalse(retrieved_policy['shared'])
48
49 # Test 'list policies'
50 policies = self.admin_client.list_qos_policies()['policies']
51 policies_ids = [p['id'] for p in policies]
52 self.assertIn(policy['id'], policies_ids)
53
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000054 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Henry Gessaufa6c78d2016-10-09 19:56:09 -040055 @test.requires_ext(extension="project-id", service="network")
56 def test_show_policy_has_project_id(self):
57 policy = self.create_qos_policy(name='test-policy', shared=False)
58 body = self.admin_client.show_qos_policy(policy['id'])
59 show_policy = body['policy']
60 self.assertIn('project_id', show_policy)
61 self.assertIn('tenant_id', show_policy)
62 self.assertEqual(self.admin_client.tenant_id,
63 show_policy['project_id'])
64 self.assertEqual(self.admin_client.tenant_id,
65 show_policy['tenant_id'])
66
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000067 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000068 def test_list_policy_filter_by_name(self):
69 self.create_qos_policy(name='test', description='test policy',
70 shared=False)
71 self.create_qos_policy(name='test2', description='test policy',
72 shared=False)
73
74 policies = (self.admin_client.
75 list_qos_policies(name='test')['policies'])
76 self.assertEqual(1, len(policies))
77
78 retrieved_policy = policies[0]
79 self.assertEqual('test', retrieved_policy['name'])
80
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000081 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000082 def test_policy_update(self):
83 policy = self.create_qos_policy(name='test-policy',
84 description='',
85 shared=False)
86 self.admin_client.update_qos_policy(policy['id'],
87 description='test policy desc2',
88 shared=True)
89
90 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
91 retrieved_policy = retrieved_policy['policy']
92 self.assertEqual('test policy desc2', retrieved_policy['description'])
93 self.assertTrue(retrieved_policy['shared'])
94 self.assertEqual([], retrieved_policy['rules'])
95
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000096 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +000097 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
98 policy = self.create_qos_policy(name='test-policy',
99 description='',
100 shared=False,
101 tenant_id=self.client.tenant_id)
102 self.assertRaises(
103 exceptions.Forbidden,
104 self.client.update_qos_policy,
105 policy['id'], description='test policy')
106
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000107 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000108 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
109 policy = self.create_qos_policy(name='test-policy',
110 description='',
111 shared=False,
112 tenant_id=self.admin_client.tenant_id)
113 self.assertRaises(
114 exceptions.NotFound,
115 self.client.update_qos_policy,
116 policy['id'], description='test policy')
117
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000118 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000119 def test_shared_policy_update(self):
120 policy = self.create_qos_policy(name='test-policy',
121 description='',
122 shared=True)
123
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
159 # TODO(QoS): since in gate we run both ovs and linuxbridge ml2 drivers,
160 # and since Linux Bridge ml2 driver does not have QoS support yet, ml2
161 # plugin reports no rule types are supported. Once linuxbridge will
162 # receive support for QoS, the list of expected rule types will change.
163 #
164 # In theory, we could make the test conditional on which ml2 drivers
165 # are enabled in gate (or more specifically, on which supported qos
166 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200167 # available through tempest.lib framework
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000168 expected_rule_types = []
169 expected_rule_details = ['type']
170
171 rule_types = client.list_qos_rule_types()
172 actual_list_rule_types = rule_types['rule_types']
173 actual_rule_types = [rule['type'] for rule in actual_list_rule_types]
174
175 # Verify that only required fields present in rule details
176 for rule in actual_list_rule_types:
177 self.assertEqual(tuple(rule.keys()), tuple(expected_rule_details))
178
179 # Verify if expected rules are present in the actual rules list
180 for rule in expected_rule_types:
181 self.assertIn(rule, actual_rule_types)
182
183 def _disassociate_network(self, client, network_id):
Hong Hui Xiao25028302016-12-13 16:29:08 +0800184 updated_network = client.update_network(network_id,
185 qos_policy_id=None)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000186 self.assertIsNone(updated_network['network']['qos_policy_id'])
187
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000188 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000189 def test_policy_association_with_admin_network(self):
190 policy = self.create_qos_policy(name='test-policy',
191 description='test policy',
192 shared=False)
193 network = self.create_shared_network('test network',
194 qos_policy_id=policy['id'])
195
196 retrieved_network = self.admin_client.show_network(network['id'])
197 self.assertEqual(
198 policy['id'], retrieved_network['network']['qos_policy_id'])
199
200 self._disassociate_network(self.admin_client, network['id'])
201
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000202 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000203 def test_policy_association_with_tenant_network(self):
204 policy = self.create_qos_policy(name='test-policy',
205 description='test policy',
206 shared=True)
207 network = self.create_network('test network',
208 qos_policy_id=policy['id'])
209
210 retrieved_network = self.admin_client.show_network(network['id'])
211 self.assertEqual(
212 policy['id'], retrieved_network['network']['qos_policy_id'])
213
214 self._disassociate_network(self.client, network['id'])
215
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000216 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000217 def test_policy_association_with_network_nonexistent_policy(self):
218 self.assertRaises(
219 exceptions.NotFound,
220 self.create_network,
221 'test network',
222 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
223
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000224 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000225 def test_policy_association_with_network_non_shared_policy(self):
226 policy = self.create_qos_policy(name='test-policy',
227 description='test policy',
228 shared=False)
229 self.assertRaises(
230 exceptions.NotFound,
231 self.create_network,
232 'test network', qos_policy_id=policy['id'])
233
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000234 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000235 def test_policy_update_association_with_admin_network(self):
236 policy = self.create_qos_policy(name='test-policy',
237 description='test policy',
238 shared=False)
239 network = self.create_shared_network('test network')
240 retrieved_network = self.admin_client.show_network(network['id'])
241 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
242
243 self.admin_client.update_network(network['id'],
244 qos_policy_id=policy['id'])
245 retrieved_network = self.admin_client.show_network(network['id'])
246 self.assertEqual(
247 policy['id'], retrieved_network['network']['qos_policy_id'])
248
249 self._disassociate_network(self.admin_client, network['id'])
250
251 def _disassociate_port(self, port_id):
252 self.client.update_port(port_id, qos_policy_id=None)
253 updated_port = self.admin_client.show_port(port_id)
254 self.assertIsNone(updated_port['port']['qos_policy_id'])
255
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000256 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000257 def test_policy_association_with_port_shared_policy(self):
258 policy = self.create_qos_policy(name='test-policy',
259 description='test policy',
260 shared=True)
261 network = self.create_shared_network('test network')
262 port = self.create_port(network, qos_policy_id=policy['id'])
263
264 retrieved_port = self.admin_client.show_port(port['id'])
265 self.assertEqual(
266 policy['id'], retrieved_port['port']['qos_policy_id'])
267
268 self._disassociate_port(port['id'])
269
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000270 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000271 def test_policy_association_with_port_nonexistent_policy(self):
272 network = self.create_shared_network('test network')
273 self.assertRaises(
274 exceptions.NotFound,
275 self.create_port,
276 network,
277 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
278
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000279 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000280 def test_policy_association_with_port_non_shared_policy(self):
281 policy = self.create_qos_policy(name='test-policy',
282 description='test policy',
283 shared=False)
284 network = self.create_shared_network('test network')
285 self.assertRaises(
286 exceptions.NotFound,
287 self.create_port,
288 network, qos_policy_id=policy['id'])
289
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000290 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000291 def test_policy_update_association_with_port_shared_policy(self):
292 policy = self.create_qos_policy(name='test-policy',
293 description='test policy',
294 shared=True)
295 network = self.create_shared_network('test network')
296 port = self.create_port(network)
297 retrieved_port = self.admin_client.show_port(port['id'])
298 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
299
300 self.client.update_port(port['id'], qos_policy_id=policy['id'])
301 retrieved_port = self.admin_client.show_port(port['id'])
302 self.assertEqual(
303 policy['id'], retrieved_port['port']['qos_policy_id'])
304
305 self._disassociate_port(port['id'])
306
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000307 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000308 def test_delete_not_allowed_if_policy_in_use_by_network(self):
309 policy = self.create_qos_policy(name='test-policy',
310 description='test policy',
311 shared=True)
312 network = self.create_shared_network(
313 'test network', qos_policy_id=policy['id'])
314 self.assertRaises(
315 exceptions.Conflict,
316 self.admin_client.delete_qos_policy, policy['id'])
317
318 self._disassociate_network(self.admin_client, network['id'])
319 self.admin_client.delete_qos_policy(policy['id'])
320
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000321 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000322 def test_delete_not_allowed_if_policy_in_use_by_port(self):
323 policy = self.create_qos_policy(name='test-policy',
324 description='test policy',
325 shared=True)
326 network = self.create_shared_network('test network')
327 port = self.create_port(network, qos_policy_id=policy['id'])
328 self.assertRaises(
329 exceptions.Conflict,
330 self.admin_client.delete_qos_policy, policy['id'])
331
332 self._disassociate_port(port['id'])
333 self.admin_client.delete_qos_policy(policy['id'])
334
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000335 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000336 def test_qos_policy_delete_with_rules(self):
337 policy = self.create_qos_policy(name='test-policy',
338 description='test policy',
339 shared=False)
340 self.admin_client.create_bandwidth_limit_rule(
341 policy['id'], 200, 1337)['bandwidth_limit_rule']
342
343 self.admin_client.delete_qos_policy(policy['id'])
344
345 with testtools.ExpectedException(exceptions.NotFound):
346 self.admin_client.show_qos_policy(policy['id'])
347
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000348 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000349 def test_get_policy_that_is_shared(self):
350 policy = self.create_qos_policy(
351 name='test-policy-shared',
352 description='shared policy',
353 shared=True,
354 tenant_id=self.admin_client.tenant_id)
355 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
356 self.assertEqual(obtained_policy, policy)
357
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000358 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100359 def test_policy_create_forbidden_for_regular_tenants(self):
360 self.assertRaises(
361 exceptions.Forbidden,
362 self.client.create_qos_policy,
363 'test-policy', 'test policy', False)
364
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000365
366class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000367
368 direction = None
369
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000370 @classmethod
371 @test.requires_ext(extension="qos", service="network")
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900372 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000373 def resource_setup(cls):
374 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
375
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000376 @property
377 def opposite_direction(self):
378 if self.direction == "ingress":
379 return "egress"
380 elif self.direction == "egress":
381 return "ingress"
382 else:
383 return None
384
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000385 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000386 def test_rule_create(self):
387 policy = self.create_qos_policy(name='test-policy',
388 description='test policy',
389 shared=False)
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000390 rule = self.create_qos_bandwidth_limit_rule(
391 policy_id=policy['id'],
392 max_kbps=200,
393 max_burst_kbps=1337,
394 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000395
396 # Test 'show rule'
397 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
398 policy['id'], rule['id'])
399 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
400 self.assertEqual(rule['id'], retrieved_rule['id'])
401 self.assertEqual(200, retrieved_rule['max_kbps'])
402 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000403 if self.direction:
404 self.assertEqual(self.direction, retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000405
406 # Test 'list rules'
407 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
408 rules = rules['bandwidth_limit_rules']
409 rules_ids = [r['id'] for r in rules]
410 self.assertIn(rule['id'], rules_ids)
411
412 # Test 'show policy'
413 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
414 policy_rules = retrieved_policy['policy']['rules']
415 self.assertEqual(1, len(policy_rules))
416 self.assertEqual(rule['id'], policy_rules[0]['id'])
417 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
418 policy_rules[0]['type'])
419
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000420 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000421 def test_rule_create_fail_for_the_same_type(self):
422 policy = self.create_qos_policy(name='test-policy',
423 description='test policy',
424 shared=False)
425 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
426 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000427 max_burst_kbps=1337,
428 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000429
430 self.assertRaises(exceptions.Conflict,
431 self.create_qos_bandwidth_limit_rule,
432 policy_id=policy['id'],
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000433 max_kbps=201, max_burst_kbps=1338,
434 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000435
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000436 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000437 def test_rule_update(self):
438 policy = self.create_qos_policy(name='test-policy',
439 description='test policy',
440 shared=False)
441 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
442 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000443 max_burst_kbps=1,
444 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000445
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000446 self.admin_client.update_bandwidth_limit_rule(
447 policy['id'],
448 rule['id'],
449 max_kbps=200,
450 max_burst_kbps=1337,
451 direction=self.opposite_direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000452
453 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
454 policy['id'], rule['id'])
455 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
456 self.assertEqual(200, retrieved_policy['max_kbps'])
457 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000458 if self.opposite_direction:
459 self.assertEqual(self.opposite_direction,
460 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000461
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000462 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000463 def test_rule_delete(self):
464 policy = self.create_qos_policy(name='test-policy',
465 description='test policy',
466 shared=False)
467 rule = self.admin_client.create_bandwidth_limit_rule(
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000468 policy['id'], 200, 1337, self.direction)['bandwidth_limit_rule']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000469
470 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
471 policy['id'], rule['id'])
472 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
473 self.assertEqual(rule['id'], retrieved_policy['id'])
474
475 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
476 self.assertRaises(exceptions.NotFound,
477 self.admin_client.show_bandwidth_limit_rule,
478 policy['id'], rule['id'])
479
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000480 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000481 def test_rule_create_rule_nonexistent_policy(self):
482 self.assertRaises(
483 exceptions.NotFound,
484 self.create_qos_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000485 'policy', 200, 1337, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000486
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000487 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000488 def test_rule_create_forbidden_for_regular_tenants(self):
489 self.assertRaises(
490 exceptions.Forbidden,
491 self.client.create_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000492 'policy', 1, 2, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000493
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000494 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000495 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
496 policy = self.create_qos_policy(name='test-policy',
497 description='test policy',
498 shared=False,
499 tenant_id=self.client.tenant_id)
500 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
501 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000502 max_burst_kbps=1,
503 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000504 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400505 exceptions.Forbidden,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000506 self.client.update_bandwidth_limit_rule,
507 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
508
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000509 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000510 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
511 policy = self.create_qos_policy(name='test-policy',
512 description='test policy',
513 shared=False,
514 tenant_id=self.admin_client.tenant_id)
515 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
516 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000517 max_burst_kbps=1,
518 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000519 self.assertRaises(
520 exceptions.NotFound,
521 self.client.update_bandwidth_limit_rule,
522 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
523
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000524 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000525 def test_get_rules_by_policy(self):
526 policy1 = self.create_qos_policy(name='test-policy1',
527 description='test policy1',
528 shared=False)
529 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
530 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000531 max_burst_kbps=1337,
532 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000533
534 policy2 = self.create_qos_policy(name='test-policy2',
535 description='test policy2',
536 shared=False)
537 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
538 max_kbps=5000,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000539 max_burst_kbps=2523,
540 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000541
542 # Test 'list rules'
543 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
544 rules = rules['bandwidth_limit_rules']
545 rules_ids = [r['id'] for r in rules]
546 self.assertIn(rule1['id'], rules_ids)
547 self.assertNotIn(rule2['id'], rules_ids)
548
549
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000550class QosBandwidthLimitRuleWithDirectionTestJSON(
551 QosBandwidthLimitRuleTestJSON):
552
553 scenarios = [
554 ('ingress', {'direction': 'ingress'}),
555 ('egress', {'direction': 'egress'}),
556 ]
557
558 @classmethod
559 @test.requires_ext(extension="qos-bw-limit-direction", service="network")
560 def resource_setup(cls):
561 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
562
563
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000564class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
565
566 force_tenant_isolation = True
567 credentials = ['primary', 'alt', 'admin']
568
569 @classmethod
570 @test.requires_ext(extension="qos", service="network")
571 def resource_setup(cls):
572 super(RbacSharedQosPoliciesTest, cls).resource_setup()
573 cls.client2 = cls.alt_manager.network_client
574
575 def _create_qos_policy(self, tenant_id=None):
576 args = {'name': data_utils.rand_name('test-policy'),
577 'description': 'test policy',
578 'shared': False,
579 'tenant_id': tenant_id}
580 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
581 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
582
583 return qos_policy
584
585 def _make_admin_policy_shared_to_tenant_id(self, tenant_id):
586 policy = self._create_qos_policy()
587 rbac_policy = self.admin_client.create_rbac_policy(
588 object_type='qos_policy',
589 object_id=policy['id'],
590 action='access_as_shared',
591 target_tenant=tenant_id,
592 )['rbac_policy']
593
594 return {'policy': policy, 'rbac_policy': rbac_policy}
595
596 def _create_network(self, qos_policy_id, client, should_cleanup=True):
597 net = client.create_network(
598 name=data_utils.rand_name('test-network'),
599 qos_policy_id=qos_policy_id)['network']
600 if should_cleanup:
601 self.addCleanup(client.delete_network, net['id'])
602
603 return net
604
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000605 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000606 def test_policy_sharing_with_wildcard(self):
607 qos_pol = self.create_qos_policy(
608 name=data_utils.rand_name('test-policy'),
609 description='test-shared-policy', shared=False)
610 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
611
612 # test update shared False -> True
613 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
614 qos_pol['shared'] = True
615 self.client2.show_qos_policy(qos_pol['id'])
616 rbac_pol = {'target_tenant': '*',
617 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000618 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000619 'object_type': 'qos_policy',
620 'object_id': qos_pol['id'],
621 'action': 'access_as_shared'}
622
623 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
624 rbac_policies = [r for r in rbac_policies if r.pop('id')]
625 self.assertIn(rbac_pol, rbac_policies)
626
627 # update shared True -> False should fail because the policy is bound
628 # to a network
629 net = self._create_network(qos_pol['id'], self.admin_client, False)
630 with testtools.ExpectedException(exceptions.Conflict):
631 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
632
633 # delete the network, and update shared True -> False should pass now
634 self.admin_client.delete_network(net['id'])
635 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
636 qos_pol['shared'] = False
637 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
638
639 def _create_net_bound_qos_rbacs(self):
640 res = self._make_admin_policy_shared_to_tenant_id(
641 self.client.tenant_id)
642 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
643
644 # add a wildcard rbac rule - now the policy globally shared
645 rbac_wildcard = self.admin_client.create_rbac_policy(
646 object_type='qos_policy',
647 object_id=qos_policy['id'],
648 action='access_as_shared',
649 target_tenant='*',
650 )['rbac_policy']
651
652 # tenant1 now uses qos policy for net
653 self._create_network(qos_policy['id'], self.client)
654
655 return rbac_for_client_tenant, rbac_wildcard
656
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000657 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000658 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self):
659 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
660 # globally unshare the qos-policy, the specific share should remain
661 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
662 self.client.list_rbac_policies(id=client_rbac['id'])
663
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000664 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000665 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self):
666 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
667 # remove client_rbac policy the wildcard share should remain
668 self.admin_client.delete_rbac_policy(client_rbac['id'])
669 self.client.list_rbac_policies(id=wildcard_rbac['id'])
670
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000671 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000672 def test_policy_sharing_with_wildcard_and_tenant_id(self):
673 res = self._make_admin_policy_shared_to_tenant_id(
674 self.client.tenant_id)
675 qos_policy, rbac = res['policy'], res['rbac_policy']
676 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
677 self.assertTrue(qos_pol['shared'])
678 with testtools.ExpectedException(exceptions.NotFound):
679 self.client2.show_qos_policy(qos_policy['id'])
680
681 # make the qos-policy globally shared
682 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
683 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
684 self.assertTrue(qos_pol['shared'])
685
686 # globally unshare the qos-policy, the specific share should remain
687 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
688 self.client.show_qos_policy(qos_policy['id'])
689 with testtools.ExpectedException(exceptions.NotFound):
690 self.client2.show_qos_policy(qos_policy['id'])
691 self.assertIn(rbac,
692 self.admin_client.list_rbac_policies()['rbac_policies'])
693
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000694 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000695 def test_policy_target_update(self):
696 res = self._make_admin_policy_shared_to_tenant_id(
697 self.client.tenant_id)
698 # change to client2
699 update_res = self.admin_client.update_rbac_policy(
700 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
701 self.assertEqual(self.client2.tenant_id,
702 update_res['rbac_policy']['target_tenant'])
703 # make sure everything else stayed the same
704 res['rbac_policy'].pop('target_tenant')
705 update_res['rbac_policy'].pop('target_tenant')
706 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
707
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000708 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000709 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
710 res = self._make_admin_policy_shared_to_tenant_id(
711 self.client2.tenant_id)
712 qos_policy_id = res['policy']['id']
713 self._create_network(qos_policy_id, self.client2)
714 # a network with shared qos-policy should prevent the deletion of an
715 # rbac-policy required for it to be shared
716 with testtools.ExpectedException(exceptions.Conflict):
717 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
718
719 # a wildcard policy should allow the specific policy to be deleted
720 # since it allows the remaining port
721 wild = self.admin_client.create_rbac_policy(
722 object_type='qos_policy', object_id=res['policy']['id'],
723 action='access_as_shared', target_tenant='*')['rbac_policy']
724 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
725
726 # now that wildcard is the only remaining, it should be subjected to
727 # the same restriction
728 with testtools.ExpectedException(exceptions.Conflict):
729 self.admin_client.delete_rbac_policy(wild['id'])
730
731 # we can't update the policy to a different tenant
732 with testtools.ExpectedException(exceptions.Conflict):
733 self.admin_client.update_rbac_policy(
734 wild['id'], target_tenant=self.client2.tenant_id)
735
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000736 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000737 def test_regular_client_shares_to_another_regular_client(self):
738 # owned by self.admin_client
739 policy = self._create_qos_policy()
740 with testtools.ExpectedException(exceptions.NotFound):
741 self.client.show_qos_policy(policy['id'])
742 rbac_policy = self.admin_client.create_rbac_policy(
743 object_type='qos_policy', object_id=policy['id'],
744 action='access_as_shared',
745 target_tenant=self.client.tenant_id)['rbac_policy']
746 self.client.show_qos_policy(policy['id'])
747
748 self.assertIn(rbac_policy,
749 self.admin_client.list_rbac_policies()['rbac_policies'])
750 # ensure that 'client2' can't see the rbac-policy sharing the
751 # qos-policy to it because the rbac-policy belongs to 'client'
752 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
753 self.client2.list_rbac_policies()['rbac_policies']])
754
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000755 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000756 def test_filter_fields(self):
757 policy = self._create_qos_policy()
758 self.admin_client.create_rbac_policy(
759 object_type='qos_policy', object_id=policy['id'],
760 action='access_as_shared', target_tenant=self.client2.tenant_id)
761 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
762 ('tenant_id', 'target_tenant'))
763 for fields in field_args:
764 res = self.admin_client.list_rbac_policies(fields=fields)
765 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
766
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000767 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000768 def test_rbac_policy_show(self):
769 res = self._make_admin_policy_shared_to_tenant_id(
770 self.client.tenant_id)
771 p1 = res['rbac_policy']
772 p2 = self.admin_client.create_rbac_policy(
773 object_type='qos_policy', object_id=res['policy']['id'],
774 action='access_as_shared',
775 target_tenant='*')['rbac_policy']
776
777 self.assertEqual(
778 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
779 self.assertEqual(
780 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
781
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000782 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000783 def test_filter_rbac_policies(self):
784 policy = self._create_qos_policy()
785 rbac_pol1 = self.admin_client.create_rbac_policy(
786 object_type='qos_policy', object_id=policy['id'],
787 action='access_as_shared',
788 target_tenant=self.client2.tenant_id)['rbac_policy']
789 rbac_pol2 = self.admin_client.create_rbac_policy(
790 object_type='qos_policy', object_id=policy['id'],
791 action='access_as_shared',
792 target_tenant=self.admin_client.tenant_id)['rbac_policy']
793 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
794 'rbac_policies']
795 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
796 'rbac_policies']
797 self.assertEqual(1, len(res1))
798 self.assertEqual(1, len(res2))
799 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
800 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
801
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000802 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000803 def test_regular_client_blocked_from_sharing_anothers_policy(self):
804 qos_policy = self._make_admin_policy_shared_to_tenant_id(
805 self.client.tenant_id)['policy']
806 with testtools.ExpectedException(exceptions.BadRequest):
807 self.client.create_rbac_policy(
808 object_type='qos_policy', object_id=qos_policy['id'],
809 action='access_as_shared',
810 target_tenant=self.client2.tenant_id)
811
812 # make sure the rbac-policy is invisible to the tenant for which it's
813 # being shared
814 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
815
816
817class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
818 VALID_DSCP_MARK1 = 56
819 VALID_DSCP_MARK2 = 48
820
821 @classmethod
822 @test.requires_ext(extension="qos", service="network")
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900823 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000824 def resource_setup(cls):
825 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
826
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000827 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000828 def test_rule_create(self):
829 policy = self.create_qos_policy(name='test-policy',
830 description='test policy',
831 shared=False)
832 rule = self.admin_client.create_dscp_marking_rule(
833 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
834
835 # Test 'show rule'
836 retrieved_rule = self.admin_client.show_dscp_marking_rule(
837 policy['id'], rule['id'])
838 retrieved_rule = retrieved_rule['dscp_marking_rule']
839 self.assertEqual(rule['id'], retrieved_rule['id'])
840 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
841
842 # Test 'list rules'
843 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
844 rules = rules['dscp_marking_rules']
845 rules_ids = [r['id'] for r in rules]
846 self.assertIn(rule['id'], rules_ids)
847
848 # Test 'show policy'
849 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
850 policy_rules = retrieved_policy['policy']['rules']
851 self.assertEqual(1, len(policy_rules))
852 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000853 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000854 policy_rules[0]['type'])
855
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000856 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000857 def test_rule_create_fail_for_the_same_type(self):
858 policy = self.create_qos_policy(name='test-policy',
859 description='test policy',
860 shared=False)
861 self.admin_client.create_dscp_marking_rule(
862 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
863
864 self.assertRaises(exceptions.Conflict,
865 self.admin_client.create_dscp_marking_rule,
866 policy_id=policy['id'],
867 dscp_mark=self.VALID_DSCP_MARK2)
868
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000869 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000870 def test_rule_update(self):
871 policy = self.create_qos_policy(name='test-policy',
872 description='test policy',
873 shared=False)
874 rule = self.admin_client.create_dscp_marking_rule(
875 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
876
877 self.admin_client.update_dscp_marking_rule(
878 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
879
880 retrieved_policy = self.admin_client.show_dscp_marking_rule(
881 policy['id'], rule['id'])
882 retrieved_policy = retrieved_policy['dscp_marking_rule']
883 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
884
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000885 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000886 def test_rule_delete(self):
887 policy = self.create_qos_policy(name='test-policy',
888 description='test policy',
889 shared=False)
890 rule = self.admin_client.create_dscp_marking_rule(
891 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
892
893 retrieved_policy = self.admin_client.show_dscp_marking_rule(
894 policy['id'], rule['id'])
895 retrieved_policy = retrieved_policy['dscp_marking_rule']
896 self.assertEqual(rule['id'], retrieved_policy['id'])
897
898 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
899 self.assertRaises(exceptions.NotFound,
900 self.admin_client.show_dscp_marking_rule,
901 policy['id'], rule['id'])
902
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000903 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000904 def test_rule_create_rule_nonexistent_policy(self):
905 self.assertRaises(
906 exceptions.NotFound,
907 self.admin_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('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000911 def test_rule_create_forbidden_for_regular_tenants(self):
912 self.assertRaises(
913 exceptions.Forbidden,
914 self.client.create_dscp_marking_rule,
915 'policy', self.VALID_DSCP_MARK1)
916
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000917 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000918 def test_invalid_rule_create(self):
919 policy = self.create_qos_policy(name='test-policy',
920 description='test policy',
921 shared=False)
922 self.assertRaises(
923 exceptions.BadRequest,
924 self.admin_client.create_dscp_marking_rule,
925 policy['id'], 58)
926
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000927 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000928 def test_get_rules_by_policy(self):
929 policy1 = self.create_qos_policy(name='test-policy1',
930 description='test policy1',
931 shared=False)
932 rule1 = self.admin_client.create_dscp_marking_rule(
933 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
934
935 policy2 = self.create_qos_policy(name='test-policy2',
936 description='test policy2',
937 shared=False)
938 rule2 = self.admin_client.create_dscp_marking_rule(
939 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
940
941 # Test 'list rules'
942 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
943 rules = rules['dscp_marking_rules']
944 rules_ids = [r['id'] for r in rules]
945 self.assertIn(rule1['id'], rules_ids)
946 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +0200947
948
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100949class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
950 DIRECTION_EGRESS = "egress"
951 DIRECTION_INGRESS = "ingress"
952 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
953 RULES_NAME = RULE_NAME + "s"
954
955 @classmethod
956 @test.requires_ext(extension="qos", service="network")
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900957 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100958 def resource_setup(cls):
959 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
960
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000961 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100962 def test_rule_create(self):
963 policy = self.create_qos_policy(name='test-policy',
964 description='test policy',
965 shared=False)
966 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000967 policy_id=policy['id'],
968 direction=self.DIRECTION_EGRESS,
969 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100970
971 # Test 'show rule'
972 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
973 policy['id'], rule['id'])
974 retrieved_rule = retrieved_rule[self.RULE_NAME]
975 self.assertEqual(rule['id'], retrieved_rule['id'])
976 self.assertEqual(1138, retrieved_rule['min_kbps'])
977 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
978
979 # Test 'list rules'
980 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
981 rules = rules[self.RULES_NAME]
982 rules_ids = [r['id'] for r in rules]
983 self.assertIn(rule['id'], rules_ids)
984
985 # Test 'show policy'
986 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
987 policy_rules = retrieved_policy['policy']['rules']
988 self.assertEqual(1, len(policy_rules))
989 self.assertEqual(rule['id'], policy_rules[0]['id'])
990 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
991 policy_rules[0]['type'])
992
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000993 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +0000994 def test_rule_create_fail_for_missing_min_kbps(self):
995 policy = self.create_qos_policy(name='test-policy',
996 description='test policy',
997 shared=False)
998 self.assertRaises(exceptions.BadRequest,
999 self.admin_client.create_minimum_bandwidth_rule,
1000 policy_id=policy['id'],
1001 direction=self.DIRECTION_EGRESS)
1002
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001003 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001004 def test_rule_create_fail_for_the_same_type(self):
1005 policy = self.create_qos_policy(name='test-policy',
1006 description='test policy',
1007 shared=False)
1008 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001009 policy_id=policy['id'],
1010 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001011
1012 self.assertRaises(exceptions.Conflict,
1013 self.admin_client.create_minimum_bandwidth_rule,
1014 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001015 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001016
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001017 @decorators.idempotent_id('d6fce764-e511-4fa6-9f86-f4b41cf142cf')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001018 def test_rule_create_fail_for_direction_ingress(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'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001025 direction=self.DIRECTION_INGRESS,
1026 min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001027
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001028 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001029 def test_rule_update(self):
1030 policy = self.create_qos_policy(name='test-policy',
1031 description='test policy',
1032 shared=False)
1033 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001034 policy_id=policy['id'],
1035 direction=self.DIRECTION_EGRESS,
1036 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001037
1038 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
1039 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
1040
1041 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1042 policy['id'], rule['id'])
1043 retrieved_policy = retrieved_policy[self.RULE_NAME]
1044 self.assertEqual(350, retrieved_policy['min_kbps'])
1045 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1046
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001047 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001048 def test_rule_delete(self):
1049 policy = self.create_qos_policy(name='test-policy',
1050 description='test policy',
1051 shared=False)
1052 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001053 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001054
1055 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1056 policy['id'], rule['id'])
1057 retrieved_policy = retrieved_policy[self.RULE_NAME]
1058 self.assertEqual(rule['id'], retrieved_policy['id'])
1059
1060 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1061 rule['id'])
1062 self.assertRaises(exceptions.NotFound,
1063 self.admin_client.show_minimum_bandwidth_rule,
1064 policy['id'], rule['id'])
1065
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001066 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001067 def test_rule_create_rule_nonexistent_policy(self):
1068 self.assertRaises(
1069 exceptions.NotFound,
1070 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001071 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001072
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001073 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001074 def test_rule_create_forbidden_for_regular_tenants(self):
1075 self.assertRaises(
1076 exceptions.Forbidden,
1077 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001078 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001079
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001080 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001081 def test_get_rules_by_policy(self):
1082 policy1 = self.create_qos_policy(name='test-policy1',
1083 description='test policy1',
1084 shared=False)
1085 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001086 policy_id=policy1['id'],
1087 direction=self.DIRECTION_EGRESS,
1088 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001089
1090 policy2 = self.create_qos_policy(name='test-policy2',
1091 description='test policy2',
1092 shared=False)
1093 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001094 policy_id=policy2['id'],
1095 direction=self.DIRECTION_EGRESS,
1096 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001097
1098 # Test 'list rules'
1099 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1100 rules = rules[self.RULES_NAME]
1101 rules_ids = [r['id'] for r in rules]
1102 self.assertIn(rule1['id'], rules_ids)
1103 self.assertNotIn(rule2['id'], rules_ids)
1104
1105
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001106class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1107 base.BaseAdminNetworkTest):
1108
1109 resource = 'policy'
1110 plural_name = 'policies'
1111
1112 # Use unique description to isolate the tests from other QoS tests
1113 list_kwargs = {'description': 'search-criteria-test'}
1114 list_as_admin = True
1115
1116 @classmethod
1117 @test.requires_ext(extension="qos", service="network")
1118 def resource_setup(cls):
1119 super(QosSearchCriteriaTest, cls).resource_setup()
1120 for name in cls.resource_names:
1121 cls.create_qos_policy(
1122 name=name, description='search-criteria-test')
1123
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001124 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001125 def test_list_sorts_asc(self):
1126 self._test_list_sorts_asc()
1127
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001128 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001129 def test_list_sorts_desc(self):
1130 self._test_list_sorts_desc()
1131
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001132 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001133 def test_list_pagination(self):
1134 self._test_list_pagination()
1135
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001136 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001137 def test_list_pagination_with_marker(self):
1138 self._test_list_pagination_with_marker()
1139
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001140 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001141 def test_list_pagination_with_href_links(self):
1142 self._test_list_pagination_with_href_links()
1143
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001144 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001145 def test_list_pagination_page_reverse_asc(self):
1146 self._test_list_pagination_page_reverse_asc()
1147
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001148 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001149 def test_list_pagination_page_reverse_desc(self):
1150 self._test_list_pagination_page_reverse_desc()
1151
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001152 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001153 def test_list_pagination_page_reverse_with_href_links(self):
1154 self._test_list_pagination_page_reverse_with_href_links()
1155
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001156 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001157 def test_list_no_pagination_limit_0(self):
1158 self._test_list_no_pagination_limit_0()