blob: 448f391b86bb3e1ddbb2bda76cda776435771e6f [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)
Takashi Kajinamida451772023-03-22 00:19:39 +090089 self.assertEqual(self.admin_client.project_id,
Henry Gessaufa6c78d2016-10-09 19:56:09 -040090 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):
Takashi Kajinamida451772023-03-22 00:19:39 +0900137 policy = self.create_qos_policy(
138 name=self.policy_name,
139 description='',
140 shared=False,
141 project_id=self.admin_client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000142 self.admin_client.update_qos_policy(policy['id'],
143 description='test policy desc2',
144 shared=True)
145
146 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
147 retrieved_policy = retrieved_policy['policy']
148 self.assertEqual('test policy desc2', retrieved_policy['description'])
149 self.assertTrue(retrieved_policy['shared'])
150 self.assertEqual([], retrieved_policy['rules'])
151
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000152 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000153 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100154 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000155 description='',
156 shared=False,
Takashi Kajinamida451772023-03-22 00:19:39 +0900157 project_id=self.client.project_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000158 self.assertRaises(
159 exceptions.Forbidden,
160 self.client.update_qos_policy,
161 policy['id'], description='test policy')
162
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000163 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000164 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
Takashi Kajinamida451772023-03-22 00:19:39 +0900165 policy = self.create_qos_policy(
166 name=self.policy_name,
167 description='',
168 shared=False,
169 project_id=self.admin_client.project_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000170 self.assertRaises(
171 exceptions.NotFound,
172 self.client.update_qos_policy,
173 policy['id'], description='test policy')
174
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000175 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000176 def test_shared_policy_update(self):
Takashi Kajinamida451772023-03-22 00:19:39 +0900177 policy = self.create_qos_policy(
178 name=self.policy_name,
179 description='',
180 shared=True,
181 project_id=self.admin_client.project_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000182
183 self.admin_client.update_qos_policy(policy['id'],
184 description='test policy desc2')
185 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
186 retrieved_policy = retrieved_policy['policy']
187 self.assertTrue(retrieved_policy['shared'])
188
189 self.admin_client.update_qos_policy(policy['id'],
190 shared=False)
191 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
192 retrieved_policy = retrieved_policy['policy']
193 self.assertFalse(retrieved_policy['shared'])
194
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000195 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000196 def test_delete_policy(self):
197 policy = self.admin_client.create_qos_policy(
198 'test-policy', 'desc', True)['policy']
199
200 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
201 retrieved_policy = retrieved_policy['policy']
202 self.assertEqual('test-policy', retrieved_policy['name'])
203
204 self.admin_client.delete_qos_policy(policy['id'])
205 self.assertRaises(exceptions.NotFound,
206 self.admin_client.show_qos_policy, policy['id'])
207
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000208 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000209 def test_list_admin_rule_types(self):
210 self._test_list_rule_types(self.admin_client)
211
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000212 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000213 def test_list_regular_rule_types(self):
214 self._test_list_rule_types(self.client)
215
216 def _test_list_rule_types(self, client):
217 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000218 # Since returned rule types depends on loaded backend drivers this test
219 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000220 #
221 # In theory, we could make the test conditional on which ml2 drivers
222 # are enabled in gate (or more specifically, on which supported qos
223 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200224 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000225 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000226
227 rule_types = client.list_qos_rule_types()
228 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000229
230 # Verify that only required fields present in rule details
231 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000232 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000233
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000234 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
235 def test_show_rule_type_details_as_user(self):
236 self.assertRaises(
237 exceptions.Forbidden,
238 self.client.show_qos_rule_type,
239 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
240
241 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
242 def test_show_rule_type_details_as_admin(self):
243 # Since returned rule types depend on loaded backend drivers this test
244 # is checking only if returned keys are same as expected keys
245
246 # In theory, we could make the test conditional on which ml2 drivers
247 # are enabled in gate, but that option doesn't seem to be
248 # available through tempest.lib framework
249 expected_rule_type_details_keys = ['type', 'drivers']
250
251 rule_type_details = self.admin_client.show_qos_rule_type(
252 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
253
254 # Verify that only required fields present in rule details
255 self.assertEqual(
256 sorted(tuple(expected_rule_type_details_keys)),
257 sorted(tuple(rule_type_details.keys())))
258
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000259 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000260 def test_policy_association_with_admin_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100261 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000262 description='test policy',
263 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200264 network = self.create_network('test network', shared=True,
265 qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000266
267 retrieved_network = self.admin_client.show_network(network['id'])
268 self.assertEqual(
269 policy['id'], retrieved_network['network']['qos_policy_id'])
270
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000271 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000272 def test_policy_association_with_tenant_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100273 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000274 description='test policy',
275 shared=True)
276 network = self.create_network('test network',
277 qos_policy_id=policy['id'])
278
279 retrieved_network = self.admin_client.show_network(network['id'])
280 self.assertEqual(
281 policy['id'], retrieved_network['network']['qos_policy_id'])
282
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000283 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000284 def test_policy_association_with_network_nonexistent_policy(self):
285 self.assertRaises(
286 exceptions.NotFound,
287 self.create_network,
288 'test network',
289 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
290
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000291 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000292 def test_policy_association_with_network_non_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100293 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000294 description='test policy',
295 shared=False)
296 self.assertRaises(
297 exceptions.NotFound,
298 self.create_network,
299 'test network', qos_policy_id=policy['id'])
300
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000301 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000302 def test_policy_update_association_with_admin_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100303 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000304 description='test policy',
305 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200306 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000307 retrieved_network = self.admin_client.show_network(network['id'])
308 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
309
310 self.admin_client.update_network(network['id'],
311 qos_policy_id=policy['id'])
312 retrieved_network = self.admin_client.show_network(network['id'])
313 self.assertEqual(
314 policy['id'], retrieved_network['network']['qos_policy_id'])
315
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000316 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000317 def test_policy_association_with_port_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100318 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000319 description='test policy',
320 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200321 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000322 port = self.create_port(network, qos_policy_id=policy['id'])
323
324 retrieved_port = self.admin_client.show_port(port['id'])
325 self.assertEqual(
326 policy['id'], retrieved_port['port']['qos_policy_id'])
327
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000328 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000329 def test_policy_association_with_port_nonexistent_policy(self):
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200330 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000331 self.assertRaises(
332 exceptions.NotFound,
333 self.create_port,
334 network,
335 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
336
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000337 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000338 def test_policy_association_with_port_non_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100339 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000340 description='test policy',
341 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200342 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000343 self.assertRaises(
344 exceptions.NotFound,
345 self.create_port,
346 network, qos_policy_id=policy['id'])
347
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000348 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000349 def test_policy_update_association_with_port_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100350 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000351 description='test policy',
352 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200353 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000354 port = self.create_port(network)
355 retrieved_port = self.admin_client.show_port(port['id'])
356 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
357
358 self.client.update_port(port['id'], qos_policy_id=policy['id'])
359 retrieved_port = self.admin_client.show_port(port['id'])
360 self.assertEqual(
361 policy['id'], retrieved_port['port']['qos_policy_id'])
362
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000363 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000364 def test_delete_not_allowed_if_policy_in_use_by_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100365 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000366 description='test policy',
367 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200368 self.create_network('test network', qos_policy_id=policy['id'],
369 shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000370 self.assertRaises(
371 exceptions.Conflict,
372 self.admin_client.delete_qos_policy, policy['id'])
373
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000374 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000375 def test_delete_not_allowed_if_policy_in_use_by_port(self):
elajkat757f3f12022-01-28 11:17:55 +0100376 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000377 description='test policy',
378 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200379 network = self.create_network('test network', shared=True)
Sławek Kapłońskie100c4d2017-08-23 21:18:34 +0000380 self.create_port(network, qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000381 self.assertRaises(
382 exceptions.Conflict,
383 self.admin_client.delete_qos_policy, policy['id'])
384
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000385 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000386 def test_qos_policy_delete_with_rules(self):
elajkat757f3f12022-01-28 11:17:55 +0100387 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000388 description='test policy',
389 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300390 self._create_qos_bw_limit_rule(
391 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000392 self.admin_client.delete_qos_policy(policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000393 with testtools.ExpectedException(exceptions.NotFound):
394 self.admin_client.show_qos_policy(policy['id'])
395
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000396 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000397 def test_get_policy_that_is_shared(self):
398 policy = self.create_qos_policy(
399 name='test-policy-shared',
400 description='shared policy',
401 shared=True,
Takashi Kajinamida451772023-03-22 00:19:39 +0900402 project_id=self.admin_client.project_id)
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000403 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
404 self.assertEqual(obtained_policy, policy)
405
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000406 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100407 def test_policy_create_forbidden_for_regular_tenants(self):
408 self.assertRaises(
409 exceptions.Forbidden,
410 self.client.create_qos_policy,
411 'test-policy', 'test policy', False)
412
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900413 @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
414 def test_default_policy_creating_network_without_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530415 project_id = self.create_project()['id']
elajkat757f3f12022-01-28 11:17:55 +0100416 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000417 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900418 is_default=True)
419 network = self.create_network('test network', client=self.admin_client,
420 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900421 retrieved_network = self.admin_client.show_network(network['id'])
422 self.assertEqual(
423 policy['id'], retrieved_network['network']['qos_policy_id'])
424
425 @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
426 def test_default_policy_creating_network_with_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530427 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900428 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 is_default=True)
431 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000432 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900433 network = self.create_network('test network', client=self.admin_client,
434 project_id=project_id,
435 qos_policy_id=policy['id'])
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900436 retrieved_network = self.admin_client.show_network(network['id'])
437 self.assertEqual(
438 policy['id'], retrieved_network['network']['qos_policy_id'])
439
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100440 @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229')
441 def test_user_create_port_with_admin_qos_policy(self):
442 qos_policy = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +0100443 name=self.policy_name,
Takashi Kajinamida451772023-03-22 00:19:39 +0900444 project_id=self.admin_client.project_id,
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100445 shared=False)
446 network = self.create_network(
447 'test network', client=self.admin_client,
Takashi Kajinamida451772023-03-22 00:19:39 +0900448 project_id=self.client.project_id,
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100449 qos_policy_id=qos_policy['id'])
450 port = self.create_port(network)
451 self.assertEqual(network['id'], port['network_id'])
452
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000453
454class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000455
zahlabut7ebb66e2021-09-01 22:39:49 +0300456 credentials = ['primary', 'admin']
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000457 direction = None
Chandan Kumarc125fd12017-11-15 19:41:01 +0530458 required_extensions = [qos_apidef.ALIAS]
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000459
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000460 @classmethod
zahlabut7ebb66e2021-09-01 22:39:49 +0300461 def setup_clients(cls):
462 super(QosBandwidthLimitRuleTestJSON, cls).setup_clients()
463 cls.qos_bw_limit_rule_client = \
464 cls.os_admin.qos_limit_bandwidth_rules_client
465 cls.qos_bw_limit_rule_client_primary = \
466 cls.os_primary.qos_limit_bandwidth_rules_client
467
468 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900469 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000470 def resource_setup(cls):
471 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
472
elajkat757f3f12022-01-28 11:17:55 +0100473 def setUp(self):
474 super(QosBandwidthLimitRuleTestJSON, self).setUp()
475 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
476
zahlabut7ebb66e2021-09-01 22:39:49 +0300477 def _create_qos_bw_limit_rule(self, policy_id, rule_data):
478 rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule(
479 qos_policy_id=policy_id,
480 **rule_data)['bandwidth_limit_rule']
481 self.addCleanup(
482 test_utils.call_and_ignore_notfound_exc,
483 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule,
484 policy_id, rule['id'])
485 return rule
486
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000487 @property
488 def opposite_direction(self):
489 if self.direction == "ingress":
490 return "egress"
491 elif self.direction == "egress":
492 return "ingress"
493 else:
494 return None
495
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000496 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000497 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +0100498 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000499 description='test policy',
500 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300501 rule = self._create_qos_bw_limit_rule(
502 policy['id'],
503 {'max_kbps': 200, 'max_burst_kbps': 1337, 'direction': 'ingress'})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000504
505 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +0300506 retrieved_rule = \
507 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
508 policy['id'], rule['id'])
509
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000510 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
511 self.assertEqual(rule['id'], retrieved_rule['id'])
512 self.assertEqual(200, retrieved_rule['max_kbps'])
513 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300514 self.assertEqual('ingress', retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000515
516 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300517 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
518 policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000519 rules = rules['bandwidth_limit_rules']
520 rules_ids = [r['id'] for r in rules]
521 self.assertIn(rule['id'], rules_ids)
522
523 # Test 'show policy'
524 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
525 policy_rules = retrieved_policy['policy']['rules']
526 self.assertEqual(1, len(policy_rules))
527 self.assertEqual(rule['id'], policy_rules[0]['id'])
528 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
529 policy_rules[0]['type'])
530
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000531 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000532 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +0100533 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000534 description='test policy',
535 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300536 self._create_qos_bw_limit_rule(
537 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000538
zahlabut7ebb66e2021-09-01 22:39:49 +0300539 self.assertRaises(
540 exceptions.Conflict,
541 self._create_qos_bw_limit_rule,
542 policy['id'],
543 {'max_kbps': 201, 'max_burst_kbps': 1338})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000544
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000545 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000546 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +0100547 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000548 description='test policy',
549 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300550 rule = self._create_qos_bw_limit_rule(
551 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000552
zahlabut7ebb66e2021-09-01 22:39:49 +0300553 if self.opposite_direction:
554 self.qos_bw_limit_rule_client.update_limit_bandwidth_rule(
555 policy['id'], rule['id'],
556 **{'max_kbps': 200, 'max_burst_kbps': 1337,
557 'direction': self.opposite_direction})
558 else:
559 self.qos_bw_limit_rule_client.update_limit_bandwidth_rule(
560 policy['id'], rule['id'],
561 **{'max_kbps': 200, 'max_burst_kbps': 1337})
562 retrieved_policy = self.qos_bw_limit_rule_client.\
563 show_limit_bandwidth_rule(policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000564 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
565 self.assertEqual(200, retrieved_policy['max_kbps'])
566 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000567 if self.opposite_direction:
568 self.assertEqual(self.opposite_direction,
569 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000570
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000571 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000572 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +0100573 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000574 description='test policy',
575 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300576 rule = self._create_qos_bw_limit_rule(
577 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
578 retrieved_policy = \
579 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
580 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000581 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
582 self.assertEqual(rule['id'], retrieved_policy['id'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300583 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule(
584 policy['id'], rule['id'])
585 self.assertRaises(
586 exceptions.NotFound,
587 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule,
588 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000589
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000590 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000591 def test_rule_create_rule_nonexistent_policy(self):
592 self.assertRaises(
593 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300594 self._create_qos_bw_limit_rule,
595 'policy', {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000596
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000597 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000598 def test_rule_create_forbidden_for_regular_tenants(self):
599 self.assertRaises(
600 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300601 self.qos_bw_limit_rule_client_primary.create_limit_bandwidth_rule,
602 'policy', **{'max_kbps': 1, 'max_burst_kbps': 2})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000603
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000604 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000605 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100606 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000607 description='test policy',
608 shared=False,
Takashi Kajinamida451772023-03-22 00:19:39 +0900609 project_id=self.client.project_id)
zahlabut7ebb66e2021-09-01 22:39:49 +0300610 rule = self._create_qos_bw_limit_rule(
611 policy['id'],
612 {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000613 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400614 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300615 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
616 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000617
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000618 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000619 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300620 policy = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +0100621 name=self.policy_name,
zahlabut7ebb66e2021-09-01 22:39:49 +0300622 description='test policy',
623 shared=False,
Takashi Kajinamida451772023-03-22 00:19:39 +0900624 project_id=self.admin_client.project_id)
zahlabut7ebb66e2021-09-01 22:39:49 +0300625 rule = self._create_qos_bw_limit_rule(
626 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000627 self.assertRaises(
628 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300629 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
630 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000631
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000632 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000633 def test_get_rules_by_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300634 policy1 = self.create_qos_policy(
635 name='test-policy1',
636 description='test policy1',
637 shared=False)
638 rule1 = self._create_qos_bw_limit_rule(
639 policy1['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000640
zahlabut7ebb66e2021-09-01 22:39:49 +0300641 policy2 = self.create_qos_policy(
642 name='test-policy2',
643 description='test policy2',
644 shared=False)
645 rule2 = self._create_qos_bw_limit_rule(
646 policy2['id'], {'max_kbps': 5000, 'max_burst_kbps': 2523})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000647
648 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300649 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
650 policy1['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000651 rules = rules['bandwidth_limit_rules']
652 rules_ids = [r['id'] for r in rules]
653 self.assertIn(rule1['id'], rules_ids)
654 self.assertNotIn(rule2['id'], rules_ids)
655
nfridman07f0e782019-11-04 09:12:58 -0500656 @testtools.skipUnless(
657 CONF.neutron_plugin_options.create_shared_resources,
658 """Creation of shared resources should be allowed,
659 setting the create_shared_resources option as 'True' is needed""")
660 @decorators.idempotent_id('d911707e-fa2c-11e9-9553-5076af30bbf5')
661 def test_attach_and_detach_a_policy_by_a_tenant(self):
662 # As an admin create an non shared QoS policy,add a rule
663 # and associate it with a network
664 self.network = self.create_network()
elajkat757f3f12022-01-28 11:17:55 +0100665 policy = self.create_qos_policy(name=self.policy_name,
nfridman07f0e782019-11-04 09:12:58 -0500666 description='test policy for attach',
667 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300668 self._create_qos_bw_limit_rule(
669 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024})
nfridman07f0e782019-11-04 09:12:58 -0500670
671 self.admin_client.update_network(
672 self.network['id'], qos_policy_id=policy['id'])
673
674 # As a tenant, try to detach the policy from the network
675 # The operation should be forbidden
676 self.assertRaises(
677 exceptions.Forbidden,
678 self.client.update_network,
679 self.network['id'], qos_policy_id=None)
680
681 # As an admin, make the policy shared
682 self.admin_client.update_qos_policy(policy['id'], shared=True)
683
684 # As a tenant, try to detach the policy from the network
685 # The operation should be allowed
686 self.client.update_network(self.network['id'],
687 qos_policy_id=None)
688
689 retrieved_network = self.admin_client.show_network(self.network['id'])
690 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
691
692 # As a tenant, try to delete the policy from the network
693 # should be forbidden
694 self.assertRaises(
695 exceptions.Forbidden,
696 self.client.delete_qos_policy,
697 policy['id'])
698
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000699
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000700class QosBandwidthLimitRuleWithDirectionTestJSON(
Brian Haley6767cec2018-04-10 15:30:23 -0400701 QosBandwidthLimitRuleTestJSON):
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000702 required_extensions = (
703 QosBandwidthLimitRuleTestJSON.required_extensions +
704 ['qos-bw-limit-direction']
705 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000706 scenarios = [
707 ('ingress', {'direction': 'ingress'}),
708 ('egress', {'direction': 'egress'}),
709 ]
710
nfridman7717d9c2019-11-25 08:58:04 -0500711 @classmethod
712 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
713 def resource_setup(cls):
714 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
715
elajkat757f3f12022-01-28 11:17:55 +0100716 def setUp(self):
717 super(QosBandwidthLimitRuleWithDirectionTestJSON, self).setUp()
718 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
719
nfridman7717d9c2019-11-25 08:58:04 -0500720 @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667')
721 def test_create_policy_with_multiple_rules(self):
722 # Create a policy with multiple rules
elajkat757f3f12022-01-28 11:17:55 +0100723 policy = self.create_qos_policy(name=self.policy_name,
nfridman7717d9c2019-11-25 08:58:04 -0500724 description='test policy1',
725 shared=False)
726
zahlabut7ebb66e2021-09-01 22:39:49 +0300727 rule1 = self._create_qos_bw_limit_rule(
728 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
729 'direction': n_constants.EGRESS_DIRECTION})
730 rule2 = self._create_qos_bw_limit_rule(
731 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
732 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500733 # Check that the rules were added to the policy
zahlabut7ebb66e2021-09-01 22:39:49 +0300734 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
nfridman7717d9c2019-11-25 08:58:04 -0500735 policy['id'])['bandwidth_limit_rules']
zahlabut7ebb66e2021-09-01 22:39:49 +0300736
nfridman7717d9c2019-11-25 08:58:04 -0500737 rules_ids = [rule['id'] for rule in rules]
738 self.assertIn(rule1['id'], rules_ids)
739 self.assertIn(rule2['id'], rules_ids)
740
741 # Check that the rules creation fails for the same rule types
zahlabut7ebb66e2021-09-01 22:39:49 +0300742 self.assertRaises(
743 exceptions.Conflict,
744 self._create_qos_bw_limit_rule,
745 policy['id'],
746 {'max_kbps': 1025, 'max_burst_kbps': 1025,
747 'direction': n_constants.EGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500748
zahlabut7ebb66e2021-09-01 22:39:49 +0300749 self.assertRaises(
750 exceptions.Conflict,
751 self._create_qos_bw_limit_rule,
752 policy['id'],
753 {'max_kbps': 1025, 'max_burst_kbps': 1025,
754 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500755
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000756
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000757class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
758
759 force_tenant_isolation = True
760 credentials = ['primary', 'alt', 'admin']
Chandan Kumarc125fd12017-11-15 19:41:01 +0530761 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000762
763 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000764 def resource_setup(cls):
765 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530766 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000767
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000768 def _create_qos_policy(self, project_id=None):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000769 args = {'name': data_utils.rand_name('test-policy'),
770 'description': 'test policy',
771 'shared': False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000772 'project_id': project_id}
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000773 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
774 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
775
776 return qos_policy
777
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000778 def _make_admin_policy_shared_to_project_id(self, project_id):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000779 policy = self._create_qos_policy()
780 rbac_policy = self.admin_client.create_rbac_policy(
781 object_type='qos_policy',
782 object_id=policy['id'],
783 action='access_as_shared',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000784 target_tenant=project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000785 )['rbac_policy']
786
787 return {'policy': policy, 'rbac_policy': rbac_policy}
788
789 def _create_network(self, qos_policy_id, client, should_cleanup=True):
790 net = client.create_network(
791 name=data_utils.rand_name('test-network'),
792 qos_policy_id=qos_policy_id)['network']
793 if should_cleanup:
794 self.addCleanup(client.delete_network, net['id'])
795
796 return net
797
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000798 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000799 def test_policy_sharing_with_wildcard(self):
800 qos_pol = self.create_qos_policy(
801 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000802 description='test-shared-policy', shared=False,
Takashi Kajinamida451772023-03-22 00:19:39 +0900803 project_id=self.admin_client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000804 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
805
806 # test update shared False -> True
807 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
808 qos_pol['shared'] = True
809 self.client2.show_qos_policy(qos_pol['id'])
810 rbac_pol = {'target_tenant': '*',
Takashi Kajinamida451772023-03-22 00:19:39 +0900811 'tenant_id': self.admin_client.project_id,
812 'project_id': self.admin_client.project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000813 'object_type': 'qos_policy',
814 'object_id': qos_pol['id'],
815 'action': 'access_as_shared'}
816
817 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
818 rbac_policies = [r for r in rbac_policies if r.pop('id')]
819 self.assertIn(rbac_pol, rbac_policies)
820
821 # update shared True -> False should fail because the policy is bound
822 # to a network
823 net = self._create_network(qos_pol['id'], self.admin_client, False)
824 with testtools.ExpectedException(exceptions.Conflict):
825 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
826
827 # delete the network, and update shared True -> False should pass now
828 self.admin_client.delete_network(net['id'])
829 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
830 qos_pol['shared'] = False
831 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
832
833 def _create_net_bound_qos_rbacs(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000834 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900835 self.client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000836 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
837
838 # add a wildcard rbac rule - now the policy globally shared
839 rbac_wildcard = self.admin_client.create_rbac_policy(
840 object_type='qos_policy',
841 object_id=qos_policy['id'],
842 action='access_as_shared',
843 target_tenant='*',
844 )['rbac_policy']
845
846 # tenant1 now uses qos policy for net
847 self._create_network(qos_policy['id'], self.client)
848
849 return rbac_for_client_tenant, rbac_wildcard
850
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000851 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000852 def test_net_bound_shared_policy_wildcard_and_project_id_wild_remove(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000853 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
854 # globally unshare the qos-policy, the specific share should remain
855 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
856 self.client.list_rbac_policies(id=client_rbac['id'])
857
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000858 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000859 def test_net_bound_shared_policy_wildcard_and_projectid_wild_remains(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000860 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
861 # remove client_rbac policy the wildcard share should remain
862 self.admin_client.delete_rbac_policy(client_rbac['id'])
863 self.client.list_rbac_policies(id=wildcard_rbac['id'])
864
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000865 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000866 def test_policy_sharing_with_wildcard_and_project_id(self):
867 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900868 self.client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000869 qos_policy, rbac = res['policy'], res['rbac_policy']
870 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
871 self.assertTrue(qos_pol['shared'])
872 with testtools.ExpectedException(exceptions.NotFound):
873 self.client2.show_qos_policy(qos_policy['id'])
874
875 # make the qos-policy globally shared
876 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
877 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
878 self.assertTrue(qos_pol['shared'])
879
880 # globally unshare the qos-policy, the specific share should remain
881 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
882 self.client.show_qos_policy(qos_policy['id'])
883 with testtools.ExpectedException(exceptions.NotFound):
884 self.client2.show_qos_policy(qos_policy['id'])
885 self.assertIn(rbac,
886 self.admin_client.list_rbac_policies()['rbac_policies'])
887
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000888 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000889 def test_policy_target_update(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000890 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900891 self.client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000892 # change to client2
893 update_res = self.admin_client.update_rbac_policy(
Takashi Kajinamida451772023-03-22 00:19:39 +0900894 res['rbac_policy']['id'], target_tenant=self.client2.project_id)
895 self.assertEqual(self.client2.project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000896 update_res['rbac_policy']['target_tenant'])
897 # make sure everything else stayed the same
898 res['rbac_policy'].pop('target_tenant')
899 update_res['rbac_policy'].pop('target_tenant')
900 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
901
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000902 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000903 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000904 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900905 self.client2.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000906 qos_policy_id = res['policy']['id']
907 self._create_network(qos_policy_id, self.client2)
908 # a network with shared qos-policy should prevent the deletion of an
909 # rbac-policy required for it to be shared
910 with testtools.ExpectedException(exceptions.Conflict):
911 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
912
913 # a wildcard policy should allow the specific policy to be deleted
914 # since it allows the remaining port
915 wild = self.admin_client.create_rbac_policy(
916 object_type='qos_policy', object_id=res['policy']['id'],
917 action='access_as_shared', target_tenant='*')['rbac_policy']
918 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
919
920 # now that wildcard is the only remaining, it should be subjected to
921 # the same restriction
922 with testtools.ExpectedException(exceptions.Conflict):
923 self.admin_client.delete_rbac_policy(wild['id'])
924
925 # we can't update the policy to a different tenant
926 with testtools.ExpectedException(exceptions.Conflict):
927 self.admin_client.update_rbac_policy(
Takashi Kajinamida451772023-03-22 00:19:39 +0900928 wild['id'], target_tenant=self.client2.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000929
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000930 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000931 def test_regular_client_shares_to_another_regular_client(self):
932 # owned by self.admin_client
933 policy = self._create_qos_policy()
934 with testtools.ExpectedException(exceptions.NotFound):
935 self.client.show_qos_policy(policy['id'])
936 rbac_policy = self.admin_client.create_rbac_policy(
937 object_type='qos_policy', object_id=policy['id'],
938 action='access_as_shared',
Takashi Kajinamida451772023-03-22 00:19:39 +0900939 target_tenant=self.client.project_id)['rbac_policy']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000940 self.client.show_qos_policy(policy['id'])
941
942 self.assertIn(rbac_policy,
943 self.admin_client.list_rbac_policies()['rbac_policies'])
944 # ensure that 'client2' can't see the rbac-policy sharing the
945 # qos-policy to it because the rbac-policy belongs to 'client'
946 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
947 self.client2.list_rbac_policies()['rbac_policies']])
948
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000949 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000950 def test_filter_fields(self):
951 policy = self._create_qos_policy()
952 self.admin_client.create_rbac_policy(
953 object_type='qos_policy', object_id=policy['id'],
Takashi Kajinamida451772023-03-22 00:19:39 +0900954 action='access_as_shared', target_tenant=self.client2.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000955 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000956 ('project_id', 'target_tenant'))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000957 for fields in field_args:
958 res = self.admin_client.list_rbac_policies(fields=fields)
959 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
960
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000961 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000962 def test_rbac_policy_show(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000963 res = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900964 self.client.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000965 p1 = res['rbac_policy']
966 p2 = self.admin_client.create_rbac_policy(
967 object_type='qos_policy', object_id=res['policy']['id'],
968 action='access_as_shared',
969 target_tenant='*')['rbac_policy']
970
971 self.assertEqual(
972 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
973 self.assertEqual(
974 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
975
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000976 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000977 def test_filter_rbac_policies(self):
978 policy = self._create_qos_policy()
979 rbac_pol1 = self.admin_client.create_rbac_policy(
980 object_type='qos_policy', object_id=policy['id'],
981 action='access_as_shared',
Takashi Kajinamida451772023-03-22 00:19:39 +0900982 target_tenant=self.client2.project_id)['rbac_policy']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000983 rbac_pol2 = self.admin_client.create_rbac_policy(
984 object_type='qos_policy', object_id=policy['id'],
985 action='access_as_shared',
Takashi Kajinamida451772023-03-22 00:19:39 +0900986 target_tenant=self.admin_client.project_id)['rbac_policy']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000987 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
988 'rbac_policies']
989 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
990 'rbac_policies']
991 self.assertEqual(1, len(res1))
992 self.assertEqual(1, len(res2))
993 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
994 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
995
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000996 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000997 def test_regular_client_blocked_from_sharing_anothers_policy(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000998 qos_policy = self._make_admin_policy_shared_to_project_id(
Takashi Kajinamida451772023-03-22 00:19:39 +0900999 self.client.project_id)['policy']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001000 with testtools.ExpectedException(exceptions.BadRequest):
1001 self.client.create_rbac_policy(
1002 object_type='qos_policy', object_id=qos_policy['id'],
1003 action='access_as_shared',
Takashi Kajinamida451772023-03-22 00:19:39 +09001004 target_tenant=self.client2.project_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001005
1006 # make sure the rbac-policy is invisible to the tenant for which it's
1007 # being shared
1008 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
1009
1010
1011class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
1012 VALID_DSCP_MARK1 = 56
1013 VALID_DSCP_MARK2 = 48
1014
Chandan Kumarc125fd12017-11-15 19:41:01 +05301015 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001016
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001017 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001018 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001019 def resource_setup(cls):
1020 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
1021
elajkat757f3f12022-01-28 11:17:55 +01001022 def setUp(self):
1023 super(QosDscpMarkingRuleTestJSON, self).setUp()
1024 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
1025
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001026 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001027 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001028 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001029 description='test policy',
1030 shared=False)
1031 rule = self.admin_client.create_dscp_marking_rule(
1032 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1033
1034 # Test 'show rule'
1035 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1036 policy['id'], rule['id'])
1037 retrieved_rule = retrieved_rule['dscp_marking_rule']
1038 self.assertEqual(rule['id'], retrieved_rule['id'])
1039 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
1040
1041 # Test 'list rules'
1042 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
1043 rules = rules['dscp_marking_rules']
1044 rules_ids = [r['id'] for r in rules]
1045 self.assertIn(rule['id'], rules_ids)
1046
1047 # Test 'show policy'
1048 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1049 policy_rules = retrieved_policy['policy']['rules']
1050 self.assertEqual(1, len(policy_rules))
1051 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +00001052 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001053 policy_rules[0]['type'])
1054
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001055 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001056 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001057 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001058 description='test policy',
1059 shared=False)
1060 self.admin_client.create_dscp_marking_rule(
1061 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1062
1063 self.assertRaises(exceptions.Conflict,
1064 self.admin_client.create_dscp_marking_rule,
1065 policy_id=policy['id'],
1066 dscp_mark=self.VALID_DSCP_MARK2)
1067
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001068 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001069 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001070 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001071 description='test policy',
1072 shared=False)
1073 rule = self.admin_client.create_dscp_marking_rule(
1074 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1075
1076 self.admin_client.update_dscp_marking_rule(
1077 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
1078
1079 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1080 policy['id'], rule['id'])
1081 retrieved_policy = retrieved_policy['dscp_marking_rule']
1082 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
1083
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001084 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001085 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001086 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001087 description='test policy',
1088 shared=False)
1089 rule = self.admin_client.create_dscp_marking_rule(
1090 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1091
1092 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1093 policy['id'], rule['id'])
1094 retrieved_policy = retrieved_policy['dscp_marking_rule']
1095 self.assertEqual(rule['id'], retrieved_policy['id'])
1096
1097 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
1098 self.assertRaises(exceptions.NotFound,
1099 self.admin_client.show_dscp_marking_rule,
1100 policy['id'], rule['id'])
1101
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001102 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001103 def test_rule_create_rule_nonexistent_policy(self):
1104 self.assertRaises(
1105 exceptions.NotFound,
1106 self.admin_client.create_dscp_marking_rule,
1107 'policy', self.VALID_DSCP_MARK1)
1108
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001109 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001110 def test_rule_create_forbidden_for_regular_tenants(self):
1111 self.assertRaises(
1112 exceptions.Forbidden,
1113 self.client.create_dscp_marking_rule,
1114 'policy', self.VALID_DSCP_MARK1)
1115
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001116 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001117 def test_invalid_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001118 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001119 description='test policy',
1120 shared=False)
1121 self.assertRaises(
1122 exceptions.BadRequest,
1123 self.admin_client.create_dscp_marking_rule,
1124 policy['id'], 58)
1125
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001126 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001127 def test_get_rules_by_policy(self):
1128 policy1 = self.create_qos_policy(name='test-policy1',
1129 description='test policy1',
1130 shared=False)
1131 rule1 = self.admin_client.create_dscp_marking_rule(
1132 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1133
1134 policy2 = self.create_qos_policy(name='test-policy2',
1135 description='test policy2',
1136 shared=False)
1137 rule2 = self.admin_client.create_dscp_marking_rule(
1138 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
1139
1140 # Test 'list rules'
1141 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
1142 rules = rules['dscp_marking_rules']
1143 rules_ids = [r['id'] for r in rules]
1144 self.assertIn(rule1['id'], rules_ids)
1145 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001146
nfridman23b44ad2019-09-05 09:46:50 -04001147 @decorators.idempotent_id('19ed2286-ccb1-11e9-87d7-525400d6f522')
1148 def test_qos_dscp_create_and_update(self):
1149 """This test covers:
1150
1151 1.Creating a basic QoS policy with DSCP marking rule.
1152 2.Updating QoS policy:
1153 Administrator should have the ability to update existing QoS policy.
1154 This test should verify that:
1155 It's possible to update the existing DSCP marking rule with all of
1156 the valid marks between 0-56, except of the invalid marks:
1157 2-6, 42, 44, and 50-54 (which should be forbidden)
1158 """
1159
Rodolfo Alonso Hernandez3de3cd92022-08-23 21:41:02 +02001160 def _test_update_dscp_mark_values(self, dscp_policy_id, rule_id,
1161 valid_dscp_marks):
1162 for mark in range(valid_dscp_marks[1], self.VALID_DSCP_MARK1 + 1):
1163 if mark in valid_dscp_marks:
nfridman23b44ad2019-09-05 09:46:50 -04001164 self.admin_client.update_dscp_marking_rule(
1165 dscp_policy_id, rule_id, dscp_mark=mark)
1166
1167 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1168 dscp_policy_id, rule_id)['dscp_marking_rule']
1169 self.assertEqual(mark, retrieved_rule['dscp_mark'],
1170 """current DSCP mark is incorrect:
1171 expected value {0} actual value {1}
1172 """.format(mark,
1173 retrieved_rule['dscp_mark']))
1174
1175 else:
1176 self.assertRaises(exceptions.BadRequest,
1177 self.admin_client.create_dscp_marking_rule,
1178 dscp_policy_id,
1179 mark)
Rodolfo Alonso Hernandez3de3cd92022-08-23 21:41:02 +02001180
1181 # Retrieve the valid range of DSCP marks from the API.
1182 rule_type_details = self.admin_client.show_qos_rule_type(
1183 qos_consts.RULE_TYPE_DSCP_MARKING).get('rule_type')
1184 # There should be at least one driver supporting the DSCP marking rule.
1185 dscp_driver = rule_type_details['drivers'][0]
1186 for parameter in dscp_driver['supported_parameters']:
1187 if parameter['parameter_name'] == qos_consts.DSCP_MARK:
1188 valid_dscp_marks = parameter['parameter_values']
1189 break
1190 else:
1191 self.fail('The DSCP marking rule does not have the %s parameter' %
1192 qos_consts.DSCP_MARK)
1193
nfridman23b44ad2019-09-05 09:46:50 -04001194 # Setup network
1195 self.network = self.create_network()
1196
1197 # Create QoS policy
1198 dscp_policy_id = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +01001199 name=self.policy_name,
nfridman23b44ad2019-09-05 09:46:50 -04001200 description='test-qos-policy',
Slawek Kaplonskifdfb4742023-05-10 12:48:49 +02001201 project_id=self.client.project_id,
nfridman23b44ad2019-09-05 09:46:50 -04001202 shared=True)['id']
1203
1204 # Associate QoS to the network
1205 self.admin_client.update_network(
1206 self.network['id'], qos_policy_id=dscp_policy_id)
1207
1208 # Set a new DSCP rule with the first mark in range
1209 rule_id = self.admin_client.create_dscp_marking_rule(
1210 dscp_policy_id,
1211 n_constants.VALID_DSCP_MARKS[0])[
1212 'dscp_marking_rule']['id']
1213
1214 # Validate that the rule was set up properly
1215 retrieved_rule = self.client.show_dscp_marking_rule(
1216 dscp_policy_id, rule_id)['dscp_marking_rule']
1217 self.assertEqual(n_constants.VALID_DSCP_MARKS[0],
1218 retrieved_rule['dscp_mark'],
1219 """current DSCP mark is incorrect:
1220 expected value {0} actual value {1}
1221 """.format(n_constants.VALID_DSCP_MARKS[0],
1222 retrieved_rule['dscp_mark']))
1223
1224 # Try to set marks in range 8:56 (invalid marks should raise an error)
Rodolfo Alonso Hernandez3de3cd92022-08-23 21:41:02 +02001225 _test_update_dscp_mark_values(self, dscp_policy_id, rule_id,
1226 valid_dscp_marks)
nfridman23b44ad2019-09-05 09:46:50 -04001227
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001228
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001229class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
1230 DIRECTION_EGRESS = "egress"
1231 DIRECTION_INGRESS = "ingress"
1232 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
1233 RULES_NAME = RULE_NAME + "s"
Chandan Kumarc125fd12017-11-15 19:41:01 +05301234 required_extensions = [qos_apidef.ALIAS]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001235
1236 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001237 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001238 def resource_setup(cls):
1239 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
1240
zahlabut7ebb66e2021-09-01 22:39:49 +03001241 @classmethod
1242 def setup_clients(cls):
1243 super(QosMinimumBandwidthRuleTestJSON, cls).setup_clients()
1244 cls.qos_min_bw_rules_client = \
1245 cls.os_admin.qos_minimum_bandwidth_rules_client
1246 cls.qos_min_bw_rules_client_primary = \
1247 cls.os_primary.qos_minimum_bandwidth_rules_client
1248
elajkat757f3f12022-01-28 11:17:55 +01001249 def setUp(self):
1250 super(QosMinimumBandwidthRuleTestJSON, self).setUp()
1251 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
1252
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001253 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001254 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001255 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001256 description='test policy',
1257 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001258 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1259 qos_policy_id=policy['id'],
1260 **{'direction': self.DIRECTION_EGRESS,
1261 'min_kbps': 1138})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001262
1263 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +03001264 retrieved_rule = \
1265 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1266 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001267 retrieved_rule = retrieved_rule[self.RULE_NAME]
1268 self.assertEqual(rule['id'], retrieved_rule['id'])
1269 self.assertEqual(1138, retrieved_rule['min_kbps'])
1270 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1271
1272 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001273 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1274 policy['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001275 rules = rules[self.RULES_NAME]
1276 rules_ids = [r['id'] for r in rules]
1277 self.assertIn(rule['id'], rules_ids)
1278
1279 # Test 'show policy'
1280 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1281 policy_rules = retrieved_policy['policy']['rules']
1282 self.assertEqual(1, len(policy_rules))
1283 self.assertEqual(rule['id'], policy_rules[0]['id'])
1284 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1285 policy_rules[0]['type'])
1286
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001287 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001288 def test_rule_create_fail_for_missing_min_kbps(self):
elajkat757f3f12022-01-28 11:17:55 +01001289 policy = self.create_qos_policy(name=self.policy_name,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001290 description='test policy',
1291 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001292 self.assertRaises(
1293 exceptions.BadRequest,
1294 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1295 qos_policy_id=policy['id'],
1296 **{'direction': self.DIRECTION_EGRESS})
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001297
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001298 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001299 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001300 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001301 description='test policy',
1302 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001303 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1304 qos_policy_id=policy['id'],
1305 **{'direction': self.DIRECTION_EGRESS,
1306 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001307
zahlabut7ebb66e2021-09-01 22:39:49 +03001308 self.assertRaises(
1309 exceptions.Conflict,
1310 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1311 qos_policy_id=policy['id'],
1312 **{'direction': self.DIRECTION_EGRESS,
1313 'min_kbps': 201})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001314
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001315 @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936')
1316 @utils.requires_ext(extension="qos-bw-minimum-ingress",
1317 service="network")
1318 def test_rule_create_pass_for_direction_ingress(self):
elajkat757f3f12022-01-28 11:17:55 +01001319 policy = self.create_qos_policy(name=self.policy_name,
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001320 description='test policy',
1321 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001322 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1323 qos_policy_id=policy['id'],
1324 **{'direction': self.DIRECTION_INGRESS,
1325 'min_kbps': 201})
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001326
1327 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1328 policy_rules = retrieved_policy['policy']['rules']
1329 self.assertEqual(1, len(policy_rules))
1330 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1331 policy_rules[0]['type'])
1332 self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction'])
1333
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001334 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001335 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001336 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001337 description='test policy',
1338 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001339 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1340 qos_policy_id=policy['id'],
1341 **{'direction': self.DIRECTION_EGRESS,
1342 'min_kbps': 300})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001343
zahlabut7ebb66e2021-09-01 22:39:49 +03001344 self.qos_min_bw_rules_client.update_minimum_bandwidth_rule(
1345 policy['id'], rule['id'],
1346 **{'min_kbps': 350, 'direction': self.DIRECTION_EGRESS})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001347
zahlabut7ebb66e2021-09-01 22:39:49 +03001348 retrieved_policy = \
1349 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1350 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001351 retrieved_policy = retrieved_policy[self.RULE_NAME]
1352 self.assertEqual(350, retrieved_policy['min_kbps'])
1353 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1354
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001355 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001356 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001357 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001358 description='test policy',
1359 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001360 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1361 policy['id'],
1362 **{'direction': self.DIRECTION_EGRESS,
1363 'min_kbps': 200})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001364
zahlabut7ebb66e2021-09-01 22:39:49 +03001365 retrieved_policy = \
1366 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1367 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001368 retrieved_policy = retrieved_policy[self.RULE_NAME]
1369 self.assertEqual(rule['id'], retrieved_policy['id'])
1370
zahlabut7ebb66e2021-09-01 22:39:49 +03001371 self.qos_min_bw_rules_client.delete_minimum_bandwidth_rule(
1372 policy['id'], rule['id'])
1373 self.assertRaises(
1374 exceptions.NotFound,
1375 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule,
1376 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001377
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001378 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001379 def test_rule_create_rule_nonexistent_policy(self):
1380 self.assertRaises(
1381 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +03001382 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1383 'policy',
1384 **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001385
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001386 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001387 def test_rule_create_forbidden_for_regular_tenants(self):
1388 self.assertRaises(
1389 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +03001390 self.qos_min_bw_rules_client_primary.create_minimum_bandwidth_rule,
1391 'policy', **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 300})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001392
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001393 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001394 def test_get_rules_by_policy(self):
1395 policy1 = self.create_qos_policy(name='test-policy1',
1396 description='test policy1',
1397 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001398 rule1 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1399 qos_policy_id=policy1['id'],
1400 **{'direction': self.DIRECTION_EGRESS,
1401 'min_kbps': 200})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001402
1403 policy2 = self.create_qos_policy(name='test-policy2',
1404 description='test policy2',
1405 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001406 rule2 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1407 qos_policy_id=policy2['id'],
1408 **{'direction': self.DIRECTION_EGRESS,
1409 'min_kbps': 5000})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001410
1411 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001412 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1413 policy1['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001414 rules = rules[self.RULES_NAME]
1415 rules_ids = [r['id'] for r in rules]
1416 self.assertIn(rule1['id'], rules_ids)
1417 self.assertNotIn(rule2['id'], rules_ids)
1418
1419
elajkat4a1357b2021-08-31 10:16:25 +02001420class QosMinimumPpsRuleTestJSON(base.BaseAdminNetworkTest):
elajkat4a1357b2021-08-31 10:16:25 +02001421 required_extensions = [qos_apidef.ALIAS]
1422
1423 @classmethod
1424 @utils.requires_ext(service='network',
1425 extension='port-resource-request-groups')
1426 def resource_setup(cls):
1427 super(QosMinimumPpsRuleTestJSON, cls).resource_setup()
1428
1429 @classmethod
1430 def setup_clients(cls):
1431 super(QosMinimumPpsRuleTestJSON, cls).setup_clients()
1432 cls.min_pps_client = cls.os_admin.qos_minimum_packet_rate_rules_client
1433 cls.min_pps_client_primary = \
1434 cls.os_primary.qos_minimum_packet_rate_rules_client
1435
elajkat757f3f12022-01-28 11:17:55 +01001436 def setUp(self):
1437 super(QosMinimumPpsRuleTestJSON, self).setUp()
1438 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
Chandan Kumar (raukadah)255586c2022-03-10 09:43:37 +05301439 self.RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_PACKET_RATE + "_rule"
1440 self.RULES_NAME = self.RULE_NAME + "s"
elajkat757f3f12022-01-28 11:17:55 +01001441
elajkat4a1357b2021-08-31 10:16:25 +02001442 def _create_qos_min_pps_rule(self, policy_id, rule_data):
1443 rule = self.min_pps_client.create_minimum_packet_rate_rule(
1444 policy_id, **rule_data)['minimum_packet_rate_rule']
1445 self.addCleanup(
1446 test_utils.call_and_ignore_notfound_exc,
1447 self.min_pps_client.delete_minimum_packet_rate_rule,
1448 policy_id, rule['id'])
1449 return rule
1450
1451 @decorators.idempotent_id('66a5b9b4-d4f9-4af8-b238-9e1881b78487')
1452 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001453 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001454 description='test policy',
1455 shared=False)
1456 rule = self._create_qos_min_pps_rule(
1457 policy['id'],
1458 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1459 qos_consts.MIN_KPPS: 1138})
1460
1461 # Test 'show rule'
1462 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1463 policy['id'], rule['id'])[self.RULE_NAME]
1464 self.assertEqual(rule['id'], retrieved_rule['id'])
1465 self.assertEqual(1138, retrieved_rule[qos_consts.MIN_KPPS])
1466 self.assertEqual(n_constants.EGRESS_DIRECTION,
1467 retrieved_rule[qos_consts.DIRECTION])
1468
1469 # Test 'list rules'
1470 rules = self.min_pps_client.list_minimum_packet_rate_rules(
1471 policy['id'])
1472 rules = rules[self.RULES_NAME]
1473 rules_ids = [r['id'] for r in rules]
1474 self.assertIn(rule['id'], rules_ids)
1475
1476 # Test 'show policy'
1477 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1478 policy_rules = retrieved_policy['policy']['rules']
1479 self.assertEqual(1, len(policy_rules))
1480 self.assertEqual(rule['id'], policy_rules[0]['id'])
1481 self.assertEqual('minimum_packet_rate',
1482 policy_rules[0]['type'])
1483
1484 @decorators.idempotent_id('6b656b57-d2bf-47f9-89a9-1baad1bd5418')
1485 def test_rule_create_fail_for_missing_min_kpps(self):
elajkat757f3f12022-01-28 11:17:55 +01001486 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001487 description='test policy',
1488 shared=False)
1489 self.assertRaises(exceptions.BadRequest,
1490 self._create_qos_min_pps_rule,
1491 policy['id'],
1492 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION})
1493
1494 @decorators.idempotent_id('f41213e5-2ab8-4916-b106-38d2cac5e18c')
1495 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001496 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001497 description='test policy',
1498 shared=False)
1499 self._create_qos_min_pps_rule(policy['id'],
1500 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1501 qos_consts.MIN_KPPS: 200})
1502
1503 self.assertRaises(exceptions.Conflict,
1504 self._create_qos_min_pps_rule,
1505 policy['id'],
1506 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1507 qos_consts.MIN_KPPS: 201})
1508
1509 @decorators.idempotent_id('ceb8e41e-3d72-11ec-a446-d7faae6daec2')
1510 def test_rule_create_any_direction_when_egress_direction_exists(self):
elajkat757f3f12022-01-28 11:17:55 +01001511 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001512 description='test policy',
1513 shared=False)
1514 self._create_qos_min_pps_rule(policy['id'],
1515 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1516 qos_consts.MIN_KPPS: 200})
1517
1518 self.assertRaises(exceptions.Conflict,
1519 self._create_qos_min_pps_rule,
1520 policy['id'],
1521 {qos_consts.DIRECTION: n_constants.ANY_DIRECTION,
1522 qos_consts.MIN_KPPS: 201})
1523
1524 @decorators.idempotent_id('a147a71e-3d7b-11ec-8097-278b1afd5fa2')
1525 def test_rule_create_egress_direction_when_any_direction_exists(self):
elajkat757f3f12022-01-28 11:17:55 +01001526 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001527 description='test policy',
1528 shared=False)
1529 self._create_qos_min_pps_rule(policy['id'],
1530 {qos_consts.DIRECTION: n_constants.ANY_DIRECTION,
1531 qos_consts.MIN_KPPS: 200})
1532
1533 self.assertRaises(exceptions.Conflict,
1534 self._create_qos_min_pps_rule,
1535 policy['id'],
1536 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1537 qos_consts.MIN_KPPS: 201})
1538
1539 @decorators.idempotent_id('522ed09a-1d7f-4c1b-9195-61f19caf916f')
1540 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001541 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001542 description='test policy',
1543 shared=False)
1544 rule = self._create_qos_min_pps_rule(
1545 policy['id'],
1546 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1547 qos_consts.MIN_KPPS: 300})
1548
1549 self.min_pps_client.update_minimum_packet_rate_rule(
1550 policy['id'], rule['id'],
1551 **{qos_consts.MIN_KPPS: 350,
1552 qos_consts.DIRECTION: n_constants.ANY_DIRECTION})
1553
1554 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1555 policy['id'], rule['id'])[self.RULE_NAME]
1556 self.assertEqual(350, retrieved_rule[qos_consts.MIN_KPPS])
1557 self.assertEqual(n_constants.ANY_DIRECTION,
1558 retrieved_rule[qos_consts.DIRECTION])
1559
1560 @decorators.idempotent_id('a020e186-3d60-11ec-88ca-d7f5eec22764')
1561 def test_rule_update_direction_conflict(self):
elajkat757f3f12022-01-28 11:17:55 +01001562 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001563 description='test policy',
1564 shared=False)
1565 rule1 = self._create_qos_min_pps_rule(
1566 policy['id'],
1567 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1568 qos_consts.MIN_KPPS: 300})
1569
1570 rule2 = self._create_qos_min_pps_rule(
1571 policy['id'],
1572 {qos_consts.DIRECTION: n_constants.INGRESS_DIRECTION,
1573 qos_consts.MIN_KPPS: 300})
1574
1575 retrieved_rule1 = self.min_pps_client.show_minimum_packet_rate_rule(
1576 policy['id'], rule1['id'])[self.RULE_NAME]
1577 self.assertEqual(n_constants.EGRESS_DIRECTION,
1578 retrieved_rule1[qos_consts.DIRECTION])
1579 retrieved_rule2 = self.min_pps_client.show_minimum_packet_rate_rule(
1580 policy['id'], rule2['id'])[self.RULE_NAME]
1581 self.assertEqual(n_constants.INGRESS_DIRECTION,
1582 retrieved_rule2[qos_consts.DIRECTION])
1583
1584 self.assertRaises(exceptions.Conflict,
1585 self.min_pps_client.update_minimum_packet_rate_rule,
1586 policy['id'], rule2['id'],
1587 **{qos_consts.DIRECTION: n_constants.ANY_DIRECTION})
1588
1589 @decorators.idempotent_id('c49018b6-d358-49a1-a94b-d53224165045')
1590 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001591 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001592 description='test policy',
1593 shared=False)
1594 rule = self._create_qos_min_pps_rule(
1595 policy['id'],
1596 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1597 qos_consts.MIN_KPPS: 200})
1598
1599 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1600 policy['id'], rule['id'])[self.RULE_NAME]
1601 self.assertEqual(rule['id'], retrieved_rule['id'])
1602
1603 self.min_pps_client.delete_minimum_packet_rate_rule(policy['id'],
1604 rule['id'])
1605 self.assertRaises(exceptions.NotFound,
1606 self.min_pps_client.show_minimum_packet_rate_rule,
1607 policy['id'], rule['id'])
1608
1609 @decorators.idempotent_id('1a6b6128-3d3e-11ec-bf49-57b326d417c0')
1610 def test_rule_create_forbidden_for_regular_tenants(self):
1611 self.assertRaises(
1612 exceptions.Forbidden,
1613 self.min_pps_client_primary.create_minimum_packet_rate_rule,
1614 'policy', **{qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1615 qos_consts.MIN_KPPS: 300})
1616
1617 @decorators.idempotent_id('1b94f4e2-3d3e-11ec-bb21-6f98e4044b8b')
1618 def test_get_rules_by_policy(self):
1619 policy1 = self.create_qos_policy(name='test-policy1',
1620 description='test policy1',
1621 shared=False)
1622 rule1 = self._create_qos_min_pps_rule(
1623 policy1['id'],
1624 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1625 qos_consts.MIN_KPPS: 200})
1626
1627 policy2 = self.create_qos_policy(name='test-policy2',
1628 description='test policy2',
1629 shared=False)
1630 rule2 = self._create_qos_min_pps_rule(
1631 policy2['id'],
1632 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1633 qos_consts.MIN_KPPS: 5000})
1634
1635 # Test 'list rules'
1636 rules = self.min_pps_client.list_minimum_packet_rate_rules(
1637 policy1['id'])
1638 rules = rules[self.RULES_NAME]
1639 rules_ids = [r['id'] for r in rules]
1640 self.assertIn(rule1['id'], rules_ids)
1641 self.assertNotIn(rule2['id'], rules_ids)
1642
1643
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001644class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1645 base.BaseAdminNetworkTest):
1646
1647 resource = 'policy'
1648 plural_name = 'policies'
1649
1650 # Use unique description to isolate the tests from other QoS tests
1651 list_kwargs = {'description': 'search-criteria-test'}
1652 list_as_admin = True
1653
Chandan Kumarc125fd12017-11-15 19:41:01 +05301654 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001655
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001656 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001657 def resource_setup(cls):
1658 super(QosSearchCriteriaTest, cls).resource_setup()
1659 for name in cls.resource_names:
1660 cls.create_qos_policy(
1661 name=name, description='search-criteria-test')
1662
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001663 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001664 def test_list_sorts_asc(self):
1665 self._test_list_sorts_asc()
1666
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001667 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001668 def test_list_sorts_desc(self):
1669 self._test_list_sorts_desc()
1670
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001671 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001672 def test_list_pagination(self):
1673 self._test_list_pagination()
1674
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001675 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001676 def test_list_pagination_with_marker(self):
1677 self._test_list_pagination_with_marker()
1678
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001679 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001680 def test_list_pagination_with_href_links(self):
1681 self._test_list_pagination_with_href_links()
1682
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001683 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001684 def test_list_pagination_page_reverse_asc(self):
1685 self._test_list_pagination_page_reverse_asc()
1686
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001687 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001688 def test_list_pagination_page_reverse_desc(self):
1689 self._test_list_pagination_page_reverse_desc()
1690
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001691 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001692 def test_list_pagination_page_reverse_with_href_links(self):
1693 self._test_list_pagination_page_reverse_with_href_links()
1694
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001695 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001696 def test_list_no_pagination_limit_0(self):
1697 self._test_list_no_pagination_limit_0()