blob: 5284688a4cc2570335082cfd3c0f57d3dce592c9 [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
zahlabut7ebb66e2021-09-01 22:39:49 +030020from tempest.lib.common.utils import test_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000021from tempest.lib import decorators
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000022from tempest.lib import exceptions
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000023
Sławek Kapłoński153f3452017-03-24 22:04:53 +000024import testscenarios
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000025import testtools
26
Chandan Kumar667d3d32017-09-22 12:24:06 +053027from neutron_tempest_plugin.api import base
nfridman07f0e782019-11-04 09:12:58 -050028from neutron_tempest_plugin import config
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000029
Sławek Kapłoński153f3452017-03-24 22:04:53 +000030load_tests = testscenarios.load_tests_apply_scenarios
nfridman07f0e782019-11-04 09:12:58 -050031CONF = config.CONF
Sławek Kapłoński153f3452017-03-24 22:04:53 +000032
33
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000034class QosTestJSON(base.BaseAdminNetworkTest):
Jakub Libosvar1982aa12017-05-30 11:15:33 +000035
Chandan Kumarc125fd12017-11-15 19:41:01 +053036 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000037
zahlabut7ebb66e2021-09-01 22:39:49 +030038 @classmethod
39 def setup_clients(cls):
40 super(QosTestJSON, cls).setup_clients()
41 cls.qos_bw_limit_rule_client = \
42 cls.os_admin.qos_limit_bandwidth_rules_client
43
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +000044 @staticmethod
45 def _get_driver_details(rule_type_details, driver_name):
46 for driver in rule_type_details['drivers']:
47 if driver['name'] == driver_name:
48 return driver
49
zahlabut7ebb66e2021-09-01 22:39:49 +030050 def _create_qos_bw_limit_rule(self, policy_id, rule_data):
51 rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule(
52 qos_policy_id=policy_id,
53 **rule_data)['bandwidth_limit_rule']
54 self.addCleanup(
55 test_utils.call_and_ignore_notfound_exc,
56 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule,
57 policy_id, rule['id'])
58 return rule
59
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000060 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000061 def test_create_policy(self):
62 policy = self.create_qos_policy(name='test-policy',
63 description='test policy desc1',
64 shared=False)
65
66 # Test 'show policy'
67 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
68 retrieved_policy = retrieved_policy['policy']
69 self.assertEqual('test-policy', retrieved_policy['name'])
70 self.assertEqual('test policy desc1', retrieved_policy['description'])
71 self.assertFalse(retrieved_policy['shared'])
72
73 # Test 'list policies'
74 policies = self.admin_client.list_qos_policies()['policies']
75 policies_ids = [p['id'] for p in policies]
76 self.assertIn(policy['id'], policies_ids)
77
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000078 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Chandan Kumarc125fd12017-11-15 19:41:01 +053079 @utils.requires_ext(extension="project-id", service="network")
Henry Gessaufa6c78d2016-10-09 19:56:09 -040080 def test_show_policy_has_project_id(self):
81 policy = self.create_qos_policy(name='test-policy', shared=False)
82 body = self.admin_client.show_qos_policy(policy['id'])
83 show_policy = body['policy']
84 self.assertIn('project_id', show_policy)
Henry Gessaufa6c78d2016-10-09 19:56:09 -040085 self.assertEqual(self.admin_client.tenant_id,
86 show_policy['project_id'])
Henry Gessaufa6c78d2016-10-09 19:56:09 -040087
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000088 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000089 def test_list_policy_filter_by_name(self):
90 self.create_qos_policy(name='test', description='test policy',
91 shared=False)
92 self.create_qos_policy(name='test2', description='test policy',
93 shared=False)
94
95 policies = (self.admin_client.
96 list_qos_policies(name='test')['policies'])
97 self.assertEqual(1, len(policies))
98
99 retrieved_policy = policies[0]
100 self.assertEqual('test', retrieved_policy['name'])
101
likangkang01afd73f72020-06-01 16:53:59 +0800102 @decorators.idempotent_id('dde0b449-a400-4a87-b5a5-4d1c413c917b')
103 def test_list_policy_sort_by_name(self):
104 policyA = 'A' + data_utils.rand_name("policy")
105 policyB = 'B' + data_utils.rand_name("policy")
106 self.create_qos_policy(name=policyA, description='test policy',
107 shared=False)
108 self.create_qos_policy(name=policyB, description='test policy',
109 shared=False)
110
111 param = {
112 'sort_key': 'name',
113 'sort_dir': 'asc'
114 }
115 policies = (self.admin_client.list_qos_policies(**param)['policies'])
116 policy_names = [p['name'] for p in policies]
117 self.assertLess(policy_names.index(policyA),
118 policy_names.index(policyB))
119
120 param = {
121 'sort_key': 'name',
122 'sort_dir': 'desc'
123 }
124 policies = (self.admin_client.list_qos_policies(**param)['policies'])
125 policy_names = [p['name'] for p in policies]
126 self.assertLess(policy_names.index(policyB),
127 policy_names.index(policyA))
128
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000129 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000130 def test_policy_update(self):
131 policy = self.create_qos_policy(name='test-policy',
132 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000133 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000134 project_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000135 self.admin_client.update_qos_policy(policy['id'],
136 description='test policy desc2',
137 shared=True)
138
139 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
140 retrieved_policy = retrieved_policy['policy']
141 self.assertEqual('test policy desc2', retrieved_policy['description'])
142 self.assertTrue(retrieved_policy['shared'])
143 self.assertEqual([], retrieved_policy['rules'])
144
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000145 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000146 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
147 policy = self.create_qos_policy(name='test-policy',
148 description='',
149 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000150 project_id=self.client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000151 self.assertRaises(
152 exceptions.Forbidden,
153 self.client.update_qos_policy,
154 policy['id'], description='test policy')
155
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000156 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000157 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
158 policy = self.create_qos_policy(name='test-policy',
159 description='',
160 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000161 project_id=self.admin_client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000162 self.assertRaises(
163 exceptions.NotFound,
164 self.client.update_qos_policy,
165 policy['id'], description='test policy')
166
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000167 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000168 def test_shared_policy_update(self):
169 policy = self.create_qos_policy(name='test-policy',
170 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000171 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000172 project_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000173
174 self.admin_client.update_qos_policy(policy['id'],
175 description='test policy desc2')
176 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
177 retrieved_policy = retrieved_policy['policy']
178 self.assertTrue(retrieved_policy['shared'])
179
180 self.admin_client.update_qos_policy(policy['id'],
181 shared=False)
182 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
183 retrieved_policy = retrieved_policy['policy']
184 self.assertFalse(retrieved_policy['shared'])
185
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000186 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000187 def test_delete_policy(self):
188 policy = self.admin_client.create_qos_policy(
189 'test-policy', 'desc', True)['policy']
190
191 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
192 retrieved_policy = retrieved_policy['policy']
193 self.assertEqual('test-policy', retrieved_policy['name'])
194
195 self.admin_client.delete_qos_policy(policy['id'])
196 self.assertRaises(exceptions.NotFound,
197 self.admin_client.show_qos_policy, policy['id'])
198
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000199 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000200 def test_list_admin_rule_types(self):
201 self._test_list_rule_types(self.admin_client)
202
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000203 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000204 def test_list_regular_rule_types(self):
205 self._test_list_rule_types(self.client)
206
207 def _test_list_rule_types(self, client):
208 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000209 # Since returned rule types depends on loaded backend drivers this test
210 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000211 #
212 # In theory, we could make the test conditional on which ml2 drivers
213 # are enabled in gate (or more specifically, on which supported qos
214 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200215 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000216 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000217
218 rule_types = client.list_qos_rule_types()
219 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000220
221 # Verify that only required fields present in rule details
222 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000223 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000224
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000225 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
226 def test_show_rule_type_details_as_user(self):
227 self.assertRaises(
228 exceptions.Forbidden,
229 self.client.show_qos_rule_type,
230 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
231
232 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
233 def test_show_rule_type_details_as_admin(self):
234 # Since returned rule types depend on loaded backend drivers this test
235 # is checking only if returned keys are same as expected keys
236
237 # In theory, we could make the test conditional on which ml2 drivers
238 # are enabled in gate, but that option doesn't seem to be
239 # available through tempest.lib framework
240 expected_rule_type_details_keys = ['type', 'drivers']
241
242 rule_type_details = self.admin_client.show_qos_rule_type(
243 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
244
245 # Verify that only required fields present in rule details
246 self.assertEqual(
247 sorted(tuple(expected_rule_type_details_keys)),
248 sorted(tuple(rule_type_details.keys())))
249
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000250 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000251 def test_policy_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,
256 qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000257
258 retrieved_network = self.admin_client.show_network(network['id'])
259 self.assertEqual(
260 policy['id'], retrieved_network['network']['qos_policy_id'])
261
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000262 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000263 def test_policy_association_with_tenant_network(self):
264 policy = self.create_qos_policy(name='test-policy',
265 description='test policy',
266 shared=True)
267 network = self.create_network('test network',
268 qos_policy_id=policy['id'])
269
270 retrieved_network = self.admin_client.show_network(network['id'])
271 self.assertEqual(
272 policy['id'], retrieved_network['network']['qos_policy_id'])
273
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000274 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000275 def test_policy_association_with_network_nonexistent_policy(self):
276 self.assertRaises(
277 exceptions.NotFound,
278 self.create_network,
279 'test network',
280 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
281
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000282 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000283 def test_policy_association_with_network_non_shared_policy(self):
284 policy = self.create_qos_policy(name='test-policy',
285 description='test policy',
286 shared=False)
287 self.assertRaises(
288 exceptions.NotFound,
289 self.create_network,
290 'test network', qos_policy_id=policy['id'])
291
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000292 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000293 def test_policy_update_association_with_admin_network(self):
294 policy = self.create_qos_policy(name='test-policy',
295 description='test policy',
296 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200297 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000298 retrieved_network = self.admin_client.show_network(network['id'])
299 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
300
301 self.admin_client.update_network(network['id'],
302 qos_policy_id=policy['id'])
303 retrieved_network = self.admin_client.show_network(network['id'])
304 self.assertEqual(
305 policy['id'], retrieved_network['network']['qos_policy_id'])
306
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000307 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000308 def test_policy_association_with_port_shared_policy(self):
309 policy = self.create_qos_policy(name='test-policy',
310 description='test policy',
311 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200312 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000313 port = self.create_port(network, qos_policy_id=policy['id'])
314
315 retrieved_port = self.admin_client.show_port(port['id'])
316 self.assertEqual(
317 policy['id'], retrieved_port['port']['qos_policy_id'])
318
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000319 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000320 def test_policy_association_with_port_nonexistent_policy(self):
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200321 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000322 self.assertRaises(
323 exceptions.NotFound,
324 self.create_port,
325 network,
326 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
327
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000328 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000329 def test_policy_association_with_port_non_shared_policy(self):
330 policy = self.create_qos_policy(name='test-policy',
331 description='test policy',
332 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200333 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000334 self.assertRaises(
335 exceptions.NotFound,
336 self.create_port,
337 network, qos_policy_id=policy['id'])
338
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000339 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000340 def test_policy_update_association_with_port_shared_policy(self):
341 policy = self.create_qos_policy(name='test-policy',
342 description='test policy',
343 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200344 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000345 port = self.create_port(network)
346 retrieved_port = self.admin_client.show_port(port['id'])
347 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
348
349 self.client.update_port(port['id'], qos_policy_id=policy['id'])
350 retrieved_port = self.admin_client.show_port(port['id'])
351 self.assertEqual(
352 policy['id'], retrieved_port['port']['qos_policy_id'])
353
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000354 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000355 def test_delete_not_allowed_if_policy_in_use_by_network(self):
356 policy = self.create_qos_policy(name='test-policy',
357 description='test policy',
358 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200359 self.create_network('test network', qos_policy_id=policy['id'],
360 shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000361 self.assertRaises(
362 exceptions.Conflict,
363 self.admin_client.delete_qos_policy, policy['id'])
364
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000365 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000366 def test_delete_not_allowed_if_policy_in_use_by_port(self):
367 policy = self.create_qos_policy(name='test-policy',
368 description='test policy',
369 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200370 network = self.create_network('test network', shared=True)
Sławek Kapłońskie100c4d2017-08-23 21:18:34 +0000371 self.create_port(network, qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000372 self.assertRaises(
373 exceptions.Conflict,
374 self.admin_client.delete_qos_policy, policy['id'])
375
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000376 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000377 def test_qos_policy_delete_with_rules(self):
378 policy = self.create_qos_policy(name='test-policy',
379 description='test policy',
380 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300381 self._create_qos_bw_limit_rule(
382 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000383 self.admin_client.delete_qos_policy(policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000384 with testtools.ExpectedException(exceptions.NotFound):
385 self.admin_client.show_qos_policy(policy['id'])
386
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000387 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000388 def test_get_policy_that_is_shared(self):
389 policy = self.create_qos_policy(
390 name='test-policy-shared',
391 description='shared policy',
392 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000393 project_id=self.admin_client.tenant_id)
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000394 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
395 self.assertEqual(obtained_policy, policy)
396
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000397 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100398 def test_policy_create_forbidden_for_regular_tenants(self):
399 self.assertRaises(
400 exceptions.Forbidden,
401 self.client.create_qos_policy,
402 'test-policy', 'test policy', False)
403
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900404 @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
405 def test_default_policy_creating_network_without_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530406 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900407 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000408 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900409 is_default=True)
410 network = self.create_network('test network', client=self.admin_client,
411 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900412 retrieved_network = self.admin_client.show_network(network['id'])
413 self.assertEqual(
414 policy['id'], retrieved_network['network']['qos_policy_id'])
415
416 @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
417 def test_default_policy_creating_network_with_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530418 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900419 self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000420 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900421 is_default=True)
422 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000423 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900424 network = self.create_network('test network', client=self.admin_client,
425 project_id=project_id,
426 qos_policy_id=policy['id'])
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900427 retrieved_network = self.admin_client.show_network(network['id'])
428 self.assertEqual(
429 policy['id'], retrieved_network['network']['qos_policy_id'])
430
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100431 @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229')
432 def test_user_create_port_with_admin_qos_policy(self):
433 qos_policy = self.create_qos_policy(
434 name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000435 project_id=self.admin_client.tenant_id,
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100436 shared=False)
437 network = self.create_network(
438 'test network', client=self.admin_client,
439 project_id=self.client.tenant_id,
440 qos_policy_id=qos_policy['id'])
441 port = self.create_port(network)
442 self.assertEqual(network['id'], port['network_id'])
443
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000444
445class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000446
zahlabut7ebb66e2021-09-01 22:39:49 +0300447 credentials = ['primary', 'admin']
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000448 direction = None
Chandan Kumarc125fd12017-11-15 19:41:01 +0530449 required_extensions = [qos_apidef.ALIAS]
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000450
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000451 @classmethod
zahlabut7ebb66e2021-09-01 22:39:49 +0300452 def setup_clients(cls):
453 super(QosBandwidthLimitRuleTestJSON, cls).setup_clients()
454 cls.qos_bw_limit_rule_client = \
455 cls.os_admin.qos_limit_bandwidth_rules_client
456 cls.qos_bw_limit_rule_client_primary = \
457 cls.os_primary.qos_limit_bandwidth_rules_client
458
459 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900460 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000461 def resource_setup(cls):
462 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
463
zahlabut7ebb66e2021-09-01 22:39:49 +0300464 def _create_qos_bw_limit_rule(self, policy_id, rule_data):
465 rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule(
466 qos_policy_id=policy_id,
467 **rule_data)['bandwidth_limit_rule']
468 self.addCleanup(
469 test_utils.call_and_ignore_notfound_exc,
470 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule,
471 policy_id, rule['id'])
472 return rule
473
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000474 @property
475 def opposite_direction(self):
476 if self.direction == "ingress":
477 return "egress"
478 elif self.direction == "egress":
479 return "ingress"
480 else:
481 return None
482
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000483 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000484 def test_rule_create(self):
485 policy = self.create_qos_policy(name='test-policy',
486 description='test policy',
487 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300488 rule = self._create_qos_bw_limit_rule(
489 policy['id'],
490 {'max_kbps': 200, 'max_burst_kbps': 1337, 'direction': 'ingress'})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000491
492 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +0300493 retrieved_rule = \
494 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
495 policy['id'], rule['id'])
496
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000497 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
498 self.assertEqual(rule['id'], retrieved_rule['id'])
499 self.assertEqual(200, retrieved_rule['max_kbps'])
500 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300501 self.assertEqual('ingress', retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000502
503 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300504 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
505 policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000506 rules = rules['bandwidth_limit_rules']
507 rules_ids = [r['id'] for r in rules]
508 self.assertIn(rule['id'], rules_ids)
509
510 # Test 'show policy'
511 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
512 policy_rules = retrieved_policy['policy']['rules']
513 self.assertEqual(1, len(policy_rules))
514 self.assertEqual(rule['id'], policy_rules[0]['id'])
515 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
516 policy_rules[0]['type'])
517
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000518 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000519 def test_rule_create_fail_for_the_same_type(self):
520 policy = self.create_qos_policy(name='test-policy',
521 description='test policy',
522 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300523 self._create_qos_bw_limit_rule(
524 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000525
zahlabut7ebb66e2021-09-01 22:39:49 +0300526 self.assertRaises(
527 exceptions.Conflict,
528 self._create_qos_bw_limit_rule,
529 policy['id'],
530 {'max_kbps': 201, 'max_burst_kbps': 1338})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000531
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000532 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000533 def test_rule_update(self):
534 policy = self.create_qos_policy(name='test-policy',
535 description='test policy',
536 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300537 rule = self._create_qos_bw_limit_rule(
538 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000539
zahlabut7ebb66e2021-09-01 22:39:49 +0300540 if self.opposite_direction:
541 self.qos_bw_limit_rule_client.update_limit_bandwidth_rule(
542 policy['id'], rule['id'],
543 **{'max_kbps': 200, 'max_burst_kbps': 1337,
544 'direction': self.opposite_direction})
545 else:
546 self.qos_bw_limit_rule_client.update_limit_bandwidth_rule(
547 policy['id'], rule['id'],
548 **{'max_kbps': 200, 'max_burst_kbps': 1337})
549 retrieved_policy = self.qos_bw_limit_rule_client.\
550 show_limit_bandwidth_rule(policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000551 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
552 self.assertEqual(200, retrieved_policy['max_kbps'])
553 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000554 if self.opposite_direction:
555 self.assertEqual(self.opposite_direction,
556 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000557
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000558 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000559 def test_rule_delete(self):
560 policy = self.create_qos_policy(name='test-policy',
561 description='test policy',
562 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300563 rule = self._create_qos_bw_limit_rule(
564 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
565 retrieved_policy = \
566 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
567 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000568 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
569 self.assertEqual(rule['id'], retrieved_policy['id'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300570 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule(
571 policy['id'], rule['id'])
572 self.assertRaises(
573 exceptions.NotFound,
574 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule,
575 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000576
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000577 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000578 def test_rule_create_rule_nonexistent_policy(self):
579 self.assertRaises(
580 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300581 self._create_qos_bw_limit_rule,
582 'policy', {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000583
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000584 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000585 def test_rule_create_forbidden_for_regular_tenants(self):
586 self.assertRaises(
587 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300588 self.qos_bw_limit_rule_client_primary.create_limit_bandwidth_rule,
589 'policy', **{'max_kbps': 1, 'max_burst_kbps': 2})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000590
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000591 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000592 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
593 policy = self.create_qos_policy(name='test-policy',
594 description='test policy',
595 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000596 project_id=self.client.tenant_id)
zahlabut7ebb66e2021-09-01 22:39:49 +0300597 rule = self._create_qos_bw_limit_rule(
598 policy['id'],
599 {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000600 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400601 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300602 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
603 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000604
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000605 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000606 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300607 policy = self.create_qos_policy(
608 name='test-policy',
609 description='test policy',
610 shared=False,
611 project_id=self.admin_client.tenant_id)
612 rule = self._create_qos_bw_limit_rule(
613 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000614 self.assertRaises(
615 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300616 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
617 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000618
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000619 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000620 def test_get_rules_by_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300621 policy1 = self.create_qos_policy(
622 name='test-policy1',
623 description='test policy1',
624 shared=False)
625 rule1 = self._create_qos_bw_limit_rule(
626 policy1['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000627
zahlabut7ebb66e2021-09-01 22:39:49 +0300628 policy2 = self.create_qos_policy(
629 name='test-policy2',
630 description='test policy2',
631 shared=False)
632 rule2 = self._create_qos_bw_limit_rule(
633 policy2['id'], {'max_kbps': 5000, 'max_burst_kbps': 2523})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000634
635 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300636 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
637 policy1['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000638 rules = rules['bandwidth_limit_rules']
639 rules_ids = [r['id'] for r in rules]
640 self.assertIn(rule1['id'], rules_ids)
641 self.assertNotIn(rule2['id'], rules_ids)
642
nfridman07f0e782019-11-04 09:12:58 -0500643 @testtools.skipUnless(
644 CONF.neutron_plugin_options.create_shared_resources,
645 """Creation of shared resources should be allowed,
646 setting the create_shared_resources option as 'True' is needed""")
647 @decorators.idempotent_id('d911707e-fa2c-11e9-9553-5076af30bbf5')
648 def test_attach_and_detach_a_policy_by_a_tenant(self):
649 # As an admin create an non shared QoS policy,add a rule
650 # and associate it with a network
651 self.network = self.create_network()
652 policy = self.create_qos_policy(name='test-policy',
653 description='test policy for attach',
654 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300655 self._create_qos_bw_limit_rule(
656 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024})
nfridman07f0e782019-11-04 09:12:58 -0500657
658 self.admin_client.update_network(
659 self.network['id'], qos_policy_id=policy['id'])
660
661 # As a tenant, try to detach the policy from the network
662 # The operation should be forbidden
663 self.assertRaises(
664 exceptions.Forbidden,
665 self.client.update_network,
666 self.network['id'], qos_policy_id=None)
667
668 # As an admin, make the policy shared
669 self.admin_client.update_qos_policy(policy['id'], shared=True)
670
671 # As a tenant, try to detach the policy from the network
672 # The operation should be allowed
673 self.client.update_network(self.network['id'],
674 qos_policy_id=None)
675
676 retrieved_network = self.admin_client.show_network(self.network['id'])
677 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
678
679 # As a tenant, try to delete the policy from the network
680 # should be forbidden
681 self.assertRaises(
682 exceptions.Forbidden,
683 self.client.delete_qos_policy,
684 policy['id'])
685
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000686
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000687class QosBandwidthLimitRuleWithDirectionTestJSON(
Brian Haley6767cec2018-04-10 15:30:23 -0400688 QosBandwidthLimitRuleTestJSON):
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000689 required_extensions = (
690 QosBandwidthLimitRuleTestJSON.required_extensions +
691 ['qos-bw-limit-direction']
692 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000693 scenarios = [
694 ('ingress', {'direction': 'ingress'}),
695 ('egress', {'direction': 'egress'}),
696 ]
697
nfridman7717d9c2019-11-25 08:58:04 -0500698 @classmethod
699 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
700 def resource_setup(cls):
701 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
702
703 @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667')
704 def test_create_policy_with_multiple_rules(self):
705 # Create a policy with multiple rules
706 policy = self.create_qos_policy(name='test-policy1',
707 description='test policy1',
708 shared=False)
709
zahlabut7ebb66e2021-09-01 22:39:49 +0300710 rule1 = self._create_qos_bw_limit_rule(
711 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
712 'direction': n_constants.EGRESS_DIRECTION})
713 rule2 = self._create_qos_bw_limit_rule(
714 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
715 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500716 # Check that the rules were added to the policy
zahlabut7ebb66e2021-09-01 22:39:49 +0300717 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
nfridman7717d9c2019-11-25 08:58:04 -0500718 policy['id'])['bandwidth_limit_rules']
zahlabut7ebb66e2021-09-01 22:39:49 +0300719
nfridman7717d9c2019-11-25 08:58:04 -0500720 rules_ids = [rule['id'] for rule in rules]
721 self.assertIn(rule1['id'], rules_ids)
722 self.assertIn(rule2['id'], rules_ids)
723
724 # Check that the rules creation fails for the same rule types
zahlabut7ebb66e2021-09-01 22:39:49 +0300725 self.assertRaises(
726 exceptions.Conflict,
727 self._create_qos_bw_limit_rule,
728 policy['id'],
729 {'max_kbps': 1025, 'max_burst_kbps': 1025,
730 'direction': n_constants.EGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500731
zahlabut7ebb66e2021-09-01 22:39:49 +0300732 self.assertRaises(
733 exceptions.Conflict,
734 self._create_qos_bw_limit_rule,
735 policy['id'],
736 {'max_kbps': 1025, 'max_burst_kbps': 1025,
737 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500738
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000739
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000740class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
741
742 force_tenant_isolation = True
743 credentials = ['primary', 'alt', 'admin']
Chandan Kumarc125fd12017-11-15 19:41:01 +0530744 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000745
746 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000747 def resource_setup(cls):
748 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530749 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000750
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000751 def _create_qos_policy(self, project_id=None):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000752 args = {'name': data_utils.rand_name('test-policy'),
753 'description': 'test policy',
754 'shared': False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000755 'project_id': project_id}
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000756 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
757 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
758
759 return qos_policy
760
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000761 def _make_admin_policy_shared_to_project_id(self, project_id):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000762 policy = self._create_qos_policy()
763 rbac_policy = self.admin_client.create_rbac_policy(
764 object_type='qos_policy',
765 object_id=policy['id'],
766 action='access_as_shared',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000767 target_tenant=project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000768 )['rbac_policy']
769
770 return {'policy': policy, 'rbac_policy': rbac_policy}
771
772 def _create_network(self, qos_policy_id, client, should_cleanup=True):
773 net = client.create_network(
774 name=data_utils.rand_name('test-network'),
775 qos_policy_id=qos_policy_id)['network']
776 if should_cleanup:
777 self.addCleanup(client.delete_network, net['id'])
778
779 return net
780
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000781 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000782 def test_policy_sharing_with_wildcard(self):
783 qos_pol = self.create_qos_policy(
784 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000785 description='test-shared-policy', shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000786 project_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000787 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
788
789 # test update shared False -> True
790 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
791 qos_pol['shared'] = True
792 self.client2.show_qos_policy(qos_pol['id'])
793 rbac_pol = {'target_tenant': '*',
794 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000795 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000796 'object_type': 'qos_policy',
797 'object_id': qos_pol['id'],
798 'action': 'access_as_shared'}
799
800 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
801 rbac_policies = [r for r in rbac_policies if r.pop('id')]
802 self.assertIn(rbac_pol, rbac_policies)
803
804 # update shared True -> False should fail because the policy is bound
805 # to a network
806 net = self._create_network(qos_pol['id'], self.admin_client, False)
807 with testtools.ExpectedException(exceptions.Conflict):
808 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
809
810 # delete the network, and update shared True -> False should pass now
811 self.admin_client.delete_network(net['id'])
812 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
813 qos_pol['shared'] = False
814 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
815
816 def _create_net_bound_qos_rbacs(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000817 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000818 self.client.tenant_id)
819 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
820
821 # add a wildcard rbac rule - now the policy globally shared
822 rbac_wildcard = self.admin_client.create_rbac_policy(
823 object_type='qos_policy',
824 object_id=qos_policy['id'],
825 action='access_as_shared',
826 target_tenant='*',
827 )['rbac_policy']
828
829 # tenant1 now uses qos policy for net
830 self._create_network(qos_policy['id'], self.client)
831
832 return rbac_for_client_tenant, rbac_wildcard
833
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000834 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000835 def test_net_bound_shared_policy_wildcard_and_project_id_wild_remove(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000836 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
837 # globally unshare the qos-policy, the specific share should remain
838 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
839 self.client.list_rbac_policies(id=client_rbac['id'])
840
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000841 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000842 def test_net_bound_shared_policy_wildcard_and_projectid_wild_remains(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000843 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
844 # remove client_rbac policy the wildcard share should remain
845 self.admin_client.delete_rbac_policy(client_rbac['id'])
846 self.client.list_rbac_policies(id=wildcard_rbac['id'])
847
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000848 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000849 def test_policy_sharing_with_wildcard_and_project_id(self):
850 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000851 self.client.tenant_id)
852 qos_policy, rbac = res['policy'], res['rbac_policy']
853 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
854 self.assertTrue(qos_pol['shared'])
855 with testtools.ExpectedException(exceptions.NotFound):
856 self.client2.show_qos_policy(qos_policy['id'])
857
858 # make the qos-policy globally shared
859 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
860 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
861 self.assertTrue(qos_pol['shared'])
862
863 # globally unshare the qos-policy, the specific share should remain
864 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
865 self.client.show_qos_policy(qos_policy['id'])
866 with testtools.ExpectedException(exceptions.NotFound):
867 self.client2.show_qos_policy(qos_policy['id'])
868 self.assertIn(rbac,
869 self.admin_client.list_rbac_policies()['rbac_policies'])
870
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000871 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000872 def test_policy_target_update(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000873 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000874 self.client.tenant_id)
875 # change to client2
876 update_res = self.admin_client.update_rbac_policy(
877 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
878 self.assertEqual(self.client2.tenant_id,
879 update_res['rbac_policy']['target_tenant'])
880 # make sure everything else stayed the same
881 res['rbac_policy'].pop('target_tenant')
882 update_res['rbac_policy'].pop('target_tenant')
883 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
884
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000885 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000886 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000887 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000888 self.client2.tenant_id)
889 qos_policy_id = res['policy']['id']
890 self._create_network(qos_policy_id, self.client2)
891 # a network with shared qos-policy should prevent the deletion of an
892 # rbac-policy required for it to be shared
893 with testtools.ExpectedException(exceptions.Conflict):
894 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
895
896 # a wildcard policy should allow the specific policy to be deleted
897 # since it allows the remaining port
898 wild = self.admin_client.create_rbac_policy(
899 object_type='qos_policy', object_id=res['policy']['id'],
900 action='access_as_shared', target_tenant='*')['rbac_policy']
901 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
902
903 # now that wildcard is the only remaining, it should be subjected to
904 # the same restriction
905 with testtools.ExpectedException(exceptions.Conflict):
906 self.admin_client.delete_rbac_policy(wild['id'])
907
908 # we can't update the policy to a different tenant
909 with testtools.ExpectedException(exceptions.Conflict):
910 self.admin_client.update_rbac_policy(
911 wild['id'], target_tenant=self.client2.tenant_id)
912
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000913 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000914 def test_regular_client_shares_to_another_regular_client(self):
915 # owned by self.admin_client
916 policy = self._create_qos_policy()
917 with testtools.ExpectedException(exceptions.NotFound):
918 self.client.show_qos_policy(policy['id'])
919 rbac_policy = self.admin_client.create_rbac_policy(
920 object_type='qos_policy', object_id=policy['id'],
921 action='access_as_shared',
922 target_tenant=self.client.tenant_id)['rbac_policy']
923 self.client.show_qos_policy(policy['id'])
924
925 self.assertIn(rbac_policy,
926 self.admin_client.list_rbac_policies()['rbac_policies'])
927 # ensure that 'client2' can't see the rbac-policy sharing the
928 # qos-policy to it because the rbac-policy belongs to 'client'
929 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
930 self.client2.list_rbac_policies()['rbac_policies']])
931
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000932 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000933 def test_filter_fields(self):
934 policy = self._create_qos_policy()
935 self.admin_client.create_rbac_policy(
936 object_type='qos_policy', object_id=policy['id'],
937 action='access_as_shared', target_tenant=self.client2.tenant_id)
938 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000939 ('project_id', 'target_tenant'))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000940 for fields in field_args:
941 res = self.admin_client.list_rbac_policies(fields=fields)
942 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
943
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000944 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000945 def test_rbac_policy_show(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000946 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000947 self.client.tenant_id)
948 p1 = res['rbac_policy']
949 p2 = self.admin_client.create_rbac_policy(
950 object_type='qos_policy', object_id=res['policy']['id'],
951 action='access_as_shared',
952 target_tenant='*')['rbac_policy']
953
954 self.assertEqual(
955 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
956 self.assertEqual(
957 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
958
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000959 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000960 def test_filter_rbac_policies(self):
961 policy = self._create_qos_policy()
962 rbac_pol1 = self.admin_client.create_rbac_policy(
963 object_type='qos_policy', object_id=policy['id'],
964 action='access_as_shared',
965 target_tenant=self.client2.tenant_id)['rbac_policy']
966 rbac_pol2 = self.admin_client.create_rbac_policy(
967 object_type='qos_policy', object_id=policy['id'],
968 action='access_as_shared',
969 target_tenant=self.admin_client.tenant_id)['rbac_policy']
970 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
971 'rbac_policies']
972 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
973 'rbac_policies']
974 self.assertEqual(1, len(res1))
975 self.assertEqual(1, len(res2))
976 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
977 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
978
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000979 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000980 def test_regular_client_blocked_from_sharing_anothers_policy(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000981 qos_policy = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000982 self.client.tenant_id)['policy']
983 with testtools.ExpectedException(exceptions.BadRequest):
984 self.client.create_rbac_policy(
985 object_type='qos_policy', object_id=qos_policy['id'],
986 action='access_as_shared',
987 target_tenant=self.client2.tenant_id)
988
989 # make sure the rbac-policy is invisible to the tenant for which it's
990 # being shared
991 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
992
993
994class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
995 VALID_DSCP_MARK1 = 56
996 VALID_DSCP_MARK2 = 48
997
Chandan Kumarc125fd12017-11-15 19:41:01 +0530998 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000999
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001000 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001001 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001002 def resource_setup(cls):
1003 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
1004
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001005 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001006 def test_rule_create(self):
1007 policy = self.create_qos_policy(name='test-policy',
1008 description='test policy',
1009 shared=False)
1010 rule = self.admin_client.create_dscp_marking_rule(
1011 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1012
1013 # Test 'show rule'
1014 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1015 policy['id'], rule['id'])
1016 retrieved_rule = retrieved_rule['dscp_marking_rule']
1017 self.assertEqual(rule['id'], retrieved_rule['id'])
1018 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
1019
1020 # Test 'list rules'
1021 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
1022 rules = rules['dscp_marking_rules']
1023 rules_ids = [r['id'] for r in rules]
1024 self.assertIn(rule['id'], rules_ids)
1025
1026 # Test 'show policy'
1027 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1028 policy_rules = retrieved_policy['policy']['rules']
1029 self.assertEqual(1, len(policy_rules))
1030 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +00001031 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001032 policy_rules[0]['type'])
1033
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001034 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001035 def test_rule_create_fail_for_the_same_type(self):
1036 policy = self.create_qos_policy(name='test-policy',
1037 description='test policy',
1038 shared=False)
1039 self.admin_client.create_dscp_marking_rule(
1040 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1041
1042 self.assertRaises(exceptions.Conflict,
1043 self.admin_client.create_dscp_marking_rule,
1044 policy_id=policy['id'],
1045 dscp_mark=self.VALID_DSCP_MARK2)
1046
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001047 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001048 def test_rule_update(self):
1049 policy = self.create_qos_policy(name='test-policy',
1050 description='test policy',
1051 shared=False)
1052 rule = self.admin_client.create_dscp_marking_rule(
1053 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1054
1055 self.admin_client.update_dscp_marking_rule(
1056 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
1057
1058 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1059 policy['id'], rule['id'])
1060 retrieved_policy = retrieved_policy['dscp_marking_rule']
1061 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
1062
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001063 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001064 def test_rule_delete(self):
1065 policy = self.create_qos_policy(name='test-policy',
1066 description='test policy',
1067 shared=False)
1068 rule = self.admin_client.create_dscp_marking_rule(
1069 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1070
1071 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1072 policy['id'], rule['id'])
1073 retrieved_policy = retrieved_policy['dscp_marking_rule']
1074 self.assertEqual(rule['id'], retrieved_policy['id'])
1075
1076 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
1077 self.assertRaises(exceptions.NotFound,
1078 self.admin_client.show_dscp_marking_rule,
1079 policy['id'], rule['id'])
1080
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001081 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001082 def test_rule_create_rule_nonexistent_policy(self):
1083 self.assertRaises(
1084 exceptions.NotFound,
1085 self.admin_client.create_dscp_marking_rule,
1086 'policy', self.VALID_DSCP_MARK1)
1087
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001088 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001089 def test_rule_create_forbidden_for_regular_tenants(self):
1090 self.assertRaises(
1091 exceptions.Forbidden,
1092 self.client.create_dscp_marking_rule,
1093 'policy', self.VALID_DSCP_MARK1)
1094
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001095 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001096 def test_invalid_rule_create(self):
1097 policy = self.create_qos_policy(name='test-policy',
1098 description='test policy',
1099 shared=False)
1100 self.assertRaises(
1101 exceptions.BadRequest,
1102 self.admin_client.create_dscp_marking_rule,
1103 policy['id'], 58)
1104
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001105 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001106 def test_get_rules_by_policy(self):
1107 policy1 = self.create_qos_policy(name='test-policy1',
1108 description='test policy1',
1109 shared=False)
1110 rule1 = self.admin_client.create_dscp_marking_rule(
1111 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1112
1113 policy2 = self.create_qos_policy(name='test-policy2',
1114 description='test policy2',
1115 shared=False)
1116 rule2 = self.admin_client.create_dscp_marking_rule(
1117 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
1118
1119 # Test 'list rules'
1120 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
1121 rules = rules['dscp_marking_rules']
1122 rules_ids = [r['id'] for r in rules]
1123 self.assertIn(rule1['id'], rules_ids)
1124 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001125
nfridman23b44ad2019-09-05 09:46:50 -04001126 @decorators.idempotent_id('19ed2286-ccb1-11e9-87d7-525400d6f522')
1127 def test_qos_dscp_create_and_update(self):
1128 """This test covers:
1129
1130 1.Creating a basic QoS policy with DSCP marking rule.
1131 2.Updating QoS policy:
1132 Administrator should have the ability to update existing QoS policy.
1133 This test should verify that:
1134 It's possible to update the existing DSCP marking rule with all of
1135 the valid marks between 0-56, except of the invalid marks:
1136 2-6, 42, 44, and 50-54 (which should be forbidden)
1137 """
1138
1139 def _test_update_dscp_mark_values(self, dscp_policy_id, rule_id):
1140 for mark in range(n_constants.VALID_DSCP_MARKS[1],
1141 self.VALID_DSCP_MARK1 + 1):
1142 if mark in n_constants.VALID_DSCP_MARKS:
1143 self.admin_client.update_dscp_marking_rule(
1144 dscp_policy_id, rule_id, dscp_mark=mark)
1145
1146 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1147 dscp_policy_id, rule_id)['dscp_marking_rule']
1148 self.assertEqual(mark, retrieved_rule['dscp_mark'],
1149 """current DSCP mark is incorrect:
1150 expected value {0} actual value {1}
1151 """.format(mark,
1152 retrieved_rule['dscp_mark']))
1153
1154 else:
1155 self.assertRaises(exceptions.BadRequest,
1156 self.admin_client.create_dscp_marking_rule,
1157 dscp_policy_id,
1158 mark)
1159 # Setup network
1160 self.network = self.create_network()
1161
1162 # Create QoS policy
1163 dscp_policy_id = self.create_qos_policy(
1164 name='test-policy',
1165 description='test-qos-policy',
1166 shared=True)['id']
1167
1168 # Associate QoS to the network
1169 self.admin_client.update_network(
1170 self.network['id'], qos_policy_id=dscp_policy_id)
1171
1172 # Set a new DSCP rule with the first mark in range
1173 rule_id = self.admin_client.create_dscp_marking_rule(
1174 dscp_policy_id,
1175 n_constants.VALID_DSCP_MARKS[0])[
1176 'dscp_marking_rule']['id']
1177
1178 # Validate that the rule was set up properly
1179 retrieved_rule = self.client.show_dscp_marking_rule(
1180 dscp_policy_id, rule_id)['dscp_marking_rule']
1181 self.assertEqual(n_constants.VALID_DSCP_MARKS[0],
1182 retrieved_rule['dscp_mark'],
1183 """current DSCP mark is incorrect:
1184 expected value {0} actual value {1}
1185 """.format(n_constants.VALID_DSCP_MARKS[0],
1186 retrieved_rule['dscp_mark']))
1187
1188 # Try to set marks in range 8:56 (invalid marks should raise an error)
1189 _test_update_dscp_mark_values(self, dscp_policy_id, rule_id)
1190
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001191
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001192class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
1193 DIRECTION_EGRESS = "egress"
1194 DIRECTION_INGRESS = "ingress"
1195 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
1196 RULES_NAME = RULE_NAME + "s"
Chandan Kumarc125fd12017-11-15 19:41:01 +05301197 required_extensions = [qos_apidef.ALIAS]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001198
1199 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001200 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001201 def resource_setup(cls):
1202 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
1203
zahlabut7ebb66e2021-09-01 22:39:49 +03001204 @classmethod
1205 def setup_clients(cls):
1206 super(QosMinimumBandwidthRuleTestJSON, cls).setup_clients()
1207 cls.qos_min_bw_rules_client = \
1208 cls.os_admin.qos_minimum_bandwidth_rules_client
1209 cls.qos_min_bw_rules_client_primary = \
1210 cls.os_primary.qos_minimum_bandwidth_rules_client
1211
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001212 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001213 def test_rule_create(self):
1214 policy = self.create_qos_policy(name='test-policy',
1215 description='test policy',
1216 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001217 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1218 qos_policy_id=policy['id'],
1219 **{'direction': self.DIRECTION_EGRESS,
1220 'min_kbps': 1138})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001221
1222 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +03001223 retrieved_rule = \
1224 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1225 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001226 retrieved_rule = retrieved_rule[self.RULE_NAME]
1227 self.assertEqual(rule['id'], retrieved_rule['id'])
1228 self.assertEqual(1138, retrieved_rule['min_kbps'])
1229 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1230
1231 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001232 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1233 policy['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001234 rules = rules[self.RULES_NAME]
1235 rules_ids = [r['id'] for r in rules]
1236 self.assertIn(rule['id'], rules_ids)
1237
1238 # Test 'show policy'
1239 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1240 policy_rules = retrieved_policy['policy']['rules']
1241 self.assertEqual(1, len(policy_rules))
1242 self.assertEqual(rule['id'], policy_rules[0]['id'])
1243 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1244 policy_rules[0]['type'])
1245
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001246 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001247 def test_rule_create_fail_for_missing_min_kbps(self):
1248 policy = self.create_qos_policy(name='test-policy',
1249 description='test policy',
1250 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001251 self.assertRaises(
1252 exceptions.BadRequest,
1253 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1254 qos_policy_id=policy['id'],
1255 **{'direction': self.DIRECTION_EGRESS})
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001256
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001257 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001258 def test_rule_create_fail_for_the_same_type(self):
1259 policy = self.create_qos_policy(name='test-policy',
1260 description='test policy',
1261 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001262 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1263 qos_policy_id=policy['id'],
1264 **{'direction': self.DIRECTION_EGRESS,
1265 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001266
zahlabut7ebb66e2021-09-01 22:39:49 +03001267 self.assertRaises(
1268 exceptions.Conflict,
1269 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1270 qos_policy_id=policy['id'],
1271 **{'direction': self.DIRECTION_EGRESS,
1272 'min_kbps': 201})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001273
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001274 @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936')
1275 @utils.requires_ext(extension="qos-bw-minimum-ingress",
1276 service="network")
1277 def test_rule_create_pass_for_direction_ingress(self):
1278 policy = self.create_qos_policy(name='test-policy',
1279 description='test policy',
1280 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001281 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1282 qos_policy_id=policy['id'],
1283 **{'direction': self.DIRECTION_INGRESS,
1284 'min_kbps': 201})
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001285
1286 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1287 policy_rules = retrieved_policy['policy']['rules']
1288 self.assertEqual(1, len(policy_rules))
1289 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1290 policy_rules[0]['type'])
1291 self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction'])
1292
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001293 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001294 def test_rule_update(self):
1295 policy = self.create_qos_policy(name='test-policy',
1296 description='test policy',
1297 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001298 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1299 qos_policy_id=policy['id'],
1300 **{'direction': self.DIRECTION_EGRESS,
1301 'min_kbps': 300})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001302
zahlabut7ebb66e2021-09-01 22:39:49 +03001303 self.qos_min_bw_rules_client.update_minimum_bandwidth_rule(
1304 policy['id'], rule['id'],
1305 **{'min_kbps': 350, 'direction': self.DIRECTION_EGRESS})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001306
zahlabut7ebb66e2021-09-01 22:39:49 +03001307 retrieved_policy = \
1308 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1309 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001310 retrieved_policy = retrieved_policy[self.RULE_NAME]
1311 self.assertEqual(350, retrieved_policy['min_kbps'])
1312 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1313
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001314 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001315 def test_rule_delete(self):
1316 policy = self.create_qos_policy(name='test-policy',
1317 description='test policy',
1318 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001319 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1320 policy['id'],
1321 **{'direction': self.DIRECTION_EGRESS,
1322 'min_kbps': 200})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001323
zahlabut7ebb66e2021-09-01 22:39:49 +03001324 retrieved_policy = \
1325 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1326 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001327 retrieved_policy = retrieved_policy[self.RULE_NAME]
1328 self.assertEqual(rule['id'], retrieved_policy['id'])
1329
zahlabut7ebb66e2021-09-01 22:39:49 +03001330 self.qos_min_bw_rules_client.delete_minimum_bandwidth_rule(
1331 policy['id'], rule['id'])
1332 self.assertRaises(
1333 exceptions.NotFound,
1334 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule,
1335 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001336
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001337 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001338 def test_rule_create_rule_nonexistent_policy(self):
1339 self.assertRaises(
1340 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +03001341 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1342 'policy',
1343 **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001344
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001345 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001346 def test_rule_create_forbidden_for_regular_tenants(self):
1347 self.assertRaises(
1348 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +03001349 self.qos_min_bw_rules_client_primary.create_minimum_bandwidth_rule,
1350 'policy', **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 300})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001351
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001352 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001353 def test_get_rules_by_policy(self):
1354 policy1 = self.create_qos_policy(name='test-policy1',
1355 description='test policy1',
1356 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001357 rule1 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1358 qos_policy_id=policy1['id'],
1359 **{'direction': self.DIRECTION_EGRESS,
1360 'min_kbps': 200})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001361
1362 policy2 = self.create_qos_policy(name='test-policy2',
1363 description='test policy2',
1364 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001365 rule2 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1366 qos_policy_id=policy2['id'],
1367 **{'direction': self.DIRECTION_EGRESS,
1368 'min_kbps': 5000})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001369
1370 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001371 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1372 policy1['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001373 rules = rules[self.RULES_NAME]
1374 rules_ids = [r['id'] for r in rules]
1375 self.assertIn(rule1['id'], rules_ids)
1376 self.assertNotIn(rule2['id'], rules_ids)
1377
1378
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001379class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1380 base.BaseAdminNetworkTest):
1381
1382 resource = 'policy'
1383 plural_name = 'policies'
1384
1385 # Use unique description to isolate the tests from other QoS tests
1386 list_kwargs = {'description': 'search-criteria-test'}
1387 list_as_admin = True
1388
Chandan Kumarc125fd12017-11-15 19:41:01 +05301389 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001390
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001391 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001392 def resource_setup(cls):
1393 super(QosSearchCriteriaTest, cls).resource_setup()
1394 for name in cls.resource_names:
1395 cls.create_qos_policy(
1396 name=name, description='search-criteria-test')
1397
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001398 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001399 def test_list_sorts_asc(self):
1400 self._test_list_sorts_asc()
1401
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001402 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001403 def test_list_sorts_desc(self):
1404 self._test_list_sorts_desc()
1405
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001406 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001407 def test_list_pagination(self):
1408 self._test_list_pagination()
1409
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001410 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001411 def test_list_pagination_with_marker(self):
1412 self._test_list_pagination_with_marker()
1413
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001414 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001415 def test_list_pagination_with_href_links(self):
1416 self._test_list_pagination_with_href_links()
1417
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001418 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001419 def test_list_pagination_page_reverse_asc(self):
1420 self._test_list_pagination_page_reverse_asc()
1421
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001422 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001423 def test_list_pagination_page_reverse_desc(self):
1424 self._test_list_pagination_page_reverse_desc()
1425
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001426 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001427 def test_list_pagination_page_reverse_with_href_links(self):
1428 self._test_list_pagination_page_reverse_with_href_links()
1429
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001430 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001431 def test_list_no_pagination_limit_0(self):
1432 self._test_list_no_pagination_limit_0()