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