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) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 212 | network = self.create_network('test network', shared=True, |
| 213 | qos_policy_id=policy['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 254 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 269 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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): |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 278 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 290 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 301 | network = self.create_network('test network', shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 302 | 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) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 316 | self.create_network('test network', qos_policy_id=policy['id'], |
| 317 | shared=True) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 318 | self.assertRaises( |
| 319 | exceptions.Conflict, |
| 320 | self.admin_client.delete_qos_policy, policy['id']) |
| 321 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 322 | @decorators.idempotent_id('24153230-84a9-4dd5-9525-bad6d2343c75') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 323 | def test_delete_not_allowed_if_policy_in_use_by_port(self): |
| 324 | policy = self.create_qos_policy(name='test-policy', |
| 325 | description='test policy', |
| 326 | shared=True) |
Federico Ressi | 2d7db2c | 2018-07-06 08:11:20 +0200 | [diff] [blame] | 327 | network = self.create_network('test network', shared=True) |
Sławek Kapłoński | e100c4d | 2017-08-23 21:18:34 +0000 | [diff] [blame] | 328 | self.create_port(network, qos_policy_id=policy['id']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 329 | self.assertRaises( |
| 330 | exceptions.Conflict, |
| 331 | self.admin_client.delete_qos_policy, policy['id']) |
| 332 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 333 | @decorators.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 334 | def test_qos_policy_delete_with_rules(self): |
| 335 | policy = self.create_qos_policy(name='test-policy', |
| 336 | description='test policy', |
| 337 | shared=False) |
| 338 | self.admin_client.create_bandwidth_limit_rule( |
| 339 | policy['id'], 200, 1337)['bandwidth_limit_rule'] |
| 340 | |
| 341 | self.admin_client.delete_qos_policy(policy['id']) |
| 342 | |
| 343 | with testtools.ExpectedException(exceptions.NotFound): |
| 344 | self.admin_client.show_qos_policy(policy['id']) |
| 345 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 346 | @decorators.idempotent_id('fb384bde-a973-41c3-a542-6f77a092155f') |
Jakub Libosvar | ab42ca8 | 2016-06-07 07:56:13 +0000 | [diff] [blame] | 347 | def test_get_policy_that_is_shared(self): |
| 348 | policy = self.create_qos_policy( |
| 349 | name='test-policy-shared', |
| 350 | description='shared policy', |
| 351 | shared=True, |
| 352 | tenant_id=self.admin_client.tenant_id) |
| 353 | obtained_policy = self.client.show_qos_policy(policy['id'])['policy'] |
| 354 | self.assertEqual(obtained_policy, policy) |
| 355 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 356 | @decorators.idempotent_id('aed8e2a6-22da-421b-89b9-935a2c1a1b50') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 357 | def test_policy_create_forbidden_for_regular_tenants(self): |
| 358 | self.assertRaises( |
| 359 | exceptions.Forbidden, |
| 360 | self.client.create_qos_policy, |
| 361 | 'test-policy', 'test policy', False) |
| 362 | |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 363 | @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3') |
| 364 | def test_default_policy_creating_network_without_policy(self): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 365 | project_id = self.create_project()['id'] |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 366 | policy = self.create_qos_policy(name='test-policy', |
| 367 | tenant_id=project_id, |
| 368 | is_default=True) |
| 369 | network = self.create_network('test network', client=self.admin_client, |
| 370 | project_id=project_id) |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 371 | retrieved_network = self.admin_client.show_network(network['id']) |
| 372 | self.assertEqual( |
| 373 | policy['id'], retrieved_network['network']['qos_policy_id']) |
| 374 | |
| 375 | @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73') |
| 376 | def test_default_policy_creating_network_with_policy(self): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 377 | project_id = self.create_project()['id'] |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 378 | self.create_qos_policy(name='test-policy', |
| 379 | tenant_id=project_id, |
| 380 | is_default=True) |
| 381 | policy = self.create_qos_policy(name='test-policy', |
| 382 | tenant_id=project_id) |
| 383 | network = self.create_network('test network', client=self.admin_client, |
| 384 | project_id=project_id, |
| 385 | qos_policy_id=policy['id']) |
Hirofumi Ichihara | 39a6ee1 | 2017-08-23 13:55:12 +0900 | [diff] [blame] | 386 | retrieved_network = self.admin_client.show_network(network['id']) |
| 387 | self.assertEqual( |
| 388 | policy['id'], retrieved_network['network']['qos_policy_id']) |
| 389 | |
Sławek Kapłoński | 508dd29 | 2018-02-22 13:41:01 +0100 | [diff] [blame] | 390 | @decorators.idempotent_id('06060880-2956-4c16-9a63-f284c3879229') |
| 391 | def test_user_create_port_with_admin_qos_policy(self): |
| 392 | qos_policy = self.create_qos_policy( |
| 393 | name='test-policy', |
| 394 | tenant_id=self.admin_client.tenant_id, |
| 395 | shared=False) |
| 396 | network = self.create_network( |
| 397 | 'test network', client=self.admin_client, |
| 398 | project_id=self.client.tenant_id, |
| 399 | qos_policy_id=qos_policy['id']) |
| 400 | port = self.create_port(network) |
| 401 | self.assertEqual(network['id'], port['network_id']) |
| 402 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 403 | |
| 404 | class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest): |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 405 | |
| 406 | direction = None |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 407 | required_extensions = [qos_apidef.ALIAS] |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 408 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 409 | @classmethod |
YAMAMOTO Takashi | 3bd3d0f | 2016-12-12 11:14:58 +0900 | [diff] [blame] | 410 | @base.require_qos_rule_type(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 411 | def resource_setup(cls): |
| 412 | super(QosBandwidthLimitRuleTestJSON, cls).resource_setup() |
| 413 | |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 414 | @property |
| 415 | def opposite_direction(self): |
| 416 | if self.direction == "ingress": |
| 417 | return "egress" |
| 418 | elif self.direction == "egress": |
| 419 | return "ingress" |
| 420 | else: |
| 421 | return None |
| 422 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 423 | @decorators.idempotent_id('8a59b00b-3e9c-4787-92f8-93a5cdf5e378') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 424 | def test_rule_create(self): |
| 425 | policy = self.create_qos_policy(name='test-policy', |
| 426 | description='test policy', |
| 427 | shared=False) |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 428 | rule = self.create_qos_bandwidth_limit_rule( |
| 429 | policy_id=policy['id'], |
| 430 | max_kbps=200, |
| 431 | max_burst_kbps=1337, |
| 432 | direction=self.direction) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 433 | |
| 434 | # Test 'show rule' |
| 435 | retrieved_rule = self.admin_client.show_bandwidth_limit_rule( |
| 436 | policy['id'], rule['id']) |
| 437 | retrieved_rule = retrieved_rule['bandwidth_limit_rule'] |
| 438 | self.assertEqual(rule['id'], retrieved_rule['id']) |
| 439 | self.assertEqual(200, retrieved_rule['max_kbps']) |
| 440 | self.assertEqual(1337, retrieved_rule['max_burst_kbps']) |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 441 | if self.direction: |
| 442 | self.assertEqual(self.direction, retrieved_rule['direction']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 443 | |
| 444 | # Test 'list rules' |
| 445 | rules = self.admin_client.list_bandwidth_limit_rules(policy['id']) |
| 446 | rules = rules['bandwidth_limit_rules'] |
| 447 | rules_ids = [r['id'] for r in rules] |
| 448 | self.assertIn(rule['id'], rules_ids) |
| 449 | |
| 450 | # Test 'show policy' |
| 451 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 452 | policy_rules = retrieved_policy['policy']['rules'] |
| 453 | self.assertEqual(1, len(policy_rules)) |
| 454 | self.assertEqual(rule['id'], policy_rules[0]['id']) |
| 455 | self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT, |
| 456 | policy_rules[0]['type']) |
| 457 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 458 | @decorators.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 459 | def test_rule_create_fail_for_the_same_type(self): |
| 460 | policy = self.create_qos_policy(name='test-policy', |
| 461 | description='test policy', |
| 462 | shared=False) |
| 463 | self.create_qos_bandwidth_limit_rule(policy_id=policy['id'], |
| 464 | max_kbps=200, |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 465 | max_burst_kbps=1337, |
| 466 | direction=self.direction) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 467 | |
| 468 | self.assertRaises(exceptions.Conflict, |
| 469 | self.create_qos_bandwidth_limit_rule, |
| 470 | policy_id=policy['id'], |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 471 | max_kbps=201, max_burst_kbps=1338, |
| 472 | direction=self.direction) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 473 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 474 | @decorators.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 475 | def test_rule_update(self): |
| 476 | policy = self.create_qos_policy(name='test-policy', |
| 477 | description='test policy', |
| 478 | shared=False) |
| 479 | rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'], |
| 480 | max_kbps=1, |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 481 | max_burst_kbps=1, |
| 482 | direction=self.direction) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 483 | |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 484 | self.admin_client.update_bandwidth_limit_rule( |
| 485 | policy['id'], |
| 486 | rule['id'], |
| 487 | max_kbps=200, |
| 488 | max_burst_kbps=1337, |
| 489 | direction=self.opposite_direction) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 490 | |
| 491 | retrieved_policy = self.admin_client.show_bandwidth_limit_rule( |
| 492 | policy['id'], rule['id']) |
| 493 | retrieved_policy = retrieved_policy['bandwidth_limit_rule'] |
| 494 | self.assertEqual(200, retrieved_policy['max_kbps']) |
| 495 | self.assertEqual(1337, retrieved_policy['max_burst_kbps']) |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 496 | if self.opposite_direction: |
| 497 | self.assertEqual(self.opposite_direction, |
| 498 | retrieved_policy['direction']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 499 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 500 | @decorators.idempotent_id('67ee6efd-7b33-4a68-927d-275b4f8ba958') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 501 | def test_rule_delete(self): |
| 502 | policy = self.create_qos_policy(name='test-policy', |
| 503 | description='test policy', |
| 504 | shared=False) |
| 505 | rule = self.admin_client.create_bandwidth_limit_rule( |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 506 | policy['id'], 200, 1337, self.direction)['bandwidth_limit_rule'] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 507 | |
| 508 | retrieved_policy = self.admin_client.show_bandwidth_limit_rule( |
| 509 | policy['id'], rule['id']) |
| 510 | retrieved_policy = retrieved_policy['bandwidth_limit_rule'] |
| 511 | self.assertEqual(rule['id'], retrieved_policy['id']) |
| 512 | |
| 513 | self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id']) |
| 514 | self.assertRaises(exceptions.NotFound, |
| 515 | self.admin_client.show_bandwidth_limit_rule, |
| 516 | policy['id'], rule['id']) |
| 517 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 518 | @decorators.idempotent_id('f211222c-5808-46cb-a961-983bbab6b852') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 519 | def test_rule_create_rule_nonexistent_policy(self): |
| 520 | self.assertRaises( |
| 521 | exceptions.NotFound, |
| 522 | self.create_qos_bandwidth_limit_rule, |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 523 | 'policy', 200, 1337, self.direction) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 524 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 525 | @decorators.idempotent_id('a4a2e7ad-786f-4927-a85a-e545a93bd274') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 526 | def test_rule_create_forbidden_for_regular_tenants(self): |
| 527 | self.assertRaises( |
| 528 | exceptions.Forbidden, |
| 529 | self.client.create_bandwidth_limit_rule, |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 530 | 'policy', 1, 2, self.direction) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 531 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 532 | @decorators.idempotent_id('1bfc55d9-6fd8-4293-ab3a-b1d69bf7cd2e') |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 533 | def test_rule_update_forbidden_for_regular_tenants_own_policy(self): |
| 534 | policy = self.create_qos_policy(name='test-policy', |
| 535 | description='test policy', |
| 536 | shared=False, |
| 537 | tenant_id=self.client.tenant_id) |
| 538 | rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'], |
| 539 | max_kbps=1, |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 540 | max_burst_kbps=1, |
| 541 | direction=self.direction) |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 542 | self.assertRaises( |
Matthew Edmonds | c13d350 | 2017-04-14 08:22:43 -0400 | [diff] [blame] | 543 | exceptions.Forbidden, |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 544 | self.client.update_bandwidth_limit_rule, |
| 545 | policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4) |
| 546 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 547 | @decorators.idempotent_id('9a607936-4b6f-4c2f-ad21-bd5b3d4fc91f') |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 548 | def test_rule_update_forbidden_for_regular_tenants_foreign_policy(self): |
| 549 | policy = self.create_qos_policy(name='test-policy', |
| 550 | description='test policy', |
| 551 | shared=False, |
| 552 | tenant_id=self.admin_client.tenant_id) |
| 553 | rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'], |
| 554 | max_kbps=1, |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 555 | max_burst_kbps=1, |
| 556 | direction=self.direction) |
Sławek Kapłoński | 0acecc6 | 2016-08-20 21:00:51 +0000 | [diff] [blame] | 557 | self.assertRaises( |
| 558 | exceptions.NotFound, |
| 559 | self.client.update_bandwidth_limit_rule, |
| 560 | policy['id'], rule['id'], max_kbps=2, max_burst_kbps=4) |
| 561 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 562 | @decorators.idempotent_id('ce0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 563 | def test_get_rules_by_policy(self): |
| 564 | policy1 = self.create_qos_policy(name='test-policy1', |
| 565 | description='test policy1', |
| 566 | shared=False) |
| 567 | rule1 = self.create_qos_bandwidth_limit_rule(policy_id=policy1['id'], |
| 568 | max_kbps=200, |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 569 | max_burst_kbps=1337, |
| 570 | direction=self.direction) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 571 | |
| 572 | policy2 = self.create_qos_policy(name='test-policy2', |
| 573 | description='test policy2', |
| 574 | shared=False) |
| 575 | rule2 = self.create_qos_bandwidth_limit_rule(policy_id=policy2['id'], |
| 576 | max_kbps=5000, |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 577 | max_burst_kbps=2523, |
| 578 | direction=self.direction) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 579 | |
| 580 | # Test 'list rules' |
| 581 | rules = self.admin_client.list_bandwidth_limit_rules(policy1['id']) |
| 582 | rules = rules['bandwidth_limit_rules'] |
| 583 | rules_ids = [r['id'] for r in rules] |
| 584 | self.assertIn(rule1['id'], rules_ids) |
| 585 | self.assertNotIn(rule2['id'], rules_ids) |
| 586 | |
| 587 | |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 588 | class QosBandwidthLimitRuleWithDirectionTestJSON( |
Brian Haley | 6767cec | 2018-04-10 15:30:23 -0400 | [diff] [blame] | 589 | QosBandwidthLimitRuleTestJSON): |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 590 | |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 591 | required_extensions = ( |
| 592 | QosBandwidthLimitRuleTestJSON.required_extensions + |
| 593 | ['qos-bw-limit-direction'] |
| 594 | ) |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 595 | scenarios = [ |
| 596 | ('ingress', {'direction': 'ingress'}), |
| 597 | ('egress', {'direction': 'egress'}), |
| 598 | ] |
| 599 | |
Sławek Kapłoński | 153f345 | 2017-03-24 22:04:53 +0000 | [diff] [blame] | 600 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 601 | class RbacSharedQosPoliciesTest(base.BaseAdminNetworkTest): |
| 602 | |
| 603 | force_tenant_isolation = True |
| 604 | credentials = ['primary', 'alt', 'admin'] |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 605 | required_extensions = [qos_apidef.ALIAS] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 606 | |
| 607 | @classmethod |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 608 | def resource_setup(cls): |
| 609 | super(RbacSharedQosPoliciesTest, cls).resource_setup() |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 610 | cls.client2 = cls.os_alt.network_client |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 611 | |
| 612 | def _create_qos_policy(self, tenant_id=None): |
| 613 | args = {'name': data_utils.rand_name('test-policy'), |
| 614 | 'description': 'test policy', |
| 615 | 'shared': False, |
| 616 | 'tenant_id': tenant_id} |
| 617 | qos_policy = self.admin_client.create_qos_policy(**args)['policy'] |
| 618 | self.addCleanup(self.admin_client.delete_qos_policy, qos_policy['id']) |
| 619 | |
| 620 | return qos_policy |
| 621 | |
| 622 | def _make_admin_policy_shared_to_tenant_id(self, tenant_id): |
| 623 | policy = self._create_qos_policy() |
| 624 | rbac_policy = self.admin_client.create_rbac_policy( |
| 625 | object_type='qos_policy', |
| 626 | object_id=policy['id'], |
| 627 | action='access_as_shared', |
| 628 | target_tenant=tenant_id, |
| 629 | )['rbac_policy'] |
| 630 | |
| 631 | return {'policy': policy, 'rbac_policy': rbac_policy} |
| 632 | |
| 633 | def _create_network(self, qos_policy_id, client, should_cleanup=True): |
| 634 | net = client.create_network( |
| 635 | name=data_utils.rand_name('test-network'), |
| 636 | qos_policy_id=qos_policy_id)['network'] |
| 637 | if should_cleanup: |
| 638 | self.addCleanup(client.delete_network, net['id']) |
| 639 | |
| 640 | return net |
| 641 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 642 | @decorators.idempotent_id('b9dcf582-d3b3-11e5-950a-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 643 | def test_policy_sharing_with_wildcard(self): |
| 644 | qos_pol = self.create_qos_policy( |
| 645 | name=data_utils.rand_name('test-policy'), |
Rodolfo Alonso Hernandez | 1e9d1fe | 2017-02-01 15:15:16 +0000 | [diff] [blame] | 646 | description='test-shared-policy', shared=False, |
| 647 | tenant_id=self.admin_client.tenant_id) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 648 | self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies']) |
| 649 | |
| 650 | # test update shared False -> True |
| 651 | self.admin_client.update_qos_policy(qos_pol['id'], shared=True) |
| 652 | qos_pol['shared'] = True |
| 653 | self.client2.show_qos_policy(qos_pol['id']) |
| 654 | rbac_pol = {'target_tenant': '*', |
| 655 | 'tenant_id': self.admin_client.tenant_id, |
Dariusz Smigiel | f5fb4c6 | 2016-08-19 15:41:17 +0000 | [diff] [blame] | 656 | 'project_id': self.admin_client.tenant_id, |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 657 | 'object_type': 'qos_policy', |
| 658 | 'object_id': qos_pol['id'], |
| 659 | 'action': 'access_as_shared'} |
| 660 | |
| 661 | rbac_policies = self.admin_client.list_rbac_policies()['rbac_policies'] |
| 662 | rbac_policies = [r for r in rbac_policies if r.pop('id')] |
| 663 | self.assertIn(rbac_pol, rbac_policies) |
| 664 | |
| 665 | # update shared True -> False should fail because the policy is bound |
| 666 | # to a network |
| 667 | net = self._create_network(qos_pol['id'], self.admin_client, False) |
| 668 | with testtools.ExpectedException(exceptions.Conflict): |
| 669 | self.admin_client.update_qos_policy(qos_pol['id'], shared=False) |
| 670 | |
| 671 | # delete the network, and update shared True -> False should pass now |
| 672 | self.admin_client.delete_network(net['id']) |
| 673 | self.admin_client.update_qos_policy(qos_pol['id'], shared=False) |
| 674 | qos_pol['shared'] = False |
| 675 | self.assertNotIn(qos_pol, self.client2.list_qos_policies()['policies']) |
| 676 | |
| 677 | def _create_net_bound_qos_rbacs(self): |
| 678 | res = self._make_admin_policy_shared_to_tenant_id( |
| 679 | self.client.tenant_id) |
| 680 | qos_policy, rbac_for_client_tenant = res['policy'], res['rbac_policy'] |
| 681 | |
| 682 | # add a wildcard rbac rule - now the policy globally shared |
| 683 | rbac_wildcard = self.admin_client.create_rbac_policy( |
| 684 | object_type='qos_policy', |
| 685 | object_id=qos_policy['id'], |
| 686 | action='access_as_shared', |
| 687 | target_tenant='*', |
| 688 | )['rbac_policy'] |
| 689 | |
| 690 | # tenant1 now uses qos policy for net |
| 691 | self._create_network(qos_policy['id'], self.client) |
| 692 | |
| 693 | return rbac_for_client_tenant, rbac_wildcard |
| 694 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 695 | @decorators.idempotent_id('328b1f70-d424-11e5-a57f-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 696 | def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remove(self): |
| 697 | client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs() |
| 698 | # globally unshare the qos-policy, the specific share should remain |
| 699 | self.admin_client.delete_rbac_policy(wildcard_rbac['id']) |
| 700 | self.client.list_rbac_policies(id=client_rbac['id']) |
| 701 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 702 | @decorators.idempotent_id('1997b00c-0c75-4e43-8ce2-999f9fa555ee') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 703 | def test_net_bound_shared_policy_wildcard_and_tenant_id_wild_remains(self): |
| 704 | client_rbac, wildcard_rbac = self._create_net_bound_qos_rbacs() |
| 705 | # remove client_rbac policy the wildcard share should remain |
| 706 | self.admin_client.delete_rbac_policy(client_rbac['id']) |
| 707 | self.client.list_rbac_policies(id=wildcard_rbac['id']) |
| 708 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 709 | @decorators.idempotent_id('2ace9adc-da6e-11e5-aafe-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 710 | def test_policy_sharing_with_wildcard_and_tenant_id(self): |
| 711 | res = self._make_admin_policy_shared_to_tenant_id( |
| 712 | self.client.tenant_id) |
| 713 | qos_policy, rbac = res['policy'], res['rbac_policy'] |
| 714 | qos_pol = self.client.show_qos_policy(qos_policy['id'])['policy'] |
| 715 | self.assertTrue(qos_pol['shared']) |
| 716 | with testtools.ExpectedException(exceptions.NotFound): |
| 717 | self.client2.show_qos_policy(qos_policy['id']) |
| 718 | |
| 719 | # make the qos-policy globally shared |
| 720 | self.admin_client.update_qos_policy(qos_policy['id'], shared=True) |
| 721 | qos_pol = self.client2.show_qos_policy(qos_policy['id'])['policy'] |
| 722 | self.assertTrue(qos_pol['shared']) |
| 723 | |
| 724 | # globally unshare the qos-policy, the specific share should remain |
| 725 | self.admin_client.update_qos_policy(qos_policy['id'], shared=False) |
| 726 | self.client.show_qos_policy(qos_policy['id']) |
| 727 | with testtools.ExpectedException(exceptions.NotFound): |
| 728 | self.client2.show_qos_policy(qos_policy['id']) |
| 729 | self.assertIn(rbac, |
| 730 | self.admin_client.list_rbac_policies()['rbac_policies']) |
| 731 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 732 | @decorators.idempotent_id('9f85c76a-a350-11e5-8ae5-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 733 | def test_policy_target_update(self): |
| 734 | res = self._make_admin_policy_shared_to_tenant_id( |
| 735 | self.client.tenant_id) |
| 736 | # change to client2 |
| 737 | update_res = self.admin_client.update_rbac_policy( |
| 738 | res['rbac_policy']['id'], target_tenant=self.client2.tenant_id) |
| 739 | self.assertEqual(self.client2.tenant_id, |
| 740 | update_res['rbac_policy']['target_tenant']) |
| 741 | # make sure everything else stayed the same |
| 742 | res['rbac_policy'].pop('target_tenant') |
| 743 | update_res['rbac_policy'].pop('target_tenant') |
| 744 | self.assertEqual(res['rbac_policy'], update_res['rbac_policy']) |
| 745 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 746 | @decorators.idempotent_id('a9b39f46-a350-11e5-97c7-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 747 | def test_network_presence_prevents_policy_rbac_policy_deletion(self): |
| 748 | res = self._make_admin_policy_shared_to_tenant_id( |
| 749 | self.client2.tenant_id) |
| 750 | qos_policy_id = res['policy']['id'] |
| 751 | self._create_network(qos_policy_id, self.client2) |
| 752 | # a network with shared qos-policy should prevent the deletion of an |
| 753 | # rbac-policy required for it to be shared |
| 754 | with testtools.ExpectedException(exceptions.Conflict): |
| 755 | self.admin_client.delete_rbac_policy(res['rbac_policy']['id']) |
| 756 | |
| 757 | # a wildcard policy should allow the specific policy to be deleted |
| 758 | # since it allows the remaining port |
| 759 | wild = self.admin_client.create_rbac_policy( |
| 760 | object_type='qos_policy', object_id=res['policy']['id'], |
| 761 | action='access_as_shared', target_tenant='*')['rbac_policy'] |
| 762 | self.admin_client.delete_rbac_policy(res['rbac_policy']['id']) |
| 763 | |
| 764 | # now that wildcard is the only remaining, it should be subjected to |
| 765 | # the same restriction |
| 766 | with testtools.ExpectedException(exceptions.Conflict): |
| 767 | self.admin_client.delete_rbac_policy(wild['id']) |
| 768 | |
| 769 | # we can't update the policy to a different tenant |
| 770 | with testtools.ExpectedException(exceptions.Conflict): |
| 771 | self.admin_client.update_rbac_policy( |
| 772 | wild['id'], target_tenant=self.client2.tenant_id) |
| 773 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 774 | @decorators.idempotent_id('b0fe87e8-a350-11e5-9f08-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 775 | def test_regular_client_shares_to_another_regular_client(self): |
| 776 | # owned by self.admin_client |
| 777 | policy = self._create_qos_policy() |
| 778 | with testtools.ExpectedException(exceptions.NotFound): |
| 779 | self.client.show_qos_policy(policy['id']) |
| 780 | rbac_policy = self.admin_client.create_rbac_policy( |
| 781 | object_type='qos_policy', object_id=policy['id'], |
| 782 | action='access_as_shared', |
| 783 | target_tenant=self.client.tenant_id)['rbac_policy'] |
| 784 | self.client.show_qos_policy(policy['id']) |
| 785 | |
| 786 | self.assertIn(rbac_policy, |
| 787 | self.admin_client.list_rbac_policies()['rbac_policies']) |
| 788 | # ensure that 'client2' can't see the rbac-policy sharing the |
| 789 | # qos-policy to it because the rbac-policy belongs to 'client' |
| 790 | self.assertNotIn(rbac_policy['id'], [p['id'] for p in |
| 791 | self.client2.list_rbac_policies()['rbac_policies']]) |
| 792 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 793 | @decorators.idempotent_id('ba88d0ca-a350-11e5-a06f-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 794 | def test_filter_fields(self): |
| 795 | policy = self._create_qos_policy() |
| 796 | self.admin_client.create_rbac_policy( |
| 797 | object_type='qos_policy', object_id=policy['id'], |
| 798 | action='access_as_shared', target_tenant=self.client2.tenant_id) |
| 799 | field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'), |
| 800 | ('tenant_id', 'target_tenant')) |
| 801 | for fields in field_args: |
| 802 | res = self.admin_client.list_rbac_policies(fields=fields) |
| 803 | self.assertEqual(set(fields), set(res['rbac_policies'][0].keys())) |
| 804 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 805 | @decorators.idempotent_id('c10d993a-a350-11e5-9c7a-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 806 | def test_rbac_policy_show(self): |
| 807 | res = self._make_admin_policy_shared_to_tenant_id( |
| 808 | self.client.tenant_id) |
| 809 | p1 = res['rbac_policy'] |
| 810 | p2 = self.admin_client.create_rbac_policy( |
| 811 | object_type='qos_policy', object_id=res['policy']['id'], |
| 812 | action='access_as_shared', |
| 813 | target_tenant='*')['rbac_policy'] |
| 814 | |
| 815 | self.assertEqual( |
| 816 | p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy']) |
| 817 | self.assertEqual( |
| 818 | p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy']) |
| 819 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 820 | @decorators.idempotent_id('c7496f86-a350-11e5-b380-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 821 | def test_filter_rbac_policies(self): |
| 822 | policy = self._create_qos_policy() |
| 823 | rbac_pol1 = self.admin_client.create_rbac_policy( |
| 824 | object_type='qos_policy', object_id=policy['id'], |
| 825 | action='access_as_shared', |
| 826 | target_tenant=self.client2.tenant_id)['rbac_policy'] |
| 827 | rbac_pol2 = self.admin_client.create_rbac_policy( |
| 828 | object_type='qos_policy', object_id=policy['id'], |
| 829 | action='access_as_shared', |
| 830 | target_tenant=self.admin_client.tenant_id)['rbac_policy'] |
| 831 | res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[ |
| 832 | 'rbac_policies'] |
| 833 | res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[ |
| 834 | 'rbac_policies'] |
| 835 | self.assertEqual(1, len(res1)) |
| 836 | self.assertEqual(1, len(res2)) |
| 837 | self.assertEqual(rbac_pol1['id'], res1[0]['id']) |
| 838 | self.assertEqual(rbac_pol2['id'], res2[0]['id']) |
| 839 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 840 | @decorators.idempotent_id('cd7d755a-a350-11e5-a344-54ee756c66df') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 841 | def test_regular_client_blocked_from_sharing_anothers_policy(self): |
| 842 | qos_policy = self._make_admin_policy_shared_to_tenant_id( |
| 843 | self.client.tenant_id)['policy'] |
| 844 | with testtools.ExpectedException(exceptions.BadRequest): |
| 845 | self.client.create_rbac_policy( |
| 846 | object_type='qos_policy', object_id=qos_policy['id'], |
| 847 | action='access_as_shared', |
| 848 | target_tenant=self.client2.tenant_id) |
| 849 | |
| 850 | # make sure the rbac-policy is invisible to the tenant for which it's |
| 851 | # being shared |
| 852 | self.assertFalse(self.client.list_rbac_policies()['rbac_policies']) |
| 853 | |
| 854 | |
| 855 | class QosDscpMarkingRuleTestJSON(base.BaseAdminNetworkTest): |
| 856 | VALID_DSCP_MARK1 = 56 |
| 857 | VALID_DSCP_MARK2 = 48 |
| 858 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 859 | required_extensions = [qos_apidef.ALIAS] |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 860 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 861 | @classmethod |
YAMAMOTO Takashi | 3bd3d0f | 2016-12-12 11:14:58 +0900 | [diff] [blame] | 862 | @base.require_qos_rule_type(qos_consts.RULE_TYPE_DSCP_MARKING) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 863 | def resource_setup(cls): |
| 864 | super(QosDscpMarkingRuleTestJSON, cls).resource_setup() |
| 865 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 866 | @decorators.idempotent_id('f5cbaceb-5829-497c-9c60-ad70969e9a08') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 867 | def test_rule_create(self): |
| 868 | policy = self.create_qos_policy(name='test-policy', |
| 869 | description='test policy', |
| 870 | shared=False) |
| 871 | rule = self.admin_client.create_dscp_marking_rule( |
| 872 | policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 873 | |
| 874 | # Test 'show rule' |
| 875 | retrieved_rule = self.admin_client.show_dscp_marking_rule( |
| 876 | policy['id'], rule['id']) |
| 877 | retrieved_rule = retrieved_rule['dscp_marking_rule'] |
| 878 | self.assertEqual(rule['id'], retrieved_rule['id']) |
| 879 | self.assertEqual(self.VALID_DSCP_MARK1, retrieved_rule['dscp_mark']) |
| 880 | |
| 881 | # Test 'list rules' |
| 882 | rules = self.admin_client.list_dscp_marking_rules(policy['id']) |
| 883 | rules = rules['dscp_marking_rules'] |
| 884 | rules_ids = [r['id'] for r in rules] |
| 885 | self.assertIn(rule['id'], rules_ids) |
| 886 | |
| 887 | # Test 'show policy' |
| 888 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 889 | policy_rules = retrieved_policy['policy']['rules'] |
| 890 | self.assertEqual(1, len(policy_rules)) |
| 891 | self.assertEqual(rule['id'], policy_rules[0]['id']) |
David Shaughnessy | dbf2482 | 2016-03-14 16:27:54 +0000 | [diff] [blame] | 892 | self.assertEqual(qos_consts.RULE_TYPE_DSCP_MARKING, |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 893 | policy_rules[0]['type']) |
| 894 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 895 | @decorators.idempotent_id('08553ffe-030f-4037-b486-7e0b8fb9385a') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 896 | def test_rule_create_fail_for_the_same_type(self): |
| 897 | policy = self.create_qos_policy(name='test-policy', |
| 898 | description='test policy', |
| 899 | shared=False) |
| 900 | self.admin_client.create_dscp_marking_rule( |
| 901 | policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 902 | |
| 903 | self.assertRaises(exceptions.Conflict, |
| 904 | self.admin_client.create_dscp_marking_rule, |
| 905 | policy_id=policy['id'], |
| 906 | dscp_mark=self.VALID_DSCP_MARK2) |
| 907 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 908 | @decorators.idempotent_id('76f632e5-3175-4408-9a32-3625e599c8a2') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 909 | def test_rule_update(self): |
| 910 | policy = self.create_qos_policy(name='test-policy', |
| 911 | description='test policy', |
| 912 | shared=False) |
| 913 | rule = self.admin_client.create_dscp_marking_rule( |
| 914 | policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 915 | |
| 916 | self.admin_client.update_dscp_marking_rule( |
| 917 | policy['id'], rule['id'], dscp_mark=self.VALID_DSCP_MARK2) |
| 918 | |
| 919 | retrieved_policy = self.admin_client.show_dscp_marking_rule( |
| 920 | policy['id'], rule['id']) |
| 921 | retrieved_policy = retrieved_policy['dscp_marking_rule'] |
| 922 | self.assertEqual(self.VALID_DSCP_MARK2, retrieved_policy['dscp_mark']) |
| 923 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 924 | @decorators.idempotent_id('74f81904-c35f-48a3-adae-1f5424cb3c18') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 925 | def test_rule_delete(self): |
| 926 | policy = self.create_qos_policy(name='test-policy', |
| 927 | description='test policy', |
| 928 | shared=False) |
| 929 | rule = self.admin_client.create_dscp_marking_rule( |
| 930 | policy['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 931 | |
| 932 | retrieved_policy = self.admin_client.show_dscp_marking_rule( |
| 933 | policy['id'], rule['id']) |
| 934 | retrieved_policy = retrieved_policy['dscp_marking_rule'] |
| 935 | self.assertEqual(rule['id'], retrieved_policy['id']) |
| 936 | |
| 937 | self.admin_client.delete_dscp_marking_rule(policy['id'], rule['id']) |
| 938 | self.assertRaises(exceptions.NotFound, |
| 939 | self.admin_client.show_dscp_marking_rule, |
| 940 | policy['id'], rule['id']) |
| 941 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 942 | @decorators.idempotent_id('9cb8ef5c-96fc-4978-9ee0-e3b02bab628a') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 943 | def test_rule_create_rule_nonexistent_policy(self): |
| 944 | self.assertRaises( |
| 945 | exceptions.NotFound, |
| 946 | self.admin_client.create_dscp_marking_rule, |
| 947 | 'policy', self.VALID_DSCP_MARK1) |
| 948 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 949 | @decorators.idempotent_id('bf6002ea-29de-486f-b65d-08aea6d4c4e2') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 950 | def test_rule_create_forbidden_for_regular_tenants(self): |
| 951 | self.assertRaises( |
| 952 | exceptions.Forbidden, |
| 953 | self.client.create_dscp_marking_rule, |
| 954 | 'policy', self.VALID_DSCP_MARK1) |
| 955 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 956 | @decorators.idempotent_id('33646b08-4f05-4493-a48a-bde768a18533') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 957 | def test_invalid_rule_create(self): |
| 958 | policy = self.create_qos_policy(name='test-policy', |
| 959 | description='test policy', |
| 960 | shared=False) |
| 961 | self.assertRaises( |
| 962 | exceptions.BadRequest, |
| 963 | self.admin_client.create_dscp_marking_rule, |
| 964 | policy['id'], 58) |
| 965 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 966 | @decorators.idempotent_id('c565131d-4c80-4231-b0f3-9ae2be4de129') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 967 | def test_get_rules_by_policy(self): |
| 968 | policy1 = self.create_qos_policy(name='test-policy1', |
| 969 | description='test policy1', |
| 970 | shared=False) |
| 971 | rule1 = self.admin_client.create_dscp_marking_rule( |
| 972 | policy1['id'], self.VALID_DSCP_MARK1)['dscp_marking_rule'] |
| 973 | |
| 974 | policy2 = self.create_qos_policy(name='test-policy2', |
| 975 | description='test policy2', |
| 976 | shared=False) |
| 977 | rule2 = self.admin_client.create_dscp_marking_rule( |
| 978 | policy2['id'], self.VALID_DSCP_MARK2)['dscp_marking_rule'] |
| 979 | |
| 980 | # Test 'list rules' |
| 981 | rules = self.admin_client.list_dscp_marking_rules(policy1['id']) |
| 982 | rules = rules['dscp_marking_rules'] |
| 983 | rules_ids = [r['id'] for r in rules] |
| 984 | self.assertIn(rule1['id'], rules_ids) |
| 985 | self.assertNotIn(rule2['id'], rules_ids) |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 986 | |
| 987 | |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 988 | class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest): |
| 989 | DIRECTION_EGRESS = "egress" |
| 990 | DIRECTION_INGRESS = "ingress" |
| 991 | RULE_NAME = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH + "_rule" |
| 992 | RULES_NAME = RULE_NAME + "s" |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 993 | required_extensions = [qos_apidef.ALIAS] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 994 | |
| 995 | @classmethod |
YAMAMOTO Takashi | 3bd3d0f | 2016-12-12 11:14:58 +0900 | [diff] [blame] | 996 | @base.require_qos_rule_type(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 997 | def resource_setup(cls): |
| 998 | super(QosMinimumBandwidthRuleTestJSON, cls).resource_setup() |
| 999 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1000 | @decorators.idempotent_id('aa59b00b-3e9c-4787-92f8-93a5cdf5e378') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1001 | def test_rule_create(self): |
| 1002 | policy = self.create_qos_policy(name='test-policy', |
| 1003 | description='test policy', |
| 1004 | shared=False) |
| 1005 | rule = self.admin_client.create_minimum_bandwidth_rule( |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1006 | policy_id=policy['id'], |
| 1007 | direction=self.DIRECTION_EGRESS, |
| 1008 | min_kbps=1138)[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1009 | |
| 1010 | # Test 'show rule' |
| 1011 | retrieved_rule = self.admin_client.show_minimum_bandwidth_rule( |
| 1012 | policy['id'], rule['id']) |
| 1013 | retrieved_rule = retrieved_rule[self.RULE_NAME] |
| 1014 | self.assertEqual(rule['id'], retrieved_rule['id']) |
| 1015 | self.assertEqual(1138, retrieved_rule['min_kbps']) |
| 1016 | self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction']) |
| 1017 | |
| 1018 | # Test 'list rules' |
| 1019 | rules = self.admin_client.list_minimum_bandwidth_rules(policy['id']) |
| 1020 | rules = rules[self.RULES_NAME] |
| 1021 | rules_ids = [r['id'] for r in rules] |
| 1022 | self.assertIn(rule['id'], rules_ids) |
| 1023 | |
| 1024 | # Test 'show policy' |
| 1025 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 1026 | policy_rules = retrieved_policy['policy']['rules'] |
| 1027 | self.assertEqual(1, len(policy_rules)) |
| 1028 | self.assertEqual(rule['id'], policy_rules[0]['id']) |
| 1029 | self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH, |
| 1030 | policy_rules[0]['type']) |
| 1031 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1032 | @decorators.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be') |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1033 | def test_rule_create_fail_for_missing_min_kbps(self): |
| 1034 | policy = self.create_qos_policy(name='test-policy', |
| 1035 | description='test policy', |
| 1036 | shared=False) |
| 1037 | self.assertRaises(exceptions.BadRequest, |
| 1038 | self.admin_client.create_minimum_bandwidth_rule, |
| 1039 | policy_id=policy['id'], |
| 1040 | direction=self.DIRECTION_EGRESS) |
| 1041 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1042 | @decorators.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1043 | def test_rule_create_fail_for_the_same_type(self): |
| 1044 | policy = self.create_qos_policy(name='test-policy', |
| 1045 | description='test policy', |
| 1046 | shared=False) |
| 1047 | self.admin_client.create_minimum_bandwidth_rule( |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1048 | policy_id=policy['id'], |
| 1049 | direction=self.DIRECTION_EGRESS, min_kbps=200) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1050 | |
| 1051 | self.assertRaises(exceptions.Conflict, |
| 1052 | self.admin_client.create_minimum_bandwidth_rule, |
| 1053 | policy_id=policy['id'], |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1054 | direction=self.DIRECTION_EGRESS, min_kbps=201) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1055 | |
Lajos Katona | dc9c6d6 | 2018-08-27 16:08:51 +0200 | [diff] [blame] | 1056 | @decorators.idempotent_id('35baf998-ae65-495c-9902-35a0d11e8936') |
| 1057 | @utils.requires_ext(extension="qos-bw-minimum-ingress", |
| 1058 | service="network") |
| 1059 | def test_rule_create_pass_for_direction_ingress(self): |
| 1060 | policy = self.create_qos_policy(name='test-policy', |
| 1061 | description='test policy', |
| 1062 | shared=False) |
| 1063 | self.admin_client.create_minimum_bandwidth_rule( |
| 1064 | policy_id=policy['id'], |
| 1065 | direction=self.DIRECTION_INGRESS, |
| 1066 | min_kbps=201) |
| 1067 | |
| 1068 | retrieved_policy = self.admin_client.show_qos_policy(policy['id']) |
| 1069 | policy_rules = retrieved_policy['policy']['rules'] |
| 1070 | self.assertEqual(1, len(policy_rules)) |
| 1071 | self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH, |
| 1072 | policy_rules[0]['type']) |
| 1073 | self.assertEqual(self.DIRECTION_INGRESS, policy_rules[0]['direction']) |
| 1074 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1075 | @decorators.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1076 | def test_rule_update(self): |
| 1077 | policy = self.create_qos_policy(name='test-policy', |
| 1078 | description='test policy', |
| 1079 | shared=False) |
| 1080 | rule = self.admin_client.create_minimum_bandwidth_rule( |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1081 | policy_id=policy['id'], |
| 1082 | direction=self.DIRECTION_EGRESS, |
| 1083 | min_kbps=300)[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1084 | |
| 1085 | self.admin_client.update_minimum_bandwidth_rule(policy['id'], |
| 1086 | rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS) |
| 1087 | |
| 1088 | retrieved_policy = self.admin_client.show_minimum_bandwidth_rule( |
| 1089 | policy['id'], rule['id']) |
| 1090 | retrieved_policy = retrieved_policy[self.RULE_NAME] |
| 1091 | self.assertEqual(350, retrieved_policy['min_kbps']) |
| 1092 | self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction']) |
| 1093 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1094 | @decorators.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1095 | def test_rule_delete(self): |
| 1096 | policy = self.create_qos_policy(name='test-policy', |
| 1097 | description='test policy', |
| 1098 | shared=False) |
| 1099 | rule = self.admin_client.create_minimum_bandwidth_rule( |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1100 | policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1101 | |
| 1102 | retrieved_policy = self.admin_client.show_minimum_bandwidth_rule( |
| 1103 | policy['id'], rule['id']) |
| 1104 | retrieved_policy = retrieved_policy[self.RULE_NAME] |
| 1105 | self.assertEqual(rule['id'], retrieved_policy['id']) |
| 1106 | |
| 1107 | self.admin_client.delete_minimum_bandwidth_rule(policy['id'], |
| 1108 | rule['id']) |
| 1109 | self.assertRaises(exceptions.NotFound, |
| 1110 | self.admin_client.show_minimum_bandwidth_rule, |
| 1111 | policy['id'], rule['id']) |
| 1112 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1113 | @decorators.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1114 | def test_rule_create_rule_nonexistent_policy(self): |
| 1115 | self.assertRaises( |
| 1116 | exceptions.NotFound, |
| 1117 | self.admin_client.create_minimum_bandwidth_rule, |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1118 | 'policy', self.DIRECTION_EGRESS, min_kbps=200) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1119 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1120 | @decorators.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1121 | def test_rule_create_forbidden_for_regular_tenants(self): |
| 1122 | self.assertRaises( |
| 1123 | exceptions.Forbidden, |
| 1124 | self.client.create_minimum_bandwidth_rule, |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1125 | 'policy', self.DIRECTION_EGRESS, min_kbps=300) |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1126 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1127 | @decorators.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2') |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1128 | def test_get_rules_by_policy(self): |
| 1129 | policy1 = self.create_qos_policy(name='test-policy1', |
| 1130 | description='test policy1', |
| 1131 | shared=False) |
| 1132 | rule1 = self.admin_client.create_minimum_bandwidth_rule( |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1133 | policy_id=policy1['id'], |
| 1134 | direction=self.DIRECTION_EGRESS, |
| 1135 | min_kbps=200)[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1136 | |
| 1137 | policy2 = self.create_qos_policy(name='test-policy2', |
| 1138 | description='test policy2', |
| 1139 | shared=False) |
| 1140 | rule2 = self.admin_client.create_minimum_bandwidth_rule( |
Ihar Hrachyshka | 33034bf | 2016-08-31 18:48:14 +0000 | [diff] [blame] | 1141 | policy_id=policy2['id'], |
| 1142 | direction=self.DIRECTION_EGRESS, |
| 1143 | min_kbps=5000)[self.RULE_NAME] |
Rodolfo Alonso Hernandez | e4c099f | 2016-07-18 11:52:12 +0100 | [diff] [blame] | 1144 | |
| 1145 | # Test 'list rules' |
| 1146 | rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id']) |
| 1147 | rules = rules[self.RULES_NAME] |
| 1148 | rules_ids = [r['id'] for r in rules] |
| 1149 | self.assertIn(rule1['id'], rules_ids) |
| 1150 | self.assertNotIn(rule2['id'], rules_ids) |
| 1151 | |
| 1152 | |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1153 | class QosSearchCriteriaTest(base.BaseSearchCriteriaTest, |
| 1154 | base.BaseAdminNetworkTest): |
| 1155 | |
| 1156 | resource = 'policy' |
| 1157 | plural_name = 'policies' |
| 1158 | |
| 1159 | # Use unique description to isolate the tests from other QoS tests |
| 1160 | list_kwargs = {'description': 'search-criteria-test'} |
| 1161 | list_as_admin = True |
| 1162 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 1163 | required_extensions = [qos_apidef.ALIAS] |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 1164 | |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1165 | @classmethod |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1166 | def resource_setup(cls): |
| 1167 | super(QosSearchCriteriaTest, cls).resource_setup() |
| 1168 | for name in cls.resource_names: |
| 1169 | cls.create_qos_policy( |
| 1170 | name=name, description='search-criteria-test') |
| 1171 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1172 | @decorators.idempotent_id('55fc0103-fdc1-4d34-ab62-c579bb739a91') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1173 | def test_list_sorts_asc(self): |
| 1174 | self._test_list_sorts_asc() |
| 1175 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1176 | @decorators.idempotent_id('13e08ac3-bfed-426b-892a-b3b158560c23') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1177 | def test_list_sorts_desc(self): |
| 1178 | self._test_list_sorts_desc() |
| 1179 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1180 | @decorators.idempotent_id('719e61cc-e33c-4918-aa4d-1a791e6e0e86') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1181 | def test_list_pagination(self): |
| 1182 | self._test_list_pagination() |
| 1183 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1184 | @decorators.idempotent_id('3bd8fb58-c0f8-4954-87fb-f286e1eb096a') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1185 | def test_list_pagination_with_marker(self): |
| 1186 | self._test_list_pagination_with_marker() |
| 1187 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1188 | @decorators.idempotent_id('3bad0747-8082-46e9-be4d-c428a842db41') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1189 | def test_list_pagination_with_href_links(self): |
| 1190 | self._test_list_pagination_with_href_links() |
| 1191 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1192 | @decorators.idempotent_id('d6a8bacd-d5e8-4ef3-bc55-23ca6998d208') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1193 | def test_list_pagination_page_reverse_asc(self): |
| 1194 | self._test_list_pagination_page_reverse_asc() |
| 1195 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1196 | @decorators.idempotent_id('0b9aecdc-2b27-421b-b104-53d24e905ae8') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1197 | def test_list_pagination_page_reverse_desc(self): |
| 1198 | self._test_list_pagination_page_reverse_desc() |
| 1199 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1200 | @decorators.idempotent_id('1a3dc257-dafd-4870-8c71-639ae7ddc6ea') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1201 | def test_list_pagination_page_reverse_with_href_links(self): |
| 1202 | self._test_list_pagination_page_reverse_with_href_links() |
| 1203 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 1204 | @decorators.idempotent_id('40e09b53-4eb8-4526-9181-d438c8005a20') |
Ihar Hrachyshka | b7940d9 | 2016-06-10 13:44:22 +0200 | [diff] [blame] | 1205 | def test_list_no_pagination_limit_0(self): |
| 1206 | self._test_list_no_pagination_limit_0() |