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