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