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