blob: e8b8606d916bbf992fd6fcba620d671d26f28e05 [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):
94 self.create_qos_policy(name='test', description='test policy',
95 shared=False)
96 self.create_qos_policy(name='test2', description='test policy',
97 shared=False)
98
99 policies = (self.admin_client.
100 list_qos_policies(name='test')['policies'])
101 self.assertEqual(1, len(policies))
102
103 retrieved_policy = policies[0]
104 self.assertEqual('test', retrieved_policy['name'])
105
likangkang01afd73f72020-06-01 16:53:59 +0800106 @decorators.idempotent_id('dde0b449-a400-4a87-b5a5-4d1c413c917b')
107 def test_list_policy_sort_by_name(self):
108 policyA = 'A' + data_utils.rand_name("policy")
109 policyB = 'B' + data_utils.rand_name("policy")
110 self.create_qos_policy(name=policyA, description='test policy',
111 shared=False)
112 self.create_qos_policy(name=policyB, description='test policy',
113 shared=False)
114
115 param = {
116 'sort_key': 'name',
117 'sort_dir': 'asc'
118 }
119 policies = (self.admin_client.list_qos_policies(**param)['policies'])
120 policy_names = [p['name'] for p in policies]
121 self.assertLess(policy_names.index(policyA),
122 policy_names.index(policyB))
123
124 param = {
125 'sort_key': 'name',
126 'sort_dir': 'desc'
127 }
128 policies = (self.admin_client.list_qos_policies(**param)['policies'])
129 policy_names = [p['name'] for p in policies]
130 self.assertLess(policy_names.index(policyB),
131 policy_names.index(policyA))
132
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000133 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000134 def test_policy_update(self):
elajkat757f3f12022-01-28 11:17:55 +0100135 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000136 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000137 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000138 project_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000139 self.admin_client.update_qos_policy(policy['id'],
140 description='test policy desc2',
141 shared=True)
142
143 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
144 retrieved_policy = retrieved_policy['policy']
145 self.assertEqual('test policy desc2', retrieved_policy['description'])
146 self.assertTrue(retrieved_policy['shared'])
147 self.assertEqual([], retrieved_policy['rules'])
148
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000149 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000150 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100151 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000152 description='',
153 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000154 project_id=self.client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000155 self.assertRaises(
156 exceptions.Forbidden,
157 self.client.update_qos_policy,
158 policy['id'], description='test policy')
159
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000160 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000161 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100162 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000163 description='',
164 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000165 project_id=self.admin_client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000166 self.assertRaises(
167 exceptions.NotFound,
168 self.client.update_qos_policy,
169 policy['id'], description='test policy')
170
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000171 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000172 def test_shared_policy_update(self):
elajkat757f3f12022-01-28 11:17:55 +0100173 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000174 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000175 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000176 project_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000177
178 self.admin_client.update_qos_policy(policy['id'],
179 description='test policy desc2')
180 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
181 retrieved_policy = retrieved_policy['policy']
182 self.assertTrue(retrieved_policy['shared'])
183
184 self.admin_client.update_qos_policy(policy['id'],
185 shared=False)
186 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
187 retrieved_policy = retrieved_policy['policy']
188 self.assertFalse(retrieved_policy['shared'])
189
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000190 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000191 def test_delete_policy(self):
192 policy = self.admin_client.create_qos_policy(
193 'test-policy', 'desc', True)['policy']
194
195 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
196 retrieved_policy = retrieved_policy['policy']
197 self.assertEqual('test-policy', retrieved_policy['name'])
198
199 self.admin_client.delete_qos_policy(policy['id'])
200 self.assertRaises(exceptions.NotFound,
201 self.admin_client.show_qos_policy, policy['id'])
202
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000203 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000204 def test_list_admin_rule_types(self):
205 self._test_list_rule_types(self.admin_client)
206
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000207 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000208 def test_list_regular_rule_types(self):
209 self._test_list_rule_types(self.client)
210
211 def _test_list_rule_types(self, client):
212 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000213 # Since returned rule types depends on loaded backend drivers this test
214 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000215 #
216 # In theory, we could make the test conditional on which ml2 drivers
217 # are enabled in gate (or more specifically, on which supported qos
218 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200219 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000220 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000221
222 rule_types = client.list_qos_rule_types()
223 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000224
225 # Verify that only required fields present in rule details
226 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000227 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000228
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000229 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
230 def test_show_rule_type_details_as_user(self):
231 self.assertRaises(
232 exceptions.Forbidden,
233 self.client.show_qos_rule_type,
234 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
235
236 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
237 def test_show_rule_type_details_as_admin(self):
238 # Since returned rule types depend on loaded backend drivers this test
239 # is checking only if returned keys are same as expected keys
240
241 # In theory, we could make the test conditional on which ml2 drivers
242 # are enabled in gate, but that option doesn't seem to be
243 # available through tempest.lib framework
244 expected_rule_type_details_keys = ['type', 'drivers']
245
246 rule_type_details = self.admin_client.show_qos_rule_type(
247 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
248
249 # Verify that only required fields present in rule details
250 self.assertEqual(
251 sorted(tuple(expected_rule_type_details_keys)),
252 sorted(tuple(rule_type_details.keys())))
253
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000254 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000255 def test_policy_association_with_admin_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100256 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000257 description='test policy',
258 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200259 network = self.create_network('test network', shared=True,
260 qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000261
262 retrieved_network = self.admin_client.show_network(network['id'])
263 self.assertEqual(
264 policy['id'], retrieved_network['network']['qos_policy_id'])
265
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000266 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000267 def test_policy_association_with_tenant_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100268 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000269 description='test policy',
270 shared=True)
271 network = self.create_network('test network',
272 qos_policy_id=policy['id'])
273
274 retrieved_network = self.admin_client.show_network(network['id'])
275 self.assertEqual(
276 policy['id'], retrieved_network['network']['qos_policy_id'])
277
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000278 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000279 def test_policy_association_with_network_nonexistent_policy(self):
280 self.assertRaises(
281 exceptions.NotFound,
282 self.create_network,
283 'test network',
284 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
285
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000286 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000287 def test_policy_association_with_network_non_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100288 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000289 description='test policy',
290 shared=False)
291 self.assertRaises(
292 exceptions.NotFound,
293 self.create_network,
294 'test network', qos_policy_id=policy['id'])
295
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000296 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000297 def test_policy_update_association_with_admin_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100298 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000299 description='test policy',
300 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200301 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000302 retrieved_network = self.admin_client.show_network(network['id'])
303 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
304
305 self.admin_client.update_network(network['id'],
306 qos_policy_id=policy['id'])
307 retrieved_network = self.admin_client.show_network(network['id'])
308 self.assertEqual(
309 policy['id'], retrieved_network['network']['qos_policy_id'])
310
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000311 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000312 def test_policy_association_with_port_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100313 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000314 description='test policy',
315 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200316 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000317 port = self.create_port(network, qos_policy_id=policy['id'])
318
319 retrieved_port = self.admin_client.show_port(port['id'])
320 self.assertEqual(
321 policy['id'], retrieved_port['port']['qos_policy_id'])
322
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000323 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000324 def test_policy_association_with_port_nonexistent_policy(self):
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200325 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000326 self.assertRaises(
327 exceptions.NotFound,
328 self.create_port,
329 network,
330 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
331
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000332 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000333 def test_policy_association_with_port_non_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100334 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000335 description='test policy',
336 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200337 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000338 self.assertRaises(
339 exceptions.NotFound,
340 self.create_port,
341 network, qos_policy_id=policy['id'])
342
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000343 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000344 def test_policy_update_association_with_port_shared_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100345 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000346 description='test policy',
347 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200348 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000349 port = self.create_port(network)
350 retrieved_port = self.admin_client.show_port(port['id'])
351 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
352
353 self.client.update_port(port['id'], qos_policy_id=policy['id'])
354 retrieved_port = self.admin_client.show_port(port['id'])
355 self.assertEqual(
356 policy['id'], retrieved_port['port']['qos_policy_id'])
357
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000358 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000359 def test_delete_not_allowed_if_policy_in_use_by_network(self):
elajkat757f3f12022-01-28 11:17:55 +0100360 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000361 description='test policy',
362 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200363 self.create_network('test network', qos_policy_id=policy['id'],
364 shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000365 self.assertRaises(
366 exceptions.Conflict,
367 self.admin_client.delete_qos_policy, policy['id'])
368
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000369 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000370 def test_delete_not_allowed_if_policy_in_use_by_port(self):
elajkat757f3f12022-01-28 11:17:55 +0100371 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000372 description='test policy',
373 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200374 network = self.create_network('test network', shared=True)
Sławek Kapłońskie100c4d2017-08-23 21:18:34 +0000375 self.create_port(network, qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000376 self.assertRaises(
377 exceptions.Conflict,
378 self.admin_client.delete_qos_policy, policy['id'])
379
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000380 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000381 def test_qos_policy_delete_with_rules(self):
elajkat757f3f12022-01-28 11:17:55 +0100382 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000383 description='test policy',
384 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300385 self._create_qos_bw_limit_rule(
386 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000387 self.admin_client.delete_qos_policy(policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000388 with testtools.ExpectedException(exceptions.NotFound):
389 self.admin_client.show_qos_policy(policy['id'])
390
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000391 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000392 def test_get_policy_that_is_shared(self):
393 policy = self.create_qos_policy(
394 name='test-policy-shared',
395 description='shared policy',
396 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000397 project_id=self.admin_client.tenant_id)
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000398 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
399 self.assertEqual(obtained_policy, policy)
400
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000401 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100402 def test_policy_create_forbidden_for_regular_tenants(self):
403 self.assertRaises(
404 exceptions.Forbidden,
405 self.client.create_qos_policy,
406 'test-policy', 'test policy', False)
407
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900408 @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
409 def test_default_policy_creating_network_without_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530410 project_id = self.create_project()['id']
elajkat757f3f12022-01-28 11:17:55 +0100411 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000412 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900413 is_default=True)
414 network = self.create_network('test network', client=self.admin_client,
415 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900416 retrieved_network = self.admin_client.show_network(network['id'])
417 self.assertEqual(
418 policy['id'], retrieved_network['network']['qos_policy_id'])
419
420 @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
421 def test_default_policy_creating_network_with_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530422 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900423 self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000424 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900425 is_default=True)
426 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000427 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900428 network = self.create_network('test network', client=self.admin_client,
429 project_id=project_id,
430 qos_policy_id=policy['id'])
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900431 retrieved_network = self.admin_client.show_network(network['id'])
432 self.assertEqual(
433 policy['id'], retrieved_network['network']['qos_policy_id'])
434
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100435 @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229')
436 def test_user_create_port_with_admin_qos_policy(self):
437 qos_policy = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +0100438 name=self.policy_name,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000439 project_id=self.admin_client.tenant_id,
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100440 shared=False)
441 network = self.create_network(
442 'test network', client=self.admin_client,
443 project_id=self.client.tenant_id,
444 qos_policy_id=qos_policy['id'])
445 port = self.create_port(network)
446 self.assertEqual(network['id'], port['network_id'])
447
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000448
449class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000450
zahlabut7ebb66e2021-09-01 22:39:49 +0300451 credentials = ['primary', 'admin']
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000452 direction = None
Chandan Kumarc125fd12017-11-15 19:41:01 +0530453 required_extensions = [qos_apidef.ALIAS]
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000454
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000455 @classmethod
zahlabut7ebb66e2021-09-01 22:39:49 +0300456 def setup_clients(cls):
457 super(QosBandwidthLimitRuleTestJSON, cls).setup_clients()
458 cls.qos_bw_limit_rule_client = \
459 cls.os_admin.qos_limit_bandwidth_rules_client
460 cls.qos_bw_limit_rule_client_primary = \
461 cls.os_primary.qos_limit_bandwidth_rules_client
462
463 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900464 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000465 def resource_setup(cls):
466 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
467
elajkat757f3f12022-01-28 11:17:55 +0100468 def setUp(self):
469 super(QosBandwidthLimitRuleTestJSON, self).setUp()
470 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
471
zahlabut7ebb66e2021-09-01 22:39:49 +0300472 def _create_qos_bw_limit_rule(self, policy_id, rule_data):
473 rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule(
474 qos_policy_id=policy_id,
475 **rule_data)['bandwidth_limit_rule']
476 self.addCleanup(
477 test_utils.call_and_ignore_notfound_exc,
478 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule,
479 policy_id, rule['id'])
480 return rule
481
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000482 @property
483 def opposite_direction(self):
484 if self.direction == "ingress":
485 return "egress"
486 elif self.direction == "egress":
487 return "ingress"
488 else:
489 return None
490
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000491 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000492 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +0100493 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000494 description='test policy',
495 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300496 rule = self._create_qos_bw_limit_rule(
497 policy['id'],
498 {'max_kbps': 200, 'max_burst_kbps': 1337, 'direction': 'ingress'})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000499
500 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +0300501 retrieved_rule = \
502 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
503 policy['id'], rule['id'])
504
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000505 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
506 self.assertEqual(rule['id'], retrieved_rule['id'])
507 self.assertEqual(200, retrieved_rule['max_kbps'])
508 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300509 self.assertEqual('ingress', retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000510
511 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300512 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
513 policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000514 rules = rules['bandwidth_limit_rules']
515 rules_ids = [r['id'] for r in rules]
516 self.assertIn(rule['id'], rules_ids)
517
518 # Test 'show policy'
519 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
520 policy_rules = retrieved_policy['policy']['rules']
521 self.assertEqual(1, len(policy_rules))
522 self.assertEqual(rule['id'], policy_rules[0]['id'])
523 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
524 policy_rules[0]['type'])
525
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000526 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000527 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +0100528 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000529 description='test policy',
530 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300531 self._create_qos_bw_limit_rule(
532 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000533
zahlabut7ebb66e2021-09-01 22:39:49 +0300534 self.assertRaises(
535 exceptions.Conflict,
536 self._create_qos_bw_limit_rule,
537 policy['id'],
538 {'max_kbps': 201, 'max_burst_kbps': 1338})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000539
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000540 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000541 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +0100542 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000543 description='test policy',
544 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300545 rule = self._create_qos_bw_limit_rule(
546 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000547
zahlabut7ebb66e2021-09-01 22:39:49 +0300548 if self.opposite_direction:
549 self.qos_bw_limit_rule_client.update_limit_bandwidth_rule(
550 policy['id'], rule['id'],
551 **{'max_kbps': 200, 'max_burst_kbps': 1337,
552 'direction': self.opposite_direction})
553 else:
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 retrieved_policy = self.qos_bw_limit_rule_client.\
558 show_limit_bandwidth_rule(policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000559 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
560 self.assertEqual(200, retrieved_policy['max_kbps'])
561 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000562 if self.opposite_direction:
563 self.assertEqual(self.opposite_direction,
564 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000565
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000566 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000567 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +0100568 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000569 description='test policy',
570 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300571 rule = self._create_qos_bw_limit_rule(
572 policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
573 retrieved_policy = \
574 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule(
575 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000576 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
577 self.assertEqual(rule['id'], retrieved_policy['id'])
zahlabut7ebb66e2021-09-01 22:39:49 +0300578 self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule(
579 policy['id'], rule['id'])
580 self.assertRaises(
581 exceptions.NotFound,
582 self.qos_bw_limit_rule_client.show_limit_bandwidth_rule,
583 policy['id'], rule['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000584
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000585 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000586 def test_rule_create_rule_nonexistent_policy(self):
587 self.assertRaises(
588 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300589 self._create_qos_bw_limit_rule,
590 'policy', {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000591
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000592 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000593 def test_rule_create_forbidden_for_regular_tenants(self):
594 self.assertRaises(
595 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300596 self.qos_bw_limit_rule_client_primary.create_limit_bandwidth_rule,
597 'policy', **{'max_kbps': 1, 'max_burst_kbps': 2})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000598
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000599 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000600 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
elajkat757f3f12022-01-28 11:17:55 +0100601 policy = self.create_qos_policy(name=self.policy_name,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000602 description='test policy',
603 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000604 project_id=self.client.tenant_id)
zahlabut7ebb66e2021-09-01 22:39:49 +0300605 rule = self._create_qos_bw_limit_rule(
606 policy['id'],
607 {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000608 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400609 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +0300610 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
611 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000612
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000613 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000614 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300615 policy = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +0100616 name=self.policy_name,
zahlabut7ebb66e2021-09-01 22:39:49 +0300617 description='test policy',
618 shared=False,
619 project_id=self.admin_client.tenant_id)
620 rule = self._create_qos_bw_limit_rule(
621 policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000622 self.assertRaises(
623 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +0300624 self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule,
625 policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4})
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000626
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000627 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000628 def test_get_rules_by_policy(self):
zahlabut7ebb66e2021-09-01 22:39:49 +0300629 policy1 = self.create_qos_policy(
630 name='test-policy1',
631 description='test policy1',
632 shared=False)
633 rule1 = self._create_qos_bw_limit_rule(
634 policy1['id'], {'max_kbps': 200, 'max_burst_kbps': 1337})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000635
zahlabut7ebb66e2021-09-01 22:39:49 +0300636 policy2 = self.create_qos_policy(
637 name='test-policy2',
638 description='test policy2',
639 shared=False)
640 rule2 = self._create_qos_bw_limit_rule(
641 policy2['id'], {'max_kbps': 5000, 'max_burst_kbps': 2523})
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000642
643 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +0300644 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
645 policy1['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000646 rules = rules['bandwidth_limit_rules']
647 rules_ids = [r['id'] for r in rules]
648 self.assertIn(rule1['id'], rules_ids)
649 self.assertNotIn(rule2['id'], rules_ids)
650
nfridman07f0e782019-11-04 09:12:58 -0500651 @testtools.skipUnless(
652 CONF.neutron_plugin_options.create_shared_resources,
653 """Creation of shared resources should be allowed,
654 setting the create_shared_resources option as 'True' is needed""")
655 @decorators.idempotent_id('d911707e-fa2c-11e9-9553-5076af30bbf5')
656 def test_attach_and_detach_a_policy_by_a_tenant(self):
657 # As an admin create an non shared QoS policy,add a rule
658 # and associate it with a network
659 self.network = self.create_network()
elajkat757f3f12022-01-28 11:17:55 +0100660 policy = self.create_qos_policy(name=self.policy_name,
nfridman07f0e782019-11-04 09:12:58 -0500661 description='test policy for attach',
662 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +0300663 self._create_qos_bw_limit_rule(
664 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024})
nfridman07f0e782019-11-04 09:12:58 -0500665
666 self.admin_client.update_network(
667 self.network['id'], qos_policy_id=policy['id'])
668
669 # As a tenant, try to detach the policy from the network
670 # The operation should be forbidden
671 self.assertRaises(
672 exceptions.Forbidden,
673 self.client.update_network,
674 self.network['id'], qos_policy_id=None)
675
676 # As an admin, make the policy shared
677 self.admin_client.update_qos_policy(policy['id'], shared=True)
678
679 # As a tenant, try to detach the policy from the network
680 # The operation should be allowed
681 self.client.update_network(self.network['id'],
682 qos_policy_id=None)
683
684 retrieved_network = self.admin_client.show_network(self.network['id'])
685 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
686
687 # As a tenant, try to delete the policy from the network
688 # should be forbidden
689 self.assertRaises(
690 exceptions.Forbidden,
691 self.client.delete_qos_policy,
692 policy['id'])
693
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000694
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000695class QosBandwidthLimitRuleWithDirectionTestJSON(
Brian Haley6767cec2018-04-10 15:30:23 -0400696 QosBandwidthLimitRuleTestJSON):
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000697 required_extensions = (
698 QosBandwidthLimitRuleTestJSON.required_extensions +
699 ['qos-bw-limit-direction']
700 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000701 scenarios = [
702 ('ingress', {'direction': 'ingress'}),
703 ('egress', {'direction': 'egress'}),
704 ]
705
nfridman7717d9c2019-11-25 08:58:04 -0500706 @classmethod
707 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
708 def resource_setup(cls):
709 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
710
elajkat757f3f12022-01-28 11:17:55 +0100711 def setUp(self):
712 super(QosBandwidthLimitRuleWithDirectionTestJSON, self).setUp()
713 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
714
nfridman7717d9c2019-11-25 08:58:04 -0500715 @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667')
716 def test_create_policy_with_multiple_rules(self):
717 # Create a policy with multiple rules
elajkat757f3f12022-01-28 11:17:55 +0100718 policy = self.create_qos_policy(name=self.policy_name,
nfridman7717d9c2019-11-25 08:58:04 -0500719 description='test policy1',
720 shared=False)
721
zahlabut7ebb66e2021-09-01 22:39:49 +0300722 rule1 = self._create_qos_bw_limit_rule(
723 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
724 'direction': n_constants.EGRESS_DIRECTION})
725 rule2 = self._create_qos_bw_limit_rule(
726 policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024,
727 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500728 # Check that the rules were added to the policy
zahlabut7ebb66e2021-09-01 22:39:49 +0300729 rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules(
nfridman7717d9c2019-11-25 08:58:04 -0500730 policy['id'])['bandwidth_limit_rules']
zahlabut7ebb66e2021-09-01 22:39:49 +0300731
nfridman7717d9c2019-11-25 08:58:04 -0500732 rules_ids = [rule['id'] for rule in rules]
733 self.assertIn(rule1['id'], rules_ids)
734 self.assertIn(rule2['id'], rules_ids)
735
736 # Check that the rules creation fails for the same rule types
zahlabut7ebb66e2021-09-01 22:39:49 +0300737 self.assertRaises(
738 exceptions.Conflict,
739 self._create_qos_bw_limit_rule,
740 policy['id'],
741 {'max_kbps': 1025, 'max_burst_kbps': 1025,
742 'direction': n_constants.EGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500743
zahlabut7ebb66e2021-09-01 22:39:49 +0300744 self.assertRaises(
745 exceptions.Conflict,
746 self._create_qos_bw_limit_rule,
747 policy['id'],
748 {'max_kbps': 1025, 'max_burst_kbps': 1025,
749 'direction': n_constants.INGRESS_DIRECTION})
nfridman7717d9c2019-11-25 08:58:04 -0500750
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000751
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000752class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
753
754 force_tenant_isolation = True
755 credentials = ['primary', 'alt', 'admin']
Chandan Kumarc125fd12017-11-15 19:41:01 +0530756 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000757
758 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000759 def resource_setup(cls):
760 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530761 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000762
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000763 def _create_qos_policy(self, project_id=None):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000764 args = {'name': data_utils.rand_name('test-policy'),
765 'description': 'test policy',
766 'shared': False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000767 'project_id': project_id}
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000768 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
769 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
770
771 return qos_policy
772
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000773 def _make_admin_policy_shared_to_project_id(self, project_id):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000774 policy = self._create_qos_policy()
775 rbac_policy = self.admin_client.create_rbac_policy(
776 object_type='qos_policy',
777 object_id=policy['id'],
778 action='access_as_shared',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000779 target_tenant=project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000780 )['rbac_policy']
781
782 return {'policy': policy, 'rbac_policy': rbac_policy}
783
784 def _create_network(self, qos_policy_id, client, should_cleanup=True):
785 net = client.create_network(
786 name=data_utils.rand_name('test-network'),
787 qos_policy_id=qos_policy_id)['network']
788 if should_cleanup:
789 self.addCleanup(client.delete_network, net['id'])
790
791 return net
792
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000793 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000794 def test_policy_sharing_with_wildcard(self):
795 qos_pol = self.create_qos_policy(
796 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000797 description='test-shared-policy', shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000798 project_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000799 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
800
801 # test update shared False -> True
802 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
803 qos_pol['shared'] = True
804 self.client2.show_qos_policy(qos_pol['id'])
805 rbac_pol = {'target_tenant': '*',
806 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000807 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000808 'object_type': 'qos_policy',
809 'object_id': qos_pol['id'],
810 'action': 'access_as_shared'}
811
812 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
813 rbac_policies = [r for r in rbac_policies if r.pop('id')]
814 self.assertIn(rbac_pol, rbac_policies)
815
816 # update shared True -> False should fail because the policy is bound
817 # to a network
818 net = self._create_network(qos_pol['id'], self.admin_client, False)
819 with testtools.ExpectedException(exceptions.Conflict):
820 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
821
822 # delete the network, and update shared True -> False should pass now
823 self.admin_client.delete_network(net['id'])
824 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
825 qos_pol['shared'] = False
826 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
827
828 def _create_net_bound_qos_rbacs(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000829 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000830 self.client.tenant_id)
831 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
832
833 # add a wildcard rbac rule - now the policy globally shared
834 rbac_wildcard = self.admin_client.create_rbac_policy(
835 object_type='qos_policy',
836 object_id=qos_policy['id'],
837 action='access_as_shared',
838 target_tenant='*',
839 )['rbac_policy']
840
841 # tenant1 now uses qos policy for net
842 self._create_network(qos_policy['id'], self.client)
843
844 return rbac_for_client_tenant, rbac_wildcard
845
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000846 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000847 def test_net_bound_shared_policy_wildcard_and_project_id_wild_remove(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000848 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
849 # globally unshare the qos-policy, the specific share should remain
850 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
851 self.client.list_rbac_policies(id=client_rbac['id'])
852
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000853 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000854 def test_net_bound_shared_policy_wildcard_and_projectid_wild_remains(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000855 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
856 # remove client_rbac policy the wildcard share should remain
857 self.admin_client.delete_rbac_policy(client_rbac['id'])
858 self.client.list_rbac_policies(id=wildcard_rbac['id'])
859
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000860 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000861 def test_policy_sharing_with_wildcard_and_project_id(self):
862 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000863 self.client.tenant_id)
864 qos_policy, rbac = res['policy'], res['rbac_policy']
865 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
866 self.assertTrue(qos_pol['shared'])
867 with testtools.ExpectedException(exceptions.NotFound):
868 self.client2.show_qos_policy(qos_policy['id'])
869
870 # make the qos-policy globally shared
871 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
872 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
873 self.assertTrue(qos_pol['shared'])
874
875 # globally unshare the qos-policy, the specific share should remain
876 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
877 self.client.show_qos_policy(qos_policy['id'])
878 with testtools.ExpectedException(exceptions.NotFound):
879 self.client2.show_qos_policy(qos_policy['id'])
880 self.assertIn(rbac,
881 self.admin_client.list_rbac_policies()['rbac_policies'])
882
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000883 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000884 def test_policy_target_update(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000885 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000886 self.client.tenant_id)
887 # change to client2
888 update_res = self.admin_client.update_rbac_policy(
889 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
890 self.assertEqual(self.client2.tenant_id,
891 update_res['rbac_policy']['target_tenant'])
892 # make sure everything else stayed the same
893 res['rbac_policy'].pop('target_tenant')
894 update_res['rbac_policy'].pop('target_tenant')
895 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
896
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000897 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000898 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000899 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000900 self.client2.tenant_id)
901 qos_policy_id = res['policy']['id']
902 self._create_network(qos_policy_id, self.client2)
903 # a network with shared qos-policy should prevent the deletion of an
904 # rbac-policy required for it to be shared
905 with testtools.ExpectedException(exceptions.Conflict):
906 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
907
908 # a wildcard policy should allow the specific policy to be deleted
909 # since it allows the remaining port
910 wild = self.admin_client.create_rbac_policy(
911 object_type='qos_policy', object_id=res['policy']['id'],
912 action='access_as_shared', target_tenant='*')['rbac_policy']
913 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
914
915 # now that wildcard is the only remaining, it should be subjected to
916 # the same restriction
917 with testtools.ExpectedException(exceptions.Conflict):
918 self.admin_client.delete_rbac_policy(wild['id'])
919
920 # we can't update the policy to a different tenant
921 with testtools.ExpectedException(exceptions.Conflict):
922 self.admin_client.update_rbac_policy(
923 wild['id'], target_tenant=self.client2.tenant_id)
924
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000925 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000926 def test_regular_client_shares_to_another_regular_client(self):
927 # owned by self.admin_client
928 policy = self._create_qos_policy()
929 with testtools.ExpectedException(exceptions.NotFound):
930 self.client.show_qos_policy(policy['id'])
931 rbac_policy = self.admin_client.create_rbac_policy(
932 object_type='qos_policy', object_id=policy['id'],
933 action='access_as_shared',
934 target_tenant=self.client.tenant_id)['rbac_policy']
935 self.client.show_qos_policy(policy['id'])
936
937 self.assertIn(rbac_policy,
938 self.admin_client.list_rbac_policies()['rbac_policies'])
939 # ensure that 'client2' can't see the rbac-policy sharing the
940 # qos-policy to it because the rbac-policy belongs to 'client'
941 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
942 self.client2.list_rbac_policies()['rbac_policies']])
943
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000944 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000945 def test_filter_fields(self):
946 policy = self._create_qos_policy()
947 self.admin_client.create_rbac_policy(
948 object_type='qos_policy', object_id=policy['id'],
949 action='access_as_shared', target_tenant=self.client2.tenant_id)
950 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000951 ('project_id', 'target_tenant'))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000952 for fields in field_args:
953 res = self.admin_client.list_rbac_policies(fields=fields)
954 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
955
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000956 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000957 def test_rbac_policy_show(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000958 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000959 self.client.tenant_id)
960 p1 = res['rbac_policy']
961 p2 = self.admin_client.create_rbac_policy(
962 object_type='qos_policy', object_id=res['policy']['id'],
963 action='access_as_shared',
964 target_tenant='*')['rbac_policy']
965
966 self.assertEqual(
967 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
968 self.assertEqual(
969 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
970
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000971 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000972 def test_filter_rbac_policies(self):
973 policy = self._create_qos_policy()
974 rbac_pol1 = self.admin_client.create_rbac_policy(
975 object_type='qos_policy', object_id=policy['id'],
976 action='access_as_shared',
977 target_tenant=self.client2.tenant_id)['rbac_policy']
978 rbac_pol2 = self.admin_client.create_rbac_policy(
979 object_type='qos_policy', object_id=policy['id'],
980 action='access_as_shared',
981 target_tenant=self.admin_client.tenant_id)['rbac_policy']
982 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
983 'rbac_policies']
984 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
985 'rbac_policies']
986 self.assertEqual(1, len(res1))
987 self.assertEqual(1, len(res2))
988 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
989 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
990
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000991 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000992 def test_regular_client_blocked_from_sharing_anothers_policy(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000993 qos_policy = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000994 self.client.tenant_id)['policy']
995 with testtools.ExpectedException(exceptions.BadRequest):
996 self.client.create_rbac_policy(
997 object_type='qos_policy', object_id=qos_policy['id'],
998 action='access_as_shared',
999 target_tenant=self.client2.tenant_id)
1000
1001 # make sure the rbac-policy is invisible to the tenant for which it's
1002 # being shared
1003 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
1004
1005
1006class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
1007 VALID_DSCP_MARK1 = 56
1008 VALID_DSCP_MARK2 = 48
1009
Chandan Kumarc125fd12017-11-15 19:41:01 +05301010 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001011
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001012 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001013 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001014 def resource_setup(cls):
1015 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
1016
elajkat757f3f12022-01-28 11:17:55 +01001017 def setUp(self):
1018 super(QosDscpMarkingRuleTestJSON, self).setUp()
1019 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
1020
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001021 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001022 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001023 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001024 description='test policy',
1025 shared=False)
1026 rule = self.admin_client.create_dscp_marking_rule(
1027 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1028
1029 # Test 'show rule'
1030 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1031 policy['id'], rule['id'])
1032 retrieved_rule = retrieved_rule['dscp_marking_rule']
1033 self.assertEqual(rule['id'], retrieved_rule['id'])
1034 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
1035
1036 # Test 'list rules'
1037 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
1038 rules = rules['dscp_marking_rules']
1039 rules_ids = [r['id'] for r in rules]
1040 self.assertIn(rule['id'], rules_ids)
1041
1042 # Test 'show policy'
1043 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1044 policy_rules = retrieved_policy['policy']['rules']
1045 self.assertEqual(1, len(policy_rules))
1046 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +00001047 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001048 policy_rules[0]['type'])
1049
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001050 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001051 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001052 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001053 description='test policy',
1054 shared=False)
1055 self.admin_client.create_dscp_marking_rule(
1056 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1057
1058 self.assertRaises(exceptions.Conflict,
1059 self.admin_client.create_dscp_marking_rule,
1060 policy_id=policy['id'],
1061 dscp_mark=self.VALID_DSCP_MARK2)
1062
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001063 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001064 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001065 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001066 description='test policy',
1067 shared=False)
1068 rule = self.admin_client.create_dscp_marking_rule(
1069 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1070
1071 self.admin_client.update_dscp_marking_rule(
1072 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
1073
1074 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1075 policy['id'], rule['id'])
1076 retrieved_policy = retrieved_policy['dscp_marking_rule']
1077 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
1078
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001079 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001080 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001081 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001082 description='test policy',
1083 shared=False)
1084 rule = self.admin_client.create_dscp_marking_rule(
1085 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1086
1087 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1088 policy['id'], rule['id'])
1089 retrieved_policy = retrieved_policy['dscp_marking_rule']
1090 self.assertEqual(rule['id'], retrieved_policy['id'])
1091
1092 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
1093 self.assertRaises(exceptions.NotFound,
1094 self.admin_client.show_dscp_marking_rule,
1095 policy['id'], rule['id'])
1096
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001097 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001098 def test_rule_create_rule_nonexistent_policy(self):
1099 self.assertRaises(
1100 exceptions.NotFound,
1101 self.admin_client.create_dscp_marking_rule,
1102 'policy', self.VALID_DSCP_MARK1)
1103
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001104 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001105 def test_rule_create_forbidden_for_regular_tenants(self):
1106 self.assertRaises(
1107 exceptions.Forbidden,
1108 self.client.create_dscp_marking_rule,
1109 'policy', self.VALID_DSCP_MARK1)
1110
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001111 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001112 def test_invalid_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001113 policy = self.create_qos_policy(name=self.policy_name,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001114 description='test policy',
1115 shared=False)
1116 self.assertRaises(
1117 exceptions.BadRequest,
1118 self.admin_client.create_dscp_marking_rule,
1119 policy['id'], 58)
1120
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001121 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001122 def test_get_rules_by_policy(self):
1123 policy1 = self.create_qos_policy(name='test-policy1',
1124 description='test policy1',
1125 shared=False)
1126 rule1 = self.admin_client.create_dscp_marking_rule(
1127 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1128
1129 policy2 = self.create_qos_policy(name='test-policy2',
1130 description='test policy2',
1131 shared=False)
1132 rule2 = self.admin_client.create_dscp_marking_rule(
1133 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
1134
1135 # Test 'list rules'
1136 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
1137 rules = rules['dscp_marking_rules']
1138 rules_ids = [r['id'] for r in rules]
1139 self.assertIn(rule1['id'], rules_ids)
1140 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001141
nfridman23b44ad2019-09-05 09:46:50 -04001142 @decorators.idempotent_id('19ed2286-ccb1-11e9-87d7-525400d6f522')
1143 def test_qos_dscp_create_and_update(self):
1144 """This test covers:
1145
1146 1.Creating a basic QoS policy with DSCP marking rule.
1147 2.Updating QoS policy:
1148 Administrator should have the ability to update existing QoS policy.
1149 This test should verify that:
1150 It's possible to update the existing DSCP marking rule with all of
1151 the valid marks between 0-56, except of the invalid marks:
1152 2-6, 42, 44, and 50-54 (which should be forbidden)
1153 """
1154
1155 def _test_update_dscp_mark_values(self, dscp_policy_id, rule_id):
1156 for mark in range(n_constants.VALID_DSCP_MARKS[1],
1157 self.VALID_DSCP_MARK1 + 1):
1158 if mark in n_constants.VALID_DSCP_MARKS:
1159 self.admin_client.update_dscp_marking_rule(
1160 dscp_policy_id, rule_id, dscp_mark=mark)
1161
1162 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1163 dscp_policy_id, rule_id)['dscp_marking_rule']
1164 self.assertEqual(mark, retrieved_rule['dscp_mark'],
1165 """current DSCP mark is incorrect:
1166 expected value {0} actual value {1}
1167 """.format(mark,
1168 retrieved_rule['dscp_mark']))
1169
1170 else:
1171 self.assertRaises(exceptions.BadRequest,
1172 self.admin_client.create_dscp_marking_rule,
1173 dscp_policy_id,
1174 mark)
1175 # Setup network
1176 self.network = self.create_network()
1177
1178 # Create QoS policy
1179 dscp_policy_id = self.create_qos_policy(
elajkat757f3f12022-01-28 11:17:55 +01001180 name=self.policy_name,
nfridman23b44ad2019-09-05 09:46:50 -04001181 description='test-qos-policy',
1182 shared=True)['id']
1183
1184 # Associate QoS to the network
1185 self.admin_client.update_network(
1186 self.network['id'], qos_policy_id=dscp_policy_id)
1187
1188 # Set a new DSCP rule with the first mark in range
1189 rule_id = self.admin_client.create_dscp_marking_rule(
1190 dscp_policy_id,
1191 n_constants.VALID_DSCP_MARKS[0])[
1192 'dscp_marking_rule']['id']
1193
1194 # Validate that the rule was set up properly
1195 retrieved_rule = self.client.show_dscp_marking_rule(
1196 dscp_policy_id, rule_id)['dscp_marking_rule']
1197 self.assertEqual(n_constants.VALID_DSCP_MARKS[0],
1198 retrieved_rule['dscp_mark'],
1199 """current DSCP mark is incorrect:
1200 expected value {0} actual value {1}
1201 """.format(n_constants.VALID_DSCP_MARKS[0],
1202 retrieved_rule['dscp_mark']))
1203
1204 # Try to set marks in range 8:56 (invalid marks should raise an error)
1205 _test_update_dscp_mark_values(self, dscp_policy_id, rule_id)
1206
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001207
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001208class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
1209 DIRECTION_EGRESS = "egress"
1210 DIRECTION_INGRESS = "ingress"
1211 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
1212 RULES_NAME = RULE_NAME + "s"
Chandan Kumarc125fd12017-11-15 19:41:01 +05301213 required_extensions = [qos_apidef.ALIAS]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001214
1215 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001216 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001217 def resource_setup(cls):
1218 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
1219
zahlabut7ebb66e2021-09-01 22:39:49 +03001220 @classmethod
1221 def setup_clients(cls):
1222 super(QosMinimumBandwidthRuleTestJSON, cls).setup_clients()
1223 cls.qos_min_bw_rules_client = \
1224 cls.os_admin.qos_minimum_bandwidth_rules_client
1225 cls.qos_min_bw_rules_client_primary = \
1226 cls.os_primary.qos_minimum_bandwidth_rules_client
1227
elajkat757f3f12022-01-28 11:17:55 +01001228 def setUp(self):
1229 super(QosMinimumBandwidthRuleTestJSON, self).setUp()
1230 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
1231
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001232 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001233 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001234 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001235 description='test policy',
1236 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001237 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1238 qos_policy_id=policy['id'],
1239 **{'direction': self.DIRECTION_EGRESS,
1240 'min_kbps': 1138})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001241
1242 # Test 'show rule'
zahlabut7ebb66e2021-09-01 22:39:49 +03001243 retrieved_rule = \
1244 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1245 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001246 retrieved_rule = retrieved_rule[self.RULE_NAME]
1247 self.assertEqual(rule['id'], retrieved_rule['id'])
1248 self.assertEqual(1138, retrieved_rule['min_kbps'])
1249 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1250
1251 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001252 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1253 policy['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001254 rules = rules[self.RULES_NAME]
1255 rules_ids = [r['id'] for r in rules]
1256 self.assertIn(rule['id'], rules_ids)
1257
1258 # Test 'show policy'
1259 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1260 policy_rules = retrieved_policy['policy']['rules']
1261 self.assertEqual(1, len(policy_rules))
1262 self.assertEqual(rule['id'], policy_rules[0]['id'])
1263 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1264 policy_rules[0]['type'])
1265
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001266 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001267 def test_rule_create_fail_for_missing_min_kbps(self):
elajkat757f3f12022-01-28 11:17:55 +01001268 policy = self.create_qos_policy(name=self.policy_name,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001269 description='test policy',
1270 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001271 self.assertRaises(
1272 exceptions.BadRequest,
1273 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1274 qos_policy_id=policy['id'],
1275 **{'direction': self.DIRECTION_EGRESS})
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001276
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001277 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001278 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001279 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001280 description='test policy',
1281 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001282 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1283 qos_policy_id=policy['id'],
1284 **{'direction': self.DIRECTION_EGRESS,
1285 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001286
zahlabut7ebb66e2021-09-01 22:39:49 +03001287 self.assertRaises(
1288 exceptions.Conflict,
1289 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1290 qos_policy_id=policy['id'],
1291 **{'direction': self.DIRECTION_EGRESS,
1292 'min_kbps': 201})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001293
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001294 @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936')
1295 @utils.requires_ext(extension="qos-bw-minimum-ingress",
1296 service="network")
1297 def test_rule_create_pass_for_direction_ingress(self):
elajkat757f3f12022-01-28 11:17:55 +01001298 policy = self.create_qos_policy(name=self.policy_name,
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001299 description='test policy',
1300 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001301 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1302 qos_policy_id=policy['id'],
1303 **{'direction': self.DIRECTION_INGRESS,
1304 'min_kbps': 201})
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001305
1306 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1307 policy_rules = retrieved_policy['policy']['rules']
1308 self.assertEqual(1, len(policy_rules))
1309 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1310 policy_rules[0]['type'])
1311 self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction'])
1312
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001313 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001314 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001315 policy = self.create_qos_policy(name=self.policy_name,
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001316 description='test policy',
1317 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001318 rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1319 qos_policy_id=policy['id'],
1320 **{'direction': self.DIRECTION_EGRESS,
1321 'min_kbps': 300})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001322
zahlabut7ebb66e2021-09-01 22:39:49 +03001323 self.qos_min_bw_rules_client.update_minimum_bandwidth_rule(
1324 policy['id'], rule['id'],
1325 **{'min_kbps': 350, 'direction': self.DIRECTION_EGRESS})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001326
zahlabut7ebb66e2021-09-01 22:39:49 +03001327 retrieved_policy = \
1328 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule(
1329 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001330 retrieved_policy = retrieved_policy[self.RULE_NAME]
1331 self.assertEqual(350, retrieved_policy['min_kbps'])
1332 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1333
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001334 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001335 def test_rule_delete(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 policy['id'],
1341 **{'direction': self.DIRECTION_EGRESS,
1342 'min_kbps': 200})[self.RULE_NAME]
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(rule['id'], retrieved_policy['id'])
1349
zahlabut7ebb66e2021-09-01 22:39:49 +03001350 self.qos_min_bw_rules_client.delete_minimum_bandwidth_rule(
1351 policy['id'], rule['id'])
1352 self.assertRaises(
1353 exceptions.NotFound,
1354 self.qos_min_bw_rules_client.show_minimum_bandwidth_rule,
1355 policy['id'], rule['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001356
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001357 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001358 def test_rule_create_rule_nonexistent_policy(self):
1359 self.assertRaises(
1360 exceptions.NotFound,
zahlabut7ebb66e2021-09-01 22:39:49 +03001361 self.qos_min_bw_rules_client.create_minimum_bandwidth_rule,
1362 'policy',
1363 **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 200})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001364
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001365 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001366 def test_rule_create_forbidden_for_regular_tenants(self):
1367 self.assertRaises(
1368 exceptions.Forbidden,
zahlabut7ebb66e2021-09-01 22:39:49 +03001369 self.qos_min_bw_rules_client_primary.create_minimum_bandwidth_rule,
1370 'policy', **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 300})
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001371
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001372 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001373 def test_get_rules_by_policy(self):
1374 policy1 = self.create_qos_policy(name='test-policy1',
1375 description='test policy1',
1376 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001377 rule1 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1378 qos_policy_id=policy1['id'],
1379 **{'direction': self.DIRECTION_EGRESS,
1380 'min_kbps': 200})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001381
1382 policy2 = self.create_qos_policy(name='test-policy2',
1383 description='test policy2',
1384 shared=False)
zahlabut7ebb66e2021-09-01 22:39:49 +03001385 rule2 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule(
1386 qos_policy_id=policy2['id'],
1387 **{'direction': self.DIRECTION_EGRESS,
1388 'min_kbps': 5000})[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001389
1390 # Test 'list rules'
zahlabut7ebb66e2021-09-01 22:39:49 +03001391 rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules(
1392 policy1['id'])
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001393 rules = rules[self.RULES_NAME]
1394 rules_ids = [r['id'] for r in rules]
1395 self.assertIn(rule1['id'], rules_ids)
1396 self.assertNotIn(rule2['id'], rules_ids)
1397
1398
elajkat4a1357b2021-08-31 10:16:25 +02001399class QosMinimumPpsRuleTestJSON(base.BaseAdminNetworkTest):
1400 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_PACKET_RATE + "_rule"
1401 RULES_NAME = RULE_NAME + "s"
1402 required_extensions = [qos_apidef.ALIAS]
1403
1404 @classmethod
1405 @utils.requires_ext(service='network',
1406 extension='port-resource-request-groups')
1407 def resource_setup(cls):
1408 super(QosMinimumPpsRuleTestJSON, cls).resource_setup()
1409
1410 @classmethod
1411 def setup_clients(cls):
1412 super(QosMinimumPpsRuleTestJSON, cls).setup_clients()
1413 cls.min_pps_client = cls.os_admin.qos_minimum_packet_rate_rules_client
1414 cls.min_pps_client_primary = \
1415 cls.os_primary.qos_minimum_packet_rate_rules_client
1416
elajkat757f3f12022-01-28 11:17:55 +01001417 def setUp(self):
1418 super(QosMinimumPpsRuleTestJSON, self).setUp()
1419 self.policy_name = data_utils.rand_name(name='test', prefix='policy')
1420
elajkat4a1357b2021-08-31 10:16:25 +02001421 def _create_qos_min_pps_rule(self, policy_id, rule_data):
1422 rule = self.min_pps_client.create_minimum_packet_rate_rule(
1423 policy_id, **rule_data)['minimum_packet_rate_rule']
1424 self.addCleanup(
1425 test_utils.call_and_ignore_notfound_exc,
1426 self.min_pps_client.delete_minimum_packet_rate_rule,
1427 policy_id, rule['id'])
1428 return rule
1429
1430 @decorators.idempotent_id('66a5b9b4-d4f9-4af8-b238-9e1881b78487')
1431 def test_rule_create(self):
elajkat757f3f12022-01-28 11:17:55 +01001432 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001433 description='test policy',
1434 shared=False)
1435 rule = self._create_qos_min_pps_rule(
1436 policy['id'],
1437 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1438 qos_consts.MIN_KPPS: 1138})
1439
1440 # Test 'show rule'
1441 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1442 policy['id'], rule['id'])[self.RULE_NAME]
1443 self.assertEqual(rule['id'], retrieved_rule['id'])
1444 self.assertEqual(1138, retrieved_rule[qos_consts.MIN_KPPS])
1445 self.assertEqual(n_constants.EGRESS_DIRECTION,
1446 retrieved_rule[qos_consts.DIRECTION])
1447
1448 # Test 'list rules'
1449 rules = self.min_pps_client.list_minimum_packet_rate_rules(
1450 policy['id'])
1451 rules = rules[self.RULES_NAME]
1452 rules_ids = [r['id'] for r in rules]
1453 self.assertIn(rule['id'], rules_ids)
1454
1455 # Test 'show policy'
1456 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1457 policy_rules = retrieved_policy['policy']['rules']
1458 self.assertEqual(1, len(policy_rules))
1459 self.assertEqual(rule['id'], policy_rules[0]['id'])
1460 self.assertEqual('minimum_packet_rate',
1461 policy_rules[0]['type'])
1462
1463 @decorators.idempotent_id('6b656b57-d2bf-47f9-89a9-1baad1bd5418')
1464 def test_rule_create_fail_for_missing_min_kpps(self):
elajkat757f3f12022-01-28 11:17:55 +01001465 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001466 description='test policy',
1467 shared=False)
1468 self.assertRaises(exceptions.BadRequest,
1469 self._create_qos_min_pps_rule,
1470 policy['id'],
1471 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION})
1472
1473 @decorators.idempotent_id('f41213e5-2ab8-4916-b106-38d2cac5e18c')
1474 def test_rule_create_fail_for_the_same_type(self):
elajkat757f3f12022-01-28 11:17:55 +01001475 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001476 description='test policy',
1477 shared=False)
1478 self._create_qos_min_pps_rule(policy['id'],
1479 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1480 qos_consts.MIN_KPPS: 200})
1481
1482 self.assertRaises(exceptions.Conflict,
1483 self._create_qos_min_pps_rule,
1484 policy['id'],
1485 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1486 qos_consts.MIN_KPPS: 201})
1487
1488 @decorators.idempotent_id('ceb8e41e-3d72-11ec-a446-d7faae6daec2')
1489 def test_rule_create_any_direction_when_egress_direction_exists(self):
elajkat757f3f12022-01-28 11:17:55 +01001490 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001491 description='test policy',
1492 shared=False)
1493 self._create_qos_min_pps_rule(policy['id'],
1494 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1495 qos_consts.MIN_KPPS: 200})
1496
1497 self.assertRaises(exceptions.Conflict,
1498 self._create_qos_min_pps_rule,
1499 policy['id'],
1500 {qos_consts.DIRECTION: n_constants.ANY_DIRECTION,
1501 qos_consts.MIN_KPPS: 201})
1502
1503 @decorators.idempotent_id('a147a71e-3d7b-11ec-8097-278b1afd5fa2')
1504 def test_rule_create_egress_direction_when_any_direction_exists(self):
elajkat757f3f12022-01-28 11:17:55 +01001505 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001506 description='test policy',
1507 shared=False)
1508 self._create_qos_min_pps_rule(policy['id'],
1509 {qos_consts.DIRECTION: n_constants.ANY_DIRECTION,
1510 qos_consts.MIN_KPPS: 200})
1511
1512 self.assertRaises(exceptions.Conflict,
1513 self._create_qos_min_pps_rule,
1514 policy['id'],
1515 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1516 qos_consts.MIN_KPPS: 201})
1517
1518 @decorators.idempotent_id('522ed09a-1d7f-4c1b-9195-61f19caf916f')
1519 def test_rule_update(self):
elajkat757f3f12022-01-28 11:17:55 +01001520 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001521 description='test policy',
1522 shared=False)
1523 rule = self._create_qos_min_pps_rule(
1524 policy['id'],
1525 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1526 qos_consts.MIN_KPPS: 300})
1527
1528 self.min_pps_client.update_minimum_packet_rate_rule(
1529 policy['id'], rule['id'],
1530 **{qos_consts.MIN_KPPS: 350,
1531 qos_consts.DIRECTION: n_constants.ANY_DIRECTION})
1532
1533 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1534 policy['id'], rule['id'])[self.RULE_NAME]
1535 self.assertEqual(350, retrieved_rule[qos_consts.MIN_KPPS])
1536 self.assertEqual(n_constants.ANY_DIRECTION,
1537 retrieved_rule[qos_consts.DIRECTION])
1538
1539 @decorators.idempotent_id('a020e186-3d60-11ec-88ca-d7f5eec22764')
1540 def test_rule_update_direction_conflict(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 rule1 = 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 rule2 = self._create_qos_min_pps_rule(
1550 policy['id'],
1551 {qos_consts.DIRECTION: n_constants.INGRESS_DIRECTION,
1552 qos_consts.MIN_KPPS: 300})
1553
1554 retrieved_rule1 = self.min_pps_client.show_minimum_packet_rate_rule(
1555 policy['id'], rule1['id'])[self.RULE_NAME]
1556 self.assertEqual(n_constants.EGRESS_DIRECTION,
1557 retrieved_rule1[qos_consts.DIRECTION])
1558 retrieved_rule2 = self.min_pps_client.show_minimum_packet_rate_rule(
1559 policy['id'], rule2['id'])[self.RULE_NAME]
1560 self.assertEqual(n_constants.INGRESS_DIRECTION,
1561 retrieved_rule2[qos_consts.DIRECTION])
1562
1563 self.assertRaises(exceptions.Conflict,
1564 self.min_pps_client.update_minimum_packet_rate_rule,
1565 policy['id'], rule2['id'],
1566 **{qos_consts.DIRECTION: n_constants.ANY_DIRECTION})
1567
1568 @decorators.idempotent_id('c49018b6-d358-49a1-a94b-d53224165045')
1569 def test_rule_delete(self):
elajkat757f3f12022-01-28 11:17:55 +01001570 policy = self.create_qos_policy(name=self.policy_name,
elajkat4a1357b2021-08-31 10:16:25 +02001571 description='test policy',
1572 shared=False)
1573 rule = self._create_qos_min_pps_rule(
1574 policy['id'],
1575 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1576 qos_consts.MIN_KPPS: 200})
1577
1578 retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule(
1579 policy['id'], rule['id'])[self.RULE_NAME]
1580 self.assertEqual(rule['id'], retrieved_rule['id'])
1581
1582 self.min_pps_client.delete_minimum_packet_rate_rule(policy['id'],
1583 rule['id'])
1584 self.assertRaises(exceptions.NotFound,
1585 self.min_pps_client.show_minimum_packet_rate_rule,
1586 policy['id'], rule['id'])
1587
1588 @decorators.idempotent_id('1a6b6128-3d3e-11ec-bf49-57b326d417c0')
1589 def test_rule_create_forbidden_for_regular_tenants(self):
1590 self.assertRaises(
1591 exceptions.Forbidden,
1592 self.min_pps_client_primary.create_minimum_packet_rate_rule,
1593 'policy', **{qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1594 qos_consts.MIN_KPPS: 300})
1595
1596 @decorators.idempotent_id('1b94f4e2-3d3e-11ec-bb21-6f98e4044b8b')
1597 def test_get_rules_by_policy(self):
1598 policy1 = self.create_qos_policy(name='test-policy1',
1599 description='test policy1',
1600 shared=False)
1601 rule1 = self._create_qos_min_pps_rule(
1602 policy1['id'],
1603 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1604 qos_consts.MIN_KPPS: 200})
1605
1606 policy2 = self.create_qos_policy(name='test-policy2',
1607 description='test policy2',
1608 shared=False)
1609 rule2 = self._create_qos_min_pps_rule(
1610 policy2['id'],
1611 {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION,
1612 qos_consts.MIN_KPPS: 5000})
1613
1614 # Test 'list rules'
1615 rules = self.min_pps_client.list_minimum_packet_rate_rules(
1616 policy1['id'])
1617 rules = rules[self.RULES_NAME]
1618 rules_ids = [r['id'] for r in rules]
1619 self.assertIn(rule1['id'], rules_ids)
1620 self.assertNotIn(rule2['id'], rules_ids)
1621
1622
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001623class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1624 base.BaseAdminNetworkTest):
1625
1626 resource = 'policy'
1627 plural_name = 'policies'
1628
1629 # Use unique description to isolate the tests from other QoS tests
1630 list_kwargs = {'description': 'search-criteria-test'}
1631 list_as_admin = True
1632
Chandan Kumarc125fd12017-11-15 19:41:01 +05301633 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001634
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001635 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001636 def resource_setup(cls):
1637 super(QosSearchCriteriaTest, cls).resource_setup()
1638 for name in cls.resource_names:
1639 cls.create_qos_policy(
1640 name=name, description='search-criteria-test')
1641
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001642 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001643 def test_list_sorts_asc(self):
1644 self._test_list_sorts_asc()
1645
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001646 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001647 def test_list_sorts_desc(self):
1648 self._test_list_sorts_desc()
1649
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001650 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001651 def test_list_pagination(self):
1652 self._test_list_pagination()
1653
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001654 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001655 def test_list_pagination_with_marker(self):
1656 self._test_list_pagination_with_marker()
1657
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001658 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001659 def test_list_pagination_with_href_links(self):
1660 self._test_list_pagination_with_href_links()
1661
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001662 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001663 def test_list_pagination_page_reverse_asc(self):
1664 self._test_list_pagination_page_reverse_asc()
1665
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001666 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001667 def test_list_pagination_page_reverse_desc(self):
1668 self._test_list_pagination_page_reverse_desc()
1669
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001670 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001671 def test_list_pagination_page_reverse_with_href_links(self):
1672 self._test_list_pagination_page_reverse_with_href_links()
1673
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001674 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001675 def test_list_no_pagination_limit_0(self):
1676 self._test_list_no_pagination_limit_0()