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