blob: b54cc660426f984ae3e7557c3c303b2c0742f12c [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
Chandan Kumarc125fd12017-11-15 19:41:01 +053015from neutron_lib.api.definitions import qos as qos_apidef
nfridman23b44ad2019-09-05 09:46:50 -040016from neutron_lib import constants as n_constants
Chandan Kumarc125fd12017-11-15 19:41:01 +053017from neutron_lib.services.qos import constants as qos_consts
18from tempest.common import utils
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000019from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000020from tempest.lib import decorators
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000021from tempest.lib import exceptions
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000022
Sławek Kapłoński153f3452017-03-24 22:04:53 +000023import testscenarios
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000024import testtools
25
Chandan Kumar667d3d32017-09-22 12:24:06 +053026from neutron_tempest_plugin.api import base
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000027
28
Sławek Kapłoński153f3452017-03-24 22:04:53 +000029load_tests = testscenarios.load_tests_apply_scenarios
30
31
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000032class QosTestJSON(base.BaseAdminNetworkTest):
Jakub Libosvar1982aa12017-05-30 11:15:33 +000033
Chandan Kumarc125fd12017-11-15 19:41:01 +053034 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000035
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +000036 @staticmethod
37 def _get_driver_details(rule_type_details, driver_name):
38 for driver in rule_type_details['drivers']:
39 if driver['name'] == driver_name:
40 return driver
41
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000042 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000043 def test_create_policy(self):
44 policy = self.create_qos_policy(name='test-policy',
45 description='test policy desc1',
46 shared=False)
47
48 # Test 'show policy'
49 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
50 retrieved_policy = retrieved_policy['policy']
51 self.assertEqual('test-policy', retrieved_policy['name'])
52 self.assertEqual('test policy desc1', retrieved_policy['description'])
53 self.assertFalse(retrieved_policy['shared'])
54
55 # Test 'list policies'
56 policies = self.admin_client.list_qos_policies()['policies']
57 policies_ids = [p['id'] for p in policies]
58 self.assertIn(policy['id'], policies_ids)
59
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000060 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Chandan Kumarc125fd12017-11-15 19:41:01 +053061 @utils.requires_ext(extension="project-id", service="network")
Henry Gessaufa6c78d2016-10-09 19:56:09 -040062 def test_show_policy_has_project_id(self):
63 policy = self.create_qos_policy(name='test-policy', shared=False)
64 body = self.admin_client.show_qos_policy(policy['id'])
65 show_policy = body['policy']
66 self.assertIn('project_id', show_policy)
67 self.assertIn('tenant_id', show_policy)
68 self.assertEqual(self.admin_client.tenant_id,
69 show_policy['project_id'])
70 self.assertEqual(self.admin_client.tenant_id,
71 show_policy['tenant_id'])
72
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000073 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000074 def test_list_policy_filter_by_name(self):
75 self.create_qos_policy(name='test', description='test policy',
76 shared=False)
77 self.create_qos_policy(name='test2', description='test policy',
78 shared=False)
79
80 policies = (self.admin_client.
81 list_qos_policies(name='test')['policies'])
82 self.assertEqual(1, len(policies))
83
84 retrieved_policy = policies[0]
85 self.assertEqual('test', retrieved_policy['name'])
86
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000087 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000088 def test_policy_update(self):
89 policy = self.create_qos_policy(name='test-policy',
90 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +000091 shared=False,
92 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000093 self.admin_client.update_qos_policy(policy['id'],
94 description='test policy desc2',
95 shared=True)
96
97 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
98 retrieved_policy = retrieved_policy['policy']
99 self.assertEqual('test policy desc2', retrieved_policy['description'])
100 self.assertTrue(retrieved_policy['shared'])
101 self.assertEqual([], retrieved_policy['rules'])
102
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000103 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000104 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
105 policy = self.create_qos_policy(name='test-policy',
106 description='',
107 shared=False,
108 tenant_id=self.client.tenant_id)
109 self.assertRaises(
110 exceptions.Forbidden,
111 self.client.update_qos_policy,
112 policy['id'], description='test policy')
113
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000114 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000115 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
116 policy = self.create_qos_policy(name='test-policy',
117 description='',
118 shared=False,
119 tenant_id=self.admin_client.tenant_id)
120 self.assertRaises(
121 exceptions.NotFound,
122 self.client.update_qos_policy,
123 policy['id'], description='test policy')
124
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000125 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000126 def test_shared_policy_update(self):
127 policy = self.create_qos_policy(name='test-policy',
128 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000129 shared=True,
130 tenant_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000131
132 self.admin_client.update_qos_policy(policy['id'],
133 description='test policy desc2')
134 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
135 retrieved_policy = retrieved_policy['policy']
136 self.assertTrue(retrieved_policy['shared'])
137
138 self.admin_client.update_qos_policy(policy['id'],
139 shared=False)
140 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
141 retrieved_policy = retrieved_policy['policy']
142 self.assertFalse(retrieved_policy['shared'])
143
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000144 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000145 def test_delete_policy(self):
146 policy = self.admin_client.create_qos_policy(
147 'test-policy', 'desc', True)['policy']
148
149 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
150 retrieved_policy = retrieved_policy['policy']
151 self.assertEqual('test-policy', retrieved_policy['name'])
152
153 self.admin_client.delete_qos_policy(policy['id'])
154 self.assertRaises(exceptions.NotFound,
155 self.admin_client.show_qos_policy, policy['id'])
156
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000157 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000158 def test_list_admin_rule_types(self):
159 self._test_list_rule_types(self.admin_client)
160
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000161 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000162 def test_list_regular_rule_types(self):
163 self._test_list_rule_types(self.client)
164
165 def _test_list_rule_types(self, client):
166 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000167 # Since returned rule types depends on loaded backend drivers this test
168 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000169 #
170 # In theory, we could make the test conditional on which ml2 drivers
171 # are enabled in gate (or more specifically, on which supported qos
172 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200173 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000174 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000175
176 rule_types = client.list_qos_rule_types()
177 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000178
179 # Verify that only required fields present in rule details
180 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000181 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000182
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000183 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
184 def test_show_rule_type_details_as_user(self):
185 self.assertRaises(
186 exceptions.Forbidden,
187 self.client.show_qos_rule_type,
188 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
189
190 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
191 def test_show_rule_type_details_as_admin(self):
192 # Since returned rule types depend on loaded backend drivers this test
193 # is checking only if returned keys are same as expected keys
194
195 # In theory, we could make the test conditional on which ml2 drivers
196 # are enabled in gate, but that option doesn't seem to be
197 # available through tempest.lib framework
198 expected_rule_type_details_keys = ['type', 'drivers']
199
200 rule_type_details = self.admin_client.show_qos_rule_type(
201 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
202
203 # Verify that only required fields present in rule details
204 self.assertEqual(
205 sorted(tuple(expected_rule_type_details_keys)),
206 sorted(tuple(rule_type_details.keys())))
207
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000208 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000209 def test_policy_association_with_admin_network(self):
210 policy = self.create_qos_policy(name='test-policy',
211 description='test policy',
212 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200213 network = self.create_network('test network', shared=True,
214 qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000215
216 retrieved_network = self.admin_client.show_network(network['id'])
217 self.assertEqual(
218 policy['id'], retrieved_network['network']['qos_policy_id'])
219
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000220 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000221 def test_policy_association_with_tenant_network(self):
222 policy = self.create_qos_policy(name='test-policy',
223 description='test policy',
224 shared=True)
225 network = self.create_network('test network',
226 qos_policy_id=policy['id'])
227
228 retrieved_network = self.admin_client.show_network(network['id'])
229 self.assertEqual(
230 policy['id'], retrieved_network['network']['qos_policy_id'])
231
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000232 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000233 def test_policy_association_with_network_nonexistent_policy(self):
234 self.assertRaises(
235 exceptions.NotFound,
236 self.create_network,
237 'test network',
238 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
239
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000240 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000241 def test_policy_association_with_network_non_shared_policy(self):
242 policy = self.create_qos_policy(name='test-policy',
243 description='test policy',
244 shared=False)
245 self.assertRaises(
246 exceptions.NotFound,
247 self.create_network,
248 'test network', qos_policy_id=policy['id'])
249
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000250 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000251 def test_policy_update_association_with_admin_network(self):
252 policy = self.create_qos_policy(name='test-policy',
253 description='test policy',
254 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200255 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000256 retrieved_network = self.admin_client.show_network(network['id'])
257 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
258
259 self.admin_client.update_network(network['id'],
260 qos_policy_id=policy['id'])
261 retrieved_network = self.admin_client.show_network(network['id'])
262 self.assertEqual(
263 policy['id'], retrieved_network['network']['qos_policy_id'])
264
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000265 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000266 def test_policy_association_with_port_shared_policy(self):
267 policy = self.create_qos_policy(name='test-policy',
268 description='test policy',
269 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200270 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000271 port = self.create_port(network, qos_policy_id=policy['id'])
272
273 retrieved_port = self.admin_client.show_port(port['id'])
274 self.assertEqual(
275 policy['id'], retrieved_port['port']['qos_policy_id'])
276
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000277 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000278 def test_policy_association_with_port_nonexistent_policy(self):
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200279 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000280 self.assertRaises(
281 exceptions.NotFound,
282 self.create_port,
283 network,
284 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
285
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000286 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000287 def test_policy_association_with_port_non_shared_policy(self):
288 policy = self.create_qos_policy(name='test-policy',
289 description='test policy',
290 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200291 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000292 self.assertRaises(
293 exceptions.NotFound,
294 self.create_port,
295 network, qos_policy_id=policy['id'])
296
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000297 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000298 def test_policy_update_association_with_port_shared_policy(self):
299 policy = self.create_qos_policy(name='test-policy',
300 description='test policy',
301 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200302 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000303 port = self.create_port(network)
304 retrieved_port = self.admin_client.show_port(port['id'])
305 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
306
307 self.client.update_port(port['id'], qos_policy_id=policy['id'])
308 retrieved_port = self.admin_client.show_port(port['id'])
309 self.assertEqual(
310 policy['id'], retrieved_port['port']['qos_policy_id'])
311
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000312 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000313 def test_delete_not_allowed_if_policy_in_use_by_network(self):
314 policy = self.create_qos_policy(name='test-policy',
315 description='test policy',
316 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200317 self.create_network('test network', qos_policy_id=policy['id'],
318 shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000319 self.assertRaises(
320 exceptions.Conflict,
321 self.admin_client.delete_qos_policy, policy['id'])
322
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000323 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000324 def test_delete_not_allowed_if_policy_in_use_by_port(self):
325 policy = self.create_qos_policy(name='test-policy',
326 description='test policy',
327 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200328 network = self.create_network('test network', shared=True)
Sławek Kapłońskie100c4d2017-08-23 21:18:34 +0000329 self.create_port(network, qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000330 self.assertRaises(
331 exceptions.Conflict,
332 self.admin_client.delete_qos_policy, policy['id'])
333
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000334 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000335 def test_qos_policy_delete_with_rules(self):
336 policy = self.create_qos_policy(name='test-policy',
337 description='test policy',
338 shared=False)
339 self.admin_client.create_bandwidth_limit_rule(
340 policy['id'], 200, 1337)['bandwidth_limit_rule']
341
342 self.admin_client.delete_qos_policy(policy['id'])
343
344 with testtools.ExpectedException(exceptions.NotFound):
345 self.admin_client.show_qos_policy(policy['id'])
346
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000347 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000348 def test_get_policy_that_is_shared(self):
349 policy = self.create_qos_policy(
350 name='test-policy-shared',
351 description='shared policy',
352 shared=True,
353 tenant_id=self.admin_client.tenant_id)
354 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
355 self.assertEqual(obtained_policy, policy)
356
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000357 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100358 def test_policy_create_forbidden_for_regular_tenants(self):
359 self.assertRaises(
360 exceptions.Forbidden,
361 self.client.create_qos_policy,
362 'test-policy', 'test policy', False)
363
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900364 @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
365 def test_default_policy_creating_network_without_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530366 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900367 policy = self.create_qos_policy(name='test-policy',
368 tenant_id=project_id,
369 is_default=True)
370 network = self.create_network('test network', client=self.admin_client,
371 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900372 retrieved_network = self.admin_client.show_network(network['id'])
373 self.assertEqual(
374 policy['id'], retrieved_network['network']['qos_policy_id'])
375
376 @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
377 def test_default_policy_creating_network_with_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530378 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900379 self.create_qos_policy(name='test-policy',
380 tenant_id=project_id,
381 is_default=True)
382 policy = self.create_qos_policy(name='test-policy',
383 tenant_id=project_id)
384 network = self.create_network('test network', client=self.admin_client,
385 project_id=project_id,
386 qos_policy_id=policy['id'])
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900387 retrieved_network = self.admin_client.show_network(network['id'])
388 self.assertEqual(
389 policy['id'], retrieved_network['network']['qos_policy_id'])
390
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100391 @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229')
392 def test_user_create_port_with_admin_qos_policy(self):
393 qos_policy = self.create_qos_policy(
394 name='test-policy',
395 tenant_id=self.admin_client.tenant_id,
396 shared=False)
397 network = self.create_network(
398 'test network', client=self.admin_client,
399 project_id=self.client.tenant_id,
400 qos_policy_id=qos_policy['id'])
401 port = self.create_port(network)
402 self.assertEqual(network['id'], port['network_id'])
403
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000404
405class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000406
407 direction = None
Chandan Kumarc125fd12017-11-15 19:41:01 +0530408 required_extensions = [qos_apidef.ALIAS]
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000409
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000410 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900411 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000412 def resource_setup(cls):
413 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
414
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000415 @property
416 def opposite_direction(self):
417 if self.direction == "ingress":
418 return "egress"
419 elif self.direction == "egress":
420 return "ingress"
421 else:
422 return None
423
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000424 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000425 def test_rule_create(self):
426 policy = self.create_qos_policy(name='test-policy',
427 description='test policy',
428 shared=False)
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000429 rule = self.create_qos_bandwidth_limit_rule(
430 policy_id=policy['id'],
431 max_kbps=200,
432 max_burst_kbps=1337,
433 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000434
435 # Test 'show rule'
436 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
437 policy['id'], rule['id'])
438 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
439 self.assertEqual(rule['id'], retrieved_rule['id'])
440 self.assertEqual(200, retrieved_rule['max_kbps'])
441 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000442 if self.direction:
443 self.assertEqual(self.direction, retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000444
445 # Test 'list rules'
446 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
447 rules = rules['bandwidth_limit_rules']
448 rules_ids = [r['id'] for r in rules]
449 self.assertIn(rule['id'], rules_ids)
450
451 # Test 'show policy'
452 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
453 policy_rules = retrieved_policy['policy']['rules']
454 self.assertEqual(1, len(policy_rules))
455 self.assertEqual(rule['id'], policy_rules[0]['id'])
456 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
457 policy_rules[0]['type'])
458
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000459 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000460 def test_rule_create_fail_for_the_same_type(self):
461 policy = self.create_qos_policy(name='test-policy',
462 description='test policy',
463 shared=False)
464 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
465 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000466 max_burst_kbps=1337,
467 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000468
469 self.assertRaises(exceptions.Conflict,
470 self.create_qos_bandwidth_limit_rule,
471 policy_id=policy['id'],
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000472 max_kbps=201, max_burst_kbps=1338,
473 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000474
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000475 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000476 def test_rule_update(self):
477 policy = self.create_qos_policy(name='test-policy',
478 description='test policy',
479 shared=False)
480 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
481 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000482 max_burst_kbps=1,
483 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000484
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000485 self.admin_client.update_bandwidth_limit_rule(
486 policy['id'],
487 rule['id'],
488 max_kbps=200,
489 max_burst_kbps=1337,
490 direction=self.opposite_direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000491
492 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
493 policy['id'], rule['id'])
494 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
495 self.assertEqual(200, retrieved_policy['max_kbps'])
496 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000497 if self.opposite_direction:
498 self.assertEqual(self.opposite_direction,
499 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000500
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000501 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000502 def test_rule_delete(self):
503 policy = self.create_qos_policy(name='test-policy',
504 description='test policy',
505 shared=False)
506 rule = self.admin_client.create_bandwidth_limit_rule(
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000507 policy['id'], 200, 1337, self.direction)['bandwidth_limit_rule']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000508
509 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
510 policy['id'], rule['id'])
511 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
512 self.assertEqual(rule['id'], retrieved_policy['id'])
513
514 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
515 self.assertRaises(exceptions.NotFound,
516 self.admin_client.show_bandwidth_limit_rule,
517 policy['id'], rule['id'])
518
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000519 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000520 def test_rule_create_rule_nonexistent_policy(self):
521 self.assertRaises(
522 exceptions.NotFound,
523 self.create_qos_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000524 'policy', 200, 1337, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000525
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000526 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000527 def test_rule_create_forbidden_for_regular_tenants(self):
528 self.assertRaises(
529 exceptions.Forbidden,
530 self.client.create_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000531 'policy', 1, 2, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000532
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000533 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000534 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
535 policy = self.create_qos_policy(name='test-policy',
536 description='test policy',
537 shared=False,
538 tenant_id=self.client.tenant_id)
539 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
540 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000541 max_burst_kbps=1,
542 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000543 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400544 exceptions.Forbidden,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000545 self.client.update_bandwidth_limit_rule,
546 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
547
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000548 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000549 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
550 policy = self.create_qos_policy(name='test-policy',
551 description='test policy',
552 shared=False,
553 tenant_id=self.admin_client.tenant_id)
554 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
555 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000556 max_burst_kbps=1,
557 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000558 self.assertRaises(
559 exceptions.NotFound,
560 self.client.update_bandwidth_limit_rule,
561 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
562
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000563 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000564 def test_get_rules_by_policy(self):
565 policy1 = self.create_qos_policy(name='test-policy1',
566 description='test policy1',
567 shared=False)
568 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
569 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000570 max_burst_kbps=1337,
571 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000572
573 policy2 = self.create_qos_policy(name='test-policy2',
574 description='test policy2',
575 shared=False)
576 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
577 max_kbps=5000,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000578 max_burst_kbps=2523,
579 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000580
581 # Test 'list rules'
582 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
583 rules = rules['bandwidth_limit_rules']
584 rules_ids = [r['id'] for r in rules]
585 self.assertIn(rule1['id'], rules_ids)
586 self.assertNotIn(rule2['id'], rules_ids)
587
588
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000589class QosBandwidthLimitRuleWithDirectionTestJSON(
Brian Haley6767cec2018-04-10 15:30:23 -0400590 QosBandwidthLimitRuleTestJSON):
nfridman7717d9c2019-11-25 08:58:04 -0500591 DIRECTION_EGRESS = "egress"
592 DIRECTION_INGRESS = "ingress"
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000593 required_extensions = (
594 QosBandwidthLimitRuleTestJSON.required_extensions +
595 ['qos-bw-limit-direction']
596 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000597 scenarios = [
598 ('ingress', {'direction': 'ingress'}),
599 ('egress', {'direction': 'egress'}),
600 ]
601
nfridman7717d9c2019-11-25 08:58:04 -0500602 @classmethod
603 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
604 def resource_setup(cls):
605 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
606
607 @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667')
608 def test_create_policy_with_multiple_rules(self):
609 # Create a policy with multiple rules
610 policy = self.create_qos_policy(name='test-policy1',
611 description='test policy1',
612 shared=False)
613
614 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
615 max_kbps=1024,
616 max_burst_kbps=1024,
617 direction=self.
618 DIRECTION_EGRESS)
619 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
620 max_kbps=1024,
621 max_burst_kbps=1024,
622 direction=self.
623 DIRECTION_INGRESS)
624 # Check that the rules were added to the policy
625 rules = self.admin_client.list_bandwidth_limit_rules(
626 policy['id'])['bandwidth_limit_rules']
627 rules_ids = [rule['id'] for rule in rules]
628 self.assertIn(rule1['id'], rules_ids)
629 self.assertIn(rule2['id'], rules_ids)
630
631 # Check that the rules creation fails for the same rule types
632 self.assertRaises(exceptions.Conflict,
633 self.create_qos_bandwidth_limit_rule,
634 policy_id=policy['id'],
635 max_kbps=1025,
636 max_burst_kbps=1025,
637 direction=self.DIRECTION_EGRESS)
638
639 self.assertRaises(exceptions.Conflict,
640 self.create_qos_bandwidth_limit_rule,
641 policy_id=policy['id'],
642 max_kbps=1025,
643 max_burst_kbps=1025,
644 direction=self.DIRECTION_INGRESS)
645
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000646
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000647class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
648
649 force_tenant_isolation = True
650 credentials = ['primary', 'alt', 'admin']
Chandan Kumarc125fd12017-11-15 19:41:01 +0530651 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000652
653 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000654 def resource_setup(cls):
655 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530656 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000657
658 def _create_qos_policy(self, tenant_id=None):
659 args = {'name': data_utils.rand_name('test-policy'),
660 'description': 'test policy',
661 'shared': False,
662 'tenant_id': tenant_id}
663 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
664 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
665
666 return qos_policy
667
668 def _make_admin_policy_shared_to_tenant_id(self, tenant_id):
669 policy = self._create_qos_policy()
670 rbac_policy = self.admin_client.create_rbac_policy(
671 object_type='qos_policy',
672 object_id=policy['id'],
673 action='access_as_shared',
674 target_tenant=tenant_id,
675 )['rbac_policy']
676
677 return {'policy': policy, 'rbac_policy': rbac_policy}
678
679 def _create_network(self, qos_policy_id, client, should_cleanup=True):
680 net = client.create_network(
681 name=data_utils.rand_name('test-network'),
682 qos_policy_id=qos_policy_id)['network']
683 if should_cleanup:
684 self.addCleanup(client.delete_network, net['id'])
685
686 return net
687
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000688 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000689 def test_policy_sharing_with_wildcard(self):
690 qos_pol = self.create_qos_policy(
691 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000692 description='test-shared-policy', shared=False,
693 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000694 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
695
696 # test update shared False -> True
697 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
698 qos_pol['shared'] = True
699 self.client2.show_qos_policy(qos_pol['id'])
700 rbac_pol = {'target_tenant': '*',
701 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000702 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000703 'object_type': 'qos_policy',
704 'object_id': qos_pol['id'],
705 'action': 'access_as_shared'}
706
707 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
708 rbac_policies = [r for r in rbac_policies if r.pop('id')]
709 self.assertIn(rbac_pol, rbac_policies)
710
711 # update shared True -> False should fail because the policy is bound
712 # to a network
713 net = self._create_network(qos_pol['id'], self.admin_client, False)
714 with testtools.ExpectedException(exceptions.Conflict):
715 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
716
717 # delete the network, and update shared True -> False should pass now
718 self.admin_client.delete_network(net['id'])
719 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
720 qos_pol['shared'] = False
721 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
722
723 def _create_net_bound_qos_rbacs(self):
724 res = self._make_admin_policy_shared_to_tenant_id(
725 self.client.tenant_id)
726 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
727
728 # add a wildcard rbac rule - now the policy globally shared
729 rbac_wildcard = self.admin_client.create_rbac_policy(
730 object_type='qos_policy',
731 object_id=qos_policy['id'],
732 action='access_as_shared',
733 target_tenant='*',
734 )['rbac_policy']
735
736 # tenant1 now uses qos policy for net
737 self._create_network(qos_policy['id'], self.client)
738
739 return rbac_for_client_tenant, rbac_wildcard
740
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000741 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000742 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self):
743 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
744 # globally unshare the qos-policy, the specific share should remain
745 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
746 self.client.list_rbac_policies(id=client_rbac['id'])
747
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000748 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000749 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self):
750 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
751 # remove client_rbac policy the wildcard share should remain
752 self.admin_client.delete_rbac_policy(client_rbac['id'])
753 self.client.list_rbac_policies(id=wildcard_rbac['id'])
754
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000755 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000756 def test_policy_sharing_with_wildcard_and_tenant_id(self):
757 res = self._make_admin_policy_shared_to_tenant_id(
758 self.client.tenant_id)
759 qos_policy, rbac = res['policy'], res['rbac_policy']
760 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
761 self.assertTrue(qos_pol['shared'])
762 with testtools.ExpectedException(exceptions.NotFound):
763 self.client2.show_qos_policy(qos_policy['id'])
764
765 # make the qos-policy globally shared
766 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
767 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
768 self.assertTrue(qos_pol['shared'])
769
770 # globally unshare the qos-policy, the specific share should remain
771 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
772 self.client.show_qos_policy(qos_policy['id'])
773 with testtools.ExpectedException(exceptions.NotFound):
774 self.client2.show_qos_policy(qos_policy['id'])
775 self.assertIn(rbac,
776 self.admin_client.list_rbac_policies()['rbac_policies'])
777
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000778 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000779 def test_policy_target_update(self):
780 res = self._make_admin_policy_shared_to_tenant_id(
781 self.client.tenant_id)
782 # change to client2
783 update_res = self.admin_client.update_rbac_policy(
784 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
785 self.assertEqual(self.client2.tenant_id,
786 update_res['rbac_policy']['target_tenant'])
787 # make sure everything else stayed the same
788 res['rbac_policy'].pop('target_tenant')
789 update_res['rbac_policy'].pop('target_tenant')
790 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
791
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000792 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000793 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
794 res = self._make_admin_policy_shared_to_tenant_id(
795 self.client2.tenant_id)
796 qos_policy_id = res['policy']['id']
797 self._create_network(qos_policy_id, self.client2)
798 # a network with shared qos-policy should prevent the deletion of an
799 # rbac-policy required for it to be shared
800 with testtools.ExpectedException(exceptions.Conflict):
801 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
802
803 # a wildcard policy should allow the specific policy to be deleted
804 # since it allows the remaining port
805 wild = self.admin_client.create_rbac_policy(
806 object_type='qos_policy', object_id=res['policy']['id'],
807 action='access_as_shared', target_tenant='*')['rbac_policy']
808 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
809
810 # now that wildcard is the only remaining, it should be subjected to
811 # the same restriction
812 with testtools.ExpectedException(exceptions.Conflict):
813 self.admin_client.delete_rbac_policy(wild['id'])
814
815 # we can't update the policy to a different tenant
816 with testtools.ExpectedException(exceptions.Conflict):
817 self.admin_client.update_rbac_policy(
818 wild['id'], target_tenant=self.client2.tenant_id)
819
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000820 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000821 def test_regular_client_shares_to_another_regular_client(self):
822 # owned by self.admin_client
823 policy = self._create_qos_policy()
824 with testtools.ExpectedException(exceptions.NotFound):
825 self.client.show_qos_policy(policy['id'])
826 rbac_policy = self.admin_client.create_rbac_policy(
827 object_type='qos_policy', object_id=policy['id'],
828 action='access_as_shared',
829 target_tenant=self.client.tenant_id)['rbac_policy']
830 self.client.show_qos_policy(policy['id'])
831
832 self.assertIn(rbac_policy,
833 self.admin_client.list_rbac_policies()['rbac_policies'])
834 # ensure that 'client2' can't see the rbac-policy sharing the
835 # qos-policy to it because the rbac-policy belongs to 'client'
836 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
837 self.client2.list_rbac_policies()['rbac_policies']])
838
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000839 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000840 def test_filter_fields(self):
841 policy = self._create_qos_policy()
842 self.admin_client.create_rbac_policy(
843 object_type='qos_policy', object_id=policy['id'],
844 action='access_as_shared', target_tenant=self.client2.tenant_id)
845 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
846 ('tenant_id', 'target_tenant'))
847 for fields in field_args:
848 res = self.admin_client.list_rbac_policies(fields=fields)
849 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
850
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000851 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000852 def test_rbac_policy_show(self):
853 res = self._make_admin_policy_shared_to_tenant_id(
854 self.client.tenant_id)
855 p1 = res['rbac_policy']
856 p2 = self.admin_client.create_rbac_policy(
857 object_type='qos_policy', object_id=res['policy']['id'],
858 action='access_as_shared',
859 target_tenant='*')['rbac_policy']
860
861 self.assertEqual(
862 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
863 self.assertEqual(
864 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
865
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000866 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000867 def test_filter_rbac_policies(self):
868 policy = self._create_qos_policy()
869 rbac_pol1 = self.admin_client.create_rbac_policy(
870 object_type='qos_policy', object_id=policy['id'],
871 action='access_as_shared',
872 target_tenant=self.client2.tenant_id)['rbac_policy']
873 rbac_pol2 = self.admin_client.create_rbac_policy(
874 object_type='qos_policy', object_id=policy['id'],
875 action='access_as_shared',
876 target_tenant=self.admin_client.tenant_id)['rbac_policy']
877 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
878 'rbac_policies']
879 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
880 'rbac_policies']
881 self.assertEqual(1, len(res1))
882 self.assertEqual(1, len(res2))
883 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
884 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
885
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000886 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000887 def test_regular_client_blocked_from_sharing_anothers_policy(self):
888 qos_policy = self._make_admin_policy_shared_to_tenant_id(
889 self.client.tenant_id)['policy']
890 with testtools.ExpectedException(exceptions.BadRequest):
891 self.client.create_rbac_policy(
892 object_type='qos_policy', object_id=qos_policy['id'],
893 action='access_as_shared',
894 target_tenant=self.client2.tenant_id)
895
896 # make sure the rbac-policy is invisible to the tenant for which it's
897 # being shared
898 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
899
900
901class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
902 VALID_DSCP_MARK1 = 56
903 VALID_DSCP_MARK2 = 48
904
Chandan Kumarc125fd12017-11-15 19:41:01 +0530905 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000906
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000907 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900908 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000909 def resource_setup(cls):
910 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
911
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000912 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000913 def test_rule_create(self):
914 policy = self.create_qos_policy(name='test-policy',
915 description='test policy',
916 shared=False)
917 rule = self.admin_client.create_dscp_marking_rule(
918 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
919
920 # Test 'show rule'
921 retrieved_rule = self.admin_client.show_dscp_marking_rule(
922 policy['id'], rule['id'])
923 retrieved_rule = retrieved_rule['dscp_marking_rule']
924 self.assertEqual(rule['id'], retrieved_rule['id'])
925 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
926
927 # Test 'list rules'
928 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
929 rules = rules['dscp_marking_rules']
930 rules_ids = [r['id'] for r in rules]
931 self.assertIn(rule['id'], rules_ids)
932
933 # Test 'show policy'
934 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
935 policy_rules = retrieved_policy['policy']['rules']
936 self.assertEqual(1, len(policy_rules))
937 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000938 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000939 policy_rules[0]['type'])
940
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000941 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000942 def test_rule_create_fail_for_the_same_type(self):
943 policy = self.create_qos_policy(name='test-policy',
944 description='test policy',
945 shared=False)
946 self.admin_client.create_dscp_marking_rule(
947 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
948
949 self.assertRaises(exceptions.Conflict,
950 self.admin_client.create_dscp_marking_rule,
951 policy_id=policy['id'],
952 dscp_mark=self.VALID_DSCP_MARK2)
953
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000954 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000955 def test_rule_update(self):
956 policy = self.create_qos_policy(name='test-policy',
957 description='test policy',
958 shared=False)
959 rule = self.admin_client.create_dscp_marking_rule(
960 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
961
962 self.admin_client.update_dscp_marking_rule(
963 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
964
965 retrieved_policy = self.admin_client.show_dscp_marking_rule(
966 policy['id'], rule['id'])
967 retrieved_policy = retrieved_policy['dscp_marking_rule']
968 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
969
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000970 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000971 def test_rule_delete(self):
972 policy = self.create_qos_policy(name='test-policy',
973 description='test policy',
974 shared=False)
975 rule = self.admin_client.create_dscp_marking_rule(
976 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
977
978 retrieved_policy = self.admin_client.show_dscp_marking_rule(
979 policy['id'], rule['id'])
980 retrieved_policy = retrieved_policy['dscp_marking_rule']
981 self.assertEqual(rule['id'], retrieved_policy['id'])
982
983 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
984 self.assertRaises(exceptions.NotFound,
985 self.admin_client.show_dscp_marking_rule,
986 policy['id'], rule['id'])
987
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000988 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000989 def test_rule_create_rule_nonexistent_policy(self):
990 self.assertRaises(
991 exceptions.NotFound,
992 self.admin_client.create_dscp_marking_rule,
993 'policy', self.VALID_DSCP_MARK1)
994
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000995 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000996 def test_rule_create_forbidden_for_regular_tenants(self):
997 self.assertRaises(
998 exceptions.Forbidden,
999 self.client.create_dscp_marking_rule,
1000 'policy', self.VALID_DSCP_MARK1)
1001
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001002 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001003 def test_invalid_rule_create(self):
1004 policy = self.create_qos_policy(name='test-policy',
1005 description='test policy',
1006 shared=False)
1007 self.assertRaises(
1008 exceptions.BadRequest,
1009 self.admin_client.create_dscp_marking_rule,
1010 policy['id'], 58)
1011
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001012 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001013 def test_get_rules_by_policy(self):
1014 policy1 = self.create_qos_policy(name='test-policy1',
1015 description='test policy1',
1016 shared=False)
1017 rule1 = self.admin_client.create_dscp_marking_rule(
1018 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1019
1020 policy2 = self.create_qos_policy(name='test-policy2',
1021 description='test policy2',
1022 shared=False)
1023 rule2 = self.admin_client.create_dscp_marking_rule(
1024 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
1025
1026 # Test 'list rules'
1027 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
1028 rules = rules['dscp_marking_rules']
1029 rules_ids = [r['id'] for r in rules]
1030 self.assertIn(rule1['id'], rules_ids)
1031 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001032
nfridman23b44ad2019-09-05 09:46:50 -04001033 @decorators.idempotent_id('19ed2286-ccb1-11e9-87d7-525400d6f522')
1034 def test_qos_dscp_create_and_update(self):
1035 """This test covers:
1036
1037 1.Creating a basic QoS policy with DSCP marking rule.
1038 2.Updating QoS policy:
1039 Administrator should have the ability to update existing QoS policy.
1040 This test should verify that:
1041 It's possible to update the existing DSCP marking rule with all of
1042 the valid marks between 0-56, except of the invalid marks:
1043 2-6, 42, 44, and 50-54 (which should be forbidden)
1044 """
1045
1046 def _test_update_dscp_mark_values(self, dscp_policy_id, rule_id):
1047 for mark in range(n_constants.VALID_DSCP_MARKS[1],
1048 self.VALID_DSCP_MARK1 + 1):
1049 if mark in n_constants.VALID_DSCP_MARKS:
1050 self.admin_client.update_dscp_marking_rule(
1051 dscp_policy_id, rule_id, dscp_mark=mark)
1052
1053 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1054 dscp_policy_id, rule_id)['dscp_marking_rule']
1055 self.assertEqual(mark, retrieved_rule['dscp_mark'],
1056 """current DSCP mark is incorrect:
1057 expected value {0} actual value {1}
1058 """.format(mark,
1059 retrieved_rule['dscp_mark']))
1060
1061 else:
1062 self.assertRaises(exceptions.BadRequest,
1063 self.admin_client.create_dscp_marking_rule,
1064 dscp_policy_id,
1065 mark)
1066 # Setup network
1067 self.network = self.create_network()
1068
1069 # Create QoS policy
1070 dscp_policy_id = self.create_qos_policy(
1071 name='test-policy',
1072 description='test-qos-policy',
1073 shared=True)['id']
1074
1075 # Associate QoS to the network
1076 self.admin_client.update_network(
1077 self.network['id'], qos_policy_id=dscp_policy_id)
1078
1079 # Set a new DSCP rule with the first mark in range
1080 rule_id = self.admin_client.create_dscp_marking_rule(
1081 dscp_policy_id,
1082 n_constants.VALID_DSCP_MARKS[0])[
1083 'dscp_marking_rule']['id']
1084
1085 # Validate that the rule was set up properly
1086 retrieved_rule = self.client.show_dscp_marking_rule(
1087 dscp_policy_id, rule_id)['dscp_marking_rule']
1088 self.assertEqual(n_constants.VALID_DSCP_MARKS[0],
1089 retrieved_rule['dscp_mark'],
1090 """current DSCP mark is incorrect:
1091 expected value {0} actual value {1}
1092 """.format(n_constants.VALID_DSCP_MARKS[0],
1093 retrieved_rule['dscp_mark']))
1094
1095 # Try to set marks in range 8:56 (invalid marks should raise an error)
1096 _test_update_dscp_mark_values(self, dscp_policy_id, rule_id)
1097
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001098
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001099class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
1100 DIRECTION_EGRESS = "egress"
1101 DIRECTION_INGRESS = "ingress"
1102 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
1103 RULES_NAME = RULE_NAME + "s"
Chandan Kumarc125fd12017-11-15 19:41:01 +05301104 required_extensions = [qos_apidef.ALIAS]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001105
1106 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001107 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001108 def resource_setup(cls):
1109 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
1110
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001111 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001112 def test_rule_create(self):
1113 policy = self.create_qos_policy(name='test-policy',
1114 description='test policy',
1115 shared=False)
1116 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001117 policy_id=policy['id'],
1118 direction=self.DIRECTION_EGRESS,
1119 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001120
1121 # Test 'show rule'
1122 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
1123 policy['id'], rule['id'])
1124 retrieved_rule = retrieved_rule[self.RULE_NAME]
1125 self.assertEqual(rule['id'], retrieved_rule['id'])
1126 self.assertEqual(1138, retrieved_rule['min_kbps'])
1127 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1128
1129 # Test 'list rules'
1130 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
1131 rules = rules[self.RULES_NAME]
1132 rules_ids = [r['id'] for r in rules]
1133 self.assertIn(rule['id'], rules_ids)
1134
1135 # Test 'show policy'
1136 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1137 policy_rules = retrieved_policy['policy']['rules']
1138 self.assertEqual(1, len(policy_rules))
1139 self.assertEqual(rule['id'], policy_rules[0]['id'])
1140 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1141 policy_rules[0]['type'])
1142
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001143 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001144 def test_rule_create_fail_for_missing_min_kbps(self):
1145 policy = self.create_qos_policy(name='test-policy',
1146 description='test policy',
1147 shared=False)
1148 self.assertRaises(exceptions.BadRequest,
1149 self.admin_client.create_minimum_bandwidth_rule,
1150 policy_id=policy['id'],
1151 direction=self.DIRECTION_EGRESS)
1152
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001153 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001154 def test_rule_create_fail_for_the_same_type(self):
1155 policy = self.create_qos_policy(name='test-policy',
1156 description='test policy',
1157 shared=False)
1158 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001159 policy_id=policy['id'],
1160 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001161
1162 self.assertRaises(exceptions.Conflict,
1163 self.admin_client.create_minimum_bandwidth_rule,
1164 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001165 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001166
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001167 @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936')
1168 @utils.requires_ext(extension="qos-bw-minimum-ingress",
1169 service="network")
1170 def test_rule_create_pass_for_direction_ingress(self):
1171 policy = self.create_qos_policy(name='test-policy',
1172 description='test policy',
1173 shared=False)
1174 self.admin_client.create_minimum_bandwidth_rule(
1175 policy_id=policy['id'],
1176 direction=self.DIRECTION_INGRESS,
1177 min_kbps=201)
1178
1179 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1180 policy_rules = retrieved_policy['policy']['rules']
1181 self.assertEqual(1, len(policy_rules))
1182 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1183 policy_rules[0]['type'])
1184 self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction'])
1185
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001186 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001187 def test_rule_update(self):
1188 policy = self.create_qos_policy(name='test-policy',
1189 description='test policy',
1190 shared=False)
1191 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001192 policy_id=policy['id'],
1193 direction=self.DIRECTION_EGRESS,
1194 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001195
1196 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
1197 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
1198
1199 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1200 policy['id'], rule['id'])
1201 retrieved_policy = retrieved_policy[self.RULE_NAME]
1202 self.assertEqual(350, retrieved_policy['min_kbps'])
1203 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1204
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001205 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001206 def test_rule_delete(self):
1207 policy = self.create_qos_policy(name='test-policy',
1208 description='test policy',
1209 shared=False)
1210 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001211 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001212
1213 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1214 policy['id'], rule['id'])
1215 retrieved_policy = retrieved_policy[self.RULE_NAME]
1216 self.assertEqual(rule['id'], retrieved_policy['id'])
1217
1218 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1219 rule['id'])
1220 self.assertRaises(exceptions.NotFound,
1221 self.admin_client.show_minimum_bandwidth_rule,
1222 policy['id'], rule['id'])
1223
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001224 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001225 def test_rule_create_rule_nonexistent_policy(self):
1226 self.assertRaises(
1227 exceptions.NotFound,
1228 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001229 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001230
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001231 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001232 def test_rule_create_forbidden_for_regular_tenants(self):
1233 self.assertRaises(
1234 exceptions.Forbidden,
1235 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001236 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001237
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001238 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001239 def test_get_rules_by_policy(self):
1240 policy1 = self.create_qos_policy(name='test-policy1',
1241 description='test policy1',
1242 shared=False)
1243 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001244 policy_id=policy1['id'],
1245 direction=self.DIRECTION_EGRESS,
1246 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001247
1248 policy2 = self.create_qos_policy(name='test-policy2',
1249 description='test policy2',
1250 shared=False)
1251 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001252 policy_id=policy2['id'],
1253 direction=self.DIRECTION_EGRESS,
1254 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001255
1256 # Test 'list rules'
1257 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1258 rules = rules[self.RULES_NAME]
1259 rules_ids = [r['id'] for r in rules]
1260 self.assertIn(rule1['id'], rules_ids)
1261 self.assertNotIn(rule2['id'], rules_ids)
1262
1263
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001264class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1265 base.BaseAdminNetworkTest):
1266
1267 resource = 'policy'
1268 plural_name = 'policies'
1269
1270 # Use unique description to isolate the tests from other QoS tests
1271 list_kwargs = {'description': 'search-criteria-test'}
1272 list_as_admin = True
1273
Chandan Kumarc125fd12017-11-15 19:41:01 +05301274 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001275
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001276 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001277 def resource_setup(cls):
1278 super(QosSearchCriteriaTest, cls).resource_setup()
1279 for name in cls.resource_names:
1280 cls.create_qos_policy(
1281 name=name, description='search-criteria-test')
1282
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001283 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001284 def test_list_sorts_asc(self):
1285 self._test_list_sorts_asc()
1286
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001287 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001288 def test_list_sorts_desc(self):
1289 self._test_list_sorts_desc()
1290
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001291 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001292 def test_list_pagination(self):
1293 self._test_list_pagination()
1294
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001295 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001296 def test_list_pagination_with_marker(self):
1297 self._test_list_pagination_with_marker()
1298
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001299 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001300 def test_list_pagination_with_href_links(self):
1301 self._test_list_pagination_with_href_links()
1302
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001303 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001304 def test_list_pagination_page_reverse_asc(self):
1305 self._test_list_pagination_page_reverse_asc()
1306
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001307 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001308 def test_list_pagination_page_reverse_desc(self):
1309 self._test_list_pagination_page_reverse_desc()
1310
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001311 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001312 def test_list_pagination_page_reverse_with_href_links(self):
1313 self._test_list_pagination_page_reverse_with_href_links()
1314
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001315 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001316 def test_list_no_pagination_limit_0(self):
1317 self._test_list_no_pagination_limit_0()