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