blob: 9f9ce674b98035e2f34f9549dda4ee7c42473e5c [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)
68 self.assertIn('tenant_id', show_policy)
69 self.assertEqual(self.admin_client.tenant_id,
70 show_policy['project_id'])
71 self.assertEqual(self.admin_client.tenant_id,
72 show_policy['tenant_id'])
73
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000074 @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000075 def test_list_policy_filter_by_name(self):
76 self.create_qos_policy(name='test', description='test policy',
77 shared=False)
78 self.create_qos_policy(name='test2', description='test policy',
79 shared=False)
80
81 policies = (self.admin_client.
82 list_qos_policies(name='test')['policies'])
83 self.assertEqual(1, len(policies))
84
85 retrieved_policy = policies[0]
86 self.assertEqual('test', retrieved_policy['name'])
87
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000088 @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000089 def test_policy_update(self):
90 policy = self.create_qos_policy(name='test-policy',
91 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +000092 shared=False,
93 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000094 self.admin_client.update_qos_policy(policy['id'],
95 description='test policy desc2',
96 shared=True)
97
98 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
99 retrieved_policy = retrieved_policy['policy']
100 self.assertEqual('test policy desc2', retrieved_policy['description'])
101 self.assertTrue(retrieved_policy['shared'])
102 self.assertEqual([], retrieved_policy['rules'])
103
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000104 @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000105 def test_policy_update_forbidden_for_regular_tenants_own_policy(self):
106 policy = self.create_qos_policy(name='test-policy',
107 description='',
108 shared=False,
109 tenant_id=self.client.tenant_id)
110 self.assertRaises(
111 exceptions.Forbidden,
112 self.client.update_qos_policy,
113 policy['id'], description='test policy')
114
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000115 @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000116 def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self):
117 policy = self.create_qos_policy(name='test-policy',
118 description='',
119 shared=False,
120 tenant_id=self.admin_client.tenant_id)
121 self.assertRaises(
122 exceptions.NotFound,
123 self.client.update_qos_policy,
124 policy['id'], description='test policy')
125
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000126 @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c')
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000127 def test_shared_policy_update(self):
128 policy = self.create_qos_policy(name='test-policy',
129 description='',
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000130 shared=True,
131 tenant_id=self.admin_client.tenant_id)
Sławek Kapłoński6bfcc752016-06-05 09:49:27 +0000132
133 self.admin_client.update_qos_policy(policy['id'],
134 description='test policy desc2')
135 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
136 retrieved_policy = retrieved_policy['policy']
137 self.assertTrue(retrieved_policy['shared'])
138
139 self.admin_client.update_qos_policy(policy['id'],
140 shared=False)
141 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
142 retrieved_policy = retrieved_policy['policy']
143 self.assertFalse(retrieved_policy['shared'])
144
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000145 @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000146 def test_delete_policy(self):
147 policy = self.admin_client.create_qos_policy(
148 'test-policy', 'desc', True)['policy']
149
150 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
151 retrieved_policy = retrieved_policy['policy']
152 self.assertEqual('test-policy', retrieved_policy['name'])
153
154 self.admin_client.delete_qos_policy(policy['id'])
155 self.assertRaises(exceptions.NotFound,
156 self.admin_client.show_qos_policy, policy['id'])
157
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000158 @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000159 def test_list_admin_rule_types(self):
160 self._test_list_rule_types(self.admin_client)
161
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000162 @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000163 def test_list_regular_rule_types(self):
164 self._test_list_rule_types(self.client)
165
166 def _test_list_rule_types(self, client):
167 # List supported rule types
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000168 # Since returned rule types depends on loaded backend drivers this test
169 # is checking only if returned keys are same as expected keys
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000170 #
171 # In theory, we could make the test conditional on which ml2 drivers
172 # are enabled in gate (or more specifically, on which supported qos
173 # rules are claimed by core plugin), but that option doesn't seem to be
karimbd4c68e72016-06-24 14:44:11 +0200174 # available through tempest.lib framework
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000175 expected_rule_keys = ['type']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000176
177 rule_types = client.list_qos_rule_types()
178 actual_list_rule_types = rule_types['rule_types']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000179
180 # Verify that only required fields present in rule details
181 for rule in actual_list_rule_types:
Sławek Kapłoński566ae692017-06-25 08:37:42 +0000182 self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys()))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000183
Sławek Kapłoński7aa3a352017-06-19 06:35:25 +0000184 @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d')
185 def test_show_rule_type_details_as_user(self):
186 self.assertRaises(
187 exceptions.Forbidden,
188 self.client.show_qos_rule_type,
189 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
190
191 @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e')
192 def test_show_rule_type_details_as_admin(self):
193 # Since returned rule types depend on loaded backend drivers this test
194 # is checking only if returned keys are same as expected keys
195
196 # In theory, we could make the test conditional on which ml2 drivers
197 # are enabled in gate, but that option doesn't seem to be
198 # available through tempest.lib framework
199 expected_rule_type_details_keys = ['type', 'drivers']
200
201 rule_type_details = self.admin_client.show_qos_rule_type(
202 qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type")
203
204 # Verify that only required fields present in rule details
205 self.assertEqual(
206 sorted(tuple(expected_rule_type_details_keys)),
207 sorted(tuple(rule_type_details.keys())))
208
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000209 @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000210 def test_policy_association_with_admin_network(self):
211 policy = self.create_qos_policy(name='test-policy',
212 description='test policy',
213 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200214 network = self.create_network('test network', shared=True,
215 qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000216
217 retrieved_network = self.admin_client.show_network(network['id'])
218 self.assertEqual(
219 policy['id'], retrieved_network['network']['qos_policy_id'])
220
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000221 @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000222 def test_policy_association_with_tenant_network(self):
223 policy = self.create_qos_policy(name='test-policy',
224 description='test policy',
225 shared=True)
226 network = self.create_network('test network',
227 qos_policy_id=policy['id'])
228
229 retrieved_network = self.admin_client.show_network(network['id'])
230 self.assertEqual(
231 policy['id'], retrieved_network['network']['qos_policy_id'])
232
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000233 @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000234 def test_policy_association_with_network_nonexistent_policy(self):
235 self.assertRaises(
236 exceptions.NotFound,
237 self.create_network,
238 'test network',
239 qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e')
240
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000241 @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000242 def test_policy_association_with_network_non_shared_policy(self):
243 policy = self.create_qos_policy(name='test-policy',
244 description='test policy',
245 shared=False)
246 self.assertRaises(
247 exceptions.NotFound,
248 self.create_network,
249 'test network', qos_policy_id=policy['id'])
250
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000251 @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000252 def test_policy_update_association_with_admin_network(self):
253 policy = self.create_qos_policy(name='test-policy',
254 description='test policy',
255 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200256 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000257 retrieved_network = self.admin_client.show_network(network['id'])
258 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
259
260 self.admin_client.update_network(network['id'],
261 qos_policy_id=policy['id'])
262 retrieved_network = self.admin_client.show_network(network['id'])
263 self.assertEqual(
264 policy['id'], retrieved_network['network']['qos_policy_id'])
265
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000266 @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000267 def test_policy_association_with_port_shared_policy(self):
268 policy = self.create_qos_policy(name='test-policy',
269 description='test policy',
270 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200271 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000272 port = self.create_port(network, qos_policy_id=policy['id'])
273
274 retrieved_port = self.admin_client.show_port(port['id'])
275 self.assertEqual(
276 policy['id'], retrieved_port['port']['qos_policy_id'])
277
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000278 @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000279 def test_policy_association_with_port_nonexistent_policy(self):
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200280 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000281 self.assertRaises(
282 exceptions.NotFound,
283 self.create_port,
284 network,
285 qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e')
286
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000287 @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000288 def test_policy_association_with_port_non_shared_policy(self):
289 policy = self.create_qos_policy(name='test-policy',
290 description='test policy',
291 shared=False)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200292 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000293 self.assertRaises(
294 exceptions.NotFound,
295 self.create_port,
296 network, qos_policy_id=policy['id'])
297
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000298 @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000299 def test_policy_update_association_with_port_shared_policy(self):
300 policy = self.create_qos_policy(name='test-policy',
301 description='test policy',
302 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200303 network = self.create_network('test network', shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000304 port = self.create_port(network)
305 retrieved_port = self.admin_client.show_port(port['id'])
306 self.assertIsNone(retrieved_port['port']['qos_policy_id'])
307
308 self.client.update_port(port['id'], qos_policy_id=policy['id'])
309 retrieved_port = self.admin_client.show_port(port['id'])
310 self.assertEqual(
311 policy['id'], retrieved_port['port']['qos_policy_id'])
312
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000313 @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000314 def test_delete_not_allowed_if_policy_in_use_by_network(self):
315 policy = self.create_qos_policy(name='test-policy',
316 description='test policy',
317 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200318 self.create_network('test network', qos_policy_id=policy['id'],
319 shared=True)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000320 self.assertRaises(
321 exceptions.Conflict,
322 self.admin_client.delete_qos_policy, policy['id'])
323
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000324 @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000325 def test_delete_not_allowed_if_policy_in_use_by_port(self):
326 policy = self.create_qos_policy(name='test-policy',
327 description='test policy',
328 shared=True)
Federico Ressi2d7db2c2018-07-06 08:11:20 +0200329 network = self.create_network('test network', shared=True)
Sławek Kapłońskie100c4d2017-08-23 21:18:34 +0000330 self.create_port(network, qos_policy_id=policy['id'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000331 self.assertRaises(
332 exceptions.Conflict,
333 self.admin_client.delete_qos_policy, policy['id'])
334
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000335 @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000336 def test_qos_policy_delete_with_rules(self):
337 policy = self.create_qos_policy(name='test-policy',
338 description='test policy',
339 shared=False)
340 self.admin_client.create_bandwidth_limit_rule(
341 policy['id'], 200, 1337)['bandwidth_limit_rule']
342
343 self.admin_client.delete_qos_policy(policy['id'])
344
345 with testtools.ExpectedException(exceptions.NotFound):
346 self.admin_client.show_qos_policy(policy['id'])
347
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000348 @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f')
Jakub Libosvarab42ca82016-06-07 07:56:13 +0000349 def test_get_policy_that_is_shared(self):
350 policy = self.create_qos_policy(
351 name='test-policy-shared',
352 description='shared policy',
353 shared=True,
354 tenant_id=self.admin_client.tenant_id)
355 obtained_policy = self.client.show_qos_policy(policy['id'])['policy']
356 self.assertEqual(obtained_policy, policy)
357
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000358 @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +0100359 def test_policy_create_forbidden_for_regular_tenants(self):
360 self.assertRaises(
361 exceptions.Forbidden,
362 self.client.create_qos_policy,
363 'test-policy', 'test policy', False)
364
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900365 @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
366 def test_default_policy_creating_network_without_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530367 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900368 policy = self.create_qos_policy(name='test-policy',
369 tenant_id=project_id,
370 is_default=True)
371 network = self.create_network('test network', client=self.admin_client,
372 project_id=project_id)
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900373 retrieved_network = self.admin_client.show_network(network['id'])
374 self.assertEqual(
375 policy['id'], retrieved_network['network']['qos_policy_id'])
376
377 @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
378 def test_default_policy_creating_network_with_policy(self):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530379 project_id = self.create_project()['id']
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900380 self.create_qos_policy(name='test-policy',
381 tenant_id=project_id,
382 is_default=True)
383 policy = self.create_qos_policy(name='test-policy',
384 tenant_id=project_id)
385 network = self.create_network('test network', client=self.admin_client,
386 project_id=project_id,
387 qos_policy_id=policy['id'])
Hirofumi Ichihara39a6ee12017-08-23 13:55:12 +0900388 retrieved_network = self.admin_client.show_network(network['id'])
389 self.assertEqual(
390 policy['id'], retrieved_network['network']['qos_policy_id'])
391
Sławek Kapłoński508dd292018-02-22 13:41:01 +0100392 @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229')
393 def test_user_create_port_with_admin_qos_policy(self):
394 qos_policy = self.create_qos_policy(
395 name='test-policy',
396 tenant_id=self.admin_client.tenant_id,
397 shared=False)
398 network = self.create_network(
399 'test network', client=self.admin_client,
400 project_id=self.client.tenant_id,
401 qos_policy_id=qos_policy['id'])
402 port = self.create_port(network)
403 self.assertEqual(network['id'], port['network_id'])
404
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000405
406class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000407
408 direction = None
Chandan Kumarc125fd12017-11-15 19:41:01 +0530409 required_extensions = [qos_apidef.ALIAS]
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000410
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000411 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900412 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000413 def resource_setup(cls):
414 super(QosBandwidthLimitRuleTestJSON, cls).resource_setup()
415
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000416 @property
417 def opposite_direction(self):
418 if self.direction == "ingress":
419 return "egress"
420 elif self.direction == "egress":
421 return "ingress"
422 else:
423 return None
424
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000425 @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000426 def test_rule_create(self):
427 policy = self.create_qos_policy(name='test-policy',
428 description='test policy',
429 shared=False)
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000430 rule = self.create_qos_bandwidth_limit_rule(
431 policy_id=policy['id'],
432 max_kbps=200,
433 max_burst_kbps=1337,
434 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000435
436 # Test 'show rule'
437 retrieved_rule = self.admin_client.show_bandwidth_limit_rule(
438 policy['id'], rule['id'])
439 retrieved_rule = retrieved_rule['bandwidth_limit_rule']
440 self.assertEqual(rule['id'], retrieved_rule['id'])
441 self.assertEqual(200, retrieved_rule['max_kbps'])
442 self.assertEqual(1337, retrieved_rule['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000443 if self.direction:
444 self.assertEqual(self.direction, retrieved_rule['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000445
446 # Test 'list rules'
447 rules = self.admin_client.list_bandwidth_limit_rules(policy['id'])
448 rules = rules['bandwidth_limit_rules']
449 rules_ids = [r['id'] for r in rules]
450 self.assertIn(rule['id'], rules_ids)
451
452 # Test 'show policy'
453 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
454 policy_rules = retrieved_policy['policy']['rules']
455 self.assertEqual(1, len(policy_rules))
456 self.assertEqual(rule['id'], policy_rules[0]['id'])
457 self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
458 policy_rules[0]['type'])
459
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000460 @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000461 def test_rule_create_fail_for_the_same_type(self):
462 policy = self.create_qos_policy(name='test-policy',
463 description='test policy',
464 shared=False)
465 self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
466 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000467 max_burst_kbps=1337,
468 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000469
470 self.assertRaises(exceptions.Conflict,
471 self.create_qos_bandwidth_limit_rule,
472 policy_id=policy['id'],
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000473 max_kbps=201, max_burst_kbps=1338,
474 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000475
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000476 @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000477 def test_rule_update(self):
478 policy = self.create_qos_policy(name='test-policy',
479 description='test policy',
480 shared=False)
481 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
482 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000483 max_burst_kbps=1,
484 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000485
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000486 self.admin_client.update_bandwidth_limit_rule(
487 policy['id'],
488 rule['id'],
489 max_kbps=200,
490 max_burst_kbps=1337,
491 direction=self.opposite_direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000492
493 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
494 policy['id'], rule['id'])
495 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
496 self.assertEqual(200, retrieved_policy['max_kbps'])
497 self.assertEqual(1337, retrieved_policy['max_burst_kbps'])
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000498 if self.opposite_direction:
499 self.assertEqual(self.opposite_direction,
500 retrieved_policy['direction'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000501
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000502 @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000503 def test_rule_delete(self):
504 policy = self.create_qos_policy(name='test-policy',
505 description='test policy',
506 shared=False)
507 rule = self.admin_client.create_bandwidth_limit_rule(
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000508 policy['id'], 200, 1337, self.direction)['bandwidth_limit_rule']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000509
510 retrieved_policy = self.admin_client.show_bandwidth_limit_rule(
511 policy['id'], rule['id'])
512 retrieved_policy = retrieved_policy['bandwidth_limit_rule']
513 self.assertEqual(rule['id'], retrieved_policy['id'])
514
515 self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
516 self.assertRaises(exceptions.NotFound,
517 self.admin_client.show_bandwidth_limit_rule,
518 policy['id'], rule['id'])
519
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000520 @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000521 def test_rule_create_rule_nonexistent_policy(self):
522 self.assertRaises(
523 exceptions.NotFound,
524 self.create_qos_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000525 'policy', 200, 1337, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000526
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000527 @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000528 def test_rule_create_forbidden_for_regular_tenants(self):
529 self.assertRaises(
530 exceptions.Forbidden,
531 self.client.create_bandwidth_limit_rule,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000532 'policy', 1, 2, self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000533
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000534 @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000535 def test_rule_update_forbidden_for_regular_tenants_own_policy(self):
536 policy = self.create_qos_policy(name='test-policy',
537 description='test policy',
538 shared=False,
539 tenant_id=self.client.tenant_id)
540 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
541 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000542 max_burst_kbps=1,
543 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000544 self.assertRaises(
Matthew Edmondsc13d3502017-04-14 08:22:43 -0400545 exceptions.Forbidden,
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000546 self.client.update_bandwidth_limit_rule,
547 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
548
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000549 @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f')
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000550 def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self):
551 policy = self.create_qos_policy(name='test-policy',
552 description='test policy',
553 shared=False,
554 tenant_id=self.admin_client.tenant_id)
555 rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
556 max_kbps=1,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000557 max_burst_kbps=1,
558 direction=self.direction)
Sławek Kapłoński0acecc62016-08-20 21:00:51 +0000559 self.assertRaises(
560 exceptions.NotFound,
561 self.client.update_bandwidth_limit_rule,
562 policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4)
563
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000564 @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000565 def test_get_rules_by_policy(self):
566 policy1 = self.create_qos_policy(name='test-policy1',
567 description='test policy1',
568 shared=False)
569 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'],
570 max_kbps=200,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000571 max_burst_kbps=1337,
572 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000573
574 policy2 = self.create_qos_policy(name='test-policy2',
575 description='test policy2',
576 shared=False)
577 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'],
578 max_kbps=5000,
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000579 max_burst_kbps=2523,
580 direction=self.direction)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000581
582 # Test 'list rules'
583 rules = self.admin_client.list_bandwidth_limit_rules(policy1['id'])
584 rules = rules['bandwidth_limit_rules']
585 rules_ids = [r['id'] for r in rules]
586 self.assertIn(rule1['id'], rules_ids)
587 self.assertNotIn(rule2['id'], rules_ids)
588
nfridman07f0e782019-11-04 09:12:58 -0500589 @testtools.skipUnless(
590 CONF.neutron_plugin_options.create_shared_resources,
591 """Creation of shared resources should be allowed,
592 setting the create_shared_resources option as 'True' is needed""")
593 @decorators.idempotent_id('d911707e-fa2c-11e9-9553-5076af30bbf5')
594 def test_attach_and_detach_a_policy_by_a_tenant(self):
595 # As an admin create an non shared QoS policy,add a rule
596 # and associate it with a network
597 self.network = self.create_network()
598 policy = self.create_qos_policy(name='test-policy',
599 description='test policy for attach',
600 shared=False)
601
602 self.admin_client.create_bandwidth_limit_rule(
603 policy['id'], 1024, 1024)
604
605 self.admin_client.update_network(
606 self.network['id'], qos_policy_id=policy['id'])
607
608 # As a tenant, try to detach the policy from the network
609 # The operation should be forbidden
610 self.assertRaises(
611 exceptions.Forbidden,
612 self.client.update_network,
613 self.network['id'], qos_policy_id=None)
614
615 # As an admin, make the policy shared
616 self.admin_client.update_qos_policy(policy['id'], shared=True)
617
618 # As a tenant, try to detach the policy from the network
619 # The operation should be allowed
620 self.client.update_network(self.network['id'],
621 qos_policy_id=None)
622
623 retrieved_network = self.admin_client.show_network(self.network['id'])
624 self.assertIsNone(retrieved_network['network']['qos_policy_id'])
625
626 # As a tenant, try to delete the policy from the network
627 # should be forbidden
628 self.assertRaises(
629 exceptions.Forbidden,
630 self.client.delete_qos_policy,
631 policy['id'])
632
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000633
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000634class QosBandwidthLimitRuleWithDirectionTestJSON(
Brian Haley6767cec2018-04-10 15:30:23 -0400635 QosBandwidthLimitRuleTestJSON):
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000636 required_extensions = (
637 QosBandwidthLimitRuleTestJSON.required_extensions +
638 ['qos-bw-limit-direction']
639 )
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000640 scenarios = [
641 ('ingress', {'direction': 'ingress'}),
642 ('egress', {'direction': 'egress'}),
643 ]
644
nfridman7717d9c2019-11-25 08:58:04 -0500645 @classmethod
646 @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT)
647 def resource_setup(cls):
648 super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup()
649
650 @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667')
651 def test_create_policy_with_multiple_rules(self):
652 # Create a policy with multiple rules
653 policy = self.create_qos_policy(name='test-policy1',
654 description='test policy1',
655 shared=False)
656
657 rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
658 max_kbps=1024,
659 max_burst_kbps=1024,
nfridman07f0e782019-11-04 09:12:58 -0500660 direction=n_constants.
661 EGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500662 rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
663 max_kbps=1024,
664 max_burst_kbps=1024,
nfridman07f0e782019-11-04 09:12:58 -0500665 direction=n_constants.
666 INGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500667 # Check that the rules were added to the policy
668 rules = self.admin_client.list_bandwidth_limit_rules(
669 policy['id'])['bandwidth_limit_rules']
670 rules_ids = [rule['id'] for rule in rules]
671 self.assertIn(rule1['id'], rules_ids)
672 self.assertIn(rule2['id'], rules_ids)
673
674 # Check that the rules creation fails for the same rule types
675 self.assertRaises(exceptions.Conflict,
676 self.create_qos_bandwidth_limit_rule,
677 policy_id=policy['id'],
678 max_kbps=1025,
679 max_burst_kbps=1025,
nfridman07f0e782019-11-04 09:12:58 -0500680 direction=n_constants.EGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500681
682 self.assertRaises(exceptions.Conflict,
683 self.create_qos_bandwidth_limit_rule,
684 policy_id=policy['id'],
685 max_kbps=1025,
686 max_burst_kbps=1025,
nfridman07f0e782019-11-04 09:12:58 -0500687 direction=n_constants.INGRESS_DIRECTION)
nfridman7717d9c2019-11-25 08:58:04 -0500688
Sławek Kapłoński153f3452017-03-24 22:04:53 +0000689
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000690class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest):
691
692 force_tenant_isolation = True
693 credentials = ['primary', 'alt', 'admin']
Chandan Kumarc125fd12017-11-15 19:41:01 +0530694 required_extensions = [qos_apidef.ALIAS]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000695
696 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000697 def resource_setup(cls):
698 super(RbacSharedQosPoliciesTest, cls).resource_setup()
rajat294495c042017-06-28 15:37:16 +0530699 cls.client2 = cls.os_alt.network_client
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000700
701 def _create_qos_policy(self, tenant_id=None):
702 args = {'name': data_utils.rand_name('test-policy'),
703 'description': 'test policy',
704 'shared': False,
705 'tenant_id': tenant_id}
706 qos_policy = self.admin_client.create_qos_policy(**args)['policy']
707 self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id'])
708
709 return qos_policy
710
711 def _make_admin_policy_shared_to_tenant_id(self, tenant_id):
712 policy = self._create_qos_policy()
713 rbac_policy = self.admin_client.create_rbac_policy(
714 object_type='qos_policy',
715 object_id=policy['id'],
716 action='access_as_shared',
717 target_tenant=tenant_id,
718 )['rbac_policy']
719
720 return {'policy': policy, 'rbac_policy': rbac_policy}
721
722 def _create_network(self, qos_policy_id, client, should_cleanup=True):
723 net = client.create_network(
724 name=data_utils.rand_name('test-network'),
725 qos_policy_id=qos_policy_id)['network']
726 if should_cleanup:
727 self.addCleanup(client.delete_network, net['id'])
728
729 return net
730
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000731 @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000732 def test_policy_sharing_with_wildcard(self):
733 qos_pol = self.create_qos_policy(
734 name=data_utils.rand_name('test-policy'),
Rodolfo Alonso Hernandez1e9d1fe2017-02-01 15:15:16 +0000735 description='test-shared-policy', shared=False,
736 tenant_id=self.admin_client.tenant_id)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000737 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
738
739 # test update shared False -> True
740 self.admin_client.update_qos_policy(qos_pol['id'], shared=True)
741 qos_pol['shared'] = True
742 self.client2.show_qos_policy(qos_pol['id'])
743 rbac_pol = {'target_tenant': '*',
744 'tenant_id': self.admin_client.tenant_id,
Dariusz Smigielf5fb4c62016-08-19 15:41:17 +0000745 'project_id': self.admin_client.tenant_id,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000746 'object_type': 'qos_policy',
747 'object_id': qos_pol['id'],
748 'action': 'access_as_shared'}
749
750 rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies']
751 rbac_policies = [r for r in rbac_policies if r.pop('id')]
752 self.assertIn(rbac_pol, rbac_policies)
753
754 # update shared True -> False should fail because the policy is bound
755 # to a network
756 net = self._create_network(qos_pol['id'], self.admin_client, False)
757 with testtools.ExpectedException(exceptions.Conflict):
758 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
759
760 # delete the network, and update shared True -> False should pass now
761 self.admin_client.delete_network(net['id'])
762 self.admin_client.update_qos_policy(qos_pol['id'], shared=False)
763 qos_pol['shared'] = False
764 self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies'])
765
766 def _create_net_bound_qos_rbacs(self):
767 res = self._make_admin_policy_shared_to_tenant_id(
768 self.client.tenant_id)
769 qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy']
770
771 # add a wildcard rbac rule - now the policy globally shared
772 rbac_wildcard = self.admin_client.create_rbac_policy(
773 object_type='qos_policy',
774 object_id=qos_policy['id'],
775 action='access_as_shared',
776 target_tenant='*',
777 )['rbac_policy']
778
779 # tenant1 now uses qos policy for net
780 self._create_network(qos_policy['id'], self.client)
781
782 return rbac_for_client_tenant, rbac_wildcard
783
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000784 @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000785 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self):
786 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
787 # globally unshare the qos-policy, the specific share should remain
788 self.admin_client.delete_rbac_policy(wildcard_rbac['id'])
789 self.client.list_rbac_policies(id=client_rbac['id'])
790
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000791 @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000792 def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self):
793 client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs()
794 # remove client_rbac policy the wildcard share should remain
795 self.admin_client.delete_rbac_policy(client_rbac['id'])
796 self.client.list_rbac_policies(id=wildcard_rbac['id'])
797
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000798 @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000799 def test_policy_sharing_with_wildcard_and_tenant_id(self):
800 res = self._make_admin_policy_shared_to_tenant_id(
801 self.client.tenant_id)
802 qos_policy, rbac = res['policy'], res['rbac_policy']
803 qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy']
804 self.assertTrue(qos_pol['shared'])
805 with testtools.ExpectedException(exceptions.NotFound):
806 self.client2.show_qos_policy(qos_policy['id'])
807
808 # make the qos-policy globally shared
809 self.admin_client.update_qos_policy(qos_policy['id'], shared=True)
810 qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy']
811 self.assertTrue(qos_pol['shared'])
812
813 # globally unshare the qos-policy, the specific share should remain
814 self.admin_client.update_qos_policy(qos_policy['id'], shared=False)
815 self.client.show_qos_policy(qos_policy['id'])
816 with testtools.ExpectedException(exceptions.NotFound):
817 self.client2.show_qos_policy(qos_policy['id'])
818 self.assertIn(rbac,
819 self.admin_client.list_rbac_policies()['rbac_policies'])
820
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000821 @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000822 def test_policy_target_update(self):
823 res = self._make_admin_policy_shared_to_tenant_id(
824 self.client.tenant_id)
825 # change to client2
826 update_res = self.admin_client.update_rbac_policy(
827 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
828 self.assertEqual(self.client2.tenant_id,
829 update_res['rbac_policy']['target_tenant'])
830 # make sure everything else stayed the same
831 res['rbac_policy'].pop('target_tenant')
832 update_res['rbac_policy'].pop('target_tenant')
833 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
834
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000835 @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000836 def test_network_presence_prevents_policy_rbac_policy_deletion(self):
837 res = self._make_admin_policy_shared_to_tenant_id(
838 self.client2.tenant_id)
839 qos_policy_id = res['policy']['id']
840 self._create_network(qos_policy_id, self.client2)
841 # a network with shared qos-policy should prevent the deletion of an
842 # rbac-policy required for it to be shared
843 with testtools.ExpectedException(exceptions.Conflict):
844 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
845
846 # a wildcard policy should allow the specific policy to be deleted
847 # since it allows the remaining port
848 wild = self.admin_client.create_rbac_policy(
849 object_type='qos_policy', object_id=res['policy']['id'],
850 action='access_as_shared', target_tenant='*')['rbac_policy']
851 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
852
853 # now that wildcard is the only remaining, it should be subjected to
854 # the same restriction
855 with testtools.ExpectedException(exceptions.Conflict):
856 self.admin_client.delete_rbac_policy(wild['id'])
857
858 # we can't update the policy to a different tenant
859 with testtools.ExpectedException(exceptions.Conflict):
860 self.admin_client.update_rbac_policy(
861 wild['id'], target_tenant=self.client2.tenant_id)
862
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000863 @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000864 def test_regular_client_shares_to_another_regular_client(self):
865 # owned by self.admin_client
866 policy = self._create_qos_policy()
867 with testtools.ExpectedException(exceptions.NotFound):
868 self.client.show_qos_policy(policy['id'])
869 rbac_policy = self.admin_client.create_rbac_policy(
870 object_type='qos_policy', object_id=policy['id'],
871 action='access_as_shared',
872 target_tenant=self.client.tenant_id)['rbac_policy']
873 self.client.show_qos_policy(policy['id'])
874
875 self.assertIn(rbac_policy,
876 self.admin_client.list_rbac_policies()['rbac_policies'])
877 # ensure that 'client2' can't see the rbac-policy sharing the
878 # qos-policy to it because the rbac-policy belongs to 'client'
879 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
880 self.client2.list_rbac_policies()['rbac_policies']])
881
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000882 @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000883 def test_filter_fields(self):
884 policy = self._create_qos_policy()
885 self.admin_client.create_rbac_policy(
886 object_type='qos_policy', object_id=policy['id'],
887 action='access_as_shared', target_tenant=self.client2.tenant_id)
888 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
889 ('tenant_id', 'target_tenant'))
890 for fields in field_args:
891 res = self.admin_client.list_rbac_policies(fields=fields)
892 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
893
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000894 @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000895 def test_rbac_policy_show(self):
896 res = self._make_admin_policy_shared_to_tenant_id(
897 self.client.tenant_id)
898 p1 = res['rbac_policy']
899 p2 = self.admin_client.create_rbac_policy(
900 object_type='qos_policy', object_id=res['policy']['id'],
901 action='access_as_shared',
902 target_tenant='*')['rbac_policy']
903
904 self.assertEqual(
905 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
906 self.assertEqual(
907 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
908
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000909 @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000910 def test_filter_rbac_policies(self):
911 policy = self._create_qos_policy()
912 rbac_pol1 = self.admin_client.create_rbac_policy(
913 object_type='qos_policy', object_id=policy['id'],
914 action='access_as_shared',
915 target_tenant=self.client2.tenant_id)['rbac_policy']
916 rbac_pol2 = self.admin_client.create_rbac_policy(
917 object_type='qos_policy', object_id=policy['id'],
918 action='access_as_shared',
919 target_tenant=self.admin_client.tenant_id)['rbac_policy']
920 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
921 'rbac_policies']
922 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
923 'rbac_policies']
924 self.assertEqual(1, len(res1))
925 self.assertEqual(1, len(res2))
926 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
927 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
928
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000929 @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000930 def test_regular_client_blocked_from_sharing_anothers_policy(self):
931 qos_policy = self._make_admin_policy_shared_to_tenant_id(
932 self.client.tenant_id)['policy']
933 with testtools.ExpectedException(exceptions.BadRequest):
934 self.client.create_rbac_policy(
935 object_type='qos_policy', object_id=qos_policy['id'],
936 action='access_as_shared',
937 target_tenant=self.client2.tenant_id)
938
939 # make sure the rbac-policy is invisible to the tenant for which it's
940 # being shared
941 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])
942
943
944class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest):
945 VALID_DSCP_MARK1 = 56
946 VALID_DSCP_MARK2 = 48
947
Chandan Kumarc125fd12017-11-15 19:41:01 +0530948 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000949
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000950 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +0900951 @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000952 def resource_setup(cls):
953 super(QosDscpMarkingRuleTestJSON, cls).resource_setup()
954
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000955 @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000956 def test_rule_create(self):
957 policy = self.create_qos_policy(name='test-policy',
958 description='test policy',
959 shared=False)
960 rule = self.admin_client.create_dscp_marking_rule(
961 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
962
963 # Test 'show rule'
964 retrieved_rule = self.admin_client.show_dscp_marking_rule(
965 policy['id'], rule['id'])
966 retrieved_rule = retrieved_rule['dscp_marking_rule']
967 self.assertEqual(rule['id'], retrieved_rule['id'])
968 self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark'])
969
970 # Test 'list rules'
971 rules = self.admin_client.list_dscp_marking_rules(policy['id'])
972 rules = rules['dscp_marking_rules']
973 rules_ids = [r['id'] for r in rules]
974 self.assertIn(rule['id'], rules_ids)
975
976 # Test 'show policy'
977 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
978 policy_rules = retrieved_policy['policy']['rules']
979 self.assertEqual(1, len(policy_rules))
980 self.assertEqual(rule['id'], policy_rules[0]['id'])
David Shaughnessydbf24822016-03-14 16:27:54 +0000981 self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING,
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000982 policy_rules[0]['type'])
983
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000984 @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000985 def test_rule_create_fail_for_the_same_type(self):
986 policy = self.create_qos_policy(name='test-policy',
987 description='test policy',
988 shared=False)
989 self.admin_client.create_dscp_marking_rule(
990 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
991
992 self.assertRaises(exceptions.Conflict,
993 self.admin_client.create_dscp_marking_rule,
994 policy_id=policy['id'],
995 dscp_mark=self.VALID_DSCP_MARK2)
996
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000997 @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000998 def test_rule_update(self):
999 policy = self.create_qos_policy(name='test-policy',
1000 description='test policy',
1001 shared=False)
1002 rule = self.admin_client.create_dscp_marking_rule(
1003 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1004
1005 self.admin_client.update_dscp_marking_rule(
1006 policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2)
1007
1008 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1009 policy['id'], rule['id'])
1010 retrieved_policy = retrieved_policy['dscp_marking_rule']
1011 self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark'])
1012
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001013 @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001014 def test_rule_delete(self):
1015 policy = self.create_qos_policy(name='test-policy',
1016 description='test policy',
1017 shared=False)
1018 rule = self.admin_client.create_dscp_marking_rule(
1019 policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1020
1021 retrieved_policy = self.admin_client.show_dscp_marking_rule(
1022 policy['id'], rule['id'])
1023 retrieved_policy = retrieved_policy['dscp_marking_rule']
1024 self.assertEqual(rule['id'], retrieved_policy['id'])
1025
1026 self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id'])
1027 self.assertRaises(exceptions.NotFound,
1028 self.admin_client.show_dscp_marking_rule,
1029 policy['id'], rule['id'])
1030
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001031 @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001032 def test_rule_create_rule_nonexistent_policy(self):
1033 self.assertRaises(
1034 exceptions.NotFound,
1035 self.admin_client.create_dscp_marking_rule,
1036 'policy', self.VALID_DSCP_MARK1)
1037
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001038 @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001039 def test_rule_create_forbidden_for_regular_tenants(self):
1040 self.assertRaises(
1041 exceptions.Forbidden,
1042 self.client.create_dscp_marking_rule,
1043 'policy', self.VALID_DSCP_MARK1)
1044
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001045 @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001046 def test_invalid_rule_create(self):
1047 policy = self.create_qos_policy(name='test-policy',
1048 description='test policy',
1049 shared=False)
1050 self.assertRaises(
1051 exceptions.BadRequest,
1052 self.admin_client.create_dscp_marking_rule,
1053 policy['id'], 58)
1054
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001055 @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001056 def test_get_rules_by_policy(self):
1057 policy1 = self.create_qos_policy(name='test-policy1',
1058 description='test policy1',
1059 shared=False)
1060 rule1 = self.admin_client.create_dscp_marking_rule(
1061 policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule']
1062
1063 policy2 = self.create_qos_policy(name='test-policy2',
1064 description='test policy2',
1065 shared=False)
1066 rule2 = self.admin_client.create_dscp_marking_rule(
1067 policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule']
1068
1069 # Test 'list rules'
1070 rules = self.admin_client.list_dscp_marking_rules(policy1['id'])
1071 rules = rules['dscp_marking_rules']
1072 rules_ids = [r['id'] for r in rules]
1073 self.assertIn(rule1['id'], rules_ids)
1074 self.assertNotIn(rule2['id'], rules_ids)
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001075
nfridman23b44ad2019-09-05 09:46:50 -04001076 @decorators.idempotent_id('19ed2286-ccb1-11e9-87d7-525400d6f522')
1077 def test_qos_dscp_create_and_update(self):
1078 """This test covers:
1079
1080 1.Creating a basic QoS policy with DSCP marking rule.
1081 2.Updating QoS policy:
1082 Administrator should have the ability to update existing QoS policy.
1083 This test should verify that:
1084 It's possible to update the existing DSCP marking rule with all of
1085 the valid marks between 0-56, except of the invalid marks:
1086 2-6, 42, 44, and 50-54 (which should be forbidden)
1087 """
1088
1089 def _test_update_dscp_mark_values(self, dscp_policy_id, rule_id):
1090 for mark in range(n_constants.VALID_DSCP_MARKS[1],
1091 self.VALID_DSCP_MARK1 + 1):
1092 if mark in n_constants.VALID_DSCP_MARKS:
1093 self.admin_client.update_dscp_marking_rule(
1094 dscp_policy_id, rule_id, dscp_mark=mark)
1095
1096 retrieved_rule = self.admin_client.show_dscp_marking_rule(
1097 dscp_policy_id, rule_id)['dscp_marking_rule']
1098 self.assertEqual(mark, retrieved_rule['dscp_mark'],
1099 """current DSCP mark is incorrect:
1100 expected value {0} actual value {1}
1101 """.format(mark,
1102 retrieved_rule['dscp_mark']))
1103
1104 else:
1105 self.assertRaises(exceptions.BadRequest,
1106 self.admin_client.create_dscp_marking_rule,
1107 dscp_policy_id,
1108 mark)
1109 # Setup network
1110 self.network = self.create_network()
1111
1112 # Create QoS policy
1113 dscp_policy_id = self.create_qos_policy(
1114 name='test-policy',
1115 description='test-qos-policy',
1116 shared=True)['id']
1117
1118 # Associate QoS to the network
1119 self.admin_client.update_network(
1120 self.network['id'], qos_policy_id=dscp_policy_id)
1121
1122 # Set a new DSCP rule with the first mark in range
1123 rule_id = self.admin_client.create_dscp_marking_rule(
1124 dscp_policy_id,
1125 n_constants.VALID_DSCP_MARKS[0])[
1126 'dscp_marking_rule']['id']
1127
1128 # Validate that the rule was set up properly
1129 retrieved_rule = self.client.show_dscp_marking_rule(
1130 dscp_policy_id, rule_id)['dscp_marking_rule']
1131 self.assertEqual(n_constants.VALID_DSCP_MARKS[0],
1132 retrieved_rule['dscp_mark'],
1133 """current DSCP mark is incorrect:
1134 expected value {0} actual value {1}
1135 """.format(n_constants.VALID_DSCP_MARKS[0],
1136 retrieved_rule['dscp_mark']))
1137
1138 # Try to set marks in range 8:56 (invalid marks should raise an error)
1139 _test_update_dscp_mark_values(self, dscp_policy_id, rule_id)
1140
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001141
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001142class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
1143 DIRECTION_EGRESS = "egress"
1144 DIRECTION_INGRESS = "ingress"
1145 RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule"
1146 RULES_NAME = RULE_NAME + "s"
Chandan Kumarc125fd12017-11-15 19:41:01 +05301147 required_extensions = [qos_apidef.ALIAS]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001148
1149 @classmethod
YAMAMOTO Takashi3bd3d0f2016-12-12 11:14:58 +09001150 @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001151 def resource_setup(cls):
1152 super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup()
1153
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001154 @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001155 def test_rule_create(self):
1156 policy = self.create_qos_policy(name='test-policy',
1157 description='test policy',
1158 shared=False)
1159 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001160 policy_id=policy['id'],
1161 direction=self.DIRECTION_EGRESS,
1162 min_kbps=1138)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001163
1164 # Test 'show rule'
1165 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
1166 policy['id'], rule['id'])
1167 retrieved_rule = retrieved_rule[self.RULE_NAME]
1168 self.assertEqual(rule['id'], retrieved_rule['id'])
1169 self.assertEqual(1138, retrieved_rule['min_kbps'])
1170 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])
1171
1172 # Test 'list rules'
1173 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])
1174 rules = rules[self.RULES_NAME]
1175 rules_ids = [r['id'] for r in rules]
1176 self.assertIn(rule['id'], rules_ids)
1177
1178 # Test 'show policy'
1179 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1180 policy_rules = retrieved_policy['policy']['rules']
1181 self.assertEqual(1, len(policy_rules))
1182 self.assertEqual(rule['id'], policy_rules[0]['id'])
1183 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1184 policy_rules[0]['type'])
1185
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001186 @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001187 def test_rule_create_fail_for_missing_min_kbps(self):
1188 policy = self.create_qos_policy(name='test-policy',
1189 description='test policy',
1190 shared=False)
1191 self.assertRaises(exceptions.BadRequest,
1192 self.admin_client.create_minimum_bandwidth_rule,
1193 policy_id=policy['id'],
1194 direction=self.DIRECTION_EGRESS)
1195
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001196 @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001197 def test_rule_create_fail_for_the_same_type(self):
1198 policy = self.create_qos_policy(name='test-policy',
1199 description='test policy',
1200 shared=False)
1201 self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001202 policy_id=policy['id'],
1203 direction=self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001204
1205 self.assertRaises(exceptions.Conflict,
1206 self.admin_client.create_minimum_bandwidth_rule,
1207 policy_id=policy['id'],
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001208 direction=self.DIRECTION_EGRESS, min_kbps=201)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001209
Lajos Katonadc9c6d62018-08-27 16:08:51 +02001210 @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936')
1211 @utils.requires_ext(extension="qos-bw-minimum-ingress",
1212 service="network")
1213 def test_rule_create_pass_for_direction_ingress(self):
1214 policy = self.create_qos_policy(name='test-policy',
1215 description='test policy',
1216 shared=False)
1217 self.admin_client.create_minimum_bandwidth_rule(
1218 policy_id=policy['id'],
1219 direction=self.DIRECTION_INGRESS,
1220 min_kbps=201)
1221
1222 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])
1223 policy_rules = retrieved_policy['policy']['rules']
1224 self.assertEqual(1, len(policy_rules))
1225 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
1226 policy_rules[0]['type'])
1227 self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction'])
1228
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001229 @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001230 def test_rule_update(self):
1231 policy = self.create_qos_policy(name='test-policy',
1232 description='test policy',
1233 shared=False)
1234 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001235 policy_id=policy['id'],
1236 direction=self.DIRECTION_EGRESS,
1237 min_kbps=300)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001238
1239 self.admin_client.update_minimum_bandwidth_rule(policy['id'],
1240 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
1241
1242 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1243 policy['id'], rule['id'])
1244 retrieved_policy = retrieved_policy[self.RULE_NAME]
1245 self.assertEqual(350, retrieved_policy['min_kbps'])
1246 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])
1247
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001248 @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001249 def test_rule_delete(self):
1250 policy = self.create_qos_policy(name='test-policy',
1251 description='test policy',
1252 shared=False)
1253 rule = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001254 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001255
1256 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
1257 policy['id'], rule['id'])
1258 retrieved_policy = retrieved_policy[self.RULE_NAME]
1259 self.assertEqual(rule['id'], retrieved_policy['id'])
1260
1261 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],
1262 rule['id'])
1263 self.assertRaises(exceptions.NotFound,
1264 self.admin_client.show_minimum_bandwidth_rule,
1265 policy['id'], rule['id'])
1266
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001267 @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001268 def test_rule_create_rule_nonexistent_policy(self):
1269 self.assertRaises(
1270 exceptions.NotFound,
1271 self.admin_client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001272 'policy', self.DIRECTION_EGRESS, min_kbps=200)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001273
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001274 @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001275 def test_rule_create_forbidden_for_regular_tenants(self):
1276 self.assertRaises(
1277 exceptions.Forbidden,
1278 self.client.create_minimum_bandwidth_rule,
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001279 'policy', self.DIRECTION_EGRESS, min_kbps=300)
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001280
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001281 @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001282 def test_get_rules_by_policy(self):
1283 policy1 = self.create_qos_policy(name='test-policy1',
1284 description='test policy1',
1285 shared=False)
1286 rule1 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001287 policy_id=policy1['id'],
1288 direction=self.DIRECTION_EGRESS,
1289 min_kbps=200)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001290
1291 policy2 = self.create_qos_policy(name='test-policy2',
1292 description='test policy2',
1293 shared=False)
1294 rule2 = self.admin_client.create_minimum_bandwidth_rule(
Ihar Hrachyshka33034bf2016-08-31 18:48:14 +00001295 policy_id=policy2['id'],
1296 direction=self.DIRECTION_EGRESS,
1297 min_kbps=5000)[self.RULE_NAME]
Rodolfo Alonso Hernandeze4c099f2016-07-18 11:52:12 +01001298
1299 # Test 'list rules'
1300 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])
1301 rules = rules[self.RULES_NAME]
1302 rules_ids = [r['id'] for r in rules]
1303 self.assertIn(rule1['id'], rules_ids)
1304 self.assertNotIn(rule2['id'], rules_ids)
1305
1306
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001307class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,
1308 base.BaseAdminNetworkTest):
1309
1310 resource = 'policy'
1311 plural_name = 'policies'
1312
1313 # Use unique description to isolate the tests from other QoS tests
1314 list_kwargs = {'description': 'search-criteria-test'}
1315 list_as_admin = True
1316
Chandan Kumarc125fd12017-11-15 19:41:01 +05301317 required_extensions = [qos_apidef.ALIAS]
Jakub Libosvar1982aa12017-05-30 11:15:33 +00001318
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001319 @classmethod
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001320 def resource_setup(cls):
1321 super(QosSearchCriteriaTest, cls).resource_setup()
1322 for name in cls.resource_names:
1323 cls.create_qos_policy(
1324 name=name, description='search-criteria-test')
1325
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001326 @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001327 def test_list_sorts_asc(self):
1328 self._test_list_sorts_asc()
1329
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001330 @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001331 def test_list_sorts_desc(self):
1332 self._test_list_sorts_desc()
1333
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001334 @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001335 def test_list_pagination(self):
1336 self._test_list_pagination()
1337
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001338 @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001339 def test_list_pagination_with_marker(self):
1340 self._test_list_pagination_with_marker()
1341
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001342 @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001343 def test_list_pagination_with_href_links(self):
1344 self._test_list_pagination_with_href_links()
1345
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001346 @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001347 def test_list_pagination_page_reverse_asc(self):
1348 self._test_list_pagination_page_reverse_asc()
1349
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001350 @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001351 def test_list_pagination_page_reverse_desc(self):
1352 self._test_list_pagination_page_reverse_desc()
1353
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001354 @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001355 def test_list_pagination_page_reverse_with_href_links(self):
1356 self._test_list_pagination_page_reverse_with_href_links()
1357
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +00001358 @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20')
Ihar Hrachyshkab7940d92016-06-10 13:44:22 +02001359 def test_list_no_pagination_limit_0(self):
1360 self._test_list_no_pagination_limit_0()