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