blob: 0fc7b15ba34a6fd1729d94098494035f3c566582 [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
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000085 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000086 def test_policy_update(self):
87 policy = self.create_qos_policy(name='test-policy',
88 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +000089 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +000090 project_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000091 self.admin_client.update_qos_policy(policy['id'],
92 description='test policy desc2',
93 shared=True)
94
95 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
96 retrieved_policy = retrieved_policy['policy']
97 self.assertEqual('test policy desc2', retrieved_policy['description'])
98 self.assertTrue(retrieved_policy['shared'])
99 self.assertEqual([], retrieved_policy['rules'])
100
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000101 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000102 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
103 policy = self.create_qos_policy(name='test-policy',
104 description='',
105 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000106 project_id=self.client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000107 self.assertRaises(
108 exceptions.Forbidden,
109 self.client.update_qos_policy,
110 policy['id'], description='test policy')
111
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000112 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000113 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
114 policy = self.create_qos_policy(name='test-policy',
115 description='',
116 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000117 project_id=self.admin_client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000118 self.assertRaises(
119 exceptions.NotFound,
120 self.client.update_qos_policy,
121 policy['id'], description='test policy')
122
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000123 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000124 def test_shared_policy_update(self):
125 policy = self.create_qos_policy(name='test-policy',
126 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000127 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000128 project_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000129
130 self.admin_client.update_qos_policy(policy['id'],
131 description='test policy desc2')
132 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
133 retrieved_policy = retrieved_policy['policy']
134 self.assertTrue(retrieved_policy['shared'])
135
136 self.admin_client.update_qos_policy(policy['id'],
137 shared=False)
138 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
139 retrieved_policy = retrieved_policy['policy']
140 self.assertFalse(retrieved_policy['shared'])
141
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000142 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000143 def test_delete_policy(self):
144 policy = self.admin_client.create_qos_policy(
145 'test-policy', 'desc', True)['policy']
146
147 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
148 retrieved_policy = retrieved_policy['policy']
149 self.assertEqual('test-policy', retrieved_policy['name'])
150
151 self.admin_client.delete_qos_policy(policy['id'])
152 self.assertRaises(exceptions.NotFound,
153 self.admin_client.show_qos_policy, policy['id'])
154
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000155 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000156 def test_list_admin_rule_types(self):
157 self._test_list_rule_types(self.admin_client)
158
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000159 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000160 def test_list_regular_rule_types(self):
161 self._test_list_rule_types(self.client)
162
163 def _test_list_rule_types(self, client):
164 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000165 # Since returned rule types depends on loaded backend drivers this test
166 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000167 #
168 # In theory, we could make the test conditional on which ml2 drivers
169 # are enabled in gate (or more specifically, on which supported qos
170 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200171 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000172 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000173
174 rule_types = client.list_qos_rule_types()
175 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000176
177 # Verify that only required fields present in rule details
178 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000179 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000180
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000181 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
182 def test_show_rule_type_details_as_user(self):
183 self.assertRaises(
184 exceptions.Forbidden,
185 self.client.show_qos_rule_type,
186 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
187
188 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
189 def test_show_rule_type_details_as_admin(self):
190 # Since returned rule types depend on loaded backend drivers this test
191 # is checking only if returned keys are same as expected keys
192
193 # In theory, we could make the test conditional on which ml2 drivers
194 # are enabled in gate, but that option doesn't seem to be
195 # available through tempest.lib framework
196 expected_rule_type_details_keys = ['type', 'drivers']
197
198 rule_type_details = self.admin_client.show_qos_rule_type(
199 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
200
201 # Verify that only required fields present in rule details
202 self.assertEqual(
203 sorted(tuple(expected_rule_type_details_keys)),
204 sorted(tuple(rule_type_details.keys())))
205
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000206 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000207 def test_policy_association_with_admin_network(self):
208 policy = self.create_qos_policy(name='test-policy',
209 description='test policy',
210 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200211 network = self.create_network('test network', shared=True,
212 qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000213
214 retrieved_network = self.admin_client.show_network(network['id'])
215 self.assertEqual(
216 policy['id'], retrieved_network['network']['qos_policy_id'])
217
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000218 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000219 def test_policy_association_with_tenant_network(self):
220 policy = self.create_qos_policy(name='test-policy',
221 description='test policy',
222 shared=True)
223 network = self.create_network('test network',
224 qos_policy_id=policy['id'])
225
226 retrieved_network = self.admin_client.show_network(network['id'])
227 self.assertEqual(
228 policy['id'], retrieved_network['network']['qos_policy_id'])
229
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000230 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000231 def test_policy_association_with_network_nonexistent_policy(self):
232 self.assertRaises(
233 exceptions.NotFound,
234 self.create_network,
235 'test network',
236 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
237
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000238 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000239 def test_policy_association_with_network_non_shared_policy(self):
240 policy = self.create_qos_policy(name='test-policy',
241 description='test policy',
242 shared=False)
243 self.assertRaises(
244 exceptions.NotFound,
245 self.create_network,
246 'test network', qos_policy_id=policy['id'])
247
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000248 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000249 def test_policy_update_association_with_admin_network(self):
250 policy = self.create_qos_policy(name='test-policy',
251 description='test policy',
252 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200253 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000254 retrieved_network = self.admin_client.show_network(network['id'])
255 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
256
257 self.admin_client.update_network(network['id'],
258 qos_policy_id=policy['id'])
259 retrieved_network = self.admin_client.show_network(network['id'])
260 self.assertEqual(
261 policy['id'], retrieved_network['network']['qos_policy_id'])
262
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000263 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000264 def test_policy_association_with_port_shared_policy(self):
265 policy = self.create_qos_policy(name='test-policy',
266 description='test policy',
267 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200268 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000269 port = self.create_port(network, qos_policy_id=policy['id'])
270
271 retrieved_port = self.admin_client.show_port(port['id'])
272 self.assertEqual(
273 policy['id'], retrieved_port['port']['qos_policy_id'])
274
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000275 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000276 def test_policy_association_with_port_nonexistent_policy(self):
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200277 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000278 self.assertRaises(
279 exceptions.NotFound,
280 self.create_port,
281 network,
282 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
283
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000284 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000285 def test_policy_association_with_port_non_shared_policy(self):
286 policy = self.create_qos_policy(name='test-policy',
287 description='test policy',
288 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200289 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000290 self.assertRaises(
291 exceptions.NotFound,
292 self.create_port,
293 network, qos_policy_id=policy['id'])
294
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000295 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000296 def test_policy_update_association_with_port_shared_policy(self):
297 policy = self.create_qos_policy(name='test-policy',
298 description='test policy',
299 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200300 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000301 port = self.create_port(network)
302 retrieved_port = self.admin_client.show_port(port['id'])
303 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
304
305 self.client.update_port(port['id'], qos_policy_id=policy['id'])
306 retrieved_port = self.admin_client.show_port(port['id'])
307 self.assertEqual(
308 policy['id'], retrieved_port['port']['qos_policy_id'])
309
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000310 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000311 def test_delete_not_allowed_if_policy_in_use_by_network(self):
312 policy = self.create_qos_policy(name='test-policy',
313 description='test policy',
314 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200315 self.create_network('test network', qos_policy_id=policy['id'],
316 shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000317 self.assertRaises(
318 exceptions.Conflict,
319 self.admin_client.delete_qos_policy, policy['id'])
320
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000321 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000322 def test_delete_not_allowed_if_policy_in_use_by_port(self):
323 policy = self.create_qos_policy(name='test-policy',
324 description='test policy',
325 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200326 network = self.create_network('test network', shared=True)
Sławek Kapłońskie100c4d2017-08-23 21:18:34 +0000327 self.create_port(network, qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000328 self.assertRaises(
329 exceptions.Conflict,
330 self.admin_client.delete_qos_policy, policy['id'])
331
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000332 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000333 def test_qos_policy_delete_with_rules(self):
334 policy = self.create_qos_policy(name='test-policy',
335 description='test policy',
336 shared=False)
337 self.admin_client.create_bandwidth_limit_rule(
338 policy['id'], 200, 1337)['bandwidth_limit_rule']
339
340 self.admin_client.delete_qos_policy(policy['id'])
341
342 with testtools.ExpectedException(exceptions.NotFound):
343 self.admin_client.show_qos_policy(policy['id'])
344
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000345 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000346 def test_get_policy_that_is_shared(self):
347 policy = self.create_qos_policy(
348 name='test-policy-shared',
349 description='shared policy',
350 shared=True,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000351 project_id=self.admin_client.tenant_id)
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000352 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
353 self.assertEqual(obtained_policy, policy)
354
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000355 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100356 def test_policy_create_forbidden_for_regular_tenants(self):
357 self.assertRaises(
358 exceptions.Forbidden,
359 self.client.create_qos_policy,
360 'test-policy', 'test policy', False)
361
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900362 @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
363 def test_default_policy_creating_network_without_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530364 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900365 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000366 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900367 is_default=True)
368 network = self.create_network('test network', client=self.admin_client,
369 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900370 retrieved_network = self.admin_client.show_network(network['id'])
371 self.assertEqual(
372 policy['id'], retrieved_network['network']['qos_policy_id'])
373
374 @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
375 def test_default_policy_creating_network_with_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530376 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900377 self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000378 project_id=project_id,
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900379 is_default=True)
380 policy = self.create_qos_policy(name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000381 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900382 network = self.create_network('test network', client=self.admin_client,
383 project_id=project_id,
384 qos_policy_id=policy['id'])
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900385 retrieved_network = self.admin_client.show_network(network['id'])
386 self.assertEqual(
387 policy['id'], retrieved_network['network']['qos_policy_id'])
388
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100389 @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229')
390 def test_user_create_port_with_admin_qos_policy(self):
391 qos_policy = self.create_qos_policy(
392 name='test-policy',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000393 project_id=self.admin_client.tenant_id,
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100394 shared=False)
395 network = self.create_network(
396 'test network', client=self.admin_client,
397 project_id=self.client.tenant_id,
398 qos_policy_id=qos_policy['id'])
399 port = self.create_port(network)
400 self.assertEqual(network['id'], port['network_id'])
401
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000402
403class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000404
405 direction = None
Chandan Kumarc125fd12017-11-15 19:41:01 +0530406 required_extensions = [qos_apidef.ALIAS]
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000407
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000408 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900409 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000410 def resource_setup(cls):
411 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
412
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000413 @property
414 def opposite_direction(self):
415 if self.direction == "ingress":
416 return "egress"
417 elif self.direction == "egress":
418 return "ingress"
419 else:
420 return None
421
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000422 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000423 def test_rule_create(self):
424 policy = self.create_qos_policy(name='test-policy',
425 description='test policy',
426 shared=False)
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000427 rule = self.create_qos_bandwidth_limit_rule(
428 policy_id=policy['id'],
429 max_kbps=200,
430 max_burst_kbps=1337,
431 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000432
433 # Test 'show rule'
434 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
435 policy['id'], rule['id'])
436 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
437 self.assertEqual(rule['id'], retrieved_rule['id'])
438 self.assertEqual(200, retrieved_rule['max_kbps'])
439 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000440 if self.direction:
441 self.assertEqual(self.direction, retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000442
443 # Test 'list rules'
444 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
445 rules = rules['bandwidth_limit_rules']
446 rules_ids = [r['id'] for r in rules]
447 self.assertIn(rule['id'], rules_ids)
448
449 # Test 'show policy'
450 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
451 policy_rules = retrieved_policy['policy']['rules']
452 self.assertEqual(1, len(policy_rules))
453 self.assertEqual(rule['id'], policy_rules[0]['id'])
454 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
455 policy_rules[0]['type'])
456
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000457 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000458 def test_rule_create_fail_for_the_same_type(self):
459 policy = self.create_qos_policy(name='test-policy',
460 description='test policy',
461 shared=False)
462 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
463 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000464 max_burst_kbps=1337,
465 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000466
467 self.assertRaises(exceptions.Conflict,
468 self.create_qos_bandwidth_limit_rule,
469 policy_id=policy['id'],
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000470 max_kbps=201, max_burst_kbps=1338,
471 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000472
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000473 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000474 def test_rule_update(self):
475 policy = self.create_qos_policy(name='test-policy',
476 description='test policy',
477 shared=False)
478 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
479 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000480 max_burst_kbps=1,
481 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000482
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000483 self.admin_client.update_bandwidth_limit_rule(
484 policy['id'],
485 rule['id'],
486 max_kbps=200,
487 max_burst_kbps=1337,
488 direction=self.opposite_direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000489
490 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
491 policy['id'], rule['id'])
492 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
493 self.assertEqual(200, retrieved_policy['max_kbps'])
494 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000495 if self.opposite_direction:
496 self.assertEqual(self.opposite_direction,
497 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000498
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000499 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000500 def test_rule_delete(self):
501 policy = self.create_qos_policy(name='test-policy',
502 description='test policy',
503 shared=False)
504 rule = self.admin_client.create_bandwidth_limit_rule(
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000505 policy['id'], 200, 1337, self.direction)['bandwidth_limit_rule']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000506
507 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
508 policy['id'], rule['id'])
509 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
510 self.assertEqual(rule['id'], retrieved_policy['id'])
511
512 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
513 self.assertRaises(exceptions.NotFound,
514 self.admin_client.show_bandwidth_limit_rule,
515 policy['id'], rule['id'])
516
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000517 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000518 def test_rule_create_rule_nonexistent_policy(self):
519 self.assertRaises(
520 exceptions.NotFound,
521 self.create_qos_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000522 'policy', 200, 1337, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000523
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000524 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000525 def test_rule_create_forbidden_for_regular_tenants(self):
526 self.assertRaises(
527 exceptions.Forbidden,
528 self.client.create_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000529 'policy', 1, 2, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000530
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000531 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000532 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
533 policy = self.create_qos_policy(name='test-policy',
534 description='test policy',
535 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000536 project_id=self.client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000537 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
538 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000539 max_burst_kbps=1,
540 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000541 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400542 exceptions.Forbidden,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000543 self.client.update_bandwidth_limit_rule,
544 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
545
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000546 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000547 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
548 policy = self.create_qos_policy(name='test-policy',
549 description='test policy',
550 shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000551 project_id=self.admin_client.tenant_id)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000552 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
553 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000554 max_burst_kbps=1,
555 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000556 self.assertRaises(
557 exceptions.NotFound,
558 self.client.update_bandwidth_limit_rule,
559 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
560
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000561 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000562 def test_get_rules_by_policy(self):
563 policy1 = self.create_qos_policy(name='test-policy1',
564 description='test policy1',
565 shared=False)
566 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
567 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000568 max_burst_kbps=1337,
569 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000570
571 policy2 = self.create_qos_policy(name='test-policy2',
572 description='test policy2',
573 shared=False)
574 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
575 max_kbps=5000,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000576 max_burst_kbps=2523,
577 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000578
579 # Test 'list rules'
580 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
581 rules = rules['bandwidth_limit_rules']
582 rules_ids = [r['id'] for r in rules]
583 self.assertIn(rule1['id'], rules_ids)
584 self.assertNotIn(rule2['id'], rules_ids)
585
nfridman07f0e782019-11-04 09:12:58 -0500586 @testtools.skipUnless(
587 CONF.neutron_plugin_options.create_shared_resources,
588 """Creation of shared resources should be allowed,
589 setting the create_shared_resources option as 'True' is needed""")
590 @decorators.idempotent_id('d911707e-fa2c-11e9-9553-5076af30bbf5')
591 def test_attach_and_detach_a_policy_by_a_tenant(self):
592 # As an admin create an non shared QoS policy,add a rule
593 # and associate it with a network
594 self.network = self.create_network()
595 policy = self.create_qos_policy(name='test-policy',
596 description='test policy for attach',
597 shared=False)
598
599 self.admin_client.create_bandwidth_limit_rule(
600 policy['id'], 1024, 1024)
601
602 self.admin_client.update_network(
603 self.network['id'], qos_policy_id=policy['id'])
604
605 # As a tenant, try to detach the policy from the network
606 # The operation should be forbidden
607 self.assertRaises(
608 exceptions.Forbidden,
609 self.client.update_network,
610 self.network['id'], qos_policy_id=None)
611
612 # As an admin, make the policy shared
613 self.admin_client.update_qos_policy(policy['id'], shared=True)
614
615 # As a tenant, try to detach the policy from the network
616 # The operation should be allowed
617 self.client.update_network(self.network['id'],
618 qos_policy_id=None)
619
620 retrieved_network = self.admin_client.show_network(self.network['id'])
621 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
622
623 # As a tenant, try to delete the policy from the network
624 # should be forbidden
625 self.assertRaises(
626 exceptions.Forbidden,
627 self.client.delete_qos_policy,
628 policy['id'])
629
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000630
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000631class QosBandwidthLimitRuleWithDirectionTestJSON(
Brian Haley6767cec2018-04-10 15:30:23 -0400632 QosBandwidthLimitRuleTestJSON):
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000633 required_extensions = (
634 QosBandwidthLimitRuleTestJSON.required_extensions +
635 ['qos-bw-limit-direction']
636 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000637 scenarios = [
638 ('ingress', {'direction': 'ingress'}),
639 ('egress', {'direction': 'egress'}),
640 ]
641
nfridman7717d9c2019-11-25 08:58:04 -0500642 @classmethod
643 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
644 def resource_setup(cls):
645 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
646
647 @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667')
648 def test_create_policy_with_multiple_rules(self):
649 # Create a policy with multiple rules
650 policy = self.create_qos_policy(name='test-policy1',
651 description='test policy1',
652 shared=False)
653
654 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
655 max_kbps=1024,
656 max_burst_kbps=1024,
nfridman07f0e782019-11-04 09:12:58 -0500657 direction=n_constants.
658 EGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500659 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
660 max_kbps=1024,
661 max_burst_kbps=1024,
nfridman07f0e782019-11-04 09:12:58 -0500662 direction=n_constants.
663 INGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500664 # Check that the rules were added to the policy
665 rules = self.admin_client.list_bandwidth_limit_rules(
666 policy['id'])['bandwidth_limit_rules']
667 rules_ids = [rule['id'] for rule in rules]
668 self.assertIn(rule1['id'], rules_ids)
669 self.assertIn(rule2['id'], rules_ids)
670
671 # Check that the rules creation fails for the same rule types
672 self.assertRaises(exceptions.Conflict,
673 self.create_qos_bandwidth_limit_rule,
674 policy_id=policy['id'],
675 max_kbps=1025,
676 max_burst_kbps=1025,
nfridman07f0e782019-11-04 09:12:58 -0500677 direction=n_constants.EGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500678
679 self.assertRaises(exceptions.Conflict,
680 self.create_qos_bandwidth_limit_rule,
681 policy_id=policy['id'],
682 max_kbps=1025,
683 max_burst_kbps=1025,
nfridman07f0e782019-11-04 09:12:58 -0500684 direction=n_constants.INGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500685
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000686
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000687class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
688
689 force_tenant_isolation = True
690 credentials = ['primary', 'alt', 'admin']
Chandan Kumarc125fd12017-11-15 19:41:01 +0530691 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000692
693 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000694 def resource_setup(cls):
695 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530696 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000697
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000698 def _create_qos_policy(self, project_id=None):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000699 args = {'name': data_utils.rand_name('test-policy'),
700 'description': 'test policy',
701 'shared': False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000702 'project_id': project_id}
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000703 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
704 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
705
706 return qos_policy
707
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000708 def _make_admin_policy_shared_to_project_id(self, project_id):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000709 policy = self._create_qos_policy()
710 rbac_policy = self.admin_client.create_rbac_policy(
711 object_type='qos_policy',
712 object_id=policy['id'],
713 action='access_as_shared',
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000714 target_tenant=project_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000715 )['rbac_policy']
716
717 return {'policy': policy, 'rbac_policy': rbac_policy}
718
719 def _create_network(self, qos_policy_id, client, should_cleanup=True):
720 net = client.create_network(
721 name=data_utils.rand_name('test-network'),
722 qos_policy_id=qos_policy_id)['network']
723 if should_cleanup:
724 self.addCleanup(client.delete_network, net['id'])
725
726 return net
727
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000728 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000729 def test_policy_sharing_with_wildcard(self):
730 qos_pol = self.create_qos_policy(
731 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000732 description='test-shared-policy', shared=False,
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000733 project_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000734 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
735
736 # test update shared False -> True
737 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
738 qos_pol['shared'] = True
739 self.client2.show_qos_policy(qos_pol['id'])
740 rbac_pol = {'target_tenant': '*',
741 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000742 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000743 'object_type': 'qos_policy',
744 'object_id': qos_pol['id'],
745 'action': 'access_as_shared'}
746
747 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
748 rbac_policies = [r for r in rbac_policies if r.pop('id')]
749 self.assertIn(rbac_pol, rbac_policies)
750
751 # update shared True -> False should fail because the policy is bound
752 # to a network
753 net = self._create_network(qos_pol['id'], self.admin_client, False)
754 with testtools.ExpectedException(exceptions.Conflict):
755 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
756
757 # delete the network, and update shared True -> False should pass now
758 self.admin_client.delete_network(net['id'])
759 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
760 qos_pol['shared'] = False
761 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
762
763 def _create_net_bound_qos_rbacs(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000764 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000765 self.client.tenant_id)
766 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
767
768 # add a wildcard rbac rule - now the policy globally shared
769 rbac_wildcard = self.admin_client.create_rbac_policy(
770 object_type='qos_policy',
771 object_id=qos_policy['id'],
772 action='access_as_shared',
773 target_tenant='*',
774 )['rbac_policy']
775
776 # tenant1 now uses qos policy for net
777 self._create_network(qos_policy['id'], self.client)
778
779 return rbac_for_client_tenant, rbac_wildcard
780
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000781 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000782 def test_net_bound_shared_policy_wildcard_and_project_id_wild_remove(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000783 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
784 # globally unshare the qos-policy, the specific share should remain
785 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
786 self.client.list_rbac_policies(id=client_rbac['id'])
787
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000788 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000789 def test_net_bound_shared_policy_wildcard_and_projectid_wild_remains(self):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000790 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
791 # remove client_rbac policy the wildcard share should remain
792 self.admin_client.delete_rbac_policy(client_rbac['id'])
793 self.client.list_rbac_policies(id=wildcard_rbac['id'])
794
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000795 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000796 def test_policy_sharing_with_wildcard_and_project_id(self):
797 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000798 self.client.tenant_id)
799 qos_policy, rbac = res['policy'], res['rbac_policy']
800 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
801 self.assertTrue(qos_pol['shared'])
802 with testtools.ExpectedException(exceptions.NotFound):
803 self.client2.show_qos_policy(qos_policy['id'])
804
805 # make the qos-policy globally shared
806 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
807 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
808 self.assertTrue(qos_pol['shared'])
809
810 # globally unshare the qos-policy, the specific share should remain
811 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
812 self.client.show_qos_policy(qos_policy['id'])
813 with testtools.ExpectedException(exceptions.NotFound):
814 self.client2.show_qos_policy(qos_policy['id'])
815 self.assertIn(rbac,
816 self.admin_client.list_rbac_policies()['rbac_policies'])
817
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000818 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000819 def test_policy_target_update(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000820 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000821 self.client.tenant_id)
822 # change to client2
823 update_res = self.admin_client.update_rbac_policy(
824 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
825 self.assertEqual(self.client2.tenant_id,
826 update_res['rbac_policy']['target_tenant'])
827 # make sure everything else stayed the same
828 res['rbac_policy'].pop('target_tenant')
829 update_res['rbac_policy'].pop('target_tenant')
830 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
831
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000832 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000833 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000834 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000835 self.client2.tenant_id)
836 qos_policy_id = res['policy']['id']
837 self._create_network(qos_policy_id, self.client2)
838 # a network with shared qos-policy should prevent the deletion of an
839 # rbac-policy required for it to be shared
840 with testtools.ExpectedException(exceptions.Conflict):
841 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
842
843 # a wildcard policy should allow the specific policy to be deleted
844 # since it allows the remaining port
845 wild = self.admin_client.create_rbac_policy(
846 object_type='qos_policy', object_id=res['policy']['id'],
847 action='access_as_shared', target_tenant='*')['rbac_policy']
848 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
849
850 # now that wildcard is the only remaining, it should be subjected to
851 # the same restriction
852 with testtools.ExpectedException(exceptions.Conflict):
853 self.admin_client.delete_rbac_policy(wild['id'])
854
855 # we can't update the policy to a different tenant
856 with testtools.ExpectedException(exceptions.Conflict):
857 self.admin_client.update_rbac_policy(
858 wild['id'], target_tenant=self.client2.tenant_id)
859
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000860 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000861 def test_regular_client_shares_to_another_regular_client(self):
862 # owned by self.admin_client
863 policy = self._create_qos_policy()
864 with testtools.ExpectedException(exceptions.NotFound):
865 self.client.show_qos_policy(policy['id'])
866 rbac_policy = self.admin_client.create_rbac_policy(
867 object_type='qos_policy', object_id=policy['id'],
868 action='access_as_shared',
869 target_tenant=self.client.tenant_id)['rbac_policy']
870 self.client.show_qos_policy(policy['id'])
871
872 self.assertIn(rbac_policy,
873 self.admin_client.list_rbac_policies()['rbac_policies'])
874 # ensure that 'client2' can't see the rbac-policy sharing the
875 # qos-policy to it because the rbac-policy belongs to 'client'
876 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
877 self.client2.list_rbac_policies()['rbac_policies']])
878
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000879 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000880 def test_filter_fields(self):
881 policy = self._create_qos_policy()
882 self.admin_client.create_rbac_policy(
883 object_type='qos_policy', object_id=policy['id'],
884 action='access_as_shared', target_tenant=self.client2.tenant_id)
885 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000886 ('project_id', 'target_tenant'))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000887 for fields in field_args:
888 res = self.admin_client.list_rbac_policies(fields=fields)
889 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
890
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000891 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000892 def test_rbac_policy_show(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000893 res = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000894 self.client.tenant_id)
895 p1 = res['rbac_policy']
896 p2 = self.admin_client.create_rbac_policy(
897 object_type='qos_policy', object_id=res['policy']['id'],
898 action='access_as_shared',
899 target_tenant='*')['rbac_policy']
900
901 self.assertEqual(
902 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
903 self.assertEqual(
904 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
905
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000906 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000907 def test_filter_rbac_policies(self):
908 policy = self._create_qos_policy()
909 rbac_pol1 = self.admin_client.create_rbac_policy(
910 object_type='qos_policy', object_id=policy['id'],
911 action='access_as_shared',
912 target_tenant=self.client2.tenant_id)['rbac_policy']
913 rbac_pol2 = self.admin_client.create_rbac_policy(
914 object_type='qos_policy', object_id=policy['id'],
915 action='access_as_shared',
916 target_tenant=self.admin_client.tenant_id)['rbac_policy']
917 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
918 'rbac_policies']
919 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
920 'rbac_policies']
921 self.assertEqual(1, len(res1))
922 self.assertEqual(1, len(res2))
923 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
924 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
925
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000926 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000927 def test_regular_client_blocked_from_sharing_anothers_policy(self):
Rodolfo Alonso Hernandeze2d062f2020-01-14 17:11:42 +0000928 qos_policy = self._make_admin_policy_shared_to_project_id(
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000929 self.client.tenant_id)['policy']
930 with testtools.ExpectedException(exceptions.BadRequest):
931 self.client.create_rbac_policy(
932 object_type='qos_policy', object_id=qos_policy['id'],
933 action='access_as_shared',
934 target_tenant=self.client2.tenant_id)
935
936 # make sure the rbac-policy is invisible to the tenant for which it's
937 # being shared
938 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
939
940
941class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
942 VALID_DSCP_MARK1 = 56
943 VALID_DSCP_MARK2 = 48
944
Chandan Kumarc125fd12017-11-15 19:41:01 +0530945 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000946
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000947 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900948 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000949 def resource_setup(cls):
950 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
951
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000952 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000953 def test_rule_create(self):
954 policy = self.create_qos_policy(name='test-policy',
955 description='test policy',
956 shared=False)
957 rule = self.admin_client.create_dscp_marking_rule(
958 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
959
960 # Test 'show rule'
961 retrieved_rule = self.admin_client.show_dscp_marking_rule(
962 policy['id'], rule['id'])
963 retrieved_rule = retrieved_rule['dscp_marking_rule']
964 self.assertEqual(rule['id'], retrieved_rule['id'])
965 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
966
967 # Test 'list rules'
968 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
969 rules = rules['dscp_marking_rules']
970 rules_ids = [r['id'] for r in rules]
971 self.assertIn(rule['id'], rules_ids)
972
973 # Test 'show policy'
974 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
975 policy_rules = retrieved_policy['policy']['rules']
976 self.assertEqual(1, len(policy_rules))
977 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000978 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000979 policy_rules[0]['type'])
980
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000981 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000982 def test_rule_create_fail_for_the_same_type(self):
983 policy = self.create_qos_policy(name='test-policy',
984 description='test policy',
985 shared=False)
986 self.admin_client.create_dscp_marking_rule(
987 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
988
989 self.assertRaises(exceptions.Conflict,
990 self.admin_client.create_dscp_marking_rule,
991 policy_id=policy['id'],
992 dscp_mark=self.VALID_DSCP_MARK2)
993
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000994 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000995 def test_rule_update(self):
996 policy = self.create_qos_policy(name='test-policy',
997 description='test policy',
998 shared=False)
999 rule = self.admin_client.create_dscp_marking_rule(
1000 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1001
1002 self.admin_client.update_dscp_marking_rule(
1003 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
1004
1005 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1006 policy['id'], rule['id'])
1007 retrieved_policy = retrieved_policy['dscp_marking_rule']
1008 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
1009
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001010 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001011 def test_rule_delete(self):
1012 policy = self.create_qos_policy(name='test-policy',
1013 description='test policy',
1014 shared=False)
1015 rule = self.admin_client.create_dscp_marking_rule(
1016 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1017
1018 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1019 policy['id'], rule['id'])
1020 retrieved_policy = retrieved_policy['dscp_marking_rule']
1021 self.assertEqual(rule['id'], retrieved_policy['id'])
1022
1023 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
1024 self.assertRaises(exceptions.NotFound,
1025 self.admin_client.show_dscp_marking_rule,
1026 policy['id'], rule['id'])
1027
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001028 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001029 def test_rule_create_rule_nonexistent_policy(self):
1030 self.assertRaises(
1031 exceptions.NotFound,
1032 self.admin_client.create_dscp_marking_rule,
1033 'policy', self.VALID_DSCP_MARK1)
1034
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001035 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001036 def test_rule_create_forbidden_for_regular_tenants(self):
1037 self.assertRaises(
1038 exceptions.Forbidden,
1039 self.client.create_dscp_marking_rule,
1040 'policy', self.VALID_DSCP_MARK1)
1041
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001042 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001043 def test_invalid_rule_create(self):
1044 policy = self.create_qos_policy(name='test-policy',
1045 description='test policy',
1046 shared=False)
1047 self.assertRaises(
1048 exceptions.BadRequest,
1049 self.admin_client.create_dscp_marking_rule,
1050 policy['id'], 58)
1051
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001052 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001053 def test_get_rules_by_policy(self):
1054 policy1 = self.create_qos_policy(name='test-policy1',
1055 description='test policy1',
1056 shared=False)
1057 rule1 = self.admin_client.create_dscp_marking_rule(
1058 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1059
1060 policy2 = self.create_qos_policy(name='test-policy2',
1061 description='test policy2',
1062 shared=False)
1063 rule2 = self.admin_client.create_dscp_marking_rule(
1064 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
1065
1066 # Test 'list rules'
1067 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
1068 rules = rules['dscp_marking_rules']
1069 rules_ids = [r['id'] for r in rules]
1070 self.assertIn(rule1['id'], rules_ids)
1071 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001072
nfridman23b44ad2019-09-05 09:46:50 -04001073 @decorators.idempotent_id('19ed2286-ccb1-11e9-87d7-525400d6f522')
1074 def test_qos_dscp_create_and_update(self):
1075 """This test covers:
1076
1077 1.Creating a basic QoS policy with DSCP marking rule.
1078 2.Updating QoS policy:
1079 Administrator should have the ability to update existing QoS policy.
1080 This test should verify that:
1081 It's possible to update the existing DSCP marking rule with all of
1082 the valid marks between 0-56, except of the invalid marks:
1083 2-6, 42, 44, and 50-54 (which should be forbidden)
1084 """
1085
1086 def _test_update_dscp_mark_values(self, dscp_policy_id, rule_id):
1087 for mark in range(n_constants.VALID_DSCP_MARKS[1],
1088 self.VALID_DSCP_MARK1 + 1):
1089 if mark in n_constants.VALID_DSCP_MARKS:
1090 self.admin_client.update_dscp_marking_rule(
1091 dscp_policy_id, rule_id, dscp_mark=mark)
1092
1093 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1094 dscp_policy_id, rule_id)['dscp_marking_rule']
1095 self.assertEqual(mark, retrieved_rule['dscp_mark'],
1096 """current DSCP mark is incorrect:
1097 expected value {0} actual value {1}
1098 """.format(mark,
1099 retrieved_rule['dscp_mark']))
1100
1101 else:
1102 self.assertRaises(exceptions.BadRequest,
1103 self.admin_client.create_dscp_marking_rule,
1104 dscp_policy_id,
1105 mark)
1106 # Setup network
1107 self.network = self.create_network()
1108
1109 # Create QoS policy
1110 dscp_policy_id = self.create_qos_policy(
1111 name='test-policy',
1112 description='test-qos-policy',
1113 shared=True)['id']
1114
1115 # Associate QoS to the network
1116 self.admin_client.update_network(
1117 self.network['id'], qos_policy_id=dscp_policy_id)
1118
1119 # Set a new DSCP rule with the first mark in range
1120 rule_id = self.admin_client.create_dscp_marking_rule(
1121 dscp_policy_id,
1122 n_constants.VALID_DSCP_MARKS[0])[
1123 'dscp_marking_rule']['id']
1124
1125 # Validate that the rule was set up properly
1126 retrieved_rule = self.client.show_dscp_marking_rule(
1127 dscp_policy_id, rule_id)['dscp_marking_rule']
1128 self.assertEqual(n_constants.VALID_DSCP_MARKS[0],
1129 retrieved_rule['dscp_mark'],
1130 """current DSCP mark is incorrect:
1131 expected value {0} actual value {1}
1132 """.format(n_constants.VALID_DSCP_MARKS[0],
1133 retrieved_rule['dscp_mark']))
1134
1135 # Try to set marks in range 8:56 (invalid marks should raise an error)
1136 _test_update_dscp_mark_values(self, dscp_policy_id, rule_id)
1137
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001138
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001139class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
1140 DIRECTION_EGRESS = "egress"
1141 DIRECTION_INGRESS = "ingress"
1142 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
1143 RULES_NAME = RULE_NAME + "s"
Chandan Kumarc125fd12017-11-15 19:41:01 +05301144 required_extensions = [qos_apidef.ALIAS]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001145
1146 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001147 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001148 def resource_setup(cls):
1149 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
1150
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001151 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001152 def test_rule_create(self):
1153 policy = self.create_qos_policy(name='test-policy',
1154 description='test policy',
1155 shared=False)
1156 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001157 policy_id=policy['id'],
1158 direction=self.DIRECTION_EGRESS,
1159 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001160
1161 # Test 'show rule'
1162 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
1163 policy['id'], rule['id'])
1164 retrieved_rule = retrieved_rule[self.RULE_NAME]
1165 self.assertEqual(rule['id'], retrieved_rule['id'])
1166 self.assertEqual(1138, retrieved_rule['min_kbps'])
1167 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1168
1169 # Test 'list rules'
1170 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
1171 rules = rules[self.RULES_NAME]
1172 rules_ids = [r['id'] for r in rules]
1173 self.assertIn(rule['id'], rules_ids)
1174
1175 # Test 'show policy'
1176 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1177 policy_rules = retrieved_policy['policy']['rules']
1178 self.assertEqual(1, len(policy_rules))
1179 self.assertEqual(rule['id'], policy_rules[0]['id'])
1180 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1181 policy_rules[0]['type'])
1182
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001183 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001184 def test_rule_create_fail_for_missing_min_kbps(self):
1185 policy = self.create_qos_policy(name='test-policy',
1186 description='test policy',
1187 shared=False)
1188 self.assertRaises(exceptions.BadRequest,
1189 self.admin_client.create_minimum_bandwidth_rule,
1190 policy_id=policy['id'],
1191 direction=self.DIRECTION_EGRESS)
1192
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001193 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001194 def test_rule_create_fail_for_the_same_type(self):
1195 policy = self.create_qos_policy(name='test-policy',
1196 description='test policy',
1197 shared=False)
1198 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001199 policy_id=policy['id'],
1200 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001201
1202 self.assertRaises(exceptions.Conflict,
1203 self.admin_client.create_minimum_bandwidth_rule,
1204 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001205 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001206
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001207 @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936')
1208 @utils.requires_ext(extension="qos-bw-minimum-ingress",
1209 service="network")
1210 def test_rule_create_pass_for_direction_ingress(self):
1211 policy = self.create_qos_policy(name='test-policy',
1212 description='test policy',
1213 shared=False)
1214 self.admin_client.create_minimum_bandwidth_rule(
1215 policy_id=policy['id'],
1216 direction=self.DIRECTION_INGRESS,
1217 min_kbps=201)
1218
1219 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1220 policy_rules = retrieved_policy['policy']['rules']
1221 self.assertEqual(1, len(policy_rules))
1222 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1223 policy_rules[0]['type'])
1224 self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction'])
1225
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001226 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001227 def test_rule_update(self):
1228 policy = self.create_qos_policy(name='test-policy',
1229 description='test policy',
1230 shared=False)
1231 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001232 policy_id=policy['id'],
1233 direction=self.DIRECTION_EGRESS,
1234 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001235
1236 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
1237 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
1238
1239 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1240 policy['id'], rule['id'])
1241 retrieved_policy = retrieved_policy[self.RULE_NAME]
1242 self.assertEqual(350, retrieved_policy['min_kbps'])
1243 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1244
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001245 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001246 def test_rule_delete(self):
1247 policy = self.create_qos_policy(name='test-policy',
1248 description='test policy',
1249 shared=False)
1250 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001251 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001252
1253 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1254 policy['id'], rule['id'])
1255 retrieved_policy = retrieved_policy[self.RULE_NAME]
1256 self.assertEqual(rule['id'], retrieved_policy['id'])
1257
1258 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1259 rule['id'])
1260 self.assertRaises(exceptions.NotFound,
1261 self.admin_client.show_minimum_bandwidth_rule,
1262 policy['id'], rule['id'])
1263
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001264 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001265 def test_rule_create_rule_nonexistent_policy(self):
1266 self.assertRaises(
1267 exceptions.NotFound,
1268 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001269 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001270
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001271 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001272 def test_rule_create_forbidden_for_regular_tenants(self):
1273 self.assertRaises(
1274 exceptions.Forbidden,
1275 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001276 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001277
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001278 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001279 def test_get_rules_by_policy(self):
1280 policy1 = self.create_qos_policy(name='test-policy1',
1281 description='test policy1',
1282 shared=False)
1283 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001284 policy_id=policy1['id'],
1285 direction=self.DIRECTION_EGRESS,
1286 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001287
1288 policy2 = self.create_qos_policy(name='test-policy2',
1289 description='test policy2',
1290 shared=False)
1291 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001292 policy_id=policy2['id'],
1293 direction=self.DIRECTION_EGRESS,
1294 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001295
1296 # Test 'list rules'
1297 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1298 rules = rules[self.RULES_NAME]
1299 rules_ids = [r['id'] for r in rules]
1300 self.assertIn(rule1['id'], rules_ids)
1301 self.assertNotIn(rule2['id'], rules_ids)
1302
1303
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001304class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1305 base.BaseAdminNetworkTest):
1306
1307 resource = 'policy'
1308 plural_name = 'policies'
1309
1310 # Use unique description to isolate the tests from other QoS tests
1311 list_kwargs = {'description': 'search-criteria-test'}
1312 list_as_admin = True
1313
Chandan Kumarc125fd12017-11-15 19:41:01 +05301314 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001315
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001316 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001317 def resource_setup(cls):
1318 super(QosSearchCriteriaTest, cls).resource_setup()
1319 for name in cls.resource_names:
1320 cls.create_qos_policy(
1321 name=name, description='search-criteria-test')
1322
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001323 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001324 def test_list_sorts_asc(self):
1325 self._test_list_sorts_asc()
1326
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001327 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001328 def test_list_sorts_desc(self):
1329 self._test_list_sorts_desc()
1330
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001331 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001332 def test_list_pagination(self):
1333 self._test_list_pagination()
1334
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001335 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001336 def test_list_pagination_with_marker(self):
1337 self._test_list_pagination_with_marker()
1338
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001339 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001340 def test_list_pagination_with_href_links(self):
1341 self._test_list_pagination_with_href_links()
1342
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001343 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001344 def test_list_pagination_page_reverse_asc(self):
1345 self._test_list_pagination_page_reverse_asc()
1346
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001347 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001348 def test_list_pagination_page_reverse_desc(self):
1349 self._test_list_pagination_page_reverse_desc()
1350
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001351 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001352 def test_list_pagination_page_reverse_with_href_links(self):
1353 self._test_list_pagination_page_reverse_with_href_links()
1354
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001355 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001356 def test_list_no_pagination_limit_0(self):
1357 self._test_list_no_pagination_limit_0()