blob: 5fb0511dda3a2ee9b8fd0074b3cf5bd8278c0a79 [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
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000020from tempest.lib import decorators
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000021from tempest.lib import exceptions
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000022
Sławek Kapłoński153f3452017-03-24 22:04:53 +000023import testscenarios
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000024import testtools
25
Chandan Kumar667d3d32017-09-22 12:24:06 +053026from neutron_tempest_plugin.api import base
nfridman07f0e782019-11-04 09:12:58 -050027from neutron_tempest_plugin import config
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000028
Sławek Kapłoński153f3452017-03-24 22:04:53 +000029load_tests = testscenarios.load_tests_apply_scenarios
nfridman07f0e782019-11-04 09:12:58 -050030CONF = config.CONF
Sławek Kapłoński153f3452017-03-24 22:04:53 +000031
32
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000033class QosTestJSON(base.BaseAdminNetworkTest):
Jakub Libosvar1982aa12017-05-30 11:15:33 +000034
Chandan Kumarc125fd12017-11-15 19:41:01 +053035 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000036
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +000037 @staticmethod
38 def _get_driver_details(rule_type_details, driver_name):
39 for driver in rule_type_details['drivers']:
40 if driver['name'] == driver_name:
41 return driver
42
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000043 @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000044 def test_create_policy(self):
45 policy = self.create_qos_policy(name='test-policy',
46 description='test policy desc1',
47 shared=False)
48
49 # Test 'show policy'
50 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
51 retrieved_policy = retrieved_policy['policy']
52 self.assertEqual('test-policy', retrieved_policy['name'])
53 self.assertEqual('test policy desc1', retrieved_policy['description'])
54 self.assertFalse(retrieved_policy['shared'])
55
56 # Test 'list policies'
57 policies = self.admin_client.list_qos_policies()['policies']
58 policies_ids = [p['id'] for p in policies]
59 self.assertIn(policy['id'], policies_ids)
60
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000061 @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76')
Chandan Kumarc125fd12017-11-15 19:41:01 +053062 @utils.requires_ext(extension="project-id", service="network")
Henry Gessaufa6c78d2016-10-09 19:56:09 -040063 def test_show_policy_has_project_id(self):
64 policy = self.create_qos_policy(name='test-policy', shared=False)
65 body = self.admin_client.show_qos_policy(policy['id'])
66 show_policy = body['policy']
67 self.assertIn('project_id', show_policy)
Henry Gessaufa6c78d2016-10-09 19:56:09 -040068 self.assertEqual(self.admin_client.tenant_id,
69 show_policy['project_id'])
Henry Gessaufa6c78d2016-10-09 19:56:09 -040070
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000071 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000072 def test_list_policy_filter_by_name(self):
73 self.create_qos_policy(name='test', description='test policy',
74 shared=False)
75 self.create_qos_policy(name='test2', description='test policy',
76 shared=False)
77
78 policies = (self.admin_client.
79 list_qos_policies(name='test')['policies'])
80 self.assertEqual(1, len(policies))
81
82 retrieved_policy = policies[0]
83 self.assertEqual('test', retrieved_policy['name'])
84
likangkang01afd73f72020-06-01 16:53:59 +080085 @decorators.idempotent_id('dde0b449-a400-4a87-b5a5-4d1c413c917b')
86 def test_list_policy_sort_by_name(self):
87 policyA = 'A' + data_utils.rand_name("policy")
88 policyB = 'B' + data_utils.rand_name("policy")
89 self.create_qos_policy(name=policyA, description='test policy',
90 shared=False)
91 self.create_qos_policy(name=policyB, description='test policy',
92 shared=False)
93
94 param = {
95 'sort_key': 'name',
96 'sort_dir': 'asc'
97 }
98 policies = (self.admin_client.list_qos_policies(**param)['policies'])
99 policy_names = [p['name'] for p in policies]
100 self.assertLess(policy_names.index(policyA),
101 policy_names.index(policyB))
102
103 param = {
104 'sort_key': 'name',
105 'sort_dir': 'desc'
106 }
107 policies = (self.admin_client.list_qos_policies(**param)['policies'])
108 policy_names = [p['name'] for p in policies]
109 self.assertLess(policy_names.index(policyB),
110 policy_names.index(policyA))
111
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000112 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000113 def test_policy_update(self):
114 policy = self.create_qos_policy(name='test-policy',
115 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000116 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000117 project_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000118 self.admin_client.update_qos_policy(policy['id'],
119 description='test policy desc2',
120 shared=True)
121
122 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
123 retrieved_policy = retrieved_policy['policy']
124 self.assertEqual('test policy desc2', retrieved_policy['description'])
125 self.assertTrue(retrieved_policy['shared'])
126 self.assertEqual([], retrieved_policy['rules'])
127
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000128 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000129 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
130 policy = self.create_qos_policy(name='test-policy',
131 description='',
132 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000133 project_id=self.client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000134 self.assertRaises(
135 exceptions.Forbidden,
136 self.client.update_qos_policy,
137 policy['id'], description='test policy')
138
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000139 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000140 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
141 policy = self.create_qos_policy(name='test-policy',
142 description='',
143 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000144 project_id=self.admin_client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000145 self.assertRaises(
146 exceptions.NotFound,
147 self.client.update_qos_policy,
148 policy['id'], description='test policy')
149
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000150 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000151 def test_shared_policy_update(self):
152 policy = self.create_qos_policy(name='test-policy',
153 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000154 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000155 project_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000156
157 self.admin_client.update_qos_policy(policy['id'],
158 description='test policy desc2')
159 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
160 retrieved_policy = retrieved_policy['policy']
161 self.assertTrue(retrieved_policy['shared'])
162
163 self.admin_client.update_qos_policy(policy['id'],
164 shared=False)
165 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
166 retrieved_policy = retrieved_policy['policy']
167 self.assertFalse(retrieved_policy['shared'])
168
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000169 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000170 def test_delete_policy(self):
171 policy = self.admin_client.create_qos_policy(
172 'test-policy', 'desc', True)['policy']
173
174 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
175 retrieved_policy = retrieved_policy['policy']
176 self.assertEqual('test-policy', retrieved_policy['name'])
177
178 self.admin_client.delete_qos_policy(policy['id'])
179 self.assertRaises(exceptions.NotFound,
180 self.admin_client.show_qos_policy, policy['id'])
181
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000182 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000183 def test_list_admin_rule_types(self):
184 self._test_list_rule_types(self.admin_client)
185
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000186 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000187 def test_list_regular_rule_types(self):
188 self._test_list_rule_types(self.client)
189
190 def _test_list_rule_types(self, client):
191 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000192 # Since returned rule types depends on loaded backend drivers this test
193 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000194 #
195 # In theory, we could make the test conditional on which ml2 drivers
196 # are enabled in gate (or more specifically, on which supported qos
197 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200198 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000199 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000200
201 rule_types = client.list_qos_rule_types()
202 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000203
204 # Verify that only required fields present in rule details
205 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000206 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000207
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000208 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
209 def test_show_rule_type_details_as_user(self):
210 self.assertRaises(
211 exceptions.Forbidden,
212 self.client.show_qos_rule_type,
213 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
214
215 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
216 def test_show_rule_type_details_as_admin(self):
217 # Since returned rule types depend on loaded backend drivers this test
218 # is checking only if returned keys are same as expected keys
219
220 # In theory, we could make the test conditional on which ml2 drivers
221 # are enabled in gate, but that option doesn't seem to be
222 # available through tempest.lib framework
223 expected_rule_type_details_keys = ['type', 'drivers']
224
225 rule_type_details = self.admin_client.show_qos_rule_type(
226 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
227
228 # Verify that only required fields present in rule details
229 self.assertEqual(
230 sorted(tuple(expected_rule_type_details_keys)),
231 sorted(tuple(rule_type_details.keys())))
232
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000233 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000234 def test_policy_association_with_admin_network(self):
235 policy = self.create_qos_policy(name='test-policy',
236 description='test policy',
237 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200238 network = self.create_network('test network', shared=True,
239 qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000240
241 retrieved_network = self.admin_client.show_network(network['id'])
242 self.assertEqual(
243 policy['id'], retrieved_network['network']['qos_policy_id'])
244
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000245 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000246 def test_policy_association_with_tenant_network(self):
247 policy = self.create_qos_policy(name='test-policy',
248 description='test policy',
249 shared=True)
250 network = self.create_network('test network',
251 qos_policy_id=policy['id'])
252
253 retrieved_network = self.admin_client.show_network(network['id'])
254 self.assertEqual(
255 policy['id'], retrieved_network['network']['qos_policy_id'])
256
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000257 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000258 def test_policy_association_with_network_nonexistent_policy(self):
259 self.assertRaises(
260 exceptions.NotFound,
261 self.create_network,
262 'test network',
263 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
264
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000265 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000266 def test_policy_association_with_network_non_shared_policy(self):
267 policy = self.create_qos_policy(name='test-policy',
268 description='test policy',
269 shared=False)
270 self.assertRaises(
271 exceptions.NotFound,
272 self.create_network,
273 'test network', qos_policy_id=policy['id'])
274
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000275 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000276 def test_policy_update_association_with_admin_network(self):
277 policy = self.create_qos_policy(name='test-policy',
278 description='test policy',
279 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200280 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000281 retrieved_network = self.admin_client.show_network(network['id'])
282 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
283
284 self.admin_client.update_network(network['id'],
285 qos_policy_id=policy['id'])
286 retrieved_network = self.admin_client.show_network(network['id'])
287 self.assertEqual(
288 policy['id'], retrieved_network['network']['qos_policy_id'])
289
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000290 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000291 def test_policy_association_with_port_shared_policy(self):
292 policy = self.create_qos_policy(name='test-policy',
293 description='test policy',
294 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200295 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000296 port = self.create_port(network, qos_policy_id=policy['id'])
297
298 retrieved_port = self.admin_client.show_port(port['id'])
299 self.assertEqual(
300 policy['id'], retrieved_port['port']['qos_policy_id'])
301
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000302 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000303 def test_policy_association_with_port_nonexistent_policy(self):
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200304 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000305 self.assertRaises(
306 exceptions.NotFound,
307 self.create_port,
308 network,
309 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
310
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000311 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000312 def test_policy_association_with_port_non_shared_policy(self):
313 policy = self.create_qos_policy(name='test-policy',
314 description='test policy',
315 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200316 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000317 self.assertRaises(
318 exceptions.NotFound,
319 self.create_port,
320 network, qos_policy_id=policy['id'])
321
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000322 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000323 def test_policy_update_association_with_port_shared_policy(self):
324 policy = self.create_qos_policy(name='test-policy',
325 description='test policy',
326 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200327 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000328 port = self.create_port(network)
329 retrieved_port = self.admin_client.show_port(port['id'])
330 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
331
332 self.client.update_port(port['id'], qos_policy_id=policy['id'])
333 retrieved_port = self.admin_client.show_port(port['id'])
334 self.assertEqual(
335 policy['id'], retrieved_port['port']['qos_policy_id'])
336
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000337 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000338 def test_delete_not_allowed_if_policy_in_use_by_network(self):
339 policy = self.create_qos_policy(name='test-policy',
340 description='test policy',
341 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200342 self.create_network('test network', qos_policy_id=policy['id'],
343 shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000344 self.assertRaises(
345 exceptions.Conflict,
346 self.admin_client.delete_qos_policy, policy['id'])
347
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000348 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000349 def test_delete_not_allowed_if_policy_in_use_by_port(self):
350 policy = self.create_qos_policy(name='test-policy',
351 description='test policy',
352 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200353 network = self.create_network('test network', shared=True)
Sławek Kapłońskie100c4d2017-08-23 21:18:34 +0000354 self.create_port(network, qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000355 self.assertRaises(
356 exceptions.Conflict,
357 self.admin_client.delete_qos_policy, policy['id'])
358
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000359 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000360 def test_qos_policy_delete_with_rules(self):
361 policy = self.create_qos_policy(name='test-policy',
362 description='test policy',
363 shared=False)
364 self.admin_client.create_bandwidth_limit_rule(
365 policy['id'], 200, 1337)['bandwidth_limit_rule']
366
367 self.admin_client.delete_qos_policy(policy['id'])
368
369 with testtools.ExpectedException(exceptions.NotFound):
370 self.admin_client.show_qos_policy(policy['id'])
371
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000372 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000373 def test_get_policy_that_is_shared(self):
374 policy = self.create_qos_policy(
375 name='test-policy-shared',
376 description='shared policy',
377 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000378 project_id=self.admin_client.tenant_id)
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000379 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
380 self.assertEqual(obtained_policy, policy)
381
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000382 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100383 def test_policy_create_forbidden_for_regular_tenants(self):
384 self.assertRaises(
385 exceptions.Forbidden,
386 self.client.create_qos_policy,
387 'test-policy', 'test policy', False)
388
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900389 @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
390 def test_default_policy_creating_network_without_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530391 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900392 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000393 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900394 is_default=True)
395 network = self.create_network('test network', client=self.admin_client,
396 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900397 retrieved_network = self.admin_client.show_network(network['id'])
398 self.assertEqual(
399 policy['id'], retrieved_network['network']['qos_policy_id'])
400
401 @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
402 def test_default_policy_creating_network_with_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530403 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900404 self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000405 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900406 is_default=True)
407 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000408 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900409 network = self.create_network('test network', client=self.admin_client,
410 project_id=project_id,
411 qos_policy_id=policy['id'])
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900412 retrieved_network = self.admin_client.show_network(network['id'])
413 self.assertEqual(
414 policy['id'], retrieved_network['network']['qos_policy_id'])
415
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100416 @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229')
417 def test_user_create_port_with_admin_qos_policy(self):
418 qos_policy = self.create_qos_policy(
419 name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000420 project_id=self.admin_client.tenant_id,
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100421 shared=False)
422 network = self.create_network(
423 'test network', client=self.admin_client,
424 project_id=self.client.tenant_id,
425 qos_policy_id=qos_policy['id'])
426 port = self.create_port(network)
427 self.assertEqual(network['id'], port['network_id'])
428
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000429
430class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000431
432 direction = None
Chandan Kumarc125fd12017-11-15 19:41:01 +0530433 required_extensions = [qos_apidef.ALIAS]
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000434
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000435 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900436 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000437 def resource_setup(cls):
438 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
439
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000440 @property
441 def opposite_direction(self):
442 if self.direction == "ingress":
443 return "egress"
444 elif self.direction == "egress":
445 return "ingress"
446 else:
447 return None
448
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000449 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000450 def test_rule_create(self):
451 policy = self.create_qos_policy(name='test-policy',
452 description='test policy',
453 shared=False)
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000454 rule = self.create_qos_bandwidth_limit_rule(
455 policy_id=policy['id'],
456 max_kbps=200,
457 max_burst_kbps=1337,
458 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000459
460 # Test 'show rule'
461 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
462 policy['id'], rule['id'])
463 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
464 self.assertEqual(rule['id'], retrieved_rule['id'])
465 self.assertEqual(200, retrieved_rule['max_kbps'])
466 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000467 if self.direction:
468 self.assertEqual(self.direction, retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000469
470 # Test 'list rules'
471 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
472 rules = rules['bandwidth_limit_rules']
473 rules_ids = [r['id'] for r in rules]
474 self.assertIn(rule['id'], rules_ids)
475
476 # Test 'show policy'
477 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
478 policy_rules = retrieved_policy['policy']['rules']
479 self.assertEqual(1, len(policy_rules))
480 self.assertEqual(rule['id'], policy_rules[0]['id'])
481 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
482 policy_rules[0]['type'])
483
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000484 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000485 def test_rule_create_fail_for_the_same_type(self):
486 policy = self.create_qos_policy(name='test-policy',
487 description='test policy',
488 shared=False)
489 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
490 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000491 max_burst_kbps=1337,
492 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000493
494 self.assertRaises(exceptions.Conflict,
495 self.create_qos_bandwidth_limit_rule,
496 policy_id=policy['id'],
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000497 max_kbps=201, max_burst_kbps=1338,
498 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000499
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000500 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000501 def test_rule_update(self):
502 policy = self.create_qos_policy(name='test-policy',
503 description='test policy',
504 shared=False)
505 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
506 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000507 max_burst_kbps=1,
508 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000509
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000510 self.admin_client.update_bandwidth_limit_rule(
511 policy['id'],
512 rule['id'],
513 max_kbps=200,
514 max_burst_kbps=1337,
515 direction=self.opposite_direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000516
517 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
518 policy['id'], rule['id'])
519 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
520 self.assertEqual(200, retrieved_policy['max_kbps'])
521 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000522 if self.opposite_direction:
523 self.assertEqual(self.opposite_direction,
524 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000525
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000526 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000527 def test_rule_delete(self):
528 policy = self.create_qos_policy(name='test-policy',
529 description='test policy',
530 shared=False)
531 rule = self.admin_client.create_bandwidth_limit_rule(
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000532 policy['id'], 200, 1337, self.direction)['bandwidth_limit_rule']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000533
534 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
535 policy['id'], rule['id'])
536 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
537 self.assertEqual(rule['id'], retrieved_policy['id'])
538
539 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
540 self.assertRaises(exceptions.NotFound,
541 self.admin_client.show_bandwidth_limit_rule,
542 policy['id'], rule['id'])
543
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000544 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000545 def test_rule_create_rule_nonexistent_policy(self):
546 self.assertRaises(
547 exceptions.NotFound,
548 self.create_qos_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000549 'policy', 200, 1337, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000550
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000551 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000552 def test_rule_create_forbidden_for_regular_tenants(self):
553 self.assertRaises(
554 exceptions.Forbidden,
555 self.client.create_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000556 'policy', 1, 2, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000557
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000558 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000559 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
560 policy = self.create_qos_policy(name='test-policy',
561 description='test policy',
562 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000563 project_id=self.client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000564 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
565 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000566 max_burst_kbps=1,
567 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000568 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400569 exceptions.Forbidden,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000570 self.client.update_bandwidth_limit_rule,
571 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
572
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000573 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000574 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
575 policy = self.create_qos_policy(name='test-policy',
576 description='test policy',
577 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000578 project_id=self.admin_client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000579 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
580 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000581 max_burst_kbps=1,
582 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000583 self.assertRaises(
584 exceptions.NotFound,
585 self.client.update_bandwidth_limit_rule,
586 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
587
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000588 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000589 def test_get_rules_by_policy(self):
590 policy1 = self.create_qos_policy(name='test-policy1',
591 description='test policy1',
592 shared=False)
593 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
594 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000595 max_burst_kbps=1337,
596 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000597
598 policy2 = self.create_qos_policy(name='test-policy2',
599 description='test policy2',
600 shared=False)
601 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
602 max_kbps=5000,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000603 max_burst_kbps=2523,
604 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000605
606 # Test 'list rules'
607 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
608 rules = rules['bandwidth_limit_rules']
609 rules_ids = [r['id'] for r in rules]
610 self.assertIn(rule1['id'], rules_ids)
611 self.assertNotIn(rule2['id'], rules_ids)
612
nfridman07f0e782019-11-04 09:12:58 -0500613 @testtools.skipUnless(
614 CONF.neutron_plugin_options.create_shared_resources,
615 """Creation of shared resources should be allowed,
616 setting the create_shared_resources option as 'True' is needed""")
617 @decorators.idempotent_id('d911707e-fa2c-11e9-9553-5076af30bbf5')
618 def test_attach_and_detach_a_policy_by_a_tenant(self):
619 # As an admin create an non shared QoS policy,add a rule
620 # and associate it with a network
621 self.network = self.create_network()
622 policy = self.create_qos_policy(name='test-policy',
623 description='test policy for attach',
624 shared=False)
625
626 self.admin_client.create_bandwidth_limit_rule(
627 policy['id'], 1024, 1024)
628
629 self.admin_client.update_network(
630 self.network['id'], qos_policy_id=policy['id'])
631
632 # As a tenant, try to detach the policy from the network
633 # The operation should be forbidden
634 self.assertRaises(
635 exceptions.Forbidden,
636 self.client.update_network,
637 self.network['id'], qos_policy_id=None)
638
639 # As an admin, make the policy shared
640 self.admin_client.update_qos_policy(policy['id'], shared=True)
641
642 # As a tenant, try to detach the policy from the network
643 # The operation should be allowed
644 self.client.update_network(self.network['id'],
645 qos_policy_id=None)
646
647 retrieved_network = self.admin_client.show_network(self.network['id'])
648 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
649
650 # As a tenant, try to delete the policy from the network
651 # should be forbidden
652 self.assertRaises(
653 exceptions.Forbidden,
654 self.client.delete_qos_policy,
655 policy['id'])
656
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000657
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000658class QosBandwidthLimitRuleWithDirectionTestJSON(
Brian Haley6767cec2018-04-10 15:30:23 -0400659 QosBandwidthLimitRuleTestJSON):
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000660 required_extensions = (
661 QosBandwidthLimitRuleTestJSON.required_extensions +
662 ['qos-bw-limit-direction']
663 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000664 scenarios = [
665 ('ingress', {'direction': 'ingress'}),
666 ('egress', {'direction': 'egress'}),
667 ]
668
nfridman7717d9c2019-11-25 08:58:04 -0500669 @classmethod
670 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
671 def resource_setup(cls):
672 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
673
674 @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667')
675 def test_create_policy_with_multiple_rules(self):
676 # Create a policy with multiple rules
677 policy = self.create_qos_policy(name='test-policy1',
678 description='test policy1',
679 shared=False)
680
681 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
682 max_kbps=1024,
683 max_burst_kbps=1024,
nfridman07f0e782019-11-04 09:12:58 -0500684 direction=n_constants.
685 EGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500686 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
687 max_kbps=1024,
688 max_burst_kbps=1024,
nfridman07f0e782019-11-04 09:12:58 -0500689 direction=n_constants.
690 INGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500691 # Check that the rules were added to the policy
692 rules = self.admin_client.list_bandwidth_limit_rules(
693 policy['id'])['bandwidth_limit_rules']
694 rules_ids = [rule['id'] for rule in rules]
695 self.assertIn(rule1['id'], rules_ids)
696 self.assertIn(rule2['id'], rules_ids)
697
698 # Check that the rules creation fails for the same rule types
699 self.assertRaises(exceptions.Conflict,
700 self.create_qos_bandwidth_limit_rule,
701 policy_id=policy['id'],
702 max_kbps=1025,
703 max_burst_kbps=1025,
nfridman07f0e782019-11-04 09:12:58 -0500704 direction=n_constants.EGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500705
706 self.assertRaises(exceptions.Conflict,
707 self.create_qos_bandwidth_limit_rule,
708 policy_id=policy['id'],
709 max_kbps=1025,
710 max_burst_kbps=1025,
nfridman07f0e782019-11-04 09:12:58 -0500711 direction=n_constants.INGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500712
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000713
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000714class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
715
716 force_tenant_isolation = True
717 credentials = ['primary', 'alt', 'admin']
Chandan Kumarc125fd12017-11-15 19:41:01 +0530718 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000719
720 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000721 def resource_setup(cls):
722 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530723 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000724
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000725 def _create_qos_policy(self, project_id=None):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000726 args = {'name': data_utils.rand_name('test-policy'),
727 'description': 'test policy',
728 'shared': False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000729 'project_id': project_id}
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000730 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
731 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
732
733 return qos_policy
734
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000735 def _make_admin_policy_shared_to_project_id(self, project_id):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000736 policy = self._create_qos_policy()
737 rbac_policy = self.admin_client.create_rbac_policy(
738 object_type='qos_policy',
739 object_id=policy['id'],
740 action='access_as_shared',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000741 target_tenant=project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000742 )['rbac_policy']
743
744 return {'policy': policy, 'rbac_policy': rbac_policy}
745
746 def _create_network(self, qos_policy_id, client, should_cleanup=True):
747 net = client.create_network(
748 name=data_utils.rand_name('test-network'),
749 qos_policy_id=qos_policy_id)['network']
750 if should_cleanup:
751 self.addCleanup(client.delete_network, net['id'])
752
753 return net
754
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000755 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000756 def test_policy_sharing_with_wildcard(self):
757 qos_pol = self.create_qos_policy(
758 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000759 description='test-shared-policy', shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000760 project_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000761 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
762
763 # test update shared False -> True
764 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
765 qos_pol['shared'] = True
766 self.client2.show_qos_policy(qos_pol['id'])
767 rbac_pol = {'target_tenant': '*',
768 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000769 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000770 'object_type': 'qos_policy',
771 'object_id': qos_pol['id'],
772 'action': 'access_as_shared'}
773
774 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
775 rbac_policies = [r for r in rbac_policies if r.pop('id')]
776 self.assertIn(rbac_pol, rbac_policies)
777
778 # update shared True -> False should fail because the policy is bound
779 # to a network
780 net = self._create_network(qos_pol['id'], self.admin_client, False)
781 with testtools.ExpectedException(exceptions.Conflict):
782 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
783
784 # delete the network, and update shared True -> False should pass now
785 self.admin_client.delete_network(net['id'])
786 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
787 qos_pol['shared'] = False
788 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
789
790 def _create_net_bound_qos_rbacs(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000791 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000792 self.client.tenant_id)
793 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
794
795 # add a wildcard rbac rule - now the policy globally shared
796 rbac_wildcard = self.admin_client.create_rbac_policy(
797 object_type='qos_policy',
798 object_id=qos_policy['id'],
799 action='access_as_shared',
800 target_tenant='*',
801 )['rbac_policy']
802
803 # tenant1 now uses qos policy for net
804 self._create_network(qos_policy['id'], self.client)
805
806 return rbac_for_client_tenant, rbac_wildcard
807
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000808 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000809 def test_net_bound_shared_policy_wildcard_and_project_id_wild_remove(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000810 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
811 # globally unshare the qos-policy, the specific share should remain
812 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
813 self.client.list_rbac_policies(id=client_rbac['id'])
814
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000815 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000816 def test_net_bound_shared_policy_wildcard_and_projectid_wild_remains(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000817 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
818 # remove client_rbac policy the wildcard share should remain
819 self.admin_client.delete_rbac_policy(client_rbac['id'])
820 self.client.list_rbac_policies(id=wildcard_rbac['id'])
821
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000822 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000823 def test_policy_sharing_with_wildcard_and_project_id(self):
824 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000825 self.client.tenant_id)
826 qos_policy, rbac = res['policy'], res['rbac_policy']
827 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
828 self.assertTrue(qos_pol['shared'])
829 with testtools.ExpectedException(exceptions.NotFound):
830 self.client2.show_qos_policy(qos_policy['id'])
831
832 # make the qos-policy globally shared
833 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
834 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
835 self.assertTrue(qos_pol['shared'])
836
837 # globally unshare the qos-policy, the specific share should remain
838 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
839 self.client.show_qos_policy(qos_policy['id'])
840 with testtools.ExpectedException(exceptions.NotFound):
841 self.client2.show_qos_policy(qos_policy['id'])
842 self.assertIn(rbac,
843 self.admin_client.list_rbac_policies()['rbac_policies'])
844
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000845 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000846 def test_policy_target_update(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000847 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000848 self.client.tenant_id)
849 # change to client2
850 update_res = self.admin_client.update_rbac_policy(
851 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
852 self.assertEqual(self.client2.tenant_id,
853 update_res['rbac_policy']['target_tenant'])
854 # make sure everything else stayed the same
855 res['rbac_policy'].pop('target_tenant')
856 update_res['rbac_policy'].pop('target_tenant')
857 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
858
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000859 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000860 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000861 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000862 self.client2.tenant_id)
863 qos_policy_id = res['policy']['id']
864 self._create_network(qos_policy_id, self.client2)
865 # a network with shared qos-policy should prevent the deletion of an
866 # rbac-policy required for it to be shared
867 with testtools.ExpectedException(exceptions.Conflict):
868 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
869
870 # a wildcard policy should allow the specific policy to be deleted
871 # since it allows the remaining port
872 wild = self.admin_client.create_rbac_policy(
873 object_type='qos_policy', object_id=res['policy']['id'],
874 action='access_as_shared', target_tenant='*')['rbac_policy']
875 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
876
877 # now that wildcard is the only remaining, it should be subjected to
878 # the same restriction
879 with testtools.ExpectedException(exceptions.Conflict):
880 self.admin_client.delete_rbac_policy(wild['id'])
881
882 # we can't update the policy to a different tenant
883 with testtools.ExpectedException(exceptions.Conflict):
884 self.admin_client.update_rbac_policy(
885 wild['id'], target_tenant=self.client2.tenant_id)
886
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000887 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000888 def test_regular_client_shares_to_another_regular_client(self):
889 # owned by self.admin_client
890 policy = self._create_qos_policy()
891 with testtools.ExpectedException(exceptions.NotFound):
892 self.client.show_qos_policy(policy['id'])
893 rbac_policy = self.admin_client.create_rbac_policy(
894 object_type='qos_policy', object_id=policy['id'],
895 action='access_as_shared',
896 target_tenant=self.client.tenant_id)['rbac_policy']
897 self.client.show_qos_policy(policy['id'])
898
899 self.assertIn(rbac_policy,
900 self.admin_client.list_rbac_policies()['rbac_policies'])
901 # ensure that 'client2' can't see the rbac-policy sharing the
902 # qos-policy to it because the rbac-policy belongs to 'client'
903 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
904 self.client2.list_rbac_policies()['rbac_policies']])
905
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000906 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000907 def test_filter_fields(self):
908 policy = self._create_qos_policy()
909 self.admin_client.create_rbac_policy(
910 object_type='qos_policy', object_id=policy['id'],
911 action='access_as_shared', target_tenant=self.client2.tenant_id)
912 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000913 ('project_id', 'target_tenant'))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000914 for fields in field_args:
915 res = self.admin_client.list_rbac_policies(fields=fields)
916 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
917
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000918 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000919 def test_rbac_policy_show(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000920 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000921 self.client.tenant_id)
922 p1 = res['rbac_policy']
923 p2 = self.admin_client.create_rbac_policy(
924 object_type='qos_policy', object_id=res['policy']['id'],
925 action='access_as_shared',
926 target_tenant='*')['rbac_policy']
927
928 self.assertEqual(
929 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
930 self.assertEqual(
931 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
932
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000933 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000934 def test_filter_rbac_policies(self):
935 policy = self._create_qos_policy()
936 rbac_pol1 = self.admin_client.create_rbac_policy(
937 object_type='qos_policy', object_id=policy['id'],
938 action='access_as_shared',
939 target_tenant=self.client2.tenant_id)['rbac_policy']
940 rbac_pol2 = self.admin_client.create_rbac_policy(
941 object_type='qos_policy', object_id=policy['id'],
942 action='access_as_shared',
943 target_tenant=self.admin_client.tenant_id)['rbac_policy']
944 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
945 'rbac_policies']
946 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
947 'rbac_policies']
948 self.assertEqual(1, len(res1))
949 self.assertEqual(1, len(res2))
950 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
951 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
952
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000953 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000954 def test_regular_client_blocked_from_sharing_anothers_policy(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000955 qos_policy = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000956 self.client.tenant_id)['policy']
957 with testtools.ExpectedException(exceptions.BadRequest):
958 self.client.create_rbac_policy(
959 object_type='qos_policy', object_id=qos_policy['id'],
960 action='access_as_shared',
961 target_tenant=self.client2.tenant_id)
962
963 # make sure the rbac-policy is invisible to the tenant for which it's
964 # being shared
965 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
966
967
968class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
969 VALID_DSCP_MARK1 = 56
970 VALID_DSCP_MARK2 = 48
971
Chandan Kumarc125fd12017-11-15 19:41:01 +0530972 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000973
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000974 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900975 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000976 def resource_setup(cls):
977 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
978
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000979 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000980 def test_rule_create(self):
981 policy = self.create_qos_policy(name='test-policy',
982 description='test policy',
983 shared=False)
984 rule = self.admin_client.create_dscp_marking_rule(
985 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
986
987 # Test 'show rule'
988 retrieved_rule = self.admin_client.show_dscp_marking_rule(
989 policy['id'], rule['id'])
990 retrieved_rule = retrieved_rule['dscp_marking_rule']
991 self.assertEqual(rule['id'], retrieved_rule['id'])
992 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
993
994 # Test 'list rules'
995 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
996 rules = rules['dscp_marking_rules']
997 rules_ids = [r['id'] for r in rules]
998 self.assertIn(rule['id'], rules_ids)
999
1000 # Test 'show policy'
1001 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1002 policy_rules = retrieved_policy['policy']['rules']
1003 self.assertEqual(1, len(policy_rules))
1004 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +00001005 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001006 policy_rules[0]['type'])
1007
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001008 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001009 def test_rule_create_fail_for_the_same_type(self):
1010 policy = self.create_qos_policy(name='test-policy',
1011 description='test policy',
1012 shared=False)
1013 self.admin_client.create_dscp_marking_rule(
1014 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1015
1016 self.assertRaises(exceptions.Conflict,
1017 self.admin_client.create_dscp_marking_rule,
1018 policy_id=policy['id'],
1019 dscp_mark=self.VALID_DSCP_MARK2)
1020
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001021 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001022 def test_rule_update(self):
1023 policy = self.create_qos_policy(name='test-policy',
1024 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 self.admin_client.update_dscp_marking_rule(
1030 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
1031
1032 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1033 policy['id'], rule['id'])
1034 retrieved_policy = retrieved_policy['dscp_marking_rule']
1035 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
1036
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001037 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001038 def test_rule_delete(self):
1039 policy = self.create_qos_policy(name='test-policy',
1040 description='test policy',
1041 shared=False)
1042 rule = self.admin_client.create_dscp_marking_rule(
1043 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1044
1045 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1046 policy['id'], rule['id'])
1047 retrieved_policy = retrieved_policy['dscp_marking_rule']
1048 self.assertEqual(rule['id'], retrieved_policy['id'])
1049
1050 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
1051 self.assertRaises(exceptions.NotFound,
1052 self.admin_client.show_dscp_marking_rule,
1053 policy['id'], rule['id'])
1054
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001055 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001056 def test_rule_create_rule_nonexistent_policy(self):
1057 self.assertRaises(
1058 exceptions.NotFound,
1059 self.admin_client.create_dscp_marking_rule,
1060 'policy', self.VALID_DSCP_MARK1)
1061
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001062 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001063 def test_rule_create_forbidden_for_regular_tenants(self):
1064 self.assertRaises(
1065 exceptions.Forbidden,
1066 self.client.create_dscp_marking_rule,
1067 'policy', self.VALID_DSCP_MARK1)
1068
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001069 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001070 def test_invalid_rule_create(self):
1071 policy = self.create_qos_policy(name='test-policy',
1072 description='test policy',
1073 shared=False)
1074 self.assertRaises(
1075 exceptions.BadRequest,
1076 self.admin_client.create_dscp_marking_rule,
1077 policy['id'], 58)
1078
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001079 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001080 def test_get_rules_by_policy(self):
1081 policy1 = self.create_qos_policy(name='test-policy1',
1082 description='test policy1',
1083 shared=False)
1084 rule1 = self.admin_client.create_dscp_marking_rule(
1085 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1086
1087 policy2 = self.create_qos_policy(name='test-policy2',
1088 description='test policy2',
1089 shared=False)
1090 rule2 = self.admin_client.create_dscp_marking_rule(
1091 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
1092
1093 # Test 'list rules'
1094 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
1095 rules = rules['dscp_marking_rules']
1096 rules_ids = [r['id'] for r in rules]
1097 self.assertIn(rule1['id'], rules_ids)
1098 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001099
nfridman23b44ad2019-09-05 09:46:50 -04001100 @decorators.idempotent_id('19ed2286-ccb1-11e9-87d7-525400d6f522')
1101 def test_qos_dscp_create_and_update(self):
1102 """This test covers:
1103
1104 1.Creating a basic QoS policy with DSCP marking rule.
1105 2.Updating QoS policy:
1106 Administrator should have the ability to update existing QoS policy.
1107 This test should verify that:
1108 It's possible to update the existing DSCP marking rule with all of
1109 the valid marks between 0-56, except of the invalid marks:
1110 2-6, 42, 44, and 50-54 (which should be forbidden)
1111 """
1112
1113 def _test_update_dscp_mark_values(self, dscp_policy_id, rule_id):
1114 for mark in range(n_constants.VALID_DSCP_MARKS[1],
1115 self.VALID_DSCP_MARK1 + 1):
1116 if mark in n_constants.VALID_DSCP_MARKS:
1117 self.admin_client.update_dscp_marking_rule(
1118 dscp_policy_id, rule_id, dscp_mark=mark)
1119
1120 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1121 dscp_policy_id, rule_id)['dscp_marking_rule']
1122 self.assertEqual(mark, retrieved_rule['dscp_mark'],
1123 """current DSCP mark is incorrect:
1124 expected value {0} actual value {1}
1125 """.format(mark,
1126 retrieved_rule['dscp_mark']))
1127
1128 else:
1129 self.assertRaises(exceptions.BadRequest,
1130 self.admin_client.create_dscp_marking_rule,
1131 dscp_policy_id,
1132 mark)
1133 # Setup network
1134 self.network = self.create_network()
1135
1136 # Create QoS policy
1137 dscp_policy_id = self.create_qos_policy(
1138 name='test-policy',
1139 description='test-qos-policy',
1140 shared=True)['id']
1141
1142 # Associate QoS to the network
1143 self.admin_client.update_network(
1144 self.network['id'], qos_policy_id=dscp_policy_id)
1145
1146 # Set a new DSCP rule with the first mark in range
1147 rule_id = self.admin_client.create_dscp_marking_rule(
1148 dscp_policy_id,
1149 n_constants.VALID_DSCP_MARKS[0])[
1150 'dscp_marking_rule']['id']
1151
1152 # Validate that the rule was set up properly
1153 retrieved_rule = self.client.show_dscp_marking_rule(
1154 dscp_policy_id, rule_id)['dscp_marking_rule']
1155 self.assertEqual(n_constants.VALID_DSCP_MARKS[0],
1156 retrieved_rule['dscp_mark'],
1157 """current DSCP mark is incorrect:
1158 expected value {0} actual value {1}
1159 """.format(n_constants.VALID_DSCP_MARKS[0],
1160 retrieved_rule['dscp_mark']))
1161
1162 # Try to set marks in range 8:56 (invalid marks should raise an error)
1163 _test_update_dscp_mark_values(self, dscp_policy_id, rule_id)
1164
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001165
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001166class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
1167 DIRECTION_EGRESS = "egress"
1168 DIRECTION_INGRESS = "ingress"
1169 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
1170 RULES_NAME = RULE_NAME + "s"
Chandan Kumarc125fd12017-11-15 19:41:01 +05301171 required_extensions = [qos_apidef.ALIAS]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001172
1173 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001174 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001175 def resource_setup(cls):
1176 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
1177
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001178 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001179 def test_rule_create(self):
1180 policy = self.create_qos_policy(name='test-policy',
1181 description='test policy',
1182 shared=False)
1183 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001184 policy_id=policy['id'],
1185 direction=self.DIRECTION_EGRESS,
1186 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001187
1188 # Test 'show rule'
1189 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
1190 policy['id'], rule['id'])
1191 retrieved_rule = retrieved_rule[self.RULE_NAME]
1192 self.assertEqual(rule['id'], retrieved_rule['id'])
1193 self.assertEqual(1138, retrieved_rule['min_kbps'])
1194 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1195
1196 # Test 'list rules'
1197 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
1198 rules = rules[self.RULES_NAME]
1199 rules_ids = [r['id'] for r in rules]
1200 self.assertIn(rule['id'], rules_ids)
1201
1202 # Test 'show policy'
1203 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1204 policy_rules = retrieved_policy['policy']['rules']
1205 self.assertEqual(1, len(policy_rules))
1206 self.assertEqual(rule['id'], policy_rules[0]['id'])
1207 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1208 policy_rules[0]['type'])
1209
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001210 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001211 def test_rule_create_fail_for_missing_min_kbps(self):
1212 policy = self.create_qos_policy(name='test-policy',
1213 description='test policy',
1214 shared=False)
1215 self.assertRaises(exceptions.BadRequest,
1216 self.admin_client.create_minimum_bandwidth_rule,
1217 policy_id=policy['id'],
1218 direction=self.DIRECTION_EGRESS)
1219
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001220 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001221 def test_rule_create_fail_for_the_same_type(self):
1222 policy = self.create_qos_policy(name='test-policy',
1223 description='test policy',
1224 shared=False)
1225 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001226 policy_id=policy['id'],
1227 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001228
1229 self.assertRaises(exceptions.Conflict,
1230 self.admin_client.create_minimum_bandwidth_rule,
1231 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001232 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001233
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001234 @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936')
1235 @utils.requires_ext(extension="qos-bw-minimum-ingress",
1236 service="network")
1237 def test_rule_create_pass_for_direction_ingress(self):
1238 policy = self.create_qos_policy(name='test-policy',
1239 description='test policy',
1240 shared=False)
1241 self.admin_client.create_minimum_bandwidth_rule(
1242 policy_id=policy['id'],
1243 direction=self.DIRECTION_INGRESS,
1244 min_kbps=201)
1245
1246 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1247 policy_rules = retrieved_policy['policy']['rules']
1248 self.assertEqual(1, len(policy_rules))
1249 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1250 policy_rules[0]['type'])
1251 self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction'])
1252
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001253 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001254 def test_rule_update(self):
1255 policy = self.create_qos_policy(name='test-policy',
1256 description='test policy',
1257 shared=False)
1258 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001259 policy_id=policy['id'],
1260 direction=self.DIRECTION_EGRESS,
1261 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001262
1263 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
1264 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
1265
1266 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1267 policy['id'], rule['id'])
1268 retrieved_policy = retrieved_policy[self.RULE_NAME]
1269 self.assertEqual(350, retrieved_policy['min_kbps'])
1270 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1271
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001272 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001273 def test_rule_delete(self):
1274 policy = self.create_qos_policy(name='test-policy',
1275 description='test policy',
1276 shared=False)
1277 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001278 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001279
1280 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1281 policy['id'], rule['id'])
1282 retrieved_policy = retrieved_policy[self.RULE_NAME]
1283 self.assertEqual(rule['id'], retrieved_policy['id'])
1284
1285 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1286 rule['id'])
1287 self.assertRaises(exceptions.NotFound,
1288 self.admin_client.show_minimum_bandwidth_rule,
1289 policy['id'], rule['id'])
1290
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001291 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001292 def test_rule_create_rule_nonexistent_policy(self):
1293 self.assertRaises(
1294 exceptions.NotFound,
1295 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001296 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001297
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001298 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001299 def test_rule_create_forbidden_for_regular_tenants(self):
1300 self.assertRaises(
1301 exceptions.Forbidden,
1302 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001303 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001304
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001305 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001306 def test_get_rules_by_policy(self):
1307 policy1 = self.create_qos_policy(name='test-policy1',
1308 description='test policy1',
1309 shared=False)
1310 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001311 policy_id=policy1['id'],
1312 direction=self.DIRECTION_EGRESS,
1313 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001314
1315 policy2 = self.create_qos_policy(name='test-policy2',
1316 description='test policy2',
1317 shared=False)
1318 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001319 policy_id=policy2['id'],
1320 direction=self.DIRECTION_EGRESS,
1321 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001322
1323 # Test 'list rules'
1324 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1325 rules = rules[self.RULES_NAME]
1326 rules_ids = [r['id'] for r in rules]
1327 self.assertIn(rule1['id'], rules_ids)
1328 self.assertNotIn(rule2['id'], rules_ids)
1329
1330
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001331class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1332 base.BaseAdminNetworkTest):
1333
1334 resource = 'policy'
1335 plural_name = 'policies'
1336
1337 # Use unique description to isolate the tests from other QoS tests
1338 list_kwargs = {'description': 'search-criteria-test'}
1339 list_as_admin = True
1340
Chandan Kumarc125fd12017-11-15 19:41:01 +05301341 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001342
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001343 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001344 def resource_setup(cls):
1345 super(QosSearchCriteriaTest, cls).resource_setup()
1346 for name in cls.resource_names:
1347 cls.create_qos_policy(
1348 name=name, description='search-criteria-test')
1349
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001350 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001351 def test_list_sorts_asc(self):
1352 self._test_list_sorts_asc()
1353
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001354 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001355 def test_list_sorts_desc(self):
1356 self._test_list_sorts_desc()
1357
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001358 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001359 def test_list_pagination(self):
1360 self._test_list_pagination()
1361
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001362 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001363 def test_list_pagination_with_marker(self):
1364 self._test_list_pagination_with_marker()
1365
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001366 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001367 def test_list_pagination_with_href_links(self):
1368 self._test_list_pagination_with_href_links()
1369
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001370 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001371 def test_list_pagination_page_reverse_asc(self):
1372 self._test_list_pagination_page_reverse_asc()
1373
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001374 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001375 def test_list_pagination_page_reverse_desc(self):
1376 self._test_list_pagination_page_reverse_desc()
1377
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001378 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001379 def test_list_pagination_page_reverse_with_href_links(self):
1380 self._test_list_pagination_page_reverse_with_href_links()
1381
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001382 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001383 def test_list_no_pagination_limit_0(self):
1384 self._test_list_no_pagination_limit_0()