blob: f1867d1633f120f7a864033482362b59c58b1031 [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
Slawek Kaplonskiec162e02024-03-06 12:21:24 +010015
16import ddt
Chandan Kumarc125fd12017-11-15 19:41:01 +053017from neutron_lib.api.definitions import qos as qos_apidef
nfridman23b44ad2019-09-05 09:46:50 -040018from neutron_lib import constants as n_constants
Chandan Kumarc125fd12017-11-15 19:41:01 +053019from neutron_lib.services.qos import constants as qos_consts
20from tempest.common import utils
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000021from tempest.lib.common.utils import data_utils
zahlabut7ebb66e2021-09-01 22:39:49 +030022from tempest.lib.common.utils import test_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000023from tempest.lib import decorators
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000024from tempest.lib import exceptions
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
nfridman07f0e782019-11-04 09:12:58 -050030CONF = config.CONF
Sławek Kapłoński153f3452017-03-24 22:04:53 +000031
32
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000033class QosTestJSON(base.BaseAdminNetworkTest):
Jakub Libosvar1982aa12017-05-30 11:15:33 +000034
Chandan Kumarc125fd12017-11-15 19:41:01 +053035 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000036
zahlabut7ebb66e2021-09-01 22:39:49 +030037 @classmethod
38 def setup_clients(cls):
39 super(QosTestJSON, cls).setup_clients()
40 cls.qos_bw_limit_rule_client = \
41 cls.os_admin.qos_limit_bandwidth_rules_client
42
elajkat757f3f12022-01-28 11:17:55 +010043 def setUp(self):
44 super(QosTestJSON, self).setUp()
45 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
46
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +000047 @staticmethod
48 def _get_driver_details(rule_type_details, driver_name):
49 for driver in rule_type_details['drivers']:
50 if driver['name'] == driver_name:
51 return driver
52
zahlabut7ebb66e2021-09-01 22:39:49 +030053 def _create_qos_bw_limit_rule(self, policy_id, rule_data):
54 rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule(
55 qos_policy_id=policy_id,
56 **rule_data)['bandwidth_limit_rule']
57 self.addCleanup(
58 test_utils.call_and_ignore_notfound_exc,
59 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule,
60 policy_id, rule['id'])
61 return rule
62
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000063 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000064 def test_create_policy(self):
65 policy = self.create_qos_policy(name='test-policy',
66 description='test policy desc1',
67 shared=False)
68
69 # Test 'show policy'
70 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
71 retrieved_policy = retrieved_policy['policy']
72 self.assertEqual('test-policy', retrieved_policy['name'])
73 self.assertEqual('test policy desc1', retrieved_policy['description'])
74 self.assertFalse(retrieved_policy['shared'])
75
76 # Test 'list policies'
77 policies = self.admin_client.list_qos_policies()['policies']
78 policies_ids = [p['id'] for p in policies]
79 self.assertIn(policy['id'], policies_ids)
80
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000081 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Chandan Kumarc125fd12017-11-15 19:41:01 +053082 @utils.requires_ext(extension="project-id", service="network")
Henry Gessaufa6c78d2016-10-09 19:56:09 -040083 def test_show_policy_has_project_id(self):
elajkat757f3f12022-01-28 11:17:55 +010084 policy = self.create_qos_policy(name=self.policy_name, shared=False)
Henry Gessaufa6c78d2016-10-09 19:56:09 -040085 body = self.admin_client.show_qos_policy(policy['id'])
86 show_policy = body['policy']
87 self.assertIn('project_id', show_policy)
Takashi Kajinamida451772023-03-22 00:19:39 +090088 self.assertEqual(self.admin_client.project_id,
Henry Gessaufa6c78d2016-10-09 19:56:09 -040089 show_policy['project_id'])
Henry Gessaufa6c78d2016-10-09 19:56:09 -040090
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000091 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000092 def test_list_policy_filter_by_name(self):
yatinkarel65fa2c02022-01-28 13:44:19 +053093 policy1 = 'test' + data_utils.rand_name("policy")
94 policy2 = 'test' + data_utils.rand_name("policy")
95 self.create_qos_policy(name=policy1, description='test policy',
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000096 shared=False)
yatinkarel65fa2c02022-01-28 13:44:19 +053097 self.create_qos_policy(name=policy2, description='test policy',
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000098 shared=False)
99
100 policies = (self.admin_client.
yatinkarel65fa2c02022-01-28 13:44:19 +0530101 list_qos_policies(name=policy1)['policies'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000102 self.assertEqual(1, len(policies))
103
104 retrieved_policy = policies[0]
yatinkarel65fa2c02022-01-28 13:44:19 +0530105 self.assertEqual(policy1, retrieved_policy['name'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000106
likangkang01afd73f72020-06-01 16:53:59 +0800107 @decorators.idempotent_id('dde0b449-a400-4a87-b5a5-4d1c413c917b')
108 def test_list_policy_sort_by_name(self):
109 policyA = 'A' + data_utils.rand_name("policy")
110 policyB = 'B' + data_utils.rand_name("policy")
111 self.create_qos_policy(name=policyA, description='test policy',
112 shared=False)
113 self.create_qos_policy(name=policyB, description='test policy',
114 shared=False)
115
116 param = {
117 'sort_key': 'name',
118 'sort_dir': 'asc'
119 }
120 policies = (self.admin_client.list_qos_policies(**param)['policies'])
121 policy_names = [p['name'] for p in policies]
122 self.assertLess(policy_names.index(policyA),
123 policy_names.index(policyB))
124
125 param = {
126 'sort_key': 'name',
127 'sort_dir': 'desc'
128 }
129 policies = (self.admin_client.list_qos_policies(**param)['policies'])
130 policy_names = [p['name'] for p in policies]
131 self.assertLess(policy_names.index(policyB),
132 policy_names.index(policyA))
133
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000134 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000135 def test_policy_update(self):
Takashi Kajinamida451772023-03-22 00:19:39 +0900136 policy = self.create_qos_policy(
137 name=self.policy_name,
138 description='',
139 shared=False,
140 project_id=self.admin_client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000141 self.admin_client.update_qos_policy(policy['id'],
142 description='test policy desc2',
143 shared=True)
144
145 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
146 retrieved_policy = retrieved_policy['policy']
147 self.assertEqual('test policy desc2', retrieved_policy['description'])
148 self.assertTrue(retrieved_policy['shared'])
149 self.assertEqual([], retrieved_policy['rules'])
150
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000151 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000152 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100153 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000154 description='',
155 shared=False,
Takashi Kajinamida451772023-03-22 00:19:39 +0900156 project_id=self.client.project_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000157 self.assertRaises(
158 exceptions.Forbidden,
159 self.client.update_qos_policy,
160 policy['id'], description='test policy')
161
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000162 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000163 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
Takashi Kajinamida451772023-03-22 00:19:39 +0900164 policy = self.create_qos_policy(
165 name=self.policy_name,
166 description='',
167 shared=False,
168 project_id=self.admin_client.project_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000169 self.assertRaises(
170 exceptions.NotFound,
171 self.client.update_qos_policy,
172 policy['id'], description='test policy')
173
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000174 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000175 def test_shared_policy_update(self):
Takashi Kajinamida451772023-03-22 00:19:39 +0900176 policy = self.create_qos_policy(
177 name=self.policy_name,
178 description='',
179 shared=True,
180 project_id=self.admin_client.project_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000181
182 self.admin_client.update_qos_policy(policy['id'],
183 description='test policy desc2')
184 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
185 retrieved_policy = retrieved_policy['policy']
186 self.assertTrue(retrieved_policy['shared'])
187
188 self.admin_client.update_qos_policy(policy['id'],
189 shared=False)
190 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
191 retrieved_policy = retrieved_policy['policy']
192 self.assertFalse(retrieved_policy['shared'])
193
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000194 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000195 def test_delete_policy(self):
196 policy = self.admin_client.create_qos_policy(
197 'test-policy', 'desc', True)['policy']
198
199 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
200 retrieved_policy = retrieved_policy['policy']
201 self.assertEqual('test-policy', retrieved_policy['name'])
202
203 self.admin_client.delete_qos_policy(policy['id'])
204 self.assertRaises(exceptions.NotFound,
205 self.admin_client.show_qos_policy, policy['id'])
206
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000207 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000208 def test_list_admin_rule_types(self):
209 self._test_list_rule_types(self.admin_client)
210
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000211 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000212 def test_list_regular_rule_types(self):
213 self._test_list_rule_types(self.client)
214
215 def _test_list_rule_types(self, client):
216 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000217 # Since returned rule types depends on loaded backend drivers this test
218 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000219 #
220 # In theory, we could make the test conditional on which ml2 drivers
221 # are enabled in gate (or more specifically, on which supported qos
222 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200223 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000224 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000225
226 rule_types = client.list_qos_rule_types()
227 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000228
229 # Verify that only required fields present in rule details
230 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000231 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000232
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000233 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
234 def test_show_rule_type_details_as_user(self):
235 self.assertRaises(
236 exceptions.Forbidden,
237 self.client.show_qos_rule_type,
238 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
239
240 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
241 def test_show_rule_type_details_as_admin(self):
242 # Since returned rule types depend on loaded backend drivers this test
243 # is checking only if returned keys are same as expected keys
244
245 # In theory, we could make the test conditional on which ml2 drivers
246 # are enabled in gate, but that option doesn't seem to be
247 # available through tempest.lib framework
248 expected_rule_type_details_keys = ['type', 'drivers']
249
250 rule_type_details = self.admin_client.show_qos_rule_type(
251 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
252
253 # Verify that only required fields present in rule details
254 self.assertEqual(
255 sorted(tuple(expected_rule_type_details_keys)),
256 sorted(tuple(rule_type_details.keys())))
257
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000258 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000259 def test_policy_association_with_admin_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100260 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000261 description='test policy',
262 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200263 network = self.create_network('test network', shared=True,
264 qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000265
266 retrieved_network = self.admin_client.show_network(network['id'])
267 self.assertEqual(
268 policy['id'], retrieved_network['network']['qos_policy_id'])
269
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000270 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000271 def test_policy_association_with_tenant_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100272 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000273 description='test policy',
274 shared=True)
275 network = self.create_network('test network',
276 qos_policy_id=policy['id'])
277
278 retrieved_network = self.admin_client.show_network(network['id'])
279 self.assertEqual(
280 policy['id'], retrieved_network['network']['qos_policy_id'])
281
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000282 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000283 def test_policy_association_with_network_nonexistent_policy(self):
284 self.assertRaises(
285 exceptions.NotFound,
286 self.create_network,
287 'test network',
288 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
289
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000290 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000291 def test_policy_association_with_network_non_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100292 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000293 description='test policy',
294 shared=False)
295 self.assertRaises(
296 exceptions.NotFound,
297 self.create_network,
298 'test network', qos_policy_id=policy['id'])
299
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000300 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000301 def test_policy_update_association_with_admin_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100302 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000303 description='test policy',
304 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200305 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000306 retrieved_network = self.admin_client.show_network(network['id'])
307 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
308
309 self.admin_client.update_network(network['id'],
310 qos_policy_id=policy['id'])
311 retrieved_network = self.admin_client.show_network(network['id'])
312 self.assertEqual(
313 policy['id'], retrieved_network['network']['qos_policy_id'])
314
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000315 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000316 def test_policy_association_with_port_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100317 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000318 description='test policy',
319 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200320 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000321 port = self.create_port(network, qos_policy_id=policy['id'])
322
323 retrieved_port = self.admin_client.show_port(port['id'])
324 self.assertEqual(
325 policy['id'], retrieved_port['port']['qos_policy_id'])
326
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000327 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000328 def test_policy_association_with_port_nonexistent_policy(self):
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200329 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000330 self.assertRaises(
331 exceptions.NotFound,
332 self.create_port,
333 network,
334 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
335
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000336 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000337 def test_policy_association_with_port_non_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100338 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000339 description='test policy',
340 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200341 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000342 self.assertRaises(
343 exceptions.NotFound,
344 self.create_port,
345 network, qos_policy_id=policy['id'])
346
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000347 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000348 def test_policy_update_association_with_port_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100349 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000350 description='test policy',
351 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200352 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000353 port = self.create_port(network)
354 retrieved_port = self.admin_client.show_port(port['id'])
355 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
356
357 self.client.update_port(port['id'], qos_policy_id=policy['id'])
358 retrieved_port = self.admin_client.show_port(port['id'])
359 self.assertEqual(
360 policy['id'], retrieved_port['port']['qos_policy_id'])
361
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000362 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000363 def test_delete_not_allowed_if_policy_in_use_by_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100364 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000365 description='test policy',
366 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200367 self.create_network('test network', qos_policy_id=policy['id'],
368 shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000369 self.assertRaises(
370 exceptions.Conflict,
371 self.admin_client.delete_qos_policy, policy['id'])
372
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000373 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000374 def test_delete_not_allowed_if_policy_in_use_by_port(self):
elajkat757f3f12022-01-28 11:17:55 +0100375 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000376 description='test policy',
377 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200378 network = self.create_network('test network', shared=True)
Sławek Kapłońskie100c4d2017-08-23 21:18:34 +0000379 self.create_port(network, qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000380 self.assertRaises(
381 exceptions.Conflict,
382 self.admin_client.delete_qos_policy, policy['id'])
383
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000384 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000385 def test_qos_policy_delete_with_rules(self):
elajkat757f3f12022-01-28 11:17:55 +0100386 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000387 description='test policy',
388 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300389 self._create_qos_bw_limit_rule(
390 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000391 self.admin_client.delete_qos_policy(policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000392 with testtools.ExpectedException(exceptions.NotFound):
393 self.admin_client.show_qos_policy(policy['id'])
394
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000395 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000396 def test_get_policy_that_is_shared(self):
397 policy = self.create_qos_policy(
398 name='test-policy-shared',
399 description='shared policy',
400 shared=True,
Takashi Kajinamida451772023-03-22 00:19:39 +0900401 project_id=self.admin_client.project_id)
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000402 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
403 self.assertEqual(obtained_policy, policy)
404
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000405 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100406 def test_policy_create_forbidden_for_regular_tenants(self):
407 self.assertRaises(
408 exceptions.Forbidden,
409 self.client.create_qos_policy,
410 'test-policy', 'test policy', False)
411
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900412 @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
413 def test_default_policy_creating_network_without_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530414 project_id = self.create_project()['id']
elajkat757f3f12022-01-28 11:17:55 +0100415 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000416 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900417 is_default=True)
418 network = self.create_network('test network', client=self.admin_client,
419 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900420 retrieved_network = self.admin_client.show_network(network['id'])
421 self.assertEqual(
422 policy['id'], retrieved_network['network']['qos_policy_id'])
423
424 @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
425 def test_default_policy_creating_network_with_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530426 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900427 self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000428 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900429 is_default=True)
430 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000431 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900432 network = self.create_network('test network', client=self.admin_client,
433 project_id=project_id,
434 qos_policy_id=policy['id'])
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900435 retrieved_network = self.admin_client.show_network(network['id'])
436 self.assertEqual(
437 policy['id'], retrieved_network['network']['qos_policy_id'])
438
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100439 @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229')
440 def test_user_create_port_with_admin_qos_policy(self):
441 qos_policy = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +0100442 name=self.policy_name,
Takashi Kajinamida451772023-03-22 00:19:39 +0900443 project_id=self.admin_client.project_id,
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100444 shared=False)
445 network = self.create_network(
446 'test network', client=self.admin_client,
Takashi Kajinamida451772023-03-22 00:19:39 +0900447 project_id=self.client.project_id,
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100448 qos_policy_id=qos_policy['id'])
449 port = self.create_port(network)
450 self.assertEqual(network['id'], port['network_id'])
451
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000452
453class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000454
zahlabut7ebb66e2021-09-01 22:39:49 +0300455 credentials = ['primary', 'admin']
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000456 direction = None
Chandan Kumarc125fd12017-11-15 19:41:01 +0530457 required_extensions = [qos_apidef.ALIAS]
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000458
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000459 @classmethod
zahlabut7ebb66e2021-09-01 22:39:49 +0300460 def setup_clients(cls):
461 super(QosBandwidthLimitRuleTestJSON, cls).setup_clients()
462 cls.qos_bw_limit_rule_client = \
463 cls.os_admin.qos_limit_bandwidth_rules_client
464 cls.qos_bw_limit_rule_client_primary = \
465 cls.os_primary.qos_limit_bandwidth_rules_client
466
467 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900468 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000469 def resource_setup(cls):
470 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
471
elajkat757f3f12022-01-28 11:17:55 +0100472 def setUp(self):
473 super(QosBandwidthLimitRuleTestJSON, self).setUp()
474 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
475
zahlabut7ebb66e2021-09-01 22:39:49 +0300476 def _create_qos_bw_limit_rule(self, policy_id, rule_data):
477 rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule(
478 qos_policy_id=policy_id,
479 **rule_data)['bandwidth_limit_rule']
480 self.addCleanup(
481 test_utils.call_and_ignore_notfound_exc,
482 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule,
483 policy_id, rule['id'])
484 return rule
485
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000486 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000487 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +0100488 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000489 description='test policy',
490 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300491 rule = self._create_qos_bw_limit_rule(
492 policy['id'],
493 {'max_kbps': 200, 'max_burst_kbps': 1337, 'direction': 'ingress'})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000494
495 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +0300496 retrieved_rule = \
497 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
498 policy['id'], rule['id'])
499
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000500 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
501 self.assertEqual(rule['id'], retrieved_rule['id'])
502 self.assertEqual(200, retrieved_rule['max_kbps'])
503 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300504 self.assertEqual('ingress', retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000505
506 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300507 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
508 policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000509 rules = rules['bandwidth_limit_rules']
510 rules_ids = [r['id'] for r in rules]
511 self.assertIn(rule['id'], rules_ids)
512
513 # Test 'show policy'
514 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
515 policy_rules = retrieved_policy['policy']['rules']
516 self.assertEqual(1, len(policy_rules))
517 self.assertEqual(rule['id'], policy_rules[0]['id'])
518 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
519 policy_rules[0]['type'])
520
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000521 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000522 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +0100523 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000524 description='test policy',
525 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300526 self._create_qos_bw_limit_rule(
527 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000528
zahlabut7ebb66e2021-09-01 22:39:49 +0300529 self.assertRaises(
530 exceptions.Conflict,
531 self._create_qos_bw_limit_rule,
532 policy['id'],
533 {'max_kbps': 201, 'max_burst_kbps': 1338})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000534
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000535 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000536 def test_rule_update(self):
Slawek Kaplonskiec162e02024-03-06 12:21:24 +0100537 self._test_rule_update(opposite_direction=None)
538
539 def _test_rule_update(self, opposite_direction=None):
elajkat757f3f12022-01-28 11:17:55 +0100540 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000541 description='test policy',
542 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300543 rule = self._create_qos_bw_limit_rule(
544 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000545
Slawek Kaplonskiec162e02024-03-06 12:21:24 +0100546 if opposite_direction:
zahlabut7ebb66e2021-09-01 22:39:49 +0300547 self.qos_bw_limit_rule_client.update_limit_bandwidth_rule(
548 policy['id'], rule['id'],
549 **{'max_kbps': 200, 'max_burst_kbps': 1337,
Slawek Kaplonskiec162e02024-03-06 12:21:24 +0100550 'direction': opposite_direction})
zahlabut7ebb66e2021-09-01 22:39:49 +0300551 else:
552 self.qos_bw_limit_rule_client.update_limit_bandwidth_rule(
553 policy['id'], rule['id'],
554 **{'max_kbps': 200, 'max_burst_kbps': 1337})
555 retrieved_policy = self.qos_bw_limit_rule_client.\
556 show_limit_bandwidth_rule(policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000557 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
558 self.assertEqual(200, retrieved_policy['max_kbps'])
559 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Slawek Kaplonskiec162e02024-03-06 12:21:24 +0100560 if opposite_direction:
561 self.assertEqual(opposite_direction,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000562 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000563
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000564 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000565 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +0100566 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000567 description='test policy',
568 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300569 rule = self._create_qos_bw_limit_rule(
570 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
571 retrieved_policy = \
572 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
573 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000574 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
575 self.assertEqual(rule['id'], retrieved_policy['id'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300576 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule(
577 policy['id'], rule['id'])
578 self.assertRaises(
579 exceptions.NotFound,
580 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule,
581 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000582
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000583 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000584 def test_rule_create_rule_nonexistent_policy(self):
585 self.assertRaises(
586 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300587 self._create_qos_bw_limit_rule,
588 'policy', {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000589
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000590 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000591 def test_rule_create_forbidden_for_regular_tenants(self):
592 self.assertRaises(
593 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300594 self.qos_bw_limit_rule_client_primary.create_limit_bandwidth_rule,
595 'policy', **{'max_kbps': 1, 'max_burst_kbps': 2})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000596
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000597 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000598 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100599 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000600 description='test policy',
601 shared=False,
Takashi Kajinamida451772023-03-22 00:19:39 +0900602 project_id=self.client.project_id)
zahlabut7ebb66e2021-09-01 22:39:49 +0300603 rule = self._create_qos_bw_limit_rule(
604 policy['id'],
605 {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000606 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400607 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300608 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
609 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000610
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000611 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000612 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300613 policy = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +0100614 name=self.policy_name,
zahlabut7ebb66e2021-09-01 22:39:49 +0300615 description='test policy',
616 shared=False,
Takashi Kajinamida451772023-03-22 00:19:39 +0900617 project_id=self.admin_client.project_id)
zahlabut7ebb66e2021-09-01 22:39:49 +0300618 rule = self._create_qos_bw_limit_rule(
619 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000620 self.assertRaises(
621 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300622 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
623 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000624
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000625 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000626 def test_get_rules_by_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300627 policy1 = self.create_qos_policy(
628 name='test-policy1',
629 description='test policy1',
630 shared=False)
631 rule1 = self._create_qos_bw_limit_rule(
632 policy1['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000633
zahlabut7ebb66e2021-09-01 22:39:49 +0300634 policy2 = self.create_qos_policy(
635 name='test-policy2',
636 description='test policy2',
637 shared=False)
638 rule2 = self._create_qos_bw_limit_rule(
639 policy2['id'], {'max_kbps': 5000, 'max_burst_kbps': 2523})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000640
641 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300642 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
643 policy1['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000644 rules = rules['bandwidth_limit_rules']
645 rules_ids = [r['id'] for r in rules]
646 self.assertIn(rule1['id'], rules_ids)
647 self.assertNotIn(rule2['id'], rules_ids)
648
nfridman07f0e782019-11-04 09:12:58 -0500649 @testtools.skipUnless(
650 CONF.neutron_plugin_options.create_shared_resources,
651 """Creation of shared resources should be allowed,
652 setting the create_shared_resources option as 'True' is needed""")
653 @decorators.idempotent_id('d911707e-fa2c-11e9-9553-5076af30bbf5')
654 def test_attach_and_detach_a_policy_by_a_tenant(self):
655 # As an admin create an non shared QoS policy,add a rule
656 # and associate it with a network
657 self.network = self.create_network()
elajkat757f3f12022-01-28 11:17:55 +0100658 policy = self.create_qos_policy(name=self.policy_name,
nfridman07f0e782019-11-04 09:12:58 -0500659 description='test policy for attach',
660 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300661 self._create_qos_bw_limit_rule(
662 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024})
nfridman07f0e782019-11-04 09:12:58 -0500663
664 self.admin_client.update_network(
665 self.network['id'], qos_policy_id=policy['id'])
666
667 # As a tenant, try to detach the policy from the network
668 # The operation should be forbidden
669 self.assertRaises(
670 exceptions.Forbidden,
671 self.client.update_network,
672 self.network['id'], qos_policy_id=None)
673
674 # As an admin, make the policy shared
675 self.admin_client.update_qos_policy(policy['id'], shared=True)
676
677 # As a tenant, try to detach the policy from the network
678 # The operation should be allowed
679 self.client.update_network(self.network['id'],
680 qos_policy_id=None)
681
682 retrieved_network = self.admin_client.show_network(self.network['id'])
683 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
684
685 # As a tenant, try to delete the policy from the network
686 # should be forbidden
687 self.assertRaises(
688 exceptions.Forbidden,
689 self.client.delete_qos_policy,
690 policy['id'])
691
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000692
Slawek Kaplonskiec162e02024-03-06 12:21:24 +0100693@ddt.ddt
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000694class QosBandwidthLimitRuleWithDirectionTestJSON(
Brian Haley6767cec2018-04-10 15:30:23 -0400695 QosBandwidthLimitRuleTestJSON):
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000696 required_extensions = (
697 QosBandwidthLimitRuleTestJSON.required_extensions +
698 ['qos-bw-limit-direction']
699 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000700
nfridman7717d9c2019-11-25 08:58:04 -0500701 @classmethod
702 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
703 def resource_setup(cls):
704 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
705
elajkat757f3f12022-01-28 11:17:55 +0100706 def setUp(self):
707 super(QosBandwidthLimitRuleWithDirectionTestJSON, self).setUp()
708 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
709
nfridman7717d9c2019-11-25 08:58:04 -0500710 @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667')
711 def test_create_policy_with_multiple_rules(self):
712 # Create a policy with multiple rules
elajkat757f3f12022-01-28 11:17:55 +0100713 policy = self.create_qos_policy(name=self.policy_name,
nfridman7717d9c2019-11-25 08:58:04 -0500714 description='test policy1',
715 shared=False)
716
zahlabut7ebb66e2021-09-01 22:39:49 +0300717 rule1 = self._create_qos_bw_limit_rule(
718 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
719 'direction': n_constants.EGRESS_DIRECTION})
720 rule2 = self._create_qos_bw_limit_rule(
721 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
722 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500723 # Check that the rules were added to the policy
zahlabut7ebb66e2021-09-01 22:39:49 +0300724 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
nfridman7717d9c2019-11-25 08:58:04 -0500725 policy['id'])['bandwidth_limit_rules']
zahlabut7ebb66e2021-09-01 22:39:49 +0300726
nfridman7717d9c2019-11-25 08:58:04 -0500727 rules_ids = [rule['id'] for rule in rules]
728 self.assertIn(rule1['id'], rules_ids)
729 self.assertIn(rule2['id'], rules_ids)
730
731 # Check that the rules creation fails for the same rule types
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.EGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500738
zahlabut7ebb66e2021-09-01 22:39:49 +0300739 self.assertRaises(
740 exceptions.Conflict,
741 self._create_qos_bw_limit_rule,
742 policy['id'],
743 {'max_kbps': 1025, 'max_burst_kbps': 1025,
744 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500745
Slawek Kaplonskiec162e02024-03-06 12:21:24 +0100746 @decorators.idempotent_id('7ca7c83b-0555-4a0f-a422-4338f77f79e5')
747 @ddt.unpack
748 @ddt.data({'opposite_direction': 'ingress'},
749 {'opposite_direction': 'egress'})
750 def test_rule_update(self, opposite_direction):
751 self._test_rule_update(opposite_direction=opposite_direction)
752
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000753
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000754class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
755
756 force_tenant_isolation = True
757 credentials = ['primary', 'alt', 'admin']
Chandan Kumarc125fd12017-11-15 19:41:01 +0530758 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000759
760 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000761 def resource_setup(cls):
762 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530763 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000764
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000765 def _create_qos_policy(self, project_id=None):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000766 args = {'name': data_utils.rand_name('test-policy'),
767 'description': 'test policy',
768 'shared': False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000769 'project_id': project_id}
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000770 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
771 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
772
773 return qos_policy
774
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000775 def _make_admin_policy_shared_to_project_id(self, project_id):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000776 policy = self._create_qos_policy()
777 rbac_policy = self.admin_client.create_rbac_policy(
778 object_type='qos_policy',
779 object_id=policy['id'],
780 action='access_as_shared',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000781 target_tenant=project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000782 )['rbac_policy']
783
784 return {'policy': policy, 'rbac_policy': rbac_policy}
785
786 def _create_network(self, qos_policy_id, client, should_cleanup=True):
787 net = client.create_network(
788 name=data_utils.rand_name('test-network'),
789 qos_policy_id=qos_policy_id)['network']
790 if should_cleanup:
791 self.addCleanup(client.delete_network, net['id'])
792
793 return net
794
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000795 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000796 def test_policy_sharing_with_wildcard(self):
797 qos_pol = self.create_qos_policy(
798 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000799 description='test-shared-policy', shared=False,
Takashi Kajinamida451772023-03-22 00:19:39 +0900800 project_id=self.admin_client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000801 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
802
803 # test update shared False -> True
804 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
805 qos_pol['shared'] = True
806 self.client2.show_qos_policy(qos_pol['id'])
807 rbac_pol = {'target_tenant': '*',
Takashi Kajinamida451772023-03-22 00:19:39 +0900808 'tenant_id': self.admin_client.project_id,
809 'project_id': self.admin_client.project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000810 'object_type': 'qos_policy',
811 'object_id': qos_pol['id'],
812 'action': 'access_as_shared'}
813
814 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
815 rbac_policies = [r for r in rbac_policies if r.pop('id')]
816 self.assertIn(rbac_pol, rbac_policies)
817
818 # update shared True -> False should fail because the policy is bound
819 # to a network
820 net = self._create_network(qos_pol['id'], self.admin_client, False)
821 with testtools.ExpectedException(exceptions.Conflict):
822 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
823
824 # delete the network, and update shared True -> False should pass now
825 self.admin_client.delete_network(net['id'])
826 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
827 qos_pol['shared'] = False
828 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
829
830 def _create_net_bound_qos_rbacs(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000831 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900832 self.client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000833 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
834
835 # add a wildcard rbac rule - now the policy globally shared
836 rbac_wildcard = self.admin_client.create_rbac_policy(
837 object_type='qos_policy',
838 object_id=qos_policy['id'],
839 action='access_as_shared',
840 target_tenant='*',
841 )['rbac_policy']
842
843 # tenant1 now uses qos policy for net
844 self._create_network(qos_policy['id'], self.client)
845
846 return rbac_for_client_tenant, rbac_wildcard
847
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000848 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000849 def test_net_bound_shared_policy_wildcard_and_project_id_wild_remove(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000850 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
851 # globally unshare the qos-policy, the specific share should remain
852 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
853 self.client.list_rbac_policies(id=client_rbac['id'])
854
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000855 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000856 def test_net_bound_shared_policy_wildcard_and_projectid_wild_remains(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000857 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
858 # remove client_rbac policy the wildcard share should remain
859 self.admin_client.delete_rbac_policy(client_rbac['id'])
860 self.client.list_rbac_policies(id=wildcard_rbac['id'])
861
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000862 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000863 def test_policy_sharing_with_wildcard_and_project_id(self):
864 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900865 self.client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000866 qos_policy, rbac = res['policy'], res['rbac_policy']
867 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
868 self.assertTrue(qos_pol['shared'])
869 with testtools.ExpectedException(exceptions.NotFound):
870 self.client2.show_qos_policy(qos_policy['id'])
871
872 # make the qos-policy globally shared
873 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
874 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
875 self.assertTrue(qos_pol['shared'])
876
877 # globally unshare the qos-policy, the specific share should remain
878 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
879 self.client.show_qos_policy(qos_policy['id'])
880 with testtools.ExpectedException(exceptions.NotFound):
881 self.client2.show_qos_policy(qos_policy['id'])
882 self.assertIn(rbac,
883 self.admin_client.list_rbac_policies()['rbac_policies'])
884
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000885 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000886 def test_policy_target_update(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000887 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900888 self.client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000889 # change to client2
890 update_res = self.admin_client.update_rbac_policy(
Takashi Kajinamida451772023-03-22 00:19:39 +0900891 res['rbac_policy']['id'], target_tenant=self.client2.project_id)
892 self.assertEqual(self.client2.project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000893 update_res['rbac_policy']['target_tenant'])
894 # make sure everything else stayed the same
895 res['rbac_policy'].pop('target_tenant')
896 update_res['rbac_policy'].pop('target_tenant')
897 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
898
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000899 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000900 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000901 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900902 self.client2.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000903 qos_policy_id = res['policy']['id']
904 self._create_network(qos_policy_id, self.client2)
905 # a network with shared qos-policy should prevent the deletion of an
906 # rbac-policy required for it to be shared
907 with testtools.ExpectedException(exceptions.Conflict):
908 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
909
910 # a wildcard policy should allow the specific policy to be deleted
911 # since it allows the remaining port
912 wild = self.admin_client.create_rbac_policy(
913 object_type='qos_policy', object_id=res['policy']['id'],
914 action='access_as_shared', target_tenant='*')['rbac_policy']
915 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
916
917 # now that wildcard is the only remaining, it should be subjected to
918 # the same restriction
919 with testtools.ExpectedException(exceptions.Conflict):
920 self.admin_client.delete_rbac_policy(wild['id'])
921
922 # we can't update the policy to a different tenant
923 with testtools.ExpectedException(exceptions.Conflict):
924 self.admin_client.update_rbac_policy(
Takashi Kajinamida451772023-03-22 00:19:39 +0900925 wild['id'], target_tenant=self.client2.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000926
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000927 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000928 def test_regular_client_shares_to_another_regular_client(self):
929 # owned by self.admin_client
930 policy = self._create_qos_policy()
931 with testtools.ExpectedException(exceptions.NotFound):
932 self.client.show_qos_policy(policy['id'])
933 rbac_policy = self.admin_client.create_rbac_policy(
934 object_type='qos_policy', object_id=policy['id'],
935 action='access_as_shared',
Takashi Kajinamida451772023-03-22 00:19:39 +0900936 target_tenant=self.client.project_id)['rbac_policy']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000937 self.client.show_qos_policy(policy['id'])
938
939 self.assertIn(rbac_policy,
940 self.admin_client.list_rbac_policies()['rbac_policies'])
941 # ensure that 'client2' can't see the rbac-policy sharing the
942 # qos-policy to it because the rbac-policy belongs to 'client'
943 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
944 self.client2.list_rbac_policies()['rbac_policies']])
945
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000946 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000947 def test_filter_fields(self):
948 policy = self._create_qos_policy()
949 self.admin_client.create_rbac_policy(
950 object_type='qos_policy', object_id=policy['id'],
Takashi Kajinamida451772023-03-22 00:19:39 +0900951 action='access_as_shared', target_tenant=self.client2.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000952 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000953 ('project_id', 'target_tenant'))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000954 for fields in field_args:
955 res = self.admin_client.list_rbac_policies(fields=fields)
956 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
957
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000958 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000959 def test_rbac_policy_show(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000960 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900961 self.client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000962 p1 = res['rbac_policy']
963 p2 = self.admin_client.create_rbac_policy(
964 object_type='qos_policy', object_id=res['policy']['id'],
965 action='access_as_shared',
966 target_tenant='*')['rbac_policy']
967
968 self.assertEqual(
969 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
970 self.assertEqual(
971 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
972
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000973 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000974 def test_filter_rbac_policies(self):
975 policy = self._create_qos_policy()
976 rbac_pol1 = self.admin_client.create_rbac_policy(
977 object_type='qos_policy', object_id=policy['id'],
978 action='access_as_shared',
Takashi Kajinamida451772023-03-22 00:19:39 +0900979 target_tenant=self.client2.project_id)['rbac_policy']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000980 rbac_pol2 = self.admin_client.create_rbac_policy(
981 object_type='qos_policy', object_id=policy['id'],
982 action='access_as_shared',
Takashi Kajinamida451772023-03-22 00:19:39 +0900983 target_tenant=self.admin_client.project_id)['rbac_policy']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000984 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
985 'rbac_policies']
986 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
987 'rbac_policies']
988 self.assertEqual(1, len(res1))
989 self.assertEqual(1, len(res2))
990 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
991 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
992
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000993 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000994 def test_regular_client_blocked_from_sharing_anothers_policy(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000995 qos_policy = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900996 self.client.project_id)['policy']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000997 with testtools.ExpectedException(exceptions.BadRequest):
998 self.client.create_rbac_policy(
999 object_type='qos_policy', object_id=qos_policy['id'],
1000 action='access_as_shared',
Takashi Kajinamida451772023-03-22 00:19:39 +09001001 target_tenant=self.client2.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001002
1003 # make sure the rbac-policy is invisible to the tenant for which it's
1004 # being shared
1005 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
1006
1007
1008class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
1009 VALID_DSCP_MARK1 = 56
1010 VALID_DSCP_MARK2 = 48
1011
Chandan Kumarc125fd12017-11-15 19:41:01 +05301012 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001013
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001014 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001015 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001016 def resource_setup(cls):
1017 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
1018
elajkat757f3f12022-01-28 11:17:55 +01001019 def setUp(self):
1020 super(QosDscpMarkingRuleTestJSON, self).setUp()
1021 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
1022
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001023 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001024 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001025 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001026 description='test policy',
1027 shared=False)
1028 rule = self.admin_client.create_dscp_marking_rule(
1029 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1030
1031 # Test 'show rule'
1032 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1033 policy['id'], rule['id'])
1034 retrieved_rule = retrieved_rule['dscp_marking_rule']
1035 self.assertEqual(rule['id'], retrieved_rule['id'])
1036 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
1037
1038 # Test 'list rules'
1039 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
1040 rules = rules['dscp_marking_rules']
1041 rules_ids = [r['id'] for r in rules]
1042 self.assertIn(rule['id'], rules_ids)
1043
1044 # Test 'show policy'
1045 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1046 policy_rules = retrieved_policy['policy']['rules']
1047 self.assertEqual(1, len(policy_rules))
1048 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +00001049 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001050 policy_rules[0]['type'])
1051
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001052 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001053 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001054 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001055 description='test policy',
1056 shared=False)
1057 self.admin_client.create_dscp_marking_rule(
1058 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1059
1060 self.assertRaises(exceptions.Conflict,
1061 self.admin_client.create_dscp_marking_rule,
1062 policy_id=policy['id'],
1063 dscp_mark=self.VALID_DSCP_MARK2)
1064
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001065 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001066 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001067 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001068 description='test policy',
1069 shared=False)
1070 rule = self.admin_client.create_dscp_marking_rule(
1071 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1072
1073 self.admin_client.update_dscp_marking_rule(
1074 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
1075
1076 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1077 policy['id'], rule['id'])
1078 retrieved_policy = retrieved_policy['dscp_marking_rule']
1079 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
1080
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001081 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001082 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001083 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001084 description='test policy',
1085 shared=False)
1086 rule = self.admin_client.create_dscp_marking_rule(
1087 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1088
1089 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1090 policy['id'], rule['id'])
1091 retrieved_policy = retrieved_policy['dscp_marking_rule']
1092 self.assertEqual(rule['id'], retrieved_policy['id'])
1093
1094 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
1095 self.assertRaises(exceptions.NotFound,
1096 self.admin_client.show_dscp_marking_rule,
1097 policy['id'], rule['id'])
1098
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001099 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001100 def test_rule_create_rule_nonexistent_policy(self):
1101 self.assertRaises(
1102 exceptions.NotFound,
1103 self.admin_client.create_dscp_marking_rule,
1104 'policy', self.VALID_DSCP_MARK1)
1105
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001106 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001107 def test_rule_create_forbidden_for_regular_tenants(self):
1108 self.assertRaises(
1109 exceptions.Forbidden,
1110 self.client.create_dscp_marking_rule,
1111 'policy', self.VALID_DSCP_MARK1)
1112
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001113 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001114 def test_invalid_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001115 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001116 description='test policy',
1117 shared=False)
1118 self.assertRaises(
1119 exceptions.BadRequest,
1120 self.admin_client.create_dscp_marking_rule,
1121 policy['id'], 58)
1122
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001123 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001124 def test_get_rules_by_policy(self):
1125 policy1 = self.create_qos_policy(name='test-policy1',
1126 description='test policy1',
1127 shared=False)
1128 rule1 = self.admin_client.create_dscp_marking_rule(
1129 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1130
1131 policy2 = self.create_qos_policy(name='test-policy2',
1132 description='test policy2',
1133 shared=False)
1134 rule2 = self.admin_client.create_dscp_marking_rule(
1135 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
1136
1137 # Test 'list rules'
1138 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
1139 rules = rules['dscp_marking_rules']
1140 rules_ids = [r['id'] for r in rules]
1141 self.assertIn(rule1['id'], rules_ids)
1142 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001143
nfridman23b44ad2019-09-05 09:46:50 -04001144 @decorators.idempotent_id('19ed2286-ccb1-11e9-87d7-525400d6f522')
1145 def test_qos_dscp_create_and_update(self):
1146 """This test covers:
1147
1148 1.Creating a basic QoS policy with DSCP marking rule.
1149 2.Updating QoS policy:
1150 Administrator should have the ability to update existing QoS policy.
1151 This test should verify that:
1152 It's possible to update the existing DSCP marking rule with all of
1153 the valid marks between 0-56, except of the invalid marks:
1154 2-6, 42, 44, and 50-54 (which should be forbidden)
1155 """
1156
Rodolfo Alonso Hernandez3de3cd92022-08-23 21:41:02 +02001157 def _test_update_dscp_mark_values(self, dscp_policy_id, rule_id,
1158 valid_dscp_marks):
1159 for mark in range(valid_dscp_marks[1], self.VALID_DSCP_MARK1 + 1):
1160 if mark in valid_dscp_marks:
nfridman23b44ad2019-09-05 09:46:50 -04001161 self.admin_client.update_dscp_marking_rule(
1162 dscp_policy_id, rule_id, dscp_mark=mark)
1163
1164 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1165 dscp_policy_id, rule_id)['dscp_marking_rule']
1166 self.assertEqual(mark, retrieved_rule['dscp_mark'],
1167 """current DSCP mark is incorrect:
1168 expected value {0} actual value {1}
1169 """.format(mark,
1170 retrieved_rule['dscp_mark']))
1171
1172 else:
1173 self.assertRaises(exceptions.BadRequest,
1174 self.admin_client.create_dscp_marking_rule,
1175 dscp_policy_id,
1176 mark)
Rodolfo Alonso Hernandez3de3cd92022-08-23 21:41:02 +02001177
1178 # Retrieve the valid range of DSCP marks from the API.
1179 rule_type_details = self.admin_client.show_qos_rule_type(
1180 qos_consts.RULE_TYPE_DSCP_MARKING).get('rule_type')
1181 # There should be at least one driver supporting the DSCP marking rule.
1182 dscp_driver = rule_type_details['drivers'][0]
1183 for parameter in dscp_driver['supported_parameters']:
1184 if parameter['parameter_name'] == qos_consts.DSCP_MARK:
1185 valid_dscp_marks = parameter['parameter_values']
1186 break
1187 else:
1188 self.fail('The DSCP marking rule does not have the %s parameter' %
1189 qos_consts.DSCP_MARK)
1190
nfridman23b44ad2019-09-05 09:46:50 -04001191 # Setup network
1192 self.network = self.create_network()
1193
1194 # Create QoS policy
1195 dscp_policy_id = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +01001196 name=self.policy_name,
nfridman23b44ad2019-09-05 09:46:50 -04001197 description='test-qos-policy',
Slawek Kaplonskifdfb4742023-05-10 12:48:49 +02001198 project_id=self.client.project_id,
nfridman23b44ad2019-09-05 09:46:50 -04001199 shared=True)['id']
1200
1201 # Associate QoS to the network
1202 self.admin_client.update_network(
1203 self.network['id'], qos_policy_id=dscp_policy_id)
1204
1205 # Set a new DSCP rule with the first mark in range
1206 rule_id = self.admin_client.create_dscp_marking_rule(
1207 dscp_policy_id,
1208 n_constants.VALID_DSCP_MARKS[0])[
1209 'dscp_marking_rule']['id']
1210
1211 # Validate that the rule was set up properly
1212 retrieved_rule = self.client.show_dscp_marking_rule(
1213 dscp_policy_id, rule_id)['dscp_marking_rule']
1214 self.assertEqual(n_constants.VALID_DSCP_MARKS[0],
1215 retrieved_rule['dscp_mark'],
1216 """current DSCP mark is incorrect:
1217 expected value {0} actual value {1}
1218 """.format(n_constants.VALID_DSCP_MARKS[0],
1219 retrieved_rule['dscp_mark']))
1220
1221 # Try to set marks in range 8:56 (invalid marks should raise an error)
Rodolfo Alonso Hernandez3de3cd92022-08-23 21:41:02 +02001222 _test_update_dscp_mark_values(self, dscp_policy_id, rule_id,
1223 valid_dscp_marks)
nfridman23b44ad2019-09-05 09:46:50 -04001224
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001225
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001226class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
1227 DIRECTION_EGRESS = "egress"
1228 DIRECTION_INGRESS = "ingress"
1229 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
1230 RULES_NAME = RULE_NAME + "s"
Chandan Kumarc125fd12017-11-15 19:41:01 +05301231 required_extensions = [qos_apidef.ALIAS]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001232
1233 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001234 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001235 def resource_setup(cls):
1236 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
1237
zahlabut7ebb66e2021-09-01 22:39:49 +03001238 @classmethod
1239 def setup_clients(cls):
1240 super(QosMinimumBandwidthRuleTestJSON, cls).setup_clients()
1241 cls.qos_min_bw_rules_client = \
1242 cls.os_admin.qos_minimum_bandwidth_rules_client
1243 cls.qos_min_bw_rules_client_primary = \
1244 cls.os_primary.qos_minimum_bandwidth_rules_client
1245
elajkat757f3f12022-01-28 11:17:55 +01001246 def setUp(self):
1247 super(QosMinimumBandwidthRuleTestJSON, self).setUp()
1248 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
1249
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001250 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001251 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001252 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001253 description='test policy',
1254 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001255 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1256 qos_policy_id=policy['id'],
1257 **{'direction': self.DIRECTION_EGRESS,
1258 'min_kbps': 1138})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001259
1260 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +03001261 retrieved_rule = \
1262 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1263 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001264 retrieved_rule = retrieved_rule[self.RULE_NAME]
1265 self.assertEqual(rule['id'], retrieved_rule['id'])
1266 self.assertEqual(1138, retrieved_rule['min_kbps'])
1267 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1268
1269 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001270 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1271 policy['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001272 rules = rules[self.RULES_NAME]
1273 rules_ids = [r['id'] for r in rules]
1274 self.assertIn(rule['id'], rules_ids)
1275
1276 # Test 'show policy'
1277 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1278 policy_rules = retrieved_policy['policy']['rules']
1279 self.assertEqual(1, len(policy_rules))
1280 self.assertEqual(rule['id'], policy_rules[0]['id'])
1281 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1282 policy_rules[0]['type'])
1283
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001284 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001285 def test_rule_create_fail_for_missing_min_kbps(self):
elajkat757f3f12022-01-28 11:17:55 +01001286 policy = self.create_qos_policy(name=self.policy_name,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001287 description='test policy',
1288 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001289 self.assertRaises(
1290 exceptions.BadRequest,
1291 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1292 qos_policy_id=policy['id'],
1293 **{'direction': self.DIRECTION_EGRESS})
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001294
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001295 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001296 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001297 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001298 description='test policy',
1299 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001300 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1301 qos_policy_id=policy['id'],
1302 **{'direction': self.DIRECTION_EGRESS,
1303 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001304
zahlabut7ebb66e2021-09-01 22:39:49 +03001305 self.assertRaises(
1306 exceptions.Conflict,
1307 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1308 qos_policy_id=policy['id'],
1309 **{'direction': self.DIRECTION_EGRESS,
1310 'min_kbps': 201})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001311
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001312 @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936')
1313 @utils.requires_ext(extension="qos-bw-minimum-ingress",
1314 service="network")
1315 def test_rule_create_pass_for_direction_ingress(self):
elajkat757f3f12022-01-28 11:17:55 +01001316 policy = self.create_qos_policy(name=self.policy_name,
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001317 description='test policy',
1318 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001319 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1320 qos_policy_id=policy['id'],
1321 **{'direction': self.DIRECTION_INGRESS,
1322 'min_kbps': 201})
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001323
1324 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1325 policy_rules = retrieved_policy['policy']['rules']
1326 self.assertEqual(1, len(policy_rules))
1327 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1328 policy_rules[0]['type'])
1329 self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction'])
1330
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001331 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001332 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001333 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001334 description='test policy',
1335 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001336 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1337 qos_policy_id=policy['id'],
1338 **{'direction': self.DIRECTION_EGRESS,
1339 'min_kbps': 300})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001340
zahlabut7ebb66e2021-09-01 22:39:49 +03001341 self.qos_min_bw_rules_client.update_minimum_bandwidth_rule(
1342 policy['id'], rule['id'],
1343 **{'min_kbps': 350, 'direction': self.DIRECTION_EGRESS})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001344
zahlabut7ebb66e2021-09-01 22:39:49 +03001345 retrieved_policy = \
1346 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1347 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001348 retrieved_policy = retrieved_policy[self.RULE_NAME]
1349 self.assertEqual(350, retrieved_policy['min_kbps'])
1350 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1351
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001352 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001353 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001354 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001355 description='test policy',
1356 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001357 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1358 policy['id'],
1359 **{'direction': self.DIRECTION_EGRESS,
1360 'min_kbps': 200})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001361
zahlabut7ebb66e2021-09-01 22:39:49 +03001362 retrieved_policy = \
1363 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1364 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001365 retrieved_policy = retrieved_policy[self.RULE_NAME]
1366 self.assertEqual(rule['id'], retrieved_policy['id'])
1367
zahlabut7ebb66e2021-09-01 22:39:49 +03001368 self.qos_min_bw_rules_client.delete_minimum_bandwidth_rule(
1369 policy['id'], rule['id'])
1370 self.assertRaises(
1371 exceptions.NotFound,
1372 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule,
1373 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001374
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001375 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001376 def test_rule_create_rule_nonexistent_policy(self):
1377 self.assertRaises(
1378 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +03001379 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1380 'policy',
1381 **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001382
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001383 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001384 def test_rule_create_forbidden_for_regular_tenants(self):
1385 self.assertRaises(
1386 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +03001387 self.qos_min_bw_rules_client_primary.create_minimum_bandwidth_rule,
1388 'policy', **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 300})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001389
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001390 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001391 def test_get_rules_by_policy(self):
1392 policy1 = self.create_qos_policy(name='test-policy1',
1393 description='test policy1',
1394 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001395 rule1 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1396 qos_policy_id=policy1['id'],
1397 **{'direction': self.DIRECTION_EGRESS,
1398 'min_kbps': 200})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001399
1400 policy2 = self.create_qos_policy(name='test-policy2',
1401 description='test policy2',
1402 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001403 rule2 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1404 qos_policy_id=policy2['id'],
1405 **{'direction': self.DIRECTION_EGRESS,
1406 'min_kbps': 5000})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001407
1408 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001409 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1410 policy1['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001411 rules = rules[self.RULES_NAME]
1412 rules_ids = [r['id'] for r in rules]
1413 self.assertIn(rule1['id'], rules_ids)
1414 self.assertNotIn(rule2['id'], rules_ids)
1415
1416
elajkat4a1357b2021-08-31 10:16:25 +02001417class QosMinimumPpsRuleTestJSON(base.BaseAdminNetworkTest):
elajkat4a1357b2021-08-31 10:16:25 +02001418 required_extensions = [qos_apidef.ALIAS]
1419
1420 @classmethod
1421 @utils.requires_ext(service='network',
1422 extension='port-resource-request-groups')
1423 def resource_setup(cls):
1424 super(QosMinimumPpsRuleTestJSON, cls).resource_setup()
1425
1426 @classmethod
1427 def setup_clients(cls):
1428 super(QosMinimumPpsRuleTestJSON, cls).setup_clients()
1429 cls.min_pps_client = cls.os_admin.qos_minimum_packet_rate_rules_client
1430 cls.min_pps_client_primary = \
1431 cls.os_primary.qos_minimum_packet_rate_rules_client
1432
elajkat757f3f12022-01-28 11:17:55 +01001433 def setUp(self):
1434 super(QosMinimumPpsRuleTestJSON, self).setUp()
1435 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
Chandan Kumar (raukadah)255586c2022-03-10 09:43:37 +05301436 self.RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_PACKET_RATE + "_rule"
1437 self.RULES_NAME = self.RULE_NAME + "s"
elajkat757f3f12022-01-28 11:17:55 +01001438
elajkat4a1357b2021-08-31 10:16:25 +02001439 def _create_qos_min_pps_rule(self, policy_id, rule_data):
1440 rule = self.min_pps_client.create_minimum_packet_rate_rule(
1441 policy_id, **rule_data)['minimum_packet_rate_rule']
1442 self.addCleanup(
1443 test_utils.call_and_ignore_notfound_exc,
1444 self.min_pps_client.delete_minimum_packet_rate_rule,
1445 policy_id, rule['id'])
1446 return rule
1447
1448 @decorators.idempotent_id('66a5b9b4-d4f9-4af8-b238-9e1881b78487')
1449 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001450 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001451 description='test policy',
1452 shared=False)
1453 rule = self._create_qos_min_pps_rule(
1454 policy['id'],
1455 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1456 qos_consts.MIN_KPPS: 1138})
1457
1458 # Test 'show rule'
1459 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1460 policy['id'], rule['id'])[self.RULE_NAME]
1461 self.assertEqual(rule['id'], retrieved_rule['id'])
1462 self.assertEqual(1138, retrieved_rule[qos_consts.MIN_KPPS])
1463 self.assertEqual(n_constants.EGRESS_DIRECTION,
1464 retrieved_rule[qos_consts.DIRECTION])
1465
1466 # Test 'list rules'
1467 rules = self.min_pps_client.list_minimum_packet_rate_rules(
1468 policy['id'])
1469 rules = rules[self.RULES_NAME]
1470 rules_ids = [r['id'] for r in rules]
1471 self.assertIn(rule['id'], rules_ids)
1472
1473 # Test 'show policy'
1474 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1475 policy_rules = retrieved_policy['policy']['rules']
1476 self.assertEqual(1, len(policy_rules))
1477 self.assertEqual(rule['id'], policy_rules[0]['id'])
1478 self.assertEqual('minimum_packet_rate',
1479 policy_rules[0]['type'])
1480
1481 @decorators.idempotent_id('6b656b57-d2bf-47f9-89a9-1baad1bd5418')
1482 def test_rule_create_fail_for_missing_min_kpps(self):
elajkat757f3f12022-01-28 11:17:55 +01001483 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001484 description='test policy',
1485 shared=False)
1486 self.assertRaises(exceptions.BadRequest,
1487 self._create_qos_min_pps_rule,
1488 policy['id'],
1489 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION})
1490
1491 @decorators.idempotent_id('f41213e5-2ab8-4916-b106-38d2cac5e18c')
1492 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001493 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001494 description='test policy',
1495 shared=False)
1496 self._create_qos_min_pps_rule(policy['id'],
1497 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1498 qos_consts.MIN_KPPS: 200})
1499
1500 self.assertRaises(exceptions.Conflict,
1501 self._create_qos_min_pps_rule,
1502 policy['id'],
1503 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1504 qos_consts.MIN_KPPS: 201})
1505
1506 @decorators.idempotent_id('ceb8e41e-3d72-11ec-a446-d7faae6daec2')
1507 def test_rule_create_any_direction_when_egress_direction_exists(self):
elajkat757f3f12022-01-28 11:17:55 +01001508 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001509 description='test policy',
1510 shared=False)
1511 self._create_qos_min_pps_rule(policy['id'],
1512 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1513 qos_consts.MIN_KPPS: 200})
1514
1515 self.assertRaises(exceptions.Conflict,
1516 self._create_qos_min_pps_rule,
1517 policy['id'],
1518 {qos_consts.DIRECTION: n_constants.ANY_DIRECTION,
1519 qos_consts.MIN_KPPS: 201})
1520
1521 @decorators.idempotent_id('a147a71e-3d7b-11ec-8097-278b1afd5fa2')
1522 def test_rule_create_egress_direction_when_any_direction_exists(self):
elajkat757f3f12022-01-28 11:17:55 +01001523 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001524 description='test policy',
1525 shared=False)
1526 self._create_qos_min_pps_rule(policy['id'],
1527 {qos_consts.DIRECTION: n_constants.ANY_DIRECTION,
1528 qos_consts.MIN_KPPS: 200})
1529
1530 self.assertRaises(exceptions.Conflict,
1531 self._create_qos_min_pps_rule,
1532 policy['id'],
1533 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1534 qos_consts.MIN_KPPS: 201})
1535
1536 @decorators.idempotent_id('522ed09a-1d7f-4c1b-9195-61f19caf916f')
1537 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001538 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001539 description='test policy',
1540 shared=False)
1541 rule = self._create_qos_min_pps_rule(
1542 policy['id'],
1543 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1544 qos_consts.MIN_KPPS: 300})
1545
1546 self.min_pps_client.update_minimum_packet_rate_rule(
1547 policy['id'], rule['id'],
1548 **{qos_consts.MIN_KPPS: 350,
1549 qos_consts.DIRECTION: n_constants.ANY_DIRECTION})
1550
1551 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1552 policy['id'], rule['id'])[self.RULE_NAME]
1553 self.assertEqual(350, retrieved_rule[qos_consts.MIN_KPPS])
1554 self.assertEqual(n_constants.ANY_DIRECTION,
1555 retrieved_rule[qos_consts.DIRECTION])
1556
1557 @decorators.idempotent_id('a020e186-3d60-11ec-88ca-d7f5eec22764')
1558 def test_rule_update_direction_conflict(self):
elajkat757f3f12022-01-28 11:17:55 +01001559 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001560 description='test policy',
1561 shared=False)
1562 rule1 = self._create_qos_min_pps_rule(
1563 policy['id'],
1564 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1565 qos_consts.MIN_KPPS: 300})
1566
1567 rule2 = self._create_qos_min_pps_rule(
1568 policy['id'],
1569 {qos_consts.DIRECTION: n_constants.INGRESS_DIRECTION,
1570 qos_consts.MIN_KPPS: 300})
1571
1572 retrieved_rule1 = self.min_pps_client.show_minimum_packet_rate_rule(
1573 policy['id'], rule1['id'])[self.RULE_NAME]
1574 self.assertEqual(n_constants.EGRESS_DIRECTION,
1575 retrieved_rule1[qos_consts.DIRECTION])
1576 retrieved_rule2 = self.min_pps_client.show_minimum_packet_rate_rule(
1577 policy['id'], rule2['id'])[self.RULE_NAME]
1578 self.assertEqual(n_constants.INGRESS_DIRECTION,
1579 retrieved_rule2[qos_consts.DIRECTION])
1580
1581 self.assertRaises(exceptions.Conflict,
1582 self.min_pps_client.update_minimum_packet_rate_rule,
1583 policy['id'], rule2['id'],
1584 **{qos_consts.DIRECTION: n_constants.ANY_DIRECTION})
1585
1586 @decorators.idempotent_id('c49018b6-d358-49a1-a94b-d53224165045')
1587 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001588 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001589 description='test policy',
1590 shared=False)
1591 rule = self._create_qos_min_pps_rule(
1592 policy['id'],
1593 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1594 qos_consts.MIN_KPPS: 200})
1595
1596 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1597 policy['id'], rule['id'])[self.RULE_NAME]
1598 self.assertEqual(rule['id'], retrieved_rule['id'])
1599
1600 self.min_pps_client.delete_minimum_packet_rate_rule(policy['id'],
1601 rule['id'])
1602 self.assertRaises(exceptions.NotFound,
1603 self.min_pps_client.show_minimum_packet_rate_rule,
1604 policy['id'], rule['id'])
1605
1606 @decorators.idempotent_id('1a6b6128-3d3e-11ec-bf49-57b326d417c0')
1607 def test_rule_create_forbidden_for_regular_tenants(self):
1608 self.assertRaises(
1609 exceptions.Forbidden,
1610 self.min_pps_client_primary.create_minimum_packet_rate_rule,
1611 'policy', **{qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1612 qos_consts.MIN_KPPS: 300})
1613
1614 @decorators.idempotent_id('1b94f4e2-3d3e-11ec-bb21-6f98e4044b8b')
1615 def test_get_rules_by_policy(self):
1616 policy1 = self.create_qos_policy(name='test-policy1',
1617 description='test policy1',
1618 shared=False)
1619 rule1 = self._create_qos_min_pps_rule(
1620 policy1['id'],
1621 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1622 qos_consts.MIN_KPPS: 200})
1623
1624 policy2 = self.create_qos_policy(name='test-policy2',
1625 description='test policy2',
1626 shared=False)
1627 rule2 = self._create_qos_min_pps_rule(
1628 policy2['id'],
1629 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1630 qos_consts.MIN_KPPS: 5000})
1631
1632 # Test 'list rules'
1633 rules = self.min_pps_client.list_minimum_packet_rate_rules(
1634 policy1['id'])
1635 rules = rules[self.RULES_NAME]
1636 rules_ids = [r['id'] for r in rules]
1637 self.assertIn(rule1['id'], rules_ids)
1638 self.assertNotIn(rule2['id'], rules_ids)
1639
1640
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001641class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1642 base.BaseAdminNetworkTest):
1643
1644 resource = 'policy'
1645 plural_name = 'policies'
1646
1647 # Use unique description to isolate the tests from other QoS tests
1648 list_kwargs = {'description': 'search-criteria-test'}
1649 list_as_admin = True
1650
Chandan Kumarc125fd12017-11-15 19:41:01 +05301651 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001652
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001653 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001654 def resource_setup(cls):
1655 super(QosSearchCriteriaTest, cls).resource_setup()
1656 for name in cls.resource_names:
1657 cls.create_qos_policy(
1658 name=name, description='search-criteria-test')
1659
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001660 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001661 def test_list_sorts_asc(self):
1662 self._test_list_sorts_asc()
1663
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001664 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001665 def test_list_sorts_desc(self):
1666 self._test_list_sorts_desc()
1667
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001668 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001669 def test_list_pagination(self):
1670 self._test_list_pagination()
1671
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001672 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001673 def test_list_pagination_with_marker(self):
1674 self._test_list_pagination_with_marker()
1675
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001676 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001677 def test_list_pagination_with_href_links(self):
1678 self._test_list_pagination_with_href_links()
1679
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001680 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001681 def test_list_pagination_page_reverse_asc(self):
1682 self._test_list_pagination_page_reverse_asc()
1683
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001684 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001685 def test_list_pagination_page_reverse_desc(self):
1686 self._test_list_pagination_page_reverse_desc()
1687
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001688 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001689 def test_list_pagination_page_reverse_with_href_links(self):
1690 self._test_list_pagination_page_reverse_with_href_links()
1691
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001692 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001693 def test_list_no_pagination_limit_0(self):
1694 self._test_list_no_pagination_limit_0()