blob: 372bf1e4a137f4954b64ca7be6e46e78928531e3 [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
elajkat757f3f12022-01-28 11:17:55 +010044 def setUp(self):
45 super(QosTestJSON, self).setUp()
46 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
47
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +000048 @staticmethod
49 def _get_driver_details(rule_type_details, driver_name):
50 for driver in rule_type_details['drivers']:
51 if driver['name'] == driver_name:
52 return driver
53
zahlabut7ebb66e2021-09-01 22:39:49 +030054 def _create_qos_bw_limit_rule(self, policy_id, rule_data):
55 rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule(
56 qos_policy_id=policy_id,
57 **rule_data)['bandwidth_limit_rule']
58 self.addCleanup(
59 test_utils.call_and_ignore_notfound_exc,
60 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule,
61 policy_id, rule['id'])
62 return rule
63
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000064 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000065 def test_create_policy(self):
66 policy = self.create_qos_policy(name='test-policy',
67 description='test policy desc1',
68 shared=False)
69
70 # Test 'show policy'
71 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
72 retrieved_policy = retrieved_policy['policy']
73 self.assertEqual('test-policy', retrieved_policy['name'])
74 self.assertEqual('test policy desc1', retrieved_policy['description'])
75 self.assertFalse(retrieved_policy['shared'])
76
77 # Test 'list policies'
78 policies = self.admin_client.list_qos_policies()['policies']
79 policies_ids = [p['id'] for p in policies]
80 self.assertIn(policy['id'], policies_ids)
81
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000082 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Chandan Kumarc125fd12017-11-15 19:41:01 +053083 @utils.requires_ext(extension="project-id", service="network")
Henry Gessaufa6c78d2016-10-09 19:56:09 -040084 def test_show_policy_has_project_id(self):
elajkat757f3f12022-01-28 11:17:55 +010085 policy = self.create_qos_policy(name=self.policy_name, shared=False)
Henry Gessaufa6c78d2016-10-09 19:56:09 -040086 body = self.admin_client.show_qos_policy(policy['id'])
87 show_policy = body['policy']
88 self.assertIn('project_id', show_policy)
Henry Gessaufa6c78d2016-10-09 19:56:09 -040089 self.assertEqual(self.admin_client.tenant_id,
90 show_policy['project_id'])
Henry Gessaufa6c78d2016-10-09 19:56:09 -040091
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000092 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000093 def test_list_policy_filter_by_name(self):
yatinkarel65fa2c02022-01-28 13:44:19 +053094 policy1 = 'test' + data_utils.rand_name("policy")
95 policy2 = 'test' + data_utils.rand_name("policy")
96 self.create_qos_policy(name=policy1, description='test policy',
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000097 shared=False)
yatinkarel65fa2c02022-01-28 13:44:19 +053098 self.create_qos_policy(name=policy2, description='test policy',
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000099 shared=False)
100
101 policies = (self.admin_client.
yatinkarel65fa2c02022-01-28 13:44:19 +0530102 list_qos_policies(name=policy1)['policies'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000103 self.assertEqual(1, len(policies))
104
105 retrieved_policy = policies[0]
yatinkarel65fa2c02022-01-28 13:44:19 +0530106 self.assertEqual(policy1, retrieved_policy['name'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000107
likangkang01afd73f72020-06-01 16:53:59 +0800108 @decorators.idempotent_id('dde0b449-a400-4a87-b5a5-4d1c413c917b')
109 def test_list_policy_sort_by_name(self):
110 policyA = 'A' + data_utils.rand_name("policy")
111 policyB = 'B' + data_utils.rand_name("policy")
112 self.create_qos_policy(name=policyA, description='test policy',
113 shared=False)
114 self.create_qos_policy(name=policyB, description='test policy',
115 shared=False)
116
117 param = {
118 'sort_key': 'name',
119 'sort_dir': 'asc'
120 }
121 policies = (self.admin_client.list_qos_policies(**param)['policies'])
122 policy_names = [p['name'] for p in policies]
123 self.assertLess(policy_names.index(policyA),
124 policy_names.index(policyB))
125
126 param = {
127 'sort_key': 'name',
128 'sort_dir': 'desc'
129 }
130 policies = (self.admin_client.list_qos_policies(**param)['policies'])
131 policy_names = [p['name'] for p in policies]
132 self.assertLess(policy_names.index(policyB),
133 policy_names.index(policyA))
134
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000135 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000136 def test_policy_update(self):
elajkat757f3f12022-01-28 11:17:55 +0100137 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000138 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000139 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000140 project_id=self.admin_client.tenant_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,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000156 project_id=self.client.tenant_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):
elajkat757f3f12022-01-28 11:17:55 +0100164 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000165 description='',
166 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000167 project_id=self.admin_client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000168 self.assertRaises(
169 exceptions.NotFound,
170 self.client.update_qos_policy,
171 policy['id'], description='test policy')
172
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000173 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000174 def test_shared_policy_update(self):
elajkat757f3f12022-01-28 11:17:55 +0100175 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000176 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000177 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000178 project_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000179
180 self.admin_client.update_qos_policy(policy['id'],
181 description='test policy desc2')
182 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
183 retrieved_policy = retrieved_policy['policy']
184 self.assertTrue(retrieved_policy['shared'])
185
186 self.admin_client.update_qos_policy(policy['id'],
187 shared=False)
188 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
189 retrieved_policy = retrieved_policy['policy']
190 self.assertFalse(retrieved_policy['shared'])
191
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000192 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000193 def test_delete_policy(self):
194 policy = self.admin_client.create_qos_policy(
195 'test-policy', 'desc', True)['policy']
196
197 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
198 retrieved_policy = retrieved_policy['policy']
199 self.assertEqual('test-policy', retrieved_policy['name'])
200
201 self.admin_client.delete_qos_policy(policy['id'])
202 self.assertRaises(exceptions.NotFound,
203 self.admin_client.show_qos_policy, policy['id'])
204
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000205 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000206 def test_list_admin_rule_types(self):
207 self._test_list_rule_types(self.admin_client)
208
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000209 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000210 def test_list_regular_rule_types(self):
211 self._test_list_rule_types(self.client)
212
213 def _test_list_rule_types(self, client):
214 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000215 # Since returned rule types depends on loaded backend drivers this test
216 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000217 #
218 # In theory, we could make the test conditional on which ml2 drivers
219 # are enabled in gate (or more specifically, on which supported qos
220 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200221 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000222 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000223
224 rule_types = client.list_qos_rule_types()
225 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000226
227 # Verify that only required fields present in rule details
228 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000229 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000230
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000231 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
232 def test_show_rule_type_details_as_user(self):
233 self.assertRaises(
234 exceptions.Forbidden,
235 self.client.show_qos_rule_type,
236 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
237
238 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
239 def test_show_rule_type_details_as_admin(self):
240 # Since returned rule types depend on loaded backend drivers this test
241 # is checking only if returned keys are same as expected keys
242
243 # In theory, we could make the test conditional on which ml2 drivers
244 # are enabled in gate, but that option doesn't seem to be
245 # available through tempest.lib framework
246 expected_rule_type_details_keys = ['type', 'drivers']
247
248 rule_type_details = self.admin_client.show_qos_rule_type(
249 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
250
251 # Verify that only required fields present in rule details
252 self.assertEqual(
253 sorted(tuple(expected_rule_type_details_keys)),
254 sorted(tuple(rule_type_details.keys())))
255
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000256 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000257 def test_policy_association_with_admin_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100258 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000259 description='test policy',
260 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200261 network = self.create_network('test network', shared=True,
262 qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000263
264 retrieved_network = self.admin_client.show_network(network['id'])
265 self.assertEqual(
266 policy['id'], retrieved_network['network']['qos_policy_id'])
267
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000268 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000269 def test_policy_association_with_tenant_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100270 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000271 description='test policy',
272 shared=True)
273 network = self.create_network('test network',
274 qos_policy_id=policy['id'])
275
276 retrieved_network = self.admin_client.show_network(network['id'])
277 self.assertEqual(
278 policy['id'], retrieved_network['network']['qos_policy_id'])
279
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000280 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000281 def test_policy_association_with_network_nonexistent_policy(self):
282 self.assertRaises(
283 exceptions.NotFound,
284 self.create_network,
285 'test network',
286 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
287
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000288 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000289 def test_policy_association_with_network_non_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100290 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000291 description='test policy',
292 shared=False)
293 self.assertRaises(
294 exceptions.NotFound,
295 self.create_network,
296 'test network', qos_policy_id=policy['id'])
297
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000298 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000299 def test_policy_update_association_with_admin_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100300 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000301 description='test policy',
302 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200303 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000304 retrieved_network = self.admin_client.show_network(network['id'])
305 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
306
307 self.admin_client.update_network(network['id'],
308 qos_policy_id=policy['id'])
309 retrieved_network = self.admin_client.show_network(network['id'])
310 self.assertEqual(
311 policy['id'], retrieved_network['network']['qos_policy_id'])
312
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000313 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000314 def test_policy_association_with_port_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100315 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000316 description='test policy',
317 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200318 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000319 port = self.create_port(network, qos_policy_id=policy['id'])
320
321 retrieved_port = self.admin_client.show_port(port['id'])
322 self.assertEqual(
323 policy['id'], retrieved_port['port']['qos_policy_id'])
324
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000325 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000326 def test_policy_association_with_port_nonexistent_policy(self):
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200327 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000328 self.assertRaises(
329 exceptions.NotFound,
330 self.create_port,
331 network,
332 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
333
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000334 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000335 def test_policy_association_with_port_non_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100336 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000337 description='test policy',
338 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200339 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000340 self.assertRaises(
341 exceptions.NotFound,
342 self.create_port,
343 network, qos_policy_id=policy['id'])
344
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000345 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000346 def test_policy_update_association_with_port_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100347 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000348 description='test policy',
349 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200350 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000351 port = self.create_port(network)
352 retrieved_port = self.admin_client.show_port(port['id'])
353 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
354
355 self.client.update_port(port['id'], qos_policy_id=policy['id'])
356 retrieved_port = self.admin_client.show_port(port['id'])
357 self.assertEqual(
358 policy['id'], retrieved_port['port']['qos_policy_id'])
359
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000360 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000361 def test_delete_not_allowed_if_policy_in_use_by_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100362 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000363 description='test policy',
364 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200365 self.create_network('test network', qos_policy_id=policy['id'],
366 shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000367 self.assertRaises(
368 exceptions.Conflict,
369 self.admin_client.delete_qos_policy, policy['id'])
370
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000371 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000372 def test_delete_not_allowed_if_policy_in_use_by_port(self):
elajkat757f3f12022-01-28 11:17:55 +0100373 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000374 description='test policy',
375 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200376 network = self.create_network('test network', shared=True)
Sławek Kapłońskie100c4d2017-08-23 21:18:34 +0000377 self.create_port(network, qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000378 self.assertRaises(
379 exceptions.Conflict,
380 self.admin_client.delete_qos_policy, policy['id'])
381
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000382 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000383 def test_qos_policy_delete_with_rules(self):
elajkat757f3f12022-01-28 11:17:55 +0100384 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000385 description='test policy',
386 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300387 self._create_qos_bw_limit_rule(
388 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000389 self.admin_client.delete_qos_policy(policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000390 with testtools.ExpectedException(exceptions.NotFound):
391 self.admin_client.show_qos_policy(policy['id'])
392
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000393 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000394 def test_get_policy_that_is_shared(self):
395 policy = self.create_qos_policy(
396 name='test-policy-shared',
397 description='shared policy',
398 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000399 project_id=self.admin_client.tenant_id)
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000400 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
401 self.assertEqual(obtained_policy, policy)
402
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000403 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100404 def test_policy_create_forbidden_for_regular_tenants(self):
405 self.assertRaises(
406 exceptions.Forbidden,
407 self.client.create_qos_policy,
408 'test-policy', 'test policy', False)
409
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900410 @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
411 def test_default_policy_creating_network_without_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530412 project_id = self.create_project()['id']
elajkat757f3f12022-01-28 11:17:55 +0100413 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000414 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900415 is_default=True)
416 network = self.create_network('test network', client=self.admin_client,
417 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900418 retrieved_network = self.admin_client.show_network(network['id'])
419 self.assertEqual(
420 policy['id'], retrieved_network['network']['qos_policy_id'])
421
422 @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
423 def test_default_policy_creating_network_with_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530424 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900425 self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000426 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900427 is_default=True)
428 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000429 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900430 network = self.create_network('test network', client=self.admin_client,
431 project_id=project_id,
432 qos_policy_id=policy['id'])
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900433 retrieved_network = self.admin_client.show_network(network['id'])
434 self.assertEqual(
435 policy['id'], retrieved_network['network']['qos_policy_id'])
436
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100437 @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229')
438 def test_user_create_port_with_admin_qos_policy(self):
439 qos_policy = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +0100440 name=self.policy_name,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000441 project_id=self.admin_client.tenant_id,
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100442 shared=False)
443 network = self.create_network(
444 'test network', client=self.admin_client,
445 project_id=self.client.tenant_id,
446 qos_policy_id=qos_policy['id'])
447 port = self.create_port(network)
448 self.assertEqual(network['id'], port['network_id'])
449
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000450
451class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000452
zahlabut7ebb66e2021-09-01 22:39:49 +0300453 credentials = ['primary', 'admin']
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000454 direction = None
Chandan Kumarc125fd12017-11-15 19:41:01 +0530455 required_extensions = [qos_apidef.ALIAS]
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000456
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000457 @classmethod
zahlabut7ebb66e2021-09-01 22:39:49 +0300458 def setup_clients(cls):
459 super(QosBandwidthLimitRuleTestJSON, cls).setup_clients()
460 cls.qos_bw_limit_rule_client = \
461 cls.os_admin.qos_limit_bandwidth_rules_client
462 cls.qos_bw_limit_rule_client_primary = \
463 cls.os_primary.qos_limit_bandwidth_rules_client
464
465 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900466 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000467 def resource_setup(cls):
468 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
469
elajkat757f3f12022-01-28 11:17:55 +0100470 def setUp(self):
471 super(QosBandwidthLimitRuleTestJSON, self).setUp()
472 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
473
zahlabut7ebb66e2021-09-01 22:39:49 +0300474 def _create_qos_bw_limit_rule(self, policy_id, rule_data):
475 rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule(
476 qos_policy_id=policy_id,
477 **rule_data)['bandwidth_limit_rule']
478 self.addCleanup(
479 test_utils.call_and_ignore_notfound_exc,
480 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule,
481 policy_id, rule['id'])
482 return rule
483
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000484 @property
485 def opposite_direction(self):
486 if self.direction == "ingress":
487 return "egress"
488 elif self.direction == "egress":
489 return "ingress"
490 else:
491 return None
492
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000493 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000494 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +0100495 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000496 description='test policy',
497 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300498 rule = self._create_qos_bw_limit_rule(
499 policy['id'],
500 {'max_kbps': 200, 'max_burst_kbps': 1337, 'direction': 'ingress'})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000501
502 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +0300503 retrieved_rule = \
504 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
505 policy['id'], rule['id'])
506
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000507 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
508 self.assertEqual(rule['id'], retrieved_rule['id'])
509 self.assertEqual(200, retrieved_rule['max_kbps'])
510 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300511 self.assertEqual('ingress', retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000512
513 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300514 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
515 policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000516 rules = rules['bandwidth_limit_rules']
517 rules_ids = [r['id'] for r in rules]
518 self.assertIn(rule['id'], rules_ids)
519
520 # Test 'show policy'
521 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
522 policy_rules = retrieved_policy['policy']['rules']
523 self.assertEqual(1, len(policy_rules))
524 self.assertEqual(rule['id'], policy_rules[0]['id'])
525 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
526 policy_rules[0]['type'])
527
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000528 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000529 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +0100530 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000531 description='test policy',
532 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300533 self._create_qos_bw_limit_rule(
534 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000535
zahlabut7ebb66e2021-09-01 22:39:49 +0300536 self.assertRaises(
537 exceptions.Conflict,
538 self._create_qos_bw_limit_rule,
539 policy['id'],
540 {'max_kbps': 201, 'max_burst_kbps': 1338})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000541
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000542 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000543 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +0100544 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000545 description='test policy',
546 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300547 rule = self._create_qos_bw_limit_rule(
548 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000549
zahlabut7ebb66e2021-09-01 22:39:49 +0300550 if self.opposite_direction:
551 self.qos_bw_limit_rule_client.update_limit_bandwidth_rule(
552 policy['id'], rule['id'],
553 **{'max_kbps': 200, 'max_burst_kbps': 1337,
554 'direction': self.opposite_direction})
555 else:
556 self.qos_bw_limit_rule_client.update_limit_bandwidth_rule(
557 policy['id'], rule['id'],
558 **{'max_kbps': 200, 'max_burst_kbps': 1337})
559 retrieved_policy = self.qos_bw_limit_rule_client.\
560 show_limit_bandwidth_rule(policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000561 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
562 self.assertEqual(200, retrieved_policy['max_kbps'])
563 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000564 if self.opposite_direction:
565 self.assertEqual(self.opposite_direction,
566 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000567
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000568 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000569 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +0100570 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000571 description='test policy',
572 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300573 rule = self._create_qos_bw_limit_rule(
574 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
575 retrieved_policy = \
576 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
577 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000578 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
579 self.assertEqual(rule['id'], retrieved_policy['id'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300580 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule(
581 policy['id'], rule['id'])
582 self.assertRaises(
583 exceptions.NotFound,
584 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule,
585 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000586
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000587 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000588 def test_rule_create_rule_nonexistent_policy(self):
589 self.assertRaises(
590 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300591 self._create_qos_bw_limit_rule,
592 'policy', {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000593
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000594 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000595 def test_rule_create_forbidden_for_regular_tenants(self):
596 self.assertRaises(
597 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300598 self.qos_bw_limit_rule_client_primary.create_limit_bandwidth_rule,
599 'policy', **{'max_kbps': 1, 'max_burst_kbps': 2})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000600
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000601 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000602 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100603 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000604 description='test policy',
605 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000606 project_id=self.client.tenant_id)
zahlabut7ebb66e2021-09-01 22:39:49 +0300607 rule = self._create_qos_bw_limit_rule(
608 policy['id'],
609 {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000610 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400611 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300612 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
613 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000614
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000615 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000616 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300617 policy = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +0100618 name=self.policy_name,
zahlabut7ebb66e2021-09-01 22:39:49 +0300619 description='test policy',
620 shared=False,
621 project_id=self.admin_client.tenant_id)
622 rule = self._create_qos_bw_limit_rule(
623 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000624 self.assertRaises(
625 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300626 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
627 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000628
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000629 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000630 def test_get_rules_by_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300631 policy1 = self.create_qos_policy(
632 name='test-policy1',
633 description='test policy1',
634 shared=False)
635 rule1 = self._create_qos_bw_limit_rule(
636 policy1['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000637
zahlabut7ebb66e2021-09-01 22:39:49 +0300638 policy2 = self.create_qos_policy(
639 name='test-policy2',
640 description='test policy2',
641 shared=False)
642 rule2 = self._create_qos_bw_limit_rule(
643 policy2['id'], {'max_kbps': 5000, 'max_burst_kbps': 2523})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000644
645 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300646 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
647 policy1['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000648 rules = rules['bandwidth_limit_rules']
649 rules_ids = [r['id'] for r in rules]
650 self.assertIn(rule1['id'], rules_ids)
651 self.assertNotIn(rule2['id'], rules_ids)
652
nfridman07f0e782019-11-04 09:12:58 -0500653 @testtools.skipUnless(
654 CONF.neutron_plugin_options.create_shared_resources,
655 """Creation of shared resources should be allowed,
656 setting the create_shared_resources option as 'True' is needed""")
657 @decorators.idempotent_id('d911707e-fa2c-11e9-9553-5076af30bbf5')
658 def test_attach_and_detach_a_policy_by_a_tenant(self):
659 # As an admin create an non shared QoS policy,add a rule
660 # and associate it with a network
661 self.network = self.create_network()
elajkat757f3f12022-01-28 11:17:55 +0100662 policy = self.create_qos_policy(name=self.policy_name,
nfridman07f0e782019-11-04 09:12:58 -0500663 description='test policy for attach',
664 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300665 self._create_qos_bw_limit_rule(
666 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024})
nfridman07f0e782019-11-04 09:12:58 -0500667
668 self.admin_client.update_network(
669 self.network['id'], qos_policy_id=policy['id'])
670
671 # As a tenant, try to detach the policy from the network
672 # The operation should be forbidden
673 self.assertRaises(
674 exceptions.Forbidden,
675 self.client.update_network,
676 self.network['id'], qos_policy_id=None)
677
678 # As an admin, make the policy shared
679 self.admin_client.update_qos_policy(policy['id'], shared=True)
680
681 # As a tenant, try to detach the policy from the network
682 # The operation should be allowed
683 self.client.update_network(self.network['id'],
684 qos_policy_id=None)
685
686 retrieved_network = self.admin_client.show_network(self.network['id'])
687 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
688
689 # As a tenant, try to delete the policy from the network
690 # should be forbidden
691 self.assertRaises(
692 exceptions.Forbidden,
693 self.client.delete_qos_policy,
694 policy['id'])
695
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000696
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000697class QosBandwidthLimitRuleWithDirectionTestJSON(
Brian Haley6767cec2018-04-10 15:30:23 -0400698 QosBandwidthLimitRuleTestJSON):
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000699 required_extensions = (
700 QosBandwidthLimitRuleTestJSON.required_extensions +
701 ['qos-bw-limit-direction']
702 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000703 scenarios = [
704 ('ingress', {'direction': 'ingress'}),
705 ('egress', {'direction': 'egress'}),
706 ]
707
nfridman7717d9c2019-11-25 08:58:04 -0500708 @classmethod
709 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
710 def resource_setup(cls):
711 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
712
elajkat757f3f12022-01-28 11:17:55 +0100713 def setUp(self):
714 super(QosBandwidthLimitRuleWithDirectionTestJSON, self).setUp()
715 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
716
nfridman7717d9c2019-11-25 08:58:04 -0500717 @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667')
718 def test_create_policy_with_multiple_rules(self):
719 # Create a policy with multiple rules
elajkat757f3f12022-01-28 11:17:55 +0100720 policy = self.create_qos_policy(name=self.policy_name,
nfridman7717d9c2019-11-25 08:58:04 -0500721 description='test policy1',
722 shared=False)
723
zahlabut7ebb66e2021-09-01 22:39:49 +0300724 rule1 = self._create_qos_bw_limit_rule(
725 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
726 'direction': n_constants.EGRESS_DIRECTION})
727 rule2 = self._create_qos_bw_limit_rule(
728 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
729 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500730 # Check that the rules were added to the policy
zahlabut7ebb66e2021-09-01 22:39:49 +0300731 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
nfridman7717d9c2019-11-25 08:58:04 -0500732 policy['id'])['bandwidth_limit_rules']
zahlabut7ebb66e2021-09-01 22:39:49 +0300733
nfridman7717d9c2019-11-25 08:58:04 -0500734 rules_ids = [rule['id'] for rule in rules]
735 self.assertIn(rule1['id'], rules_ids)
736 self.assertIn(rule2['id'], rules_ids)
737
738 # Check that the rules creation fails for the same rule types
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.EGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500745
zahlabut7ebb66e2021-09-01 22:39:49 +0300746 self.assertRaises(
747 exceptions.Conflict,
748 self._create_qos_bw_limit_rule,
749 policy['id'],
750 {'max_kbps': 1025, 'max_burst_kbps': 1025,
751 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500752
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,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000800 project_id=self.admin_client.tenant_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': '*',
808 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000809 'project_id': self.admin_client.tenant_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(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000832 self.client.tenant_id)
833 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(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000865 self.client.tenant_id)
866 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(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000888 self.client.tenant_id)
889 # change to client2
890 update_res = self.admin_client.update_rbac_policy(
891 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
892 self.assertEqual(self.client2.tenant_id,
893 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(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000902 self.client2.tenant_id)
903 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(
925 wild['id'], target_tenant=self.client2.tenant_id)
926
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',
936 target_tenant=self.client.tenant_id)['rbac_policy']
937 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'],
951 action='access_as_shared', target_tenant=self.client2.tenant_id)
952 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(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000961 self.client.tenant_id)
962 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',
979 target_tenant=self.client2.tenant_id)['rbac_policy']
980 rbac_pol2 = self.admin_client.create_rbac_policy(
981 object_type='qos_policy', object_id=policy['id'],
982 action='access_as_shared',
983 target_tenant=self.admin_client.tenant_id)['rbac_policy']
984 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(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000996 self.client.tenant_id)['policy']
997 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',
1001 target_tenant=self.client2.tenant_id)
1002
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',
1198 shared=True)['id']
1199
1200 # Associate QoS to the network
1201 self.admin_client.update_network(
1202 self.network['id'], qos_policy_id=dscp_policy_id)
1203
1204 # Set a new DSCP rule with the first mark in range
1205 rule_id = self.admin_client.create_dscp_marking_rule(
1206 dscp_policy_id,
1207 n_constants.VALID_DSCP_MARKS[0])[
1208 'dscp_marking_rule']['id']
1209
1210 # Validate that the rule was set up properly
1211 retrieved_rule = self.client.show_dscp_marking_rule(
1212 dscp_policy_id, rule_id)['dscp_marking_rule']
1213 self.assertEqual(n_constants.VALID_DSCP_MARKS[0],
1214 retrieved_rule['dscp_mark'],
1215 """current DSCP mark is incorrect:
1216 expected value {0} actual value {1}
1217 """.format(n_constants.VALID_DSCP_MARKS[0],
1218 retrieved_rule['dscp_mark']))
1219
1220 # Try to set marks in range 8:56 (invalid marks should raise an error)
Rodolfo Alonso Hernandez3de3cd92022-08-23 21:41:02 +02001221 _test_update_dscp_mark_values(self, dscp_policy_id, rule_id,
1222 valid_dscp_marks)
nfridman23b44ad2019-09-05 09:46:50 -04001223
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001224
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001225class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
1226 DIRECTION_EGRESS = "egress"
1227 DIRECTION_INGRESS = "ingress"
1228 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
1229 RULES_NAME = RULE_NAME + "s"
Chandan Kumarc125fd12017-11-15 19:41:01 +05301230 required_extensions = [qos_apidef.ALIAS]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001231
1232 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001233 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001234 def resource_setup(cls):
1235 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
1236
zahlabut7ebb66e2021-09-01 22:39:49 +03001237 @classmethod
1238 def setup_clients(cls):
1239 super(QosMinimumBandwidthRuleTestJSON, cls).setup_clients()
1240 cls.qos_min_bw_rules_client = \
1241 cls.os_admin.qos_minimum_bandwidth_rules_client
1242 cls.qos_min_bw_rules_client_primary = \
1243 cls.os_primary.qos_minimum_bandwidth_rules_client
1244
elajkat757f3f12022-01-28 11:17:55 +01001245 def setUp(self):
1246 super(QosMinimumBandwidthRuleTestJSON, self).setUp()
1247 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
1248
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001249 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001250 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001251 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001252 description='test policy',
1253 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001254 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1255 qos_policy_id=policy['id'],
1256 **{'direction': self.DIRECTION_EGRESS,
1257 'min_kbps': 1138})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001258
1259 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +03001260 retrieved_rule = \
1261 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1262 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001263 retrieved_rule = retrieved_rule[self.RULE_NAME]
1264 self.assertEqual(rule['id'], retrieved_rule['id'])
1265 self.assertEqual(1138, retrieved_rule['min_kbps'])
1266 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1267
1268 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001269 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1270 policy['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001271 rules = rules[self.RULES_NAME]
1272 rules_ids = [r['id'] for r in rules]
1273 self.assertIn(rule['id'], rules_ids)
1274
1275 # Test 'show policy'
1276 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1277 policy_rules = retrieved_policy['policy']['rules']
1278 self.assertEqual(1, len(policy_rules))
1279 self.assertEqual(rule['id'], policy_rules[0]['id'])
1280 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1281 policy_rules[0]['type'])
1282
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001283 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001284 def test_rule_create_fail_for_missing_min_kbps(self):
elajkat757f3f12022-01-28 11:17:55 +01001285 policy = self.create_qos_policy(name=self.policy_name,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001286 description='test policy',
1287 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001288 self.assertRaises(
1289 exceptions.BadRequest,
1290 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1291 qos_policy_id=policy['id'],
1292 **{'direction': self.DIRECTION_EGRESS})
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001293
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001294 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001295 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001296 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001297 description='test policy',
1298 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001299 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1300 qos_policy_id=policy['id'],
1301 **{'direction': self.DIRECTION_EGRESS,
1302 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001303
zahlabut7ebb66e2021-09-01 22:39:49 +03001304 self.assertRaises(
1305 exceptions.Conflict,
1306 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1307 qos_policy_id=policy['id'],
1308 **{'direction': self.DIRECTION_EGRESS,
1309 'min_kbps': 201})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001310
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001311 @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936')
1312 @utils.requires_ext(extension="qos-bw-minimum-ingress",
1313 service="network")
1314 def test_rule_create_pass_for_direction_ingress(self):
elajkat757f3f12022-01-28 11:17:55 +01001315 policy = self.create_qos_policy(name=self.policy_name,
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001316 description='test policy',
1317 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001318 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1319 qos_policy_id=policy['id'],
1320 **{'direction': self.DIRECTION_INGRESS,
1321 'min_kbps': 201})
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001322
1323 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1324 policy_rules = retrieved_policy['policy']['rules']
1325 self.assertEqual(1, len(policy_rules))
1326 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1327 policy_rules[0]['type'])
1328 self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction'])
1329
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001330 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001331 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001332 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001333 description='test policy',
1334 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001335 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1336 qos_policy_id=policy['id'],
1337 **{'direction': self.DIRECTION_EGRESS,
1338 'min_kbps': 300})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001339
zahlabut7ebb66e2021-09-01 22:39:49 +03001340 self.qos_min_bw_rules_client.update_minimum_bandwidth_rule(
1341 policy['id'], rule['id'],
1342 **{'min_kbps': 350, 'direction': self.DIRECTION_EGRESS})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001343
zahlabut7ebb66e2021-09-01 22:39:49 +03001344 retrieved_policy = \
1345 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1346 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001347 retrieved_policy = retrieved_policy[self.RULE_NAME]
1348 self.assertEqual(350, retrieved_policy['min_kbps'])
1349 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1350
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001351 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001352 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001353 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001354 description='test policy',
1355 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001356 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1357 policy['id'],
1358 **{'direction': self.DIRECTION_EGRESS,
1359 'min_kbps': 200})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001360
zahlabut7ebb66e2021-09-01 22:39:49 +03001361 retrieved_policy = \
1362 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1363 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001364 retrieved_policy = retrieved_policy[self.RULE_NAME]
1365 self.assertEqual(rule['id'], retrieved_policy['id'])
1366
zahlabut7ebb66e2021-09-01 22:39:49 +03001367 self.qos_min_bw_rules_client.delete_minimum_bandwidth_rule(
1368 policy['id'], rule['id'])
1369 self.assertRaises(
1370 exceptions.NotFound,
1371 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule,
1372 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001373
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001374 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001375 def test_rule_create_rule_nonexistent_policy(self):
1376 self.assertRaises(
1377 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +03001378 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1379 'policy',
1380 **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001381
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001382 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001383 def test_rule_create_forbidden_for_regular_tenants(self):
1384 self.assertRaises(
1385 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +03001386 self.qos_min_bw_rules_client_primary.create_minimum_bandwidth_rule,
1387 'policy', **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 300})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001388
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001389 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001390 def test_get_rules_by_policy(self):
1391 policy1 = self.create_qos_policy(name='test-policy1',
1392 description='test policy1',
1393 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001394 rule1 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1395 qos_policy_id=policy1['id'],
1396 **{'direction': self.DIRECTION_EGRESS,
1397 'min_kbps': 200})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001398
1399 policy2 = self.create_qos_policy(name='test-policy2',
1400 description='test policy2',
1401 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001402 rule2 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1403 qos_policy_id=policy2['id'],
1404 **{'direction': self.DIRECTION_EGRESS,
1405 'min_kbps': 5000})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001406
1407 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001408 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1409 policy1['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001410 rules = rules[self.RULES_NAME]
1411 rules_ids = [r['id'] for r in rules]
1412 self.assertIn(rule1['id'], rules_ids)
1413 self.assertNotIn(rule2['id'], rules_ids)
1414
1415
elajkat4a1357b2021-08-31 10:16:25 +02001416class QosMinimumPpsRuleTestJSON(base.BaseAdminNetworkTest):
elajkat4a1357b2021-08-31 10:16:25 +02001417 required_extensions = [qos_apidef.ALIAS]
1418
1419 @classmethod
1420 @utils.requires_ext(service='network',
1421 extension='port-resource-request-groups')
1422 def resource_setup(cls):
1423 super(QosMinimumPpsRuleTestJSON, cls).resource_setup()
1424
1425 @classmethod
1426 def setup_clients(cls):
1427 super(QosMinimumPpsRuleTestJSON, cls).setup_clients()
1428 cls.min_pps_client = cls.os_admin.qos_minimum_packet_rate_rules_client
1429 cls.min_pps_client_primary = \
1430 cls.os_primary.qos_minimum_packet_rate_rules_client
1431
elajkat757f3f12022-01-28 11:17:55 +01001432 def setUp(self):
1433 super(QosMinimumPpsRuleTestJSON, self).setUp()
1434 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
Chandan Kumar (raukadah)255586c2022-03-10 09:43:37 +05301435 self.RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_PACKET_RATE + "_rule"
1436 self.RULES_NAME = self.RULE_NAME + "s"
elajkat757f3f12022-01-28 11:17:55 +01001437
elajkat4a1357b2021-08-31 10:16:25 +02001438 def _create_qos_min_pps_rule(self, policy_id, rule_data):
1439 rule = self.min_pps_client.create_minimum_packet_rate_rule(
1440 policy_id, **rule_data)['minimum_packet_rate_rule']
1441 self.addCleanup(
1442 test_utils.call_and_ignore_notfound_exc,
1443 self.min_pps_client.delete_minimum_packet_rate_rule,
1444 policy_id, rule['id'])
1445 return rule
1446
1447 @decorators.idempotent_id('66a5b9b4-d4f9-4af8-b238-9e1881b78487')
1448 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001449 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001450 description='test policy',
1451 shared=False)
1452 rule = self._create_qos_min_pps_rule(
1453 policy['id'],
1454 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1455 qos_consts.MIN_KPPS: 1138})
1456
1457 # Test 'show rule'
1458 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1459 policy['id'], rule['id'])[self.RULE_NAME]
1460 self.assertEqual(rule['id'], retrieved_rule['id'])
1461 self.assertEqual(1138, retrieved_rule[qos_consts.MIN_KPPS])
1462 self.assertEqual(n_constants.EGRESS_DIRECTION,
1463 retrieved_rule[qos_consts.DIRECTION])
1464
1465 # Test 'list rules'
1466 rules = self.min_pps_client.list_minimum_packet_rate_rules(
1467 policy['id'])
1468 rules = rules[self.RULES_NAME]
1469 rules_ids = [r['id'] for r in rules]
1470 self.assertIn(rule['id'], rules_ids)
1471
1472 # Test 'show policy'
1473 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1474 policy_rules = retrieved_policy['policy']['rules']
1475 self.assertEqual(1, len(policy_rules))
1476 self.assertEqual(rule['id'], policy_rules[0]['id'])
1477 self.assertEqual('minimum_packet_rate',
1478 policy_rules[0]['type'])
1479
1480 @decorators.idempotent_id('6b656b57-d2bf-47f9-89a9-1baad1bd5418')
1481 def test_rule_create_fail_for_missing_min_kpps(self):
elajkat757f3f12022-01-28 11:17:55 +01001482 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001483 description='test policy',
1484 shared=False)
1485 self.assertRaises(exceptions.BadRequest,
1486 self._create_qos_min_pps_rule,
1487 policy['id'],
1488 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION})
1489
1490 @decorators.idempotent_id('f41213e5-2ab8-4916-b106-38d2cac5e18c')
1491 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001492 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001493 description='test policy',
1494 shared=False)
1495 self._create_qos_min_pps_rule(policy['id'],
1496 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1497 qos_consts.MIN_KPPS: 200})
1498
1499 self.assertRaises(exceptions.Conflict,
1500 self._create_qos_min_pps_rule,
1501 policy['id'],
1502 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1503 qos_consts.MIN_KPPS: 201})
1504
1505 @decorators.idempotent_id('ceb8e41e-3d72-11ec-a446-d7faae6daec2')
1506 def test_rule_create_any_direction_when_egress_direction_exists(self):
elajkat757f3f12022-01-28 11:17:55 +01001507 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001508 description='test policy',
1509 shared=False)
1510 self._create_qos_min_pps_rule(policy['id'],
1511 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1512 qos_consts.MIN_KPPS: 200})
1513
1514 self.assertRaises(exceptions.Conflict,
1515 self._create_qos_min_pps_rule,
1516 policy['id'],
1517 {qos_consts.DIRECTION: n_constants.ANY_DIRECTION,
1518 qos_consts.MIN_KPPS: 201})
1519
1520 @decorators.idempotent_id('a147a71e-3d7b-11ec-8097-278b1afd5fa2')
1521 def test_rule_create_egress_direction_when_any_direction_exists(self):
elajkat757f3f12022-01-28 11:17:55 +01001522 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001523 description='test policy',
1524 shared=False)
1525 self._create_qos_min_pps_rule(policy['id'],
1526 {qos_consts.DIRECTION: n_constants.ANY_DIRECTION,
1527 qos_consts.MIN_KPPS: 200})
1528
1529 self.assertRaises(exceptions.Conflict,
1530 self._create_qos_min_pps_rule,
1531 policy['id'],
1532 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1533 qos_consts.MIN_KPPS: 201})
1534
1535 @decorators.idempotent_id('522ed09a-1d7f-4c1b-9195-61f19caf916f')
1536 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001537 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001538 description='test policy',
1539 shared=False)
1540 rule = self._create_qos_min_pps_rule(
1541 policy['id'],
1542 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1543 qos_consts.MIN_KPPS: 300})
1544
1545 self.min_pps_client.update_minimum_packet_rate_rule(
1546 policy['id'], rule['id'],
1547 **{qos_consts.MIN_KPPS: 350,
1548 qos_consts.DIRECTION: n_constants.ANY_DIRECTION})
1549
1550 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1551 policy['id'], rule['id'])[self.RULE_NAME]
1552 self.assertEqual(350, retrieved_rule[qos_consts.MIN_KPPS])
1553 self.assertEqual(n_constants.ANY_DIRECTION,
1554 retrieved_rule[qos_consts.DIRECTION])
1555
1556 @decorators.idempotent_id('a020e186-3d60-11ec-88ca-d7f5eec22764')
1557 def test_rule_update_direction_conflict(self):
elajkat757f3f12022-01-28 11:17:55 +01001558 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001559 description='test policy',
1560 shared=False)
1561 rule1 = self._create_qos_min_pps_rule(
1562 policy['id'],
1563 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1564 qos_consts.MIN_KPPS: 300})
1565
1566 rule2 = self._create_qos_min_pps_rule(
1567 policy['id'],
1568 {qos_consts.DIRECTION: n_constants.INGRESS_DIRECTION,
1569 qos_consts.MIN_KPPS: 300})
1570
1571 retrieved_rule1 = self.min_pps_client.show_minimum_packet_rate_rule(
1572 policy['id'], rule1['id'])[self.RULE_NAME]
1573 self.assertEqual(n_constants.EGRESS_DIRECTION,
1574 retrieved_rule1[qos_consts.DIRECTION])
1575 retrieved_rule2 = self.min_pps_client.show_minimum_packet_rate_rule(
1576 policy['id'], rule2['id'])[self.RULE_NAME]
1577 self.assertEqual(n_constants.INGRESS_DIRECTION,
1578 retrieved_rule2[qos_consts.DIRECTION])
1579
1580 self.assertRaises(exceptions.Conflict,
1581 self.min_pps_client.update_minimum_packet_rate_rule,
1582 policy['id'], rule2['id'],
1583 **{qos_consts.DIRECTION: n_constants.ANY_DIRECTION})
1584
1585 @decorators.idempotent_id('c49018b6-d358-49a1-a94b-d53224165045')
1586 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001587 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001588 description='test policy',
1589 shared=False)
1590 rule = self._create_qos_min_pps_rule(
1591 policy['id'],
1592 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1593 qos_consts.MIN_KPPS: 200})
1594
1595 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1596 policy['id'], rule['id'])[self.RULE_NAME]
1597 self.assertEqual(rule['id'], retrieved_rule['id'])
1598
1599 self.min_pps_client.delete_minimum_packet_rate_rule(policy['id'],
1600 rule['id'])
1601 self.assertRaises(exceptions.NotFound,
1602 self.min_pps_client.show_minimum_packet_rate_rule,
1603 policy['id'], rule['id'])
1604
1605 @decorators.idempotent_id('1a6b6128-3d3e-11ec-bf49-57b326d417c0')
1606 def test_rule_create_forbidden_for_regular_tenants(self):
1607 self.assertRaises(
1608 exceptions.Forbidden,
1609 self.min_pps_client_primary.create_minimum_packet_rate_rule,
1610 'policy', **{qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1611 qos_consts.MIN_KPPS: 300})
1612
1613 @decorators.idempotent_id('1b94f4e2-3d3e-11ec-bb21-6f98e4044b8b')
1614 def test_get_rules_by_policy(self):
1615 policy1 = self.create_qos_policy(name='test-policy1',
1616 description='test policy1',
1617 shared=False)
1618 rule1 = self._create_qos_min_pps_rule(
1619 policy1['id'],
1620 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1621 qos_consts.MIN_KPPS: 200})
1622
1623 policy2 = self.create_qos_policy(name='test-policy2',
1624 description='test policy2',
1625 shared=False)
1626 rule2 = self._create_qos_min_pps_rule(
1627 policy2['id'],
1628 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1629 qos_consts.MIN_KPPS: 5000})
1630
1631 # Test 'list rules'
1632 rules = self.min_pps_client.list_minimum_packet_rate_rules(
1633 policy1['id'])
1634 rules = rules[self.RULES_NAME]
1635 rules_ids = [r['id'] for r in rules]
1636 self.assertIn(rule1['id'], rules_ids)
1637 self.assertNotIn(rule2['id'], rules_ids)
1638
1639
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001640class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1641 base.BaseAdminNetworkTest):
1642
1643 resource = 'policy'
1644 plural_name = 'policies'
1645
1646 # Use unique description to isolate the tests from other QoS tests
1647 list_kwargs = {'description': 'search-criteria-test'}
1648 list_as_admin = True
1649
Chandan Kumarc125fd12017-11-15 19:41:01 +05301650 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001651
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001652 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001653 def resource_setup(cls):
1654 super(QosSearchCriteriaTest, cls).resource_setup()
1655 for name in cls.resource_names:
1656 cls.create_qos_policy(
1657 name=name, description='search-criteria-test')
1658
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001659 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001660 def test_list_sorts_asc(self):
1661 self._test_list_sorts_asc()
1662
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001663 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001664 def test_list_sorts_desc(self):
1665 self._test_list_sorts_desc()
1666
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001667 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001668 def test_list_pagination(self):
1669 self._test_list_pagination()
1670
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001671 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001672 def test_list_pagination_with_marker(self):
1673 self._test_list_pagination_with_marker()
1674
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001675 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001676 def test_list_pagination_with_href_links(self):
1677 self._test_list_pagination_with_href_links()
1678
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001679 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001680 def test_list_pagination_page_reverse_asc(self):
1681 self._test_list_pagination_page_reverse_asc()
1682
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001683 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001684 def test_list_pagination_page_reverse_desc(self):
1685 self._test_list_pagination_page_reverse_desc()
1686
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001687 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001688 def test_list_pagination_page_reverse_with_href_links(self):
1689 self._test_list_pagination_page_reverse_with_href_links()
1690
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001691 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001692 def test_list_no_pagination_limit_0(self):
1693 self._test_list_no_pagination_limit_0()