Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1 | # 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 15 | from neutron_lib.api.definitions import qos as qos_apidef |
nfridman | 23b44ad | 2019-09-05 09:46:50 -0400 | [diff] [blame] | 16 | from neutron_lib import constants as n_constants |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 17 | from neutron_lib.services.qos import constants as qos_consts |
| 18 | from tempest.common import utils |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 19 | from tempest.lib.common.utils import data_utils |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 20 | from tempest.lib.common.utils import test_utils |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 21 | from tempest.lib import decorators |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 22 | from tempest.lib import exceptions |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 23 | |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 24 | import testscenarios |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 25 | import testtools |
| 26 | |
Chandan Kumar | 667d3d3 | 2017-09-22 12:24:06 +0530 | [diff] [blame] | 27 | from neutron_tempest_plugin.api import base |
nfridman | 07f0e78 | 2019-11-04 09:12:58 -0500 | [diff] [blame] | 28 | from neutron_tempest_plugin import config |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 29 | |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 30 | load_tests = testscenarios.load_tests_apply_scenarios |
nfridman | 07f0e78 | 2019-11-04 09:12:58 -0500 | [diff] [blame] | 31 | CONF = config.CONF |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 32 | |
| 33 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 34 | class QosTestJSON(base.BaseAdminNetworkTest): |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 35 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 36 | required_extensions = [qos_apidef.ALIAS] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 37 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 38 | @classmethod |
| 39 | def setup_clients(cls): |
| 40 | super(QosTestJSON, cls).setup_clients() |
| 41 | cls.qos_bw_limit_rule_client = \ |
| 42 | cls.os_admin.qos_limit_bandwidth_rules_client |
| 43 | |
Sławek Kapłoński | 7aa3a35 | 2017-06-19 06:35:25 +0000 | [diff] [blame] | 44 | @staticmethod |
| 45 | def _get_driver_details(rule_type_details, driver_name): |
| 46 | for driver in rule_type_details['drivers']: |
| 47 | if driver['name'] == driver_name: |
| 48 | return driver |
| 49 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 50 | def _create_qos_bw_limit_rule(self, policy_id, rule_data): |
| 51 | rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule( |
| 52 | qos_policy_id=policy_id, |
| 53 | **rule_data)['bandwidth_limit_rule'] |
| 54 | self.addCleanup( |
| 55 | test_utils.call_and_ignore_notfound_exc, |
| 56 | self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule, |
| 57 | policy_id, rule['id']) |
| 58 | return rule |
| 59 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 60 | @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 61 | def test_create_policy(self): |
| 62 | policy = self.create_qos_policy(name='test-policy', |
| 63 | description='test policy desc1', |
| 64 | shared=False) |
| 65 | |
| 66 | # Test 'show policy' |
| 67 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 68 | retrieved_policy = retrieved_policy['policy'] |
| 69 | self.assertEqual('test-policy', retrieved_policy['name']) |
| 70 | self.assertEqual('test policy desc1', retrieved_policy['description']) |
| 71 | self.assertFalse(retrieved_policy['shared']) |
| 72 | |
| 73 | # Test 'list policies' |
| 74 | policies = self.admin_client.list_qos_policies()['policies'] |
| 75 | policies_ids = [p['id'] for p in policies] |
| 76 | self.assertIn(policy['id'], policies_ids) |
| 77 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 78 | @decorators.idempotent_id('606a48e2-5403-4052-b40f-4d54b855af76') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 79 | @utils.requires_ext(extension="project-id", service="network") |
Henry Gessau | fa6c78d | 2016-10-09 19:56:09 -0400 | [diff] [blame] | 80 | def test_show_policy_has_project_id(self): |
| 81 | policy = self.create_qos_policy(name='test-policy', shared=False) |
| 82 | body = self.admin_client.show_qos_policy(policy['id']) |
| 83 | show_policy = body['policy'] |
| 84 | self.assertIn('project_id', show_policy) |
Henry Gessau | fa6c78d | 2016-10-09 19:56:09 -0400 | [diff] [blame] | 85 | self.assertEqual(self.admin_client.tenant_id, |
| 86 | show_policy['project_id']) |
Henry Gessau | fa6c78d | 2016-10-09 19:56:09 -0400 | [diff] [blame] | 87 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 88 | @decorators.idempotent_id('f8d20e92-f06d-4805-b54f-230f77715815') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 89 | def test_list_policy_filter_by_name(self): |
| 90 | self.create_qos_policy(name='test', description='test policy', |
| 91 | shared=False) |
| 92 | self.create_qos_policy(name='test2', description='test policy', |
| 93 | shared=False) |
| 94 | |
| 95 | policies = (self.admin_client. |
| 96 | list_qos_policies(name='test')['policies']) |
| 97 | self.assertEqual(1, len(policies)) |
| 98 | |
| 99 | retrieved_policy = policies[0] |
| 100 | self.assertEqual('test', retrieved_policy['name']) |
| 101 | |
likangkang01 | afd73f7 | 2020-06-01 16:53:59 +0800 | [diff] [blame] | 102 | @decorators.idempotent_id('dde0b449-a400-4a87-b5a5-4d1c413c917b') |
| 103 | def test_list_policy_sort_by_name(self): |
| 104 | policyA = 'A' + data_utils.rand_name("policy") |
| 105 | policyB = 'B' + data_utils.rand_name("policy") |
| 106 | self.create_qos_policy(name=policyA, description='test policy', |
| 107 | shared=False) |
| 108 | self.create_qos_policy(name=policyB, description='test policy', |
| 109 | shared=False) |
| 110 | |
| 111 | param = { |
| 112 | 'sort_key': 'name', |
| 113 | 'sort_dir': 'asc' |
| 114 | } |
| 115 | policies = (self.admin_client.list_qos_policies(**param)['policies']) |
| 116 | policy_names = [p['name'] for p in policies] |
| 117 | self.assertLess(policy_names.index(policyA), |
| 118 | policy_names.index(policyB)) |
| 119 | |
| 120 | param = { |
| 121 | 'sort_key': 'name', |
| 122 | 'sort_dir': 'desc' |
| 123 | } |
| 124 | policies = (self.admin_client.list_qos_policies(**param)['policies']) |
| 125 | policy_names = [p['name'] for p in policies] |
| 126 | self.assertLess(policy_names.index(policyB), |
| 127 | policy_names.index(policyA)) |
| 128 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 129 | @decorators.idempotent_id('8e88a54b-f0b2-4b7d-b061-a15d93c2c7d6') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 130 | def test_policy_update(self): |
| 131 | policy = self.create_qos_policy(name='test-policy', |
| 132 | description='', |
Rodolfo Alonso Hernandez | 1e9d1fe | 2017-02-01 15:15:16 +0000 | [diff] [blame] | 133 | shared=False, |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 134 | project_id=self.admin_client.tenant_id) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 135 | self.admin_client.update_qos_policy(policy['id'], |
| 136 | description='test policy desc2', |
| 137 | shared=True) |
| 138 | |
| 139 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 140 | retrieved_policy = retrieved_policy['policy'] |
| 141 | self.assertEqual('test policy desc2', retrieved_policy['description']) |
| 142 | self.assertTrue(retrieved_policy['shared']) |
| 143 | self.assertEqual([], retrieved_policy['rules']) |
| 144 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 145 | @decorators.idempotent_id('6e880e0f-bbfc-4e54-87c6-680f90e1b618') |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 146 | def test_policy_update_forbidden_for_regular_tenants_own_policy(self): |
| 147 | policy = self.create_qos_policy(name='test-policy', |
| 148 | description='', |
| 149 | shared=False, |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 150 | project_id=self.client.tenant_id) |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 151 | self.assertRaises( |
| 152 | exceptions.Forbidden, |
| 153 | self.client.update_qos_policy, |
| 154 | policy['id'], description='test policy') |
| 155 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 156 | @decorators.idempotent_id('4ecfd7e7-47b6-4702-be38-be9235901a87') |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 157 | def test_policy_update_forbidden_for_regular_tenants_foreign_policy(self): |
| 158 | policy = self.create_qos_policy(name='test-policy', |
| 159 | description='', |
| 160 | shared=False, |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 161 | project_id=self.admin_client.tenant_id) |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 162 | self.assertRaises( |
| 163 | exceptions.NotFound, |
| 164 | self.client.update_qos_policy, |
| 165 | policy['id'], description='test policy') |
| 166 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 167 | @decorators.idempotent_id('ee263db4-009a-4641-83e5-d0e83506ba4c') |
Sławek Kapłoński | 6bfcc75 | 2016-06-05 09:49:27 +0000 | [diff] [blame] | 168 | def test_shared_policy_update(self): |
| 169 | policy = self.create_qos_policy(name='test-policy', |
| 170 | description='', |
Rodolfo Alonso Hernandez | 1e9d1fe | 2017-02-01 15:15:16 +0000 | [diff] [blame] | 171 | shared=True, |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 172 | project_id=self.admin_client.tenant_id) |
Sławek Kapłoński | 6bfcc75 | 2016-06-05 09:49:27 +0000 | [diff] [blame] | 173 | |
| 174 | self.admin_client.update_qos_policy(policy['id'], |
| 175 | description='test policy desc2') |
| 176 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 177 | retrieved_policy = retrieved_policy['policy'] |
| 178 | self.assertTrue(retrieved_policy['shared']) |
| 179 | |
| 180 | self.admin_client.update_qos_policy(policy['id'], |
| 181 | shared=False) |
| 182 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 183 | retrieved_policy = retrieved_policy['policy'] |
| 184 | self.assertFalse(retrieved_policy['shared']) |
| 185 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 186 | @decorators.idempotent_id('1cb42653-54bd-4a9a-b888-c55e18199201') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 187 | def test_delete_policy(self): |
| 188 | policy = self.admin_client.create_qos_policy( |
| 189 | 'test-policy', 'desc', True)['policy'] |
| 190 | |
| 191 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 192 | retrieved_policy = retrieved_policy['policy'] |
| 193 | self.assertEqual('test-policy', retrieved_policy['name']) |
| 194 | |
| 195 | self.admin_client.delete_qos_policy(policy['id']) |
| 196 | self.assertRaises(exceptions.NotFound, |
| 197 | self.admin_client.show_qos_policy, policy['id']) |
| 198 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 199 | @decorators.idempotent_id('cf776f77-8d3d-49f2-8572-12d6a1557224') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 200 | def test_list_admin_rule_types(self): |
| 201 | self._test_list_rule_types(self.admin_client) |
| 202 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 203 | @decorators.idempotent_id('49c8ea35-83a9-453a-bd23-239cf3b13929') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 204 | def test_list_regular_rule_types(self): |
| 205 | self._test_list_rule_types(self.client) |
| 206 | |
| 207 | def _test_list_rule_types(self, client): |
| 208 | # List supported rule types |
Sławek Kapłoński | 566ae69 | 2017-06-25 08:37:42 +0000 | [diff] [blame] | 209 | # Since returned rule types depends on loaded backend drivers this test |
| 210 | # is checking only if returned keys are same as expected keys |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 211 | # |
| 212 | # In theory, we could make the test conditional on which ml2 drivers |
| 213 | # are enabled in gate (or more specifically, on which supported qos |
| 214 | # rules are claimed by core plugin), but that option doesn't seem to be |
karimb | d4c68e7 | 2016-06-24 14:44:11 +0200 | [diff] [blame] | 215 | # available through tempest.lib framework |
Sławek Kapłoński | 566ae69 | 2017-06-25 08:37:42 +0000 | [diff] [blame] | 216 | expected_rule_keys = ['type'] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 217 | |
| 218 | rule_types = client.list_qos_rule_types() |
| 219 | actual_list_rule_types = rule_types['rule_types'] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 220 | |
| 221 | # Verify that only required fields present in rule details |
| 222 | for rule in actual_list_rule_types: |
Sławek Kapłoński | 566ae69 | 2017-06-25 08:37:42 +0000 | [diff] [blame] | 223 | self.assertEqual(tuple(expected_rule_keys), tuple(rule.keys())) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 224 | |
Sławek Kapłoński | 7aa3a35 | 2017-06-19 06:35:25 +0000 | [diff] [blame] | 225 | @decorators.idempotent_id('8ececa21-ef97-4904-a152-9f04c90f484d') |
| 226 | def test_show_rule_type_details_as_user(self): |
| 227 | self.assertRaises( |
| 228 | exceptions.Forbidden, |
| 229 | self.client.show_qos_rule_type, |
| 230 | qos_consts.RULE_TYPE_BANDWIDTH_LIMIT) |
| 231 | |
| 232 | @decorators.idempotent_id('d0a2460b-7325-481f-a531-050bd96ab25e') |
| 233 | def test_show_rule_type_details_as_admin(self): |
| 234 | # Since returned rule types depend on loaded backend drivers this test |
| 235 | # is checking only if returned keys are same as expected keys |
| 236 | |
| 237 | # In theory, we could make the test conditional on which ml2 drivers |
| 238 | # are enabled in gate, but that option doesn't seem to be |
| 239 | # available through tempest.lib framework |
| 240 | expected_rule_type_details_keys = ['type', 'drivers'] |
| 241 | |
| 242 | rule_type_details = self.admin_client.show_qos_rule_type( |
| 243 | qos_consts.RULE_TYPE_BANDWIDTH_LIMIT).get("rule_type") |
| 244 | |
| 245 | # Verify that only required fields present in rule details |
| 246 | self.assertEqual( |
| 247 | sorted(tuple(expected_rule_type_details_keys)), |
| 248 | sorted(tuple(rule_type_details.keys()))) |
| 249 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 250 | @decorators.idempotent_id('65b9ef75-1911-406a-bbdb-ca1d68d528b0') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 251 | def test_policy_association_with_admin_network(self): |
| 252 | policy = self.create_qos_policy(name='test-policy', |
| 253 | description='test policy', |
| 254 | shared=False) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 255 | network = self.create_network('test network', shared=True, |
| 256 | qos_policy_id=policy['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 257 | |
| 258 | retrieved_network = self.admin_client.show_network(network['id']) |
| 259 | self.assertEqual( |
| 260 | policy['id'], retrieved_network['network']['qos_policy_id']) |
| 261 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 262 | @decorators.idempotent_id('1738de5d-0476-4163-9022-5e1b548c208e') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 263 | def test_policy_association_with_tenant_network(self): |
| 264 | policy = self.create_qos_policy(name='test-policy', |
| 265 | description='test policy', |
| 266 | shared=True) |
| 267 | network = self.create_network('test network', |
| 268 | qos_policy_id=policy['id']) |
| 269 | |
| 270 | retrieved_network = self.admin_client.show_network(network['id']) |
| 271 | self.assertEqual( |
| 272 | policy['id'], retrieved_network['network']['qos_policy_id']) |
| 273 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 274 | @decorators.idempotent_id('9efe63d0-836f-4cc2-b00c-468e63aa614e') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 275 | def test_policy_association_with_network_nonexistent_policy(self): |
| 276 | self.assertRaises( |
| 277 | exceptions.NotFound, |
| 278 | self.create_network, |
| 279 | 'test network', |
| 280 | qos_policy_id='9efe63d0-836f-4cc2-b00c-468e63aa614e') |
| 281 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 282 | @decorators.idempotent_id('1aa55a79-324f-47d9-a076-894a8fc2448b') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 283 | def test_policy_association_with_network_non_shared_policy(self): |
| 284 | policy = self.create_qos_policy(name='test-policy', |
| 285 | description='test policy', |
| 286 | shared=False) |
| 287 | self.assertRaises( |
| 288 | exceptions.NotFound, |
| 289 | self.create_network, |
| 290 | 'test network', qos_policy_id=policy['id']) |
| 291 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 292 | @decorators.idempotent_id('09a9392c-1359-4cbb-989f-fb768e5834a8') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 293 | def test_policy_update_association_with_admin_network(self): |
| 294 | policy = self.create_qos_policy(name='test-policy', |
| 295 | description='test policy', |
| 296 | shared=False) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 297 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 298 | retrieved_network = self.admin_client.show_network(network['id']) |
| 299 | self.assertIsNone(retrieved_network['network']['qos_policy_id']) |
| 300 | |
| 301 | self.admin_client.update_network(network['id'], |
| 302 | qos_policy_id=policy['id']) |
| 303 | retrieved_network = self.admin_client.show_network(network['id']) |
| 304 | self.assertEqual( |
| 305 | policy['id'], retrieved_network['network']['qos_policy_id']) |
| 306 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 307 | @decorators.idempotent_id('98fcd95e-84cf-4746-860e-44692e674f2e') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 308 | def test_policy_association_with_port_shared_policy(self): |
| 309 | policy = self.create_qos_policy(name='test-policy', |
| 310 | description='test policy', |
| 311 | shared=True) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 312 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 313 | port = self.create_port(network, qos_policy_id=policy['id']) |
| 314 | |
| 315 | retrieved_port = self.admin_client.show_port(port['id']) |
| 316 | self.assertEqual( |
| 317 | policy['id'], retrieved_port['port']['qos_policy_id']) |
| 318 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 319 | @decorators.idempotent_id('49e02f5a-e1dd-41d5-9855-cfa37f2d195e') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 320 | def test_policy_association_with_port_nonexistent_policy(self): |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 321 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 322 | self.assertRaises( |
| 323 | exceptions.NotFound, |
| 324 | self.create_port, |
| 325 | network, |
| 326 | qos_policy_id='49e02f5a-e1dd-41d5-9855-cfa37f2d195e') |
| 327 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 328 | @decorators.idempotent_id('f53d961c-9fe5-4422-8b66-7add972c6031') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 329 | def test_policy_association_with_port_non_shared_policy(self): |
| 330 | policy = self.create_qos_policy(name='test-policy', |
| 331 | description='test policy', |
| 332 | shared=False) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 333 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 334 | self.assertRaises( |
| 335 | exceptions.NotFound, |
| 336 | self.create_port, |
| 337 | network, qos_policy_id=policy['id']) |
| 338 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 339 | @decorators.idempotent_id('f8163237-fba9-4db5-9526-bad6d2343c76') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 340 | def test_policy_update_association_with_port_shared_policy(self): |
| 341 | policy = self.create_qos_policy(name='test-policy', |
| 342 | description='test policy', |
| 343 | shared=True) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 344 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 345 | port = self.create_port(network) |
| 346 | retrieved_port = self.admin_client.show_port(port['id']) |
| 347 | self.assertIsNone(retrieved_port['port']['qos_policy_id']) |
| 348 | |
| 349 | self.client.update_port(port['id'], qos_policy_id=policy['id']) |
| 350 | retrieved_port = self.admin_client.show_port(port['id']) |
| 351 | self.assertEqual( |
| 352 | policy['id'], retrieved_port['port']['qos_policy_id']) |
| 353 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 354 | @decorators.idempotent_id('18163237-8ba9-4db5-9525-bad6d2343c75') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 355 | def test_delete_not_allowed_if_policy_in_use_by_network(self): |
| 356 | policy = self.create_qos_policy(name='test-policy', |
| 357 | description='test policy', |
| 358 | shared=True) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 359 | self.create_network('test network', qos_policy_id=policy['id'], |
| 360 | shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 361 | self.assertRaises( |
| 362 | exceptions.Conflict, |
| 363 | self.admin_client.delete_qos_policy, policy['id']) |
| 364 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 365 | @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 366 | def test_delete_not_allowed_if_policy_in_use_by_port(self): |
| 367 | policy = self.create_qos_policy(name='test-policy', |
| 368 | description='test policy', |
| 369 | shared=True) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 370 | network = self.create_network('test network', shared=True) |
Sławek Kapłoński | e100c4d | 2017-08-23 21:18:34 +0000 | [diff] [blame] | 371 | self.create_port(network, qos_policy_id=policy['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 372 | self.assertRaises( |
| 373 | exceptions.Conflict, |
| 374 | self.admin_client.delete_qos_policy, policy['id']) |
| 375 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 376 | @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 377 | def test_qos_policy_delete_with_rules(self): |
| 378 | policy = self.create_qos_policy(name='test-policy', |
| 379 | description='test policy', |
| 380 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 381 | self._create_qos_bw_limit_rule( |
| 382 | policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337}) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 383 | self.admin_client.delete_qos_policy(policy['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 384 | with testtools.ExpectedException(exceptions.NotFound): |
| 385 | self.admin_client.show_qos_policy(policy['id']) |
| 386 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 387 | @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f') |
Jakub Libosvar | ab42ca8 | 2016-06-07 07:56:13 +0000 | [diff] [blame] | 388 | def test_get_policy_that_is_shared(self): |
| 389 | policy = self.create_qos_policy( |
| 390 | name='test-policy-shared', |
| 391 | description='shared policy', |
| 392 | shared=True, |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 393 | project_id=self.admin_client.tenant_id) |
Jakub Libosvar | ab42ca8 | 2016-06-07 07:56:13 +0000 | [diff] [blame] | 394 | obtained_policy = self.client.show_qos_policy(policy['id'])['policy'] |
| 395 | self.assertEqual(obtained_policy, policy) |
| 396 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 397 | @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 398 | def test_policy_create_forbidden_for_regular_tenants(self): |
| 399 | self.assertRaises( |
| 400 | exceptions.Forbidden, |
| 401 | self.client.create_qos_policy, |
| 402 | 'test-policy', 'test policy', False) |
| 403 | |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 404 | @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3') |
| 405 | def test_default_policy_creating_network_without_policy(self): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 406 | project_id = self.create_project()['id'] |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 407 | policy = self.create_qos_policy(name='test-policy', |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 408 | project_id=project_id, |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 409 | is_default=True) |
| 410 | network = self.create_network('test network', client=self.admin_client, |
| 411 | project_id=project_id) |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 412 | retrieved_network = self.admin_client.show_network(network['id']) |
| 413 | self.assertEqual( |
| 414 | policy['id'], retrieved_network['network']['qos_policy_id']) |
| 415 | |
| 416 | @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73') |
| 417 | def test_default_policy_creating_network_with_policy(self): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 418 | project_id = self.create_project()['id'] |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 419 | self.create_qos_policy(name='test-policy', |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 420 | project_id=project_id, |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 421 | is_default=True) |
| 422 | policy = self.create_qos_policy(name='test-policy', |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 423 | project_id=project_id) |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 424 | network = self.create_network('test network', client=self.admin_client, |
| 425 | project_id=project_id, |
| 426 | qos_policy_id=policy['id']) |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 427 | retrieved_network = self.admin_client.show_network(network['id']) |
| 428 | self.assertEqual( |
| 429 | policy['id'], retrieved_network['network']['qos_policy_id']) |
| 430 | |
Sławek Kapłoński | 508dd29 | 2018-02-22 13:41:01 +0100 | [diff] [blame] | 431 | @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229') |
| 432 | def test_user_create_port_with_admin_qos_policy(self): |
| 433 | qos_policy = self.create_qos_policy( |
| 434 | name='test-policy', |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 435 | project_id=self.admin_client.tenant_id, |
Sławek Kapłoński | 508dd29 | 2018-02-22 13:41:01 +0100 | [diff] [blame] | 436 | shared=False) |
| 437 | network = self.create_network( |
| 438 | 'test network', client=self.admin_client, |
| 439 | project_id=self.client.tenant_id, |
| 440 | qos_policy_id=qos_policy['id']) |
| 441 | port = self.create_port(network) |
| 442 | self.assertEqual(network['id'], port['network_id']) |
| 443 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 444 | |
| 445 | class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest): |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 446 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 447 | credentials = ['primary', 'admin'] |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 448 | direction = None |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 449 | required_extensions = [qos_apidef.ALIAS] |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 450 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 451 | @classmethod |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 452 | def setup_clients(cls): |
| 453 | super(QosBandwidthLimitRuleTestJSON, cls).setup_clients() |
| 454 | cls.qos_bw_limit_rule_client = \ |
| 455 | cls.os_admin.qos_limit_bandwidth_rules_client |
| 456 | cls.qos_bw_limit_rule_client_primary = \ |
| 457 | cls.os_primary.qos_limit_bandwidth_rules_client |
| 458 | |
| 459 | @classmethod |
YAMAMOTO Takashi | 3bd3d0f | 2016-12-12 11:14:58 +0900 | [diff] [blame] | 460 | @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 461 | def resource_setup(cls): |
| 462 | super(QosBandwidthLimitRuleTestJSON, cls).resource_setup() |
| 463 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 464 | def _create_qos_bw_limit_rule(self, policy_id, rule_data): |
| 465 | rule = self.qos_bw_limit_rule_client.create_limit_bandwidth_rule( |
| 466 | qos_policy_id=policy_id, |
| 467 | **rule_data)['bandwidth_limit_rule'] |
| 468 | self.addCleanup( |
| 469 | test_utils.call_and_ignore_notfound_exc, |
| 470 | self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule, |
| 471 | policy_id, rule['id']) |
| 472 | return rule |
| 473 | |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 474 | @property |
| 475 | def opposite_direction(self): |
| 476 | if self.direction == "ingress": |
| 477 | return "egress" |
| 478 | elif self.direction == "egress": |
| 479 | return "ingress" |
| 480 | else: |
| 481 | return None |
| 482 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 483 | @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 484 | def test_rule_create(self): |
| 485 | policy = self.create_qos_policy(name='test-policy', |
| 486 | description='test policy', |
| 487 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 488 | rule = self._create_qos_bw_limit_rule( |
| 489 | policy['id'], |
| 490 | {'max_kbps': 200, 'max_burst_kbps': 1337, 'direction': 'ingress'}) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 491 | |
| 492 | # Test 'show rule' |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 493 | retrieved_rule = \ |
| 494 | self.qos_bw_limit_rule_client.show_limit_bandwidth_rule( |
| 495 | policy['id'], rule['id']) |
| 496 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 497 | retrieved_rule = retrieved_rule['bandwidth_limit_rule'] |
| 498 | self.assertEqual(rule['id'], retrieved_rule['id']) |
| 499 | self.assertEqual(200, retrieved_rule['max_kbps']) |
| 500 | self.assertEqual(1337, retrieved_rule['max_burst_kbps']) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 501 | self.assertEqual('ingress', retrieved_rule['direction']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 502 | |
| 503 | # Test 'list rules' |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 504 | rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules( |
| 505 | policy['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 506 | rules = rules['bandwidth_limit_rules'] |
| 507 | rules_ids = [r['id'] for r in rules] |
| 508 | self.assertIn(rule['id'], rules_ids) |
| 509 | |
| 510 | # Test 'show policy' |
| 511 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 512 | policy_rules = retrieved_policy['policy']['rules'] |
| 513 | self.assertEqual(1, len(policy_rules)) |
| 514 | self.assertEqual(rule['id'], policy_rules[0]['id']) |
| 515 | self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT, |
| 516 | policy_rules[0]['type']) |
| 517 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 518 | @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 519 | def test_rule_create_fail_for_the_same_type(self): |
| 520 | policy = self.create_qos_policy(name='test-policy', |
| 521 | description='test policy', |
| 522 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 523 | self._create_qos_bw_limit_rule( |
| 524 | policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337}) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 525 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 526 | self.assertRaises( |
| 527 | exceptions.Conflict, |
| 528 | self._create_qos_bw_limit_rule, |
| 529 | policy['id'], |
| 530 | {'max_kbps': 201, 'max_burst_kbps': 1338}) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 531 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 532 | @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 533 | def test_rule_update(self): |
| 534 | policy = self.create_qos_policy(name='test-policy', |
| 535 | description='test policy', |
| 536 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 537 | rule = self._create_qos_bw_limit_rule( |
| 538 | policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1}) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 539 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 540 | if self.opposite_direction: |
| 541 | self.qos_bw_limit_rule_client.update_limit_bandwidth_rule( |
| 542 | policy['id'], rule['id'], |
| 543 | **{'max_kbps': 200, 'max_burst_kbps': 1337, |
| 544 | 'direction': self.opposite_direction}) |
| 545 | else: |
| 546 | self.qos_bw_limit_rule_client.update_limit_bandwidth_rule( |
| 547 | policy['id'], rule['id'], |
| 548 | **{'max_kbps': 200, 'max_burst_kbps': 1337}) |
| 549 | retrieved_policy = self.qos_bw_limit_rule_client.\ |
| 550 | show_limit_bandwidth_rule(policy['id'], rule['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 551 | retrieved_policy = retrieved_policy['bandwidth_limit_rule'] |
| 552 | self.assertEqual(200, retrieved_policy['max_kbps']) |
| 553 | self.assertEqual(1337, retrieved_policy['max_burst_kbps']) |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 554 | if self.opposite_direction: |
| 555 | self.assertEqual(self.opposite_direction, |
| 556 | retrieved_policy['direction']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 557 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 558 | @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 559 | def test_rule_delete(self): |
| 560 | policy = self.create_qos_policy(name='test-policy', |
| 561 | description='test policy', |
| 562 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 563 | rule = self._create_qos_bw_limit_rule( |
| 564 | policy['id'], {'max_kbps': 200, 'max_burst_kbps': 1337}) |
| 565 | retrieved_policy = \ |
| 566 | self.qos_bw_limit_rule_client.show_limit_bandwidth_rule( |
| 567 | policy['id'], rule['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 568 | retrieved_policy = retrieved_policy['bandwidth_limit_rule'] |
| 569 | self.assertEqual(rule['id'], retrieved_policy['id']) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 570 | self.qos_bw_limit_rule_client.delete_limit_bandwidth_rule( |
| 571 | policy['id'], rule['id']) |
| 572 | self.assertRaises( |
| 573 | exceptions.NotFound, |
| 574 | self.qos_bw_limit_rule_client.show_limit_bandwidth_rule, |
| 575 | policy['id'], rule['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 576 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 577 | @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 578 | def test_rule_create_rule_nonexistent_policy(self): |
| 579 | self.assertRaises( |
| 580 | exceptions.NotFound, |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 581 | self._create_qos_bw_limit_rule, |
| 582 | 'policy', {'max_kbps': 200, 'max_burst_kbps': 1337}) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 583 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 584 | @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 585 | def test_rule_create_forbidden_for_regular_tenants(self): |
| 586 | self.assertRaises( |
| 587 | exceptions.Forbidden, |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 588 | self.qos_bw_limit_rule_client_primary.create_limit_bandwidth_rule, |
| 589 | 'policy', **{'max_kbps': 1, 'max_burst_kbps': 2}) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 590 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 591 | @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e') |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 592 | def test_rule_update_forbidden_for_regular_tenants_own_policy(self): |
| 593 | policy = self.create_qos_policy(name='test-policy', |
| 594 | description='test policy', |
| 595 | shared=False, |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 596 | project_id=self.client.tenant_id) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 597 | rule = self._create_qos_bw_limit_rule( |
| 598 | policy['id'], |
| 599 | {'max_kbps': 1, 'max_burst_kbps': 1}) |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 600 | self.assertRaises( |
Matthew Edmonds | c13d350 | 2017-04-14 08:22:43 -0400 | [diff] [blame] | 601 | exceptions.Forbidden, |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 602 | self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule, |
| 603 | policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4}) |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 604 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 605 | @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f') |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 606 | def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self): |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 607 | policy = self.create_qos_policy( |
| 608 | name='test-policy', |
| 609 | description='test policy', |
| 610 | shared=False, |
| 611 | project_id=self.admin_client.tenant_id) |
| 612 | rule = self._create_qos_bw_limit_rule( |
| 613 | policy['id'], {'max_kbps': 1, 'max_burst_kbps': 1}) |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 614 | self.assertRaises( |
| 615 | exceptions.NotFound, |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 616 | self.qos_bw_limit_rule_client_primary.update_limit_bandwidth_rule, |
| 617 | policy['id'], rule['id'], **{'max_kbps': 2, 'max_burst_kbps': 4}) |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 618 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 619 | @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 620 | def test_get_rules_by_policy(self): |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 621 | policy1 = self.create_qos_policy( |
| 622 | name='test-policy1', |
| 623 | description='test policy1', |
| 624 | shared=False) |
| 625 | rule1 = self._create_qos_bw_limit_rule( |
| 626 | policy1['id'], {'max_kbps': 200, 'max_burst_kbps': 1337}) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 627 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 628 | policy2 = self.create_qos_policy( |
| 629 | name='test-policy2', |
| 630 | description='test policy2', |
| 631 | shared=False) |
| 632 | rule2 = self._create_qos_bw_limit_rule( |
| 633 | policy2['id'], {'max_kbps': 5000, 'max_burst_kbps': 2523}) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 634 | |
| 635 | # Test 'list rules' |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 636 | rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules( |
| 637 | policy1['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 638 | rules = rules['bandwidth_limit_rules'] |
| 639 | rules_ids = [r['id'] for r in rules] |
| 640 | self.assertIn(rule1['id'], rules_ids) |
| 641 | self.assertNotIn(rule2['id'], rules_ids) |
| 642 | |
nfridman | 07f0e78 | 2019-11-04 09:12:58 -0500 | [diff] [blame] | 643 | @testtools.skipUnless( |
| 644 | CONF.neutron_plugin_options.create_shared_resources, |
| 645 | """Creation of shared resources should be allowed, |
| 646 | setting the create_shared_resources option as 'True' is needed""") |
| 647 | @decorators.idempotent_id('d911707e-fa2c-11e9-9553-5076af30bbf5') |
| 648 | def test_attach_and_detach_a_policy_by_a_tenant(self): |
| 649 | # As an admin create an non shared QoS policy,add a rule |
| 650 | # and associate it with a network |
| 651 | self.network = self.create_network() |
| 652 | policy = self.create_qos_policy(name='test-policy', |
| 653 | description='test policy for attach', |
| 654 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 655 | self._create_qos_bw_limit_rule( |
| 656 | policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024}) |
nfridman | 07f0e78 | 2019-11-04 09:12:58 -0500 | [diff] [blame] | 657 | |
| 658 | self.admin_client.update_network( |
| 659 | self.network['id'], qos_policy_id=policy['id']) |
| 660 | |
| 661 | # As a tenant, try to detach the policy from the network |
| 662 | # The operation should be forbidden |
| 663 | self.assertRaises( |
| 664 | exceptions.Forbidden, |
| 665 | self.client.update_network, |
| 666 | self.network['id'], qos_policy_id=None) |
| 667 | |
| 668 | # As an admin, make the policy shared |
| 669 | self.admin_client.update_qos_policy(policy['id'], shared=True) |
| 670 | |
| 671 | # As a tenant, try to detach the policy from the network |
| 672 | # The operation should be allowed |
| 673 | self.client.update_network(self.network['id'], |
| 674 | qos_policy_id=None) |
| 675 | |
| 676 | retrieved_network = self.admin_client.show_network(self.network['id']) |
| 677 | self.assertIsNone(retrieved_network['network']['qos_policy_id']) |
| 678 | |
| 679 | # As a tenant, try to delete the policy from the network |
| 680 | # should be forbidden |
| 681 | self.assertRaises( |
| 682 | exceptions.Forbidden, |
| 683 | self.client.delete_qos_policy, |
| 684 | policy['id']) |
| 685 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 686 | |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 687 | class QosBandwidthLimitRuleWithDirectionTestJSON( |
Brian Haley | 6767cec | 2018-04-10 15:30:23 -0400 | [diff] [blame] | 688 | QosBandwidthLimitRuleTestJSON): |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 689 | required_extensions = ( |
| 690 | QosBandwidthLimitRuleTestJSON.required_extensions + |
| 691 | ['qos-bw-limit-direction'] |
| 692 | ) |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 693 | scenarios = [ |
| 694 | ('ingress', {'direction': 'ingress'}), |
| 695 | ('egress', {'direction': 'egress'}), |
| 696 | ] |
| 697 | |
nfridman | 7717d9c | 2019-11-25 08:58:04 -0500 | [diff] [blame] | 698 | @classmethod |
| 699 | @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT) |
| 700 | def resource_setup(cls): |
| 701 | super(QosBandwidthLimitRuleWithDirectionTestJSON, cls).resource_setup() |
| 702 | |
| 703 | @decorators.idempotent_id('c8cbe502-0f7e-11ea-8d71-362b9e155667') |
| 704 | def test_create_policy_with_multiple_rules(self): |
| 705 | # Create a policy with multiple rules |
| 706 | policy = self.create_qos_policy(name='test-policy1', |
| 707 | description='test policy1', |
| 708 | shared=False) |
| 709 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 710 | rule1 = self._create_qos_bw_limit_rule( |
| 711 | policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024, |
| 712 | 'direction': n_constants.EGRESS_DIRECTION}) |
| 713 | rule2 = self._create_qos_bw_limit_rule( |
| 714 | policy['id'], {'max_kbps': 1024, 'max_burst_kbps': 1024, |
| 715 | 'direction': n_constants.INGRESS_DIRECTION}) |
nfridman | 7717d9c | 2019-11-25 08:58:04 -0500 | [diff] [blame] | 716 | # Check that the rules were added to the policy |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 717 | rules = self.qos_bw_limit_rule_client.list_limit_bandwidth_rules( |
nfridman | 7717d9c | 2019-11-25 08:58:04 -0500 | [diff] [blame] | 718 | policy['id'])['bandwidth_limit_rules'] |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 719 | |
nfridman | 7717d9c | 2019-11-25 08:58:04 -0500 | [diff] [blame] | 720 | rules_ids = [rule['id'] for rule in rules] |
| 721 | self.assertIn(rule1['id'], rules_ids) |
| 722 | self.assertIn(rule2['id'], rules_ids) |
| 723 | |
| 724 | # Check that the rules creation fails for the same rule types |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 725 | self.assertRaises( |
| 726 | exceptions.Conflict, |
| 727 | self._create_qos_bw_limit_rule, |
| 728 | policy['id'], |
| 729 | {'max_kbps': 1025, 'max_burst_kbps': 1025, |
| 730 | 'direction': n_constants.EGRESS_DIRECTION}) |
nfridman | 7717d9c | 2019-11-25 08:58:04 -0500 | [diff] [blame] | 731 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 732 | self.assertRaises( |
| 733 | exceptions.Conflict, |
| 734 | self._create_qos_bw_limit_rule, |
| 735 | policy['id'], |
| 736 | {'max_kbps': 1025, 'max_burst_kbps': 1025, |
| 737 | 'direction': n_constants.INGRESS_DIRECTION}) |
nfridman | 7717d9c | 2019-11-25 08:58:04 -0500 | [diff] [blame] | 738 | |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 739 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 740 | class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest): |
| 741 | |
| 742 | force_tenant_isolation = True |
| 743 | credentials = ['primary', 'alt', 'admin'] |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 744 | required_extensions = [qos_apidef.ALIAS] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 745 | |
| 746 | @classmethod |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 747 | def resource_setup(cls): |
| 748 | super(RbacSharedQosPoliciesTest, cls).resource_setup() |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 749 | cls.client2 = cls.os_alt.network_client |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 750 | |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 751 | def _create_qos_policy(self, project_id=None): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 752 | args = {'name': data_utils.rand_name('test-policy'), |
| 753 | 'description': 'test policy', |
| 754 | 'shared': False, |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 755 | 'project_id': project_id} |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 756 | qos_policy = self.admin_client.create_qos_policy(**args)['policy'] |
| 757 | self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id']) |
| 758 | |
| 759 | return qos_policy |
| 760 | |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 761 | def _make_admin_policy_shared_to_project_id(self, project_id): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 762 | policy = self._create_qos_policy() |
| 763 | rbac_policy = self.admin_client.create_rbac_policy( |
| 764 | object_type='qos_policy', |
| 765 | object_id=policy['id'], |
| 766 | action='access_as_shared', |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 767 | target_tenant=project_id, |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 768 | )['rbac_policy'] |
| 769 | |
| 770 | return {'policy': policy, 'rbac_policy': rbac_policy} |
| 771 | |
| 772 | def _create_network(self, qos_policy_id, client, should_cleanup=True): |
| 773 | net = client.create_network( |
| 774 | name=data_utils.rand_name('test-network'), |
| 775 | qos_policy_id=qos_policy_id)['network'] |
| 776 | if should_cleanup: |
| 777 | self.addCleanup(client.delete_network, net['id']) |
| 778 | |
| 779 | return net |
| 780 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 781 | @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 782 | def test_policy_sharing_with_wildcard(self): |
| 783 | qos_pol = self.create_qos_policy( |
| 784 | name=data_utils.rand_name('test-policy'), |
Rodolfo Alonso Hernandez | 1e9d1fe | 2017-02-01 15:15:16 +0000 | [diff] [blame] | 785 | description='test-shared-policy', shared=False, |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 786 | project_id=self.admin_client.tenant_id) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 787 | self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies']) |
| 788 | |
| 789 | # test update shared False -> True |
| 790 | self.admin_client.update_qos_policy(qos_pol['id'], shared=True) |
| 791 | qos_pol['shared'] = True |
| 792 | self.client2.show_qos_policy(qos_pol['id']) |
| 793 | rbac_pol = {'target_tenant': '*', |
| 794 | 'tenant_id': self.admin_client.tenant_id, |
Dariusz Smigiel | f5fb4c6 | 2016-08-19 15:41:17 +0000 | [diff] [blame] | 795 | 'project_id': self.admin_client.tenant_id, |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 796 | 'object_type': 'qos_policy', |
| 797 | 'object_id': qos_pol['id'], |
| 798 | 'action': 'access_as_shared'} |
| 799 | |
| 800 | rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies'] |
| 801 | rbac_policies = [r for r in rbac_policies if r.pop('id')] |
| 802 | self.assertIn(rbac_pol, rbac_policies) |
| 803 | |
| 804 | # update shared True -> False should fail because the policy is bound |
| 805 | # to a network |
| 806 | net = self._create_network(qos_pol['id'], self.admin_client, False) |
| 807 | with testtools.ExpectedException(exceptions.Conflict): |
| 808 | self.admin_client.update_qos_policy(qos_pol['id'], shared=False) |
| 809 | |
| 810 | # delete the network, and update shared True -> False should pass now |
| 811 | self.admin_client.delete_network(net['id']) |
| 812 | self.admin_client.update_qos_policy(qos_pol['id'], shared=False) |
| 813 | qos_pol['shared'] = False |
| 814 | self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies']) |
| 815 | |
| 816 | def _create_net_bound_qos_rbacs(self): |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 817 | res = self._make_admin_policy_shared_to_project_id( |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 818 | self.client.tenant_id) |
| 819 | qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy'] |
| 820 | |
| 821 | # add a wildcard rbac rule - now the policy globally shared |
| 822 | rbac_wildcard = self.admin_client.create_rbac_policy( |
| 823 | object_type='qos_policy', |
| 824 | object_id=qos_policy['id'], |
| 825 | action='access_as_shared', |
| 826 | target_tenant='*', |
| 827 | )['rbac_policy'] |
| 828 | |
| 829 | # tenant1 now uses qos policy for net |
| 830 | self._create_network(qos_policy['id'], self.client) |
| 831 | |
| 832 | return rbac_for_client_tenant, rbac_wildcard |
| 833 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 834 | @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df') |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 835 | def test_net_bound_shared_policy_wildcard_and_project_id_wild_remove(self): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 836 | client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs() |
| 837 | # globally unshare the qos-policy, the specific share should remain |
| 838 | self.admin_client.delete_rbac_policy(wildcard_rbac['id']) |
| 839 | self.client.list_rbac_policies(id=client_rbac['id']) |
| 840 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 841 | @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee') |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 842 | def test_net_bound_shared_policy_wildcard_and_projectid_wild_remains(self): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 843 | client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs() |
| 844 | # remove client_rbac policy the wildcard share should remain |
| 845 | self.admin_client.delete_rbac_policy(client_rbac['id']) |
| 846 | self.client.list_rbac_policies(id=wildcard_rbac['id']) |
| 847 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 848 | @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df') |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 849 | def test_policy_sharing_with_wildcard_and_project_id(self): |
| 850 | res = self._make_admin_policy_shared_to_project_id( |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 851 | self.client.tenant_id) |
| 852 | qos_policy, rbac = res['policy'], res['rbac_policy'] |
| 853 | qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy'] |
| 854 | self.assertTrue(qos_pol['shared']) |
| 855 | with testtools.ExpectedException(exceptions.NotFound): |
| 856 | self.client2.show_qos_policy(qos_policy['id']) |
| 857 | |
| 858 | # make the qos-policy globally shared |
| 859 | self.admin_client.update_qos_policy(qos_policy['id'], shared=True) |
| 860 | qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy'] |
| 861 | self.assertTrue(qos_pol['shared']) |
| 862 | |
| 863 | # globally unshare the qos-policy, the specific share should remain |
| 864 | self.admin_client.update_qos_policy(qos_policy['id'], shared=False) |
| 865 | self.client.show_qos_policy(qos_policy['id']) |
| 866 | with testtools.ExpectedException(exceptions.NotFound): |
| 867 | self.client2.show_qos_policy(qos_policy['id']) |
| 868 | self.assertIn(rbac, |
| 869 | self.admin_client.list_rbac_policies()['rbac_policies']) |
| 870 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 871 | @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 872 | def test_policy_target_update(self): |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 873 | res = self._make_admin_policy_shared_to_project_id( |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 874 | self.client.tenant_id) |
| 875 | # change to client2 |
| 876 | update_res = self.admin_client.update_rbac_policy( |
| 877 | res['rbac_policy']['id'], target_tenant=self.client2.tenant_id) |
| 878 | self.assertEqual(self.client2.tenant_id, |
| 879 | update_res['rbac_policy']['target_tenant']) |
| 880 | # make sure everything else stayed the same |
| 881 | res['rbac_policy'].pop('target_tenant') |
| 882 | update_res['rbac_policy'].pop('target_tenant') |
| 883 | self.assertEqual(res['rbac_policy'], update_res['rbac_policy']) |
| 884 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 885 | @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 886 | def test_network_presence_prevents_policy_rbac_policy_deletion(self): |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 887 | res = self._make_admin_policy_shared_to_project_id( |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 888 | self.client2.tenant_id) |
| 889 | qos_policy_id = res['policy']['id'] |
| 890 | self._create_network(qos_policy_id, self.client2) |
| 891 | # a network with shared qos-policy should prevent the deletion of an |
| 892 | # rbac-policy required for it to be shared |
| 893 | with testtools.ExpectedException(exceptions.Conflict): |
| 894 | self.admin_client.delete_rbac_policy(res['rbac_policy']['id']) |
| 895 | |
| 896 | # a wildcard policy should allow the specific policy to be deleted |
| 897 | # since it allows the remaining port |
| 898 | wild = self.admin_client.create_rbac_policy( |
| 899 | object_type='qos_policy', object_id=res['policy']['id'], |
| 900 | action='access_as_shared', target_tenant='*')['rbac_policy'] |
| 901 | self.admin_client.delete_rbac_policy(res['rbac_policy']['id']) |
| 902 | |
| 903 | # now that wildcard is the only remaining, it should be subjected to |
| 904 | # the same restriction |
| 905 | with testtools.ExpectedException(exceptions.Conflict): |
| 906 | self.admin_client.delete_rbac_policy(wild['id']) |
| 907 | |
| 908 | # we can't update the policy to a different tenant |
| 909 | with testtools.ExpectedException(exceptions.Conflict): |
| 910 | self.admin_client.update_rbac_policy( |
| 911 | wild['id'], target_tenant=self.client2.tenant_id) |
| 912 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 913 | @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 914 | def test_regular_client_shares_to_another_regular_client(self): |
| 915 | # owned by self.admin_client |
| 916 | policy = self._create_qos_policy() |
| 917 | with testtools.ExpectedException(exceptions.NotFound): |
| 918 | self.client.show_qos_policy(policy['id']) |
| 919 | rbac_policy = self.admin_client.create_rbac_policy( |
| 920 | object_type='qos_policy', object_id=policy['id'], |
| 921 | action='access_as_shared', |
| 922 | target_tenant=self.client.tenant_id)['rbac_policy'] |
| 923 | self.client.show_qos_policy(policy['id']) |
| 924 | |
| 925 | self.assertIn(rbac_policy, |
| 926 | self.admin_client.list_rbac_policies()['rbac_policies']) |
| 927 | # ensure that 'client2' can't see the rbac-policy sharing the |
| 928 | # qos-policy to it because the rbac-policy belongs to 'client' |
| 929 | self.assertNotIn(rbac_policy['id'], [p['id'] for p in |
| 930 | self.client2.list_rbac_policies()['rbac_policies']]) |
| 931 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 932 | @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 933 | def test_filter_fields(self): |
| 934 | policy = self._create_qos_policy() |
| 935 | self.admin_client.create_rbac_policy( |
| 936 | object_type='qos_policy', object_id=policy['id'], |
| 937 | action='access_as_shared', target_tenant=self.client2.tenant_id) |
| 938 | field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'), |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 939 | ('project_id', 'target_tenant')) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 940 | for fields in field_args: |
| 941 | res = self.admin_client.list_rbac_policies(fields=fields) |
| 942 | self.assertEqual(set(fields), set(res['rbac_policies'][0].keys())) |
| 943 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 944 | @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 945 | def test_rbac_policy_show(self): |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 946 | res = self._make_admin_policy_shared_to_project_id( |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 947 | self.client.tenant_id) |
| 948 | p1 = res['rbac_policy'] |
| 949 | p2 = self.admin_client.create_rbac_policy( |
| 950 | object_type='qos_policy', object_id=res['policy']['id'], |
| 951 | action='access_as_shared', |
| 952 | target_tenant='*')['rbac_policy'] |
| 953 | |
| 954 | self.assertEqual( |
| 955 | p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy']) |
| 956 | self.assertEqual( |
| 957 | p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy']) |
| 958 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 959 | @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 960 | def test_filter_rbac_policies(self): |
| 961 | policy = self._create_qos_policy() |
| 962 | rbac_pol1 = self.admin_client.create_rbac_policy( |
| 963 | object_type='qos_policy', object_id=policy['id'], |
| 964 | action='access_as_shared', |
| 965 | target_tenant=self.client2.tenant_id)['rbac_policy'] |
| 966 | rbac_pol2 = self.admin_client.create_rbac_policy( |
| 967 | object_type='qos_policy', object_id=policy['id'], |
| 968 | action='access_as_shared', |
| 969 | target_tenant=self.admin_client.tenant_id)['rbac_policy'] |
| 970 | res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[ |
| 971 | 'rbac_policies'] |
| 972 | res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[ |
| 973 | 'rbac_policies'] |
| 974 | self.assertEqual(1, len(res1)) |
| 975 | self.assertEqual(1, len(res2)) |
| 976 | self.assertEqual(rbac_pol1['id'], res1[0]['id']) |
| 977 | self.assertEqual(rbac_pol2['id'], res2[0]['id']) |
| 978 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 979 | @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 980 | def test_regular_client_blocked_from_sharing_anothers_policy(self): |
Rodolfo Alonso Hernandez | e2d062f | 2020-01-14 17:11:42 +0000 | [diff] [blame] | 981 | qos_policy = self._make_admin_policy_shared_to_project_id( |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 982 | self.client.tenant_id)['policy'] |
| 983 | with testtools.ExpectedException(exceptions.BadRequest): |
| 984 | self.client.create_rbac_policy( |
| 985 | object_type='qos_policy', object_id=qos_policy['id'], |
| 986 | action='access_as_shared', |
| 987 | target_tenant=self.client2.tenant_id) |
| 988 | |
| 989 | # make sure the rbac-policy is invisible to the tenant for which it's |
| 990 | # being shared |
| 991 | self.assertFalse(self.client.list_rbac_policies()['rbac_policies']) |
| 992 | |
| 993 | |
| 994 | class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest): |
| 995 | VALID_DSCP_MARK1 = 56 |
| 996 | VALID_DSCP_MARK2 = 48 |
| 997 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 998 | required_extensions = [qos_apidef.ALIAS] |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 999 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1000 | @classmethod |
YAMAMOTO Takashi | 3bd3d0f | 2016-12-12 11:14:58 +0900 | [diff] [blame] | 1001 | @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1002 | def resource_setup(cls): |
| 1003 | super(QosDscpMarkingRuleTestJSON, cls).resource_setup() |
| 1004 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1005 | @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1006 | def test_rule_create(self): |
| 1007 | policy = self.create_qos_policy(name='test-policy', |
| 1008 | description='test policy', |
| 1009 | shared=False) |
| 1010 | rule = self.admin_client.create_dscp_marking_rule( |
| 1011 | policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 1012 | |
| 1013 | # Test 'show rule' |
| 1014 | retrieved_rule = self.admin_client.show_dscp_marking_rule( |
| 1015 | policy['id'], rule['id']) |
| 1016 | retrieved_rule = retrieved_rule['dscp_marking_rule'] |
| 1017 | self.assertEqual(rule['id'], retrieved_rule['id']) |
| 1018 | self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark']) |
| 1019 | |
| 1020 | # Test 'list rules' |
| 1021 | rules = self.admin_client.list_dscp_marking_rules(policy['id']) |
| 1022 | rules = rules['dscp_marking_rules'] |
| 1023 | rules_ids = [r['id'] for r in rules] |
| 1024 | self.assertIn(rule['id'], rules_ids) |
| 1025 | |
| 1026 | # Test 'show policy' |
| 1027 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 1028 | policy_rules = retrieved_policy['policy']['rules'] |
| 1029 | self.assertEqual(1, len(policy_rules)) |
| 1030 | self.assertEqual(rule['id'], policy_rules[0]['id']) |
David Shaughnessy | dbf2482 | 2016-03-14 16:27:54 +0000 | [diff] [blame] | 1031 | self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING, |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1032 | policy_rules[0]['type']) |
| 1033 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1034 | @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1035 | def test_rule_create_fail_for_the_same_type(self): |
| 1036 | policy = self.create_qos_policy(name='test-policy', |
| 1037 | description='test policy', |
| 1038 | shared=False) |
| 1039 | self.admin_client.create_dscp_marking_rule( |
| 1040 | policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 1041 | |
| 1042 | self.assertRaises(exceptions.Conflict, |
| 1043 | self.admin_client.create_dscp_marking_rule, |
| 1044 | policy_id=policy['id'], |
| 1045 | dscp_mark=self.VALID_DSCP_MARK2) |
| 1046 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1047 | @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1048 | def test_rule_update(self): |
| 1049 | policy = self.create_qos_policy(name='test-policy', |
| 1050 | description='test policy', |
| 1051 | shared=False) |
| 1052 | rule = self.admin_client.create_dscp_marking_rule( |
| 1053 | policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 1054 | |
| 1055 | self.admin_client.update_dscp_marking_rule( |
| 1056 | policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2) |
| 1057 | |
| 1058 | retrieved_policy = self.admin_client.show_dscp_marking_rule( |
| 1059 | policy['id'], rule['id']) |
| 1060 | retrieved_policy = retrieved_policy['dscp_marking_rule'] |
| 1061 | self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark']) |
| 1062 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1063 | @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1064 | def test_rule_delete(self): |
| 1065 | policy = self.create_qos_policy(name='test-policy', |
| 1066 | description='test policy', |
| 1067 | shared=False) |
| 1068 | rule = self.admin_client.create_dscp_marking_rule( |
| 1069 | policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 1070 | |
| 1071 | retrieved_policy = self.admin_client.show_dscp_marking_rule( |
| 1072 | policy['id'], rule['id']) |
| 1073 | retrieved_policy = retrieved_policy['dscp_marking_rule'] |
| 1074 | self.assertEqual(rule['id'], retrieved_policy['id']) |
| 1075 | |
| 1076 | self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id']) |
| 1077 | self.assertRaises(exceptions.NotFound, |
| 1078 | self.admin_client.show_dscp_marking_rule, |
| 1079 | policy['id'], rule['id']) |
| 1080 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1081 | @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1082 | def test_rule_create_rule_nonexistent_policy(self): |
| 1083 | self.assertRaises( |
| 1084 | exceptions.NotFound, |
| 1085 | self.admin_client.create_dscp_marking_rule, |
| 1086 | 'policy', self.VALID_DSCP_MARK1) |
| 1087 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1088 | @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1089 | def test_rule_create_forbidden_for_regular_tenants(self): |
| 1090 | self.assertRaises( |
| 1091 | exceptions.Forbidden, |
| 1092 | self.client.create_dscp_marking_rule, |
| 1093 | 'policy', self.VALID_DSCP_MARK1) |
| 1094 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1095 | @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1096 | def test_invalid_rule_create(self): |
| 1097 | policy = self.create_qos_policy(name='test-policy', |
| 1098 | description='test policy', |
| 1099 | shared=False) |
| 1100 | self.assertRaises( |
| 1101 | exceptions.BadRequest, |
| 1102 | self.admin_client.create_dscp_marking_rule, |
| 1103 | policy['id'], 58) |
| 1104 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1105 | @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1106 | def test_get_rules_by_policy(self): |
| 1107 | policy1 = self.create_qos_policy(name='test-policy1', |
| 1108 | description='test policy1', |
| 1109 | shared=False) |
| 1110 | rule1 = self.admin_client.create_dscp_marking_rule( |
| 1111 | policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 1112 | |
| 1113 | policy2 = self.create_qos_policy(name='test-policy2', |
| 1114 | description='test policy2', |
| 1115 | shared=False) |
| 1116 | rule2 = self.admin_client.create_dscp_marking_rule( |
| 1117 | policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule'] |
| 1118 | |
| 1119 | # Test 'list rules' |
| 1120 | rules = self.admin_client.list_dscp_marking_rules(policy1['id']) |
| 1121 | rules = rules['dscp_marking_rules'] |
| 1122 | rules_ids = [r['id'] for r in rules] |
| 1123 | self.assertIn(rule1['id'], rules_ids) |
| 1124 | self.assertNotIn(rule2['id'], rules_ids) |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1125 | |
nfridman | 23b44ad | 2019-09-05 09:46:50 -0400 | [diff] [blame] | 1126 | @decorators.idempotent_id('19ed2286-ccb1-11e9-87d7-525400d6f522') |
| 1127 | def test_qos_dscp_create_and_update(self): |
| 1128 | """This test covers: |
| 1129 | |
| 1130 | 1.Creating a basic QoS policy with DSCP marking rule. |
| 1131 | 2.Updating QoS policy: |
| 1132 | Administrator should have the ability to update existing QoS policy. |
| 1133 | This test should verify that: |
| 1134 | It's possible to update the existing DSCP marking rule with all of |
| 1135 | the valid marks between 0-56, except of the invalid marks: |
| 1136 | 2-6, 42, 44, and 50-54 (which should be forbidden) |
| 1137 | """ |
| 1138 | |
| 1139 | def _test_update_dscp_mark_values(self, dscp_policy_id, rule_id): |
| 1140 | for mark in range(n_constants.VALID_DSCP_MARKS[1], |
| 1141 | self.VALID_DSCP_MARK1 + 1): |
| 1142 | if mark in n_constants.VALID_DSCP_MARKS: |
| 1143 | self.admin_client.update_dscp_marking_rule( |
| 1144 | dscp_policy_id, rule_id, dscp_mark=mark) |
| 1145 | |
| 1146 | retrieved_rule = self.admin_client.show_dscp_marking_rule( |
| 1147 | dscp_policy_id, rule_id)['dscp_marking_rule'] |
| 1148 | self.assertEqual(mark, retrieved_rule['dscp_mark'], |
| 1149 | """current DSCP mark is incorrect: |
| 1150 | expected value {0} actual value {1} |
| 1151 | """.format(mark, |
| 1152 | retrieved_rule['dscp_mark'])) |
| 1153 | |
| 1154 | else: |
| 1155 | self.assertRaises(exceptions.BadRequest, |
| 1156 | self.admin_client.create_dscp_marking_rule, |
| 1157 | dscp_policy_id, |
| 1158 | mark) |
| 1159 | # Setup network |
| 1160 | self.network = self.create_network() |
| 1161 | |
| 1162 | # Create QoS policy |
| 1163 | dscp_policy_id = self.create_qos_policy( |
| 1164 | name='test-policy', |
| 1165 | description='test-qos-policy', |
| 1166 | shared=True)['id'] |
| 1167 | |
| 1168 | # Associate QoS to the network |
| 1169 | self.admin_client.update_network( |
| 1170 | self.network['id'], qos_policy_id=dscp_policy_id) |
| 1171 | |
| 1172 | # Set a new DSCP rule with the first mark in range |
| 1173 | rule_id = self.admin_client.create_dscp_marking_rule( |
| 1174 | dscp_policy_id, |
| 1175 | n_constants.VALID_DSCP_MARKS[0])[ |
| 1176 | 'dscp_marking_rule']['id'] |
| 1177 | |
| 1178 | # Validate that the rule was set up properly |
| 1179 | retrieved_rule = self.client.show_dscp_marking_rule( |
| 1180 | dscp_policy_id, rule_id)['dscp_marking_rule'] |
| 1181 | self.assertEqual(n_constants.VALID_DSCP_MARKS[0], |
| 1182 | retrieved_rule['dscp_mark'], |
| 1183 | """current DSCP mark is incorrect: |
| 1184 | expected value {0} actual value {1} |
| 1185 | """.format(n_constants.VALID_DSCP_MARKS[0], |
| 1186 | retrieved_rule['dscp_mark'])) |
| 1187 | |
| 1188 | # Try to set marks in range 8:56 (invalid marks should raise an error) |
| 1189 | _test_update_dscp_mark_values(self, dscp_policy_id, rule_id) |
| 1190 | |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1191 | |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1192 | class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest): |
| 1193 | DIRECTION_EGRESS = "egress" |
| 1194 | DIRECTION_INGRESS = "ingress" |
| 1195 | RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule" |
| 1196 | RULES_NAME = RULE_NAME + "s" |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 1197 | required_extensions = [qos_apidef.ALIAS] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1198 | |
| 1199 | @classmethod |
YAMAMOTO Takashi | 3bd3d0f | 2016-12-12 11:14:58 +0900 | [diff] [blame] | 1200 | @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1201 | def resource_setup(cls): |
| 1202 | super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup() |
| 1203 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1204 | @classmethod |
| 1205 | def setup_clients(cls): |
| 1206 | super(QosMinimumBandwidthRuleTestJSON, cls).setup_clients() |
| 1207 | cls.qos_min_bw_rules_client = \ |
| 1208 | cls.os_admin.qos_minimum_bandwidth_rules_client |
| 1209 | cls.qos_min_bw_rules_client_primary = \ |
| 1210 | cls.os_primary.qos_minimum_bandwidth_rules_client |
| 1211 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1212 | @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1213 | def test_rule_create(self): |
| 1214 | policy = self.create_qos_policy(name='test-policy', |
| 1215 | description='test policy', |
| 1216 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1217 | rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule( |
| 1218 | qos_policy_id=policy['id'], |
| 1219 | **{'direction': self.DIRECTION_EGRESS, |
| 1220 | 'min_kbps': 1138})[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1221 | |
| 1222 | # Test 'show rule' |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1223 | retrieved_rule = \ |
| 1224 | self.qos_min_bw_rules_client.show_minimum_bandwidth_rule( |
| 1225 | policy['id'], rule['id']) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1226 | retrieved_rule = retrieved_rule[self.RULE_NAME] |
| 1227 | self.assertEqual(rule['id'], retrieved_rule['id']) |
| 1228 | self.assertEqual(1138, retrieved_rule['min_kbps']) |
| 1229 | self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction']) |
| 1230 | |
| 1231 | # Test 'list rules' |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1232 | rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules( |
| 1233 | policy['id']) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1234 | rules = rules[self.RULES_NAME] |
| 1235 | rules_ids = [r['id'] for r in rules] |
| 1236 | self.assertIn(rule['id'], rules_ids) |
| 1237 | |
| 1238 | # Test 'show policy' |
| 1239 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 1240 | policy_rules = retrieved_policy['policy']['rules'] |
| 1241 | self.assertEqual(1, len(policy_rules)) |
| 1242 | self.assertEqual(rule['id'], policy_rules[0]['id']) |
| 1243 | self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH, |
| 1244 | policy_rules[0]['type']) |
| 1245 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1246 | @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be') |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1247 | def test_rule_create_fail_for_missing_min_kbps(self): |
| 1248 | policy = self.create_qos_policy(name='test-policy', |
| 1249 | description='test policy', |
| 1250 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1251 | self.assertRaises( |
| 1252 | exceptions.BadRequest, |
| 1253 | self.qos_min_bw_rules_client.create_minimum_bandwidth_rule, |
| 1254 | qos_policy_id=policy['id'], |
| 1255 | **{'direction': self.DIRECTION_EGRESS}) |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1256 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1257 | @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1258 | def test_rule_create_fail_for_the_same_type(self): |
| 1259 | policy = self.create_qos_policy(name='test-policy', |
| 1260 | description='test policy', |
| 1261 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1262 | self.qos_min_bw_rules_client.create_minimum_bandwidth_rule( |
| 1263 | qos_policy_id=policy['id'], |
| 1264 | **{'direction': self.DIRECTION_EGRESS, |
| 1265 | 'min_kbps': 200}) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1266 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1267 | self.assertRaises( |
| 1268 | exceptions.Conflict, |
| 1269 | self.qos_min_bw_rules_client.create_minimum_bandwidth_rule, |
| 1270 | qos_policy_id=policy['id'], |
| 1271 | **{'direction': self.DIRECTION_EGRESS, |
| 1272 | 'min_kbps': 201}) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1273 | |
Lajos Katona | dc9c6d6 | 2018-08-27 16:08:51 +0200 | [diff] [blame] | 1274 | @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936') |
| 1275 | @utils.requires_ext(extension="qos-bw-minimum-ingress", |
| 1276 | service="network") |
| 1277 | def test_rule_create_pass_for_direction_ingress(self): |
| 1278 | policy = self.create_qos_policy(name='test-policy', |
| 1279 | description='test policy', |
| 1280 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1281 | self.qos_min_bw_rules_client.create_minimum_bandwidth_rule( |
| 1282 | qos_policy_id=policy['id'], |
| 1283 | **{'direction': self.DIRECTION_INGRESS, |
| 1284 | 'min_kbps': 201}) |
Lajos Katona | dc9c6d6 | 2018-08-27 16:08:51 +0200 | [diff] [blame] | 1285 | |
| 1286 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 1287 | policy_rules = retrieved_policy['policy']['rules'] |
| 1288 | self.assertEqual(1, len(policy_rules)) |
| 1289 | self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH, |
| 1290 | policy_rules[0]['type']) |
| 1291 | self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction']) |
| 1292 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1293 | @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1294 | def test_rule_update(self): |
| 1295 | policy = self.create_qos_policy(name='test-policy', |
| 1296 | description='test policy', |
| 1297 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1298 | rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule( |
| 1299 | qos_policy_id=policy['id'], |
| 1300 | **{'direction': self.DIRECTION_EGRESS, |
| 1301 | 'min_kbps': 300})[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1302 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1303 | self.qos_min_bw_rules_client.update_minimum_bandwidth_rule( |
| 1304 | policy['id'], rule['id'], |
| 1305 | **{'min_kbps': 350, 'direction': self.DIRECTION_EGRESS}) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1306 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1307 | retrieved_policy = \ |
| 1308 | self.qos_min_bw_rules_client.show_minimum_bandwidth_rule( |
| 1309 | policy['id'], rule['id']) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1310 | retrieved_policy = retrieved_policy[self.RULE_NAME] |
| 1311 | self.assertEqual(350, retrieved_policy['min_kbps']) |
| 1312 | self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction']) |
| 1313 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1314 | @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1315 | def test_rule_delete(self): |
| 1316 | policy = self.create_qos_policy(name='test-policy', |
| 1317 | description='test policy', |
| 1318 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1319 | rule = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule( |
| 1320 | policy['id'], |
| 1321 | **{'direction': self.DIRECTION_EGRESS, |
| 1322 | 'min_kbps': 200})[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1323 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1324 | retrieved_policy = \ |
| 1325 | self.qos_min_bw_rules_client.show_minimum_bandwidth_rule( |
| 1326 | policy['id'], rule['id']) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1327 | retrieved_policy = retrieved_policy[self.RULE_NAME] |
| 1328 | self.assertEqual(rule['id'], retrieved_policy['id']) |
| 1329 | |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1330 | self.qos_min_bw_rules_client.delete_minimum_bandwidth_rule( |
| 1331 | policy['id'], rule['id']) |
| 1332 | self.assertRaises( |
| 1333 | exceptions.NotFound, |
| 1334 | self.qos_min_bw_rules_client.show_minimum_bandwidth_rule, |
| 1335 | policy['id'], rule['id']) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1336 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1337 | @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1338 | def test_rule_create_rule_nonexistent_policy(self): |
| 1339 | self.assertRaises( |
| 1340 | exceptions.NotFound, |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1341 | self.qos_min_bw_rules_client.create_minimum_bandwidth_rule, |
| 1342 | 'policy', |
| 1343 | **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 200}) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1344 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1345 | @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1346 | def test_rule_create_forbidden_for_regular_tenants(self): |
| 1347 | self.assertRaises( |
| 1348 | exceptions.Forbidden, |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1349 | self.qos_min_bw_rules_client_primary.create_minimum_bandwidth_rule, |
| 1350 | 'policy', **{'direction': self.DIRECTION_EGRESS, 'min_kbps': 300}) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1351 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1352 | @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1353 | def test_get_rules_by_policy(self): |
| 1354 | policy1 = self.create_qos_policy(name='test-policy1', |
| 1355 | description='test policy1', |
| 1356 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1357 | rule1 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule( |
| 1358 | qos_policy_id=policy1['id'], |
| 1359 | **{'direction': self.DIRECTION_EGRESS, |
| 1360 | 'min_kbps': 200})[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1361 | |
| 1362 | policy2 = self.create_qos_policy(name='test-policy2', |
| 1363 | description='test policy2', |
| 1364 | shared=False) |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1365 | rule2 = self.qos_min_bw_rules_client.create_minimum_bandwidth_rule( |
| 1366 | qos_policy_id=policy2['id'], |
| 1367 | **{'direction': self.DIRECTION_EGRESS, |
| 1368 | 'min_kbps': 5000})[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1369 | |
| 1370 | # Test 'list rules' |
zahlabut | 7ebb66e | 2021-09-01 22:39:49 +0300 | [diff] [blame] | 1371 | rules = self.qos_min_bw_rules_client.list_minimum_bandwidth_rules( |
| 1372 | policy1['id']) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1373 | rules = rules[self.RULES_NAME] |
| 1374 | rules_ids = [r['id'] for r in rules] |
| 1375 | self.assertIn(rule1['id'], rules_ids) |
| 1376 | self.assertNotIn(rule2['id'], rules_ids) |
| 1377 | |
| 1378 | |
elajkat | 4a1357b | 2021-08-31 10:16:25 +0200 | [diff] [blame^] | 1379 | class QosMinimumPpsRuleTestJSON(base.BaseAdminNetworkTest): |
| 1380 | RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_PACKET_RATE + "_rule" |
| 1381 | RULES_NAME = RULE_NAME + "s" |
| 1382 | required_extensions = [qos_apidef.ALIAS] |
| 1383 | |
| 1384 | @classmethod |
| 1385 | @utils.requires_ext(service='network', |
| 1386 | extension='port-resource-request-groups') |
| 1387 | def resource_setup(cls): |
| 1388 | super(QosMinimumPpsRuleTestJSON, cls).resource_setup() |
| 1389 | |
| 1390 | @classmethod |
| 1391 | def setup_clients(cls): |
| 1392 | super(QosMinimumPpsRuleTestJSON, cls).setup_clients() |
| 1393 | cls.min_pps_client = cls.os_admin.qos_minimum_packet_rate_rules_client |
| 1394 | cls.min_pps_client_primary = \ |
| 1395 | cls.os_primary.qos_minimum_packet_rate_rules_client |
| 1396 | |
| 1397 | def _create_qos_min_pps_rule(self, policy_id, rule_data): |
| 1398 | rule = self.min_pps_client.create_minimum_packet_rate_rule( |
| 1399 | policy_id, **rule_data)['minimum_packet_rate_rule'] |
| 1400 | self.addCleanup( |
| 1401 | test_utils.call_and_ignore_notfound_exc, |
| 1402 | self.min_pps_client.delete_minimum_packet_rate_rule, |
| 1403 | policy_id, rule['id']) |
| 1404 | return rule |
| 1405 | |
| 1406 | @decorators.idempotent_id('66a5b9b4-d4f9-4af8-b238-9e1881b78487') |
| 1407 | def test_rule_create(self): |
| 1408 | policy = self.create_qos_policy(name='test-policy', |
| 1409 | description='test policy', |
| 1410 | shared=False) |
| 1411 | rule = self._create_qos_min_pps_rule( |
| 1412 | policy['id'], |
| 1413 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1414 | qos_consts.MIN_KPPS: 1138}) |
| 1415 | |
| 1416 | # Test 'show rule' |
| 1417 | retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule( |
| 1418 | policy['id'], rule['id'])[self.RULE_NAME] |
| 1419 | self.assertEqual(rule['id'], retrieved_rule['id']) |
| 1420 | self.assertEqual(1138, retrieved_rule[qos_consts.MIN_KPPS]) |
| 1421 | self.assertEqual(n_constants.EGRESS_DIRECTION, |
| 1422 | retrieved_rule[qos_consts.DIRECTION]) |
| 1423 | |
| 1424 | # Test 'list rules' |
| 1425 | rules = self.min_pps_client.list_minimum_packet_rate_rules( |
| 1426 | policy['id']) |
| 1427 | rules = rules[self.RULES_NAME] |
| 1428 | rules_ids = [r['id'] for r in rules] |
| 1429 | self.assertIn(rule['id'], rules_ids) |
| 1430 | |
| 1431 | # Test 'show policy' |
| 1432 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 1433 | policy_rules = retrieved_policy['policy']['rules'] |
| 1434 | self.assertEqual(1, len(policy_rules)) |
| 1435 | self.assertEqual(rule['id'], policy_rules[0]['id']) |
| 1436 | self.assertEqual('minimum_packet_rate', |
| 1437 | policy_rules[0]['type']) |
| 1438 | |
| 1439 | @decorators.idempotent_id('6b656b57-d2bf-47f9-89a9-1baad1bd5418') |
| 1440 | def test_rule_create_fail_for_missing_min_kpps(self): |
| 1441 | policy = self.create_qos_policy(name='test-policy', |
| 1442 | description='test policy', |
| 1443 | shared=False) |
| 1444 | self.assertRaises(exceptions.BadRequest, |
| 1445 | self._create_qos_min_pps_rule, |
| 1446 | policy['id'], |
| 1447 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION}) |
| 1448 | |
| 1449 | @decorators.idempotent_id('f41213e5-2ab8-4916-b106-38d2cac5e18c') |
| 1450 | def test_rule_create_fail_for_the_same_type(self): |
| 1451 | policy = self.create_qos_policy(name='test-policy', |
| 1452 | description='test policy', |
| 1453 | shared=False) |
| 1454 | self._create_qos_min_pps_rule(policy['id'], |
| 1455 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1456 | qos_consts.MIN_KPPS: 200}) |
| 1457 | |
| 1458 | self.assertRaises(exceptions.Conflict, |
| 1459 | self._create_qos_min_pps_rule, |
| 1460 | policy['id'], |
| 1461 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1462 | qos_consts.MIN_KPPS: 201}) |
| 1463 | |
| 1464 | @decorators.idempotent_id('ceb8e41e-3d72-11ec-a446-d7faae6daec2') |
| 1465 | def test_rule_create_any_direction_when_egress_direction_exists(self): |
| 1466 | policy = self.create_qos_policy(name='test-policy', |
| 1467 | description='test policy', |
| 1468 | shared=False) |
| 1469 | self._create_qos_min_pps_rule(policy['id'], |
| 1470 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1471 | qos_consts.MIN_KPPS: 200}) |
| 1472 | |
| 1473 | self.assertRaises(exceptions.Conflict, |
| 1474 | self._create_qos_min_pps_rule, |
| 1475 | policy['id'], |
| 1476 | {qos_consts.DIRECTION: n_constants.ANY_DIRECTION, |
| 1477 | qos_consts.MIN_KPPS: 201}) |
| 1478 | |
| 1479 | @decorators.idempotent_id('a147a71e-3d7b-11ec-8097-278b1afd5fa2') |
| 1480 | def test_rule_create_egress_direction_when_any_direction_exists(self): |
| 1481 | policy = self.create_qos_policy(name='test-policy', |
| 1482 | description='test policy', |
| 1483 | shared=False) |
| 1484 | self._create_qos_min_pps_rule(policy['id'], |
| 1485 | {qos_consts.DIRECTION: n_constants.ANY_DIRECTION, |
| 1486 | qos_consts.MIN_KPPS: 200}) |
| 1487 | |
| 1488 | self.assertRaises(exceptions.Conflict, |
| 1489 | self._create_qos_min_pps_rule, |
| 1490 | policy['id'], |
| 1491 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1492 | qos_consts.MIN_KPPS: 201}) |
| 1493 | |
| 1494 | @decorators.idempotent_id('522ed09a-1d7f-4c1b-9195-61f19caf916f') |
| 1495 | def test_rule_update(self): |
| 1496 | policy = self.create_qos_policy(name='test-policy', |
| 1497 | description='test policy', |
| 1498 | shared=False) |
| 1499 | rule = self._create_qos_min_pps_rule( |
| 1500 | policy['id'], |
| 1501 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1502 | qos_consts.MIN_KPPS: 300}) |
| 1503 | |
| 1504 | self.min_pps_client.update_minimum_packet_rate_rule( |
| 1505 | policy['id'], rule['id'], |
| 1506 | **{qos_consts.MIN_KPPS: 350, |
| 1507 | qos_consts.DIRECTION: n_constants.ANY_DIRECTION}) |
| 1508 | |
| 1509 | retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule( |
| 1510 | policy['id'], rule['id'])[self.RULE_NAME] |
| 1511 | self.assertEqual(350, retrieved_rule[qos_consts.MIN_KPPS]) |
| 1512 | self.assertEqual(n_constants.ANY_DIRECTION, |
| 1513 | retrieved_rule[qos_consts.DIRECTION]) |
| 1514 | |
| 1515 | @decorators.idempotent_id('a020e186-3d60-11ec-88ca-d7f5eec22764') |
| 1516 | def test_rule_update_direction_conflict(self): |
| 1517 | policy = self.create_qos_policy(name='test-policy', |
| 1518 | description='test policy', |
| 1519 | shared=False) |
| 1520 | rule1 = self._create_qos_min_pps_rule( |
| 1521 | policy['id'], |
| 1522 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1523 | qos_consts.MIN_KPPS: 300}) |
| 1524 | |
| 1525 | rule2 = self._create_qos_min_pps_rule( |
| 1526 | policy['id'], |
| 1527 | {qos_consts.DIRECTION: n_constants.INGRESS_DIRECTION, |
| 1528 | qos_consts.MIN_KPPS: 300}) |
| 1529 | |
| 1530 | retrieved_rule1 = self.min_pps_client.show_minimum_packet_rate_rule( |
| 1531 | policy['id'], rule1['id'])[self.RULE_NAME] |
| 1532 | self.assertEqual(n_constants.EGRESS_DIRECTION, |
| 1533 | retrieved_rule1[qos_consts.DIRECTION]) |
| 1534 | retrieved_rule2 = self.min_pps_client.show_minimum_packet_rate_rule( |
| 1535 | policy['id'], rule2['id'])[self.RULE_NAME] |
| 1536 | self.assertEqual(n_constants.INGRESS_DIRECTION, |
| 1537 | retrieved_rule2[qos_consts.DIRECTION]) |
| 1538 | |
| 1539 | self.assertRaises(exceptions.Conflict, |
| 1540 | self.min_pps_client.update_minimum_packet_rate_rule, |
| 1541 | policy['id'], rule2['id'], |
| 1542 | **{qos_consts.DIRECTION: n_constants.ANY_DIRECTION}) |
| 1543 | |
| 1544 | @decorators.idempotent_id('c49018b6-d358-49a1-a94b-d53224165045') |
| 1545 | def test_rule_delete(self): |
| 1546 | policy = self.create_qos_policy(name='test-policy', |
| 1547 | description='test policy', |
| 1548 | shared=False) |
| 1549 | rule = self._create_qos_min_pps_rule( |
| 1550 | policy['id'], |
| 1551 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1552 | qos_consts.MIN_KPPS: 200}) |
| 1553 | |
| 1554 | retrieved_rule = self.min_pps_client.show_minimum_packet_rate_rule( |
| 1555 | policy['id'], rule['id'])[self.RULE_NAME] |
| 1556 | self.assertEqual(rule['id'], retrieved_rule['id']) |
| 1557 | |
| 1558 | self.min_pps_client.delete_minimum_packet_rate_rule(policy['id'], |
| 1559 | rule['id']) |
| 1560 | self.assertRaises(exceptions.NotFound, |
| 1561 | self.min_pps_client.show_minimum_packet_rate_rule, |
| 1562 | policy['id'], rule['id']) |
| 1563 | |
| 1564 | @decorators.idempotent_id('1a6b6128-3d3e-11ec-bf49-57b326d417c0') |
| 1565 | def test_rule_create_forbidden_for_regular_tenants(self): |
| 1566 | self.assertRaises( |
| 1567 | exceptions.Forbidden, |
| 1568 | self.min_pps_client_primary.create_minimum_packet_rate_rule, |
| 1569 | 'policy', **{qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1570 | qos_consts.MIN_KPPS: 300}) |
| 1571 | |
| 1572 | @decorators.idempotent_id('1b94f4e2-3d3e-11ec-bb21-6f98e4044b8b') |
| 1573 | def test_get_rules_by_policy(self): |
| 1574 | policy1 = self.create_qos_policy(name='test-policy1', |
| 1575 | description='test policy1', |
| 1576 | shared=False) |
| 1577 | rule1 = self._create_qos_min_pps_rule( |
| 1578 | policy1['id'], |
| 1579 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1580 | qos_consts.MIN_KPPS: 200}) |
| 1581 | |
| 1582 | policy2 = self.create_qos_policy(name='test-policy2', |
| 1583 | description='test policy2', |
| 1584 | shared=False) |
| 1585 | rule2 = self._create_qos_min_pps_rule( |
| 1586 | policy2['id'], |
| 1587 | {qos_consts.DIRECTION: n_constants.EGRESS_DIRECTION, |
| 1588 | qos_consts.MIN_KPPS: 5000}) |
| 1589 | |
| 1590 | # Test 'list rules' |
| 1591 | rules = self.min_pps_client.list_minimum_packet_rate_rules( |
| 1592 | policy1['id']) |
| 1593 | rules = rules[self.RULES_NAME] |
| 1594 | rules_ids = [r['id'] for r in rules] |
| 1595 | self.assertIn(rule1['id'], rules_ids) |
| 1596 | self.assertNotIn(rule2['id'], rules_ids) |
| 1597 | |
| 1598 | |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1599 | class QosSearchCriteriaTest(base.BaseSearchCriteriaTest, |
| 1600 | base.BaseAdminNetworkTest): |
| 1601 | |
| 1602 | resource = 'policy' |
| 1603 | plural_name = 'policies' |
| 1604 | |
| 1605 | # Use unique description to isolate the tests from other QoS tests |
| 1606 | list_kwargs = {'description': 'search-criteria-test'} |
| 1607 | list_as_admin = True |
| 1608 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 1609 | required_extensions = [qos_apidef.ALIAS] |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 1610 | |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1611 | @classmethod |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1612 | def resource_setup(cls): |
| 1613 | super(QosSearchCriteriaTest, cls).resource_setup() |
| 1614 | for name in cls.resource_names: |
| 1615 | cls.create_qos_policy( |
| 1616 | name=name, description='search-criteria-test') |
| 1617 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1618 | @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1619 | def test_list_sorts_asc(self): |
| 1620 | self._test_list_sorts_asc() |
| 1621 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1622 | @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1623 | def test_list_sorts_desc(self): |
| 1624 | self._test_list_sorts_desc() |
| 1625 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1626 | @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1627 | def test_list_pagination(self): |
| 1628 | self._test_list_pagination() |
| 1629 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1630 | @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1631 | def test_list_pagination_with_marker(self): |
| 1632 | self._test_list_pagination_with_marker() |
| 1633 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1634 | @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1635 | def test_list_pagination_with_href_links(self): |
| 1636 | self._test_list_pagination_with_href_links() |
| 1637 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1638 | @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1639 | def test_list_pagination_page_reverse_asc(self): |
| 1640 | self._test_list_pagination_page_reverse_asc() |
| 1641 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1642 | @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1643 | def test_list_pagination_page_reverse_desc(self): |
| 1644 | self._test_list_pagination_page_reverse_desc() |
| 1645 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1646 | @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1647 | def test_list_pagination_page_reverse_with_href_links(self): |
| 1648 | self._test_list_pagination_page_reverse_with_href_links() |
| 1649 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1650 | @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1651 | def test_list_no_pagination_limit_0(self): |
| 1652 | self._test_list_no_pagination_limit_0() |