Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 1 | # Copyright 2015 Hewlett-Packard Development Company, L.P. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
Igor Malinovskiy | 649c018 | 2020-03-06 17:30:47 +0200 | [diff] [blame^] | 15 | import testtools |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 16 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 17 | from tempest.common import utils |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 18 | from tempest.lib.common.utils import data_utils |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 19 | from tempest.lib import decorators |
Igor Malinovskiy | 649c018 | 2020-03-06 17:30:47 +0200 | [diff] [blame^] | 20 | from tempest.lib import exceptions as lib_exc |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 21 | |
Chandan Kumar | 667d3d3 | 2017-09-22 12:24:06 +0530 | [diff] [blame] | 22 | from neutron_tempest_plugin.api import base |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 23 | |
| 24 | SUBNETPOOL_NAME = 'smoke-subnetpool' |
| 25 | SUBNET_NAME = 'smoke-subnet' |
| 26 | |
| 27 | |
| 28 | class SubnetPoolsTestBase(base.BaseAdminNetworkTest): |
| 29 | |
| 30 | @classmethod |
| 31 | def resource_setup(cls): |
| 32 | super(SubnetPoolsTestBase, cls).resource_setup() |
| 33 | min_prefixlen = '29' |
| 34 | prefixes = [u'10.11.12.0/24'] |
| 35 | cls._subnetpool_data = {'prefixes': prefixes, |
| 36 | 'min_prefixlen': min_prefixlen} |
| 37 | |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 38 | @classmethod |
| 39 | def _create_subnetpool(cls, is_admin=False, **kwargs): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 40 | if 'name' not in kwargs: |
| 41 | name = data_utils.rand_name(SUBNETPOOL_NAME) |
| 42 | else: |
| 43 | name = kwargs.pop('name') |
| 44 | |
| 45 | if 'prefixes' not in kwargs: |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 46 | kwargs['prefixes'] = cls._subnetpool_data['prefixes'] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 47 | |
| 48 | if 'min_prefixlen' not in kwargs: |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 49 | kwargs['min_prefixlen'] = cls._subnetpool_data['min_prefixlen'] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 50 | |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 51 | return cls.create_subnetpool(name=name, is_admin=is_admin, **kwargs) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | class SubnetPoolsTest(SubnetPoolsTestBase): |
| 55 | |
| 56 | min_prefixlen = '28' |
Lucas Alvares Gomes | 7ff60d8 | 2018-04-09 16:28:49 +0100 | [diff] [blame] | 57 | max_prefixlen = '30' |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 58 | _ip_version = 4 |
Lucas Alvares Gomes | 7ff60d8 | 2018-04-09 16:28:49 +0100 | [diff] [blame] | 59 | subnet_cidr = u'10.11.12.0/29' |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 60 | new_prefix = u'10.11.15.0/24' |
| 61 | larger_prefix = u'10.11.0.0/16' |
| 62 | |
Brian Haley | ae328b9 | 2018-10-09 19:51:54 -0400 | [diff] [blame] | 63 | """Test Subnet Pools |
| 64 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 65 | Tests the following operations in the Neutron API using the REST client for |
| 66 | Neutron: |
| 67 | |
| 68 | create a subnetpool for a tenant |
| 69 | list tenant's subnetpools |
| 70 | show a tenant subnetpool details |
| 71 | subnetpool update |
| 72 | delete a subnetpool |
| 73 | |
| 74 | All subnetpool tests are run once with ipv4 and once with ipv6. |
| 75 | |
| 76 | v2.0 of the Neutron API is assumed. |
| 77 | |
| 78 | """ |
| 79 | |
| 80 | def _new_subnetpool_attributes(self): |
| 81 | new_name = data_utils.rand_name(SUBNETPOOL_NAME) |
| 82 | return {'name': new_name, 'min_prefixlen': self.min_prefixlen, |
| 83 | 'max_prefixlen': self.max_prefixlen} |
| 84 | |
| 85 | def _check_equality_updated_subnetpool(self, expected_values, |
| 86 | updated_pool): |
| 87 | self.assertEqual(expected_values['name'], |
| 88 | updated_pool['name']) |
| 89 | self.assertEqual(expected_values['min_prefixlen'], |
| 90 | updated_pool['min_prefixlen']) |
| 91 | self.assertEqual(expected_values['max_prefixlen'], |
| 92 | updated_pool['max_prefixlen']) |
| 93 | # expected_values may not contains all subnetpool values |
| 94 | if 'prefixes' in expected_values: |
| 95 | self.assertEqual(expected_values['prefixes'], |
| 96 | updated_pool['prefixes']) |
| 97 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 98 | @decorators.idempotent_id('6e1781ec-b45b-4042-aebe-f485c022996e') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 99 | def test_create_list_subnetpool(self): |
| 100 | created_subnetpool = self._create_subnetpool() |
| 101 | body = self.client.list_subnetpools() |
| 102 | subnetpools = body['subnetpools'] |
| 103 | self.assertIn(created_subnetpool['id'], |
| 104 | [sp['id'] for sp in subnetpools], |
| 105 | "Created subnetpool id should be in the list") |
| 106 | self.assertIn(created_subnetpool['name'], |
| 107 | [sp['name'] for sp in subnetpools], |
| 108 | "Created subnetpool name should be in the list") |
| 109 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 110 | @decorators.idempotent_id('c72c1c0c-2193-4aca-ddd4-b1442640bbbb') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 111 | @utils.requires_ext(extension="standard-attr-description", |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 112 | service="network") |
| 113 | def test_create_update_subnetpool_description(self): |
| 114 | body = self._create_subnetpool(description='d1') |
| 115 | self.assertEqual('d1', body['description']) |
| 116 | sub_id = body['id'] |
Nguyen Phuong An | c486b97 | 2016-08-29 18:15:30 +0700 | [diff] [blame] | 117 | subnet_pools = [x for x in |
| 118 | self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id] |
| 119 | body = subnet_pools[0] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 120 | self.assertEqual('d1', body['description']) |
| 121 | body = self.client.update_subnetpool(sub_id, description='d2') |
| 122 | self.assertEqual('d2', body['subnetpool']['description']) |
Nguyen Phuong An | c486b97 | 2016-08-29 18:15:30 +0700 | [diff] [blame] | 123 | subnet_pools = [x for x in |
| 124 | self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id] |
| 125 | body = subnet_pools[0] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 126 | self.assertEqual('d2', body['description']) |
| 127 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 128 | @decorators.idempotent_id('741d08c2-1e3f-42be-99c7-0ea93c5b728c') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 129 | def test_get_subnetpool(self): |
| 130 | created_subnetpool = self._create_subnetpool() |
| 131 | prefixlen = self._subnetpool_data['min_prefixlen'] |
| 132 | body = self.client.show_subnetpool(created_subnetpool['id']) |
| 133 | subnetpool = body['subnetpool'] |
| 134 | self.assertEqual(created_subnetpool['name'], subnetpool['name']) |
| 135 | self.assertEqual(created_subnetpool['id'], subnetpool['id']) |
| 136 | self.assertEqual(prefixlen, subnetpool['min_prefixlen']) |
| 137 | self.assertEqual(prefixlen, subnetpool['default_prefixlen']) |
| 138 | self.assertFalse(subnetpool['shared']) |
| 139 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 140 | @decorators.idempotent_id('5bf9f1e2-efc8-4195-acf3-d12b2bd68dd3') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 141 | @utils.requires_ext(extension="project-id", service="network") |
Henry Gessau | fa6c78d | 2016-10-09 19:56:09 -0400 | [diff] [blame] | 142 | def test_show_subnetpool_has_project_id(self): |
| 143 | subnetpool = self._create_subnetpool() |
| 144 | body = self.client.show_subnetpool(subnetpool['id']) |
| 145 | show_subnetpool = body['subnetpool'] |
| 146 | self.assertIn('project_id', show_subnetpool) |
| 147 | self.assertIn('tenant_id', show_subnetpool) |
| 148 | self.assertEqual(self.client.tenant_id, show_subnetpool['project_id']) |
| 149 | self.assertEqual(self.client.tenant_id, show_subnetpool['tenant_id']) |
| 150 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 151 | @decorators.idempotent_id('764f1b93-1c4a-4513-9e7b-6c2fc5e9270c') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 152 | def test_tenant_update_subnetpool(self): |
| 153 | created_subnetpool = self._create_subnetpool() |
| 154 | pool_id = created_subnetpool['id'] |
| 155 | subnetpool_data = self._new_subnetpool_attributes() |
| 156 | self.client.update_subnetpool(created_subnetpool['id'], |
| 157 | **subnetpool_data) |
| 158 | |
| 159 | body = self.client.show_subnetpool(pool_id) |
| 160 | subnetpool = body['subnetpool'] |
| 161 | self._check_equality_updated_subnetpool(subnetpool_data, |
| 162 | subnetpool) |
| 163 | self.assertFalse(subnetpool['shared']) |
| 164 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 165 | @decorators.idempotent_id('4b496082-c992-4319-90be-d4a7ce646290') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 166 | def test_update_subnetpool_prefixes_append(self): |
| 167 | # We can append new prefixes to subnetpool |
| 168 | create_subnetpool = self._create_subnetpool() |
| 169 | pool_id = create_subnetpool['id'] |
| 170 | old_prefixes = self._subnetpool_data['prefixes'] |
| 171 | new_prefixes = old_prefixes[:] |
| 172 | new_prefixes.append(self.new_prefix) |
| 173 | subnetpool_data = {'prefixes': new_prefixes} |
| 174 | self.client.update_subnetpool(pool_id, **subnetpool_data) |
| 175 | body = self.client.show_subnetpool(pool_id) |
| 176 | prefixes = body['subnetpool']['prefixes'] |
| 177 | self.assertIn(self.new_prefix, prefixes) |
| 178 | self.assertIn(old_prefixes[0], prefixes) |
| 179 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 180 | @decorators.idempotent_id('2cae5d6a-9d32-42d8-8067-f13970ae13bb') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 181 | def test_update_subnetpool_prefixes_extend(self): |
| 182 | # We can extend current subnetpool prefixes |
| 183 | created_subnetpool = self._create_subnetpool() |
| 184 | pool_id = created_subnetpool['id'] |
| 185 | old_prefixes = self._subnetpool_data['prefixes'] |
| 186 | subnetpool_data = {'prefixes': [self.larger_prefix]} |
| 187 | self.client.update_subnetpool(pool_id, **subnetpool_data) |
| 188 | body = self.client.show_subnetpool(pool_id) |
| 189 | prefixes = body['subnetpool']['prefixes'] |
| 190 | self.assertIn(self.larger_prefix, prefixes) |
| 191 | self.assertNotIn(old_prefixes[0], prefixes) |
| 192 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 193 | @decorators.idempotent_id('d70c6c35-913b-4f24-909f-14cd0d29b2d2') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 194 | def test_admin_create_shared_subnetpool(self): |
| 195 | created_subnetpool = self._create_subnetpool(is_admin=True, |
| 196 | shared=True) |
| 197 | pool_id = created_subnetpool['id'] |
| 198 | # Shared subnetpool can be retrieved by tenant user. |
| 199 | body = self.client.show_subnetpool(pool_id) |
| 200 | subnetpool = body['subnetpool'] |
| 201 | self.assertEqual(created_subnetpool['name'], subnetpool['name']) |
| 202 | self.assertTrue(subnetpool['shared']) |
| 203 | |
| 204 | def _create_subnet_from_pool(self, subnet_values=None, pool_values=None): |
| 205 | if pool_values is None: |
| 206 | pool_values = {} |
| 207 | |
| 208 | created_subnetpool = self._create_subnetpool(**pool_values) |
| 209 | pool_id = created_subnetpool['id'] |
| 210 | subnet_name = data_utils.rand_name(SUBNETPOOL_NAME) |
| 211 | network = self.create_network() |
| 212 | subnet_kwargs = {'name': subnet_name, |
| 213 | 'subnetpool_id': pool_id} |
| 214 | if subnet_values: |
| 215 | subnet_kwargs.update(subnet_values) |
| 216 | # not creating the subnet using the base.create_subnet because |
| 217 | # that function needs to be enhanced to support subnet_create when |
| 218 | # prefixlen and subnetpool_id is specified. |
| 219 | body = self.client.create_subnet( |
| 220 | network_id=network['id'], |
| 221 | ip_version=self._ip_version, |
| 222 | **subnet_kwargs) |
| 223 | subnet = body['subnet'] |
| 224 | return pool_id, subnet |
| 225 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 226 | @decorators.idempotent_id('1362ed7d-3089-42eb-b3a5-d6cb8398ee77') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 227 | def test_create_subnet_from_pool_with_prefixlen(self): |
| 228 | subnet_values = {"prefixlen": self.max_prefixlen} |
| 229 | pool_id, subnet = self._create_subnet_from_pool( |
| 230 | subnet_values=subnet_values) |
| 231 | cidr = str(subnet['cidr']) |
| 232 | self.assertEqual(pool_id, subnet['subnetpool_id']) |
| 233 | self.assertTrue(cidr.endswith(str(self.max_prefixlen))) |
| 234 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 235 | @decorators.idempotent_id('86b86189-9789-4582-9c3b-7e2bfe5735ee') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 236 | def test_create_subnet_from_pool_with_subnet_cidr(self): |
| 237 | subnet_values = {"cidr": self.subnet_cidr} |
| 238 | pool_id, subnet = self._create_subnet_from_pool( |
| 239 | subnet_values=subnet_values) |
| 240 | cidr = str(subnet['cidr']) |
| 241 | self.assertEqual(pool_id, subnet['subnetpool_id']) |
| 242 | self.assertEqual(cidr, self.subnet_cidr) |
| 243 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 244 | @decorators.idempotent_id('83f76e3a-9c40-40c2-a015-b7c5242178d8') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 245 | def test_create_subnet_from_pool_with_default_prefixlen(self): |
| 246 | # If neither cidr nor prefixlen is specified, |
| 247 | # subnet will use subnetpool default_prefixlen for cidr. |
| 248 | pool_id, subnet = self._create_subnet_from_pool() |
| 249 | cidr = str(subnet['cidr']) |
| 250 | self.assertEqual(pool_id, subnet['subnetpool_id']) |
| 251 | prefixlen = self._subnetpool_data['min_prefixlen'] |
| 252 | self.assertTrue(cidr.endswith(str(prefixlen))) |
| 253 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 254 | @decorators.idempotent_id('a64af292-ec52-4bde-b654-a6984acaf477') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 255 | def test_create_subnet_from_pool_with_quota(self): |
| 256 | pool_values = {'default_quota': 4} |
| 257 | subnet_values = {"prefixlen": self.max_prefixlen} |
| 258 | pool_id, subnet = self._create_subnet_from_pool( |
| 259 | subnet_values=subnet_values, pool_values=pool_values) |
| 260 | cidr = str(subnet['cidr']) |
| 261 | self.assertEqual(pool_id, subnet['subnetpool_id']) |
| 262 | self.assertTrue(cidr.endswith(str(self.max_prefixlen))) |
| 263 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 264 | @decorators.idempotent_id('49b44c64-1619-4b29-b527-ffc3c3115dc4') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 265 | @utils.requires_ext(extension='address-scope', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 266 | def test_create_subnetpool_associate_address_scope(self): |
| 267 | address_scope = self.create_address_scope( |
| 268 | name=data_utils.rand_name('smoke-address-scope'), |
| 269 | ip_version=self._ip_version) |
| 270 | created_subnetpool = self._create_subnetpool( |
| 271 | address_scope_id=address_scope['id']) |
| 272 | body = self.client.show_subnetpool(created_subnetpool['id']) |
| 273 | self.assertEqual(address_scope['id'], |
| 274 | body['subnetpool']['address_scope_id']) |
| 275 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 276 | @decorators.idempotent_id('910b6393-db24-4f6f-87dc-b36892ad6c8c') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 277 | @utils.requires_ext(extension='address-scope', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 278 | def test_update_subnetpool_associate_address_scope(self): |
| 279 | address_scope = self.create_address_scope( |
| 280 | name=data_utils.rand_name('smoke-address-scope'), |
| 281 | ip_version=self._ip_version) |
| 282 | created_subnetpool = self._create_subnetpool() |
| 283 | pool_id = created_subnetpool['id'] |
| 284 | body = self.client.show_subnetpool(pool_id) |
| 285 | self.assertIsNone(body['subnetpool']['address_scope_id']) |
| 286 | self.client.update_subnetpool(pool_id, |
| 287 | address_scope_id=address_scope['id']) |
| 288 | body = self.client.show_subnetpool(pool_id) |
| 289 | self.assertEqual(address_scope['id'], |
| 290 | body['subnetpool']['address_scope_id']) |
| 291 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 292 | @decorators.idempotent_id('18302e80-46a3-4563-82ac-ccd1dd57f652') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 293 | @utils.requires_ext(extension='address-scope', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 294 | def test_update_subnetpool_associate_another_address_scope(self): |
| 295 | address_scope = self.create_address_scope( |
| 296 | name=data_utils.rand_name('smoke-address-scope'), |
| 297 | ip_version=self._ip_version) |
| 298 | another_address_scope = self.create_address_scope( |
| 299 | name=data_utils.rand_name('smoke-address-scope'), |
| 300 | ip_version=self._ip_version) |
| 301 | created_subnetpool = self._create_subnetpool( |
| 302 | address_scope_id=address_scope['id']) |
| 303 | pool_id = created_subnetpool['id'] |
| 304 | body = self.client.show_subnetpool(pool_id) |
| 305 | self.assertEqual(address_scope['id'], |
| 306 | body['subnetpool']['address_scope_id']) |
| 307 | self.client.update_subnetpool( |
| 308 | pool_id, address_scope_id=another_address_scope['id']) |
| 309 | body = self.client.show_subnetpool(pool_id) |
| 310 | self.assertEqual(another_address_scope['id'], |
| 311 | body['subnetpool']['address_scope_id']) |
| 312 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 313 | @decorators.idempotent_id('f8970048-e41b-42d6-934b-a1297b07706a') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 314 | @utils.requires_ext(extension='address-scope', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 315 | def test_update_subnetpool_disassociate_address_scope(self): |
| 316 | address_scope = self.create_address_scope( |
| 317 | name=data_utils.rand_name('smoke-address-scope'), |
| 318 | ip_version=self._ip_version) |
| 319 | created_subnetpool = self._create_subnetpool( |
| 320 | address_scope_id=address_scope['id']) |
| 321 | pool_id = created_subnetpool['id'] |
| 322 | body = self.client.show_subnetpool(pool_id) |
| 323 | self.assertEqual(address_scope['id'], |
| 324 | body['subnetpool']['address_scope_id']) |
| 325 | self.client.update_subnetpool(pool_id, |
| 326 | address_scope_id=None) |
| 327 | body = self.client.show_subnetpool(pool_id) |
| 328 | self.assertIsNone(body['subnetpool']['address_scope_id']) |
| 329 | |
Dongcan Ye | 2bc62bb | 2017-05-26 10:48:40 +0800 | [diff] [blame] | 330 | @decorators.idempotent_id('4c6963c2-f54c-4347-b288-75d18421c4c4') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 331 | @utils.requires_ext(extension='default-subnetpools', service='network') |
Dongcan Ye | 2bc62bb | 2017-05-26 10:48:40 +0800 | [diff] [blame] | 332 | def test_tenant_create_non_default_subnetpool(self): |
Brian Haley | ae328b9 | 2018-10-09 19:51:54 -0400 | [diff] [blame] | 333 | """Test creates a subnetpool, the "is_default" attribute is False.""" |
Dongcan Ye | 2bc62bb | 2017-05-26 10:48:40 +0800 | [diff] [blame] | 334 | created_subnetpool = self._create_subnetpool() |
| 335 | self.assertFalse(created_subnetpool['is_default']) |
| 336 | |
| 337 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 338 | class SubnetPoolsTestV6(SubnetPoolsTest): |
| 339 | |
| 340 | min_prefixlen = '48' |
| 341 | max_prefixlen = '64' |
| 342 | _ip_version = 6 |
| 343 | subnet_cidr = '2001:db8:3::/64' |
| 344 | new_prefix = u'2001:db8:5::/64' |
| 345 | larger_prefix = u'2001:db8::/32' |
| 346 | |
| 347 | @classmethod |
| 348 | def resource_setup(cls): |
| 349 | super(SubnetPoolsTestV6, cls).resource_setup() |
| 350 | min_prefixlen = '64' |
| 351 | prefixes = [u'2001:db8:3::/48'] |
| 352 | cls._subnetpool_data = {'min_prefixlen': min_prefixlen, |
| 353 | 'prefixes': prefixes} |
| 354 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 355 | @decorators.idempotent_id('f62d73dc-cf6f-4879-b94b-dab53982bf3b') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 356 | def test_create_dual_stack_subnets_from_subnetpools(self): |
| 357 | pool_id_v6, subnet_v6 = self._create_subnet_from_pool() |
| 358 | pool_values_v4 = {'prefixes': ['192.168.0.0/16'], |
| 359 | 'min_prefixlen': 21, |
| 360 | 'max_prefixlen': 32} |
| 361 | create_v4_subnetpool = self._create_subnetpool(**pool_values_v4) |
| 362 | pool_id_v4 = create_v4_subnetpool['id'] |
| 363 | subnet_v4 = self.client.create_subnet( |
| 364 | network_id=subnet_v6['network_id'], ip_version=4, |
| 365 | subnetpool_id=pool_id_v4)['subnet'] |
| 366 | self.assertEqual(subnet_v4['network_id'], subnet_v6['network_id']) |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 367 | |
| 368 | |
| 369 | class SubnetPoolsSearchCriteriaTest(base.BaseSearchCriteriaTest, |
| 370 | SubnetPoolsTestBase): |
| 371 | |
| 372 | resource = 'subnetpool' |
| 373 | |
Ihar Hrachyshka | a9035b6 | 2016-06-13 11:21:38 +0200 | [diff] [blame] | 374 | list_kwargs = {'shared': False} |
| 375 | |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 376 | @classmethod |
| 377 | def resource_setup(cls): |
| 378 | super(SubnetPoolsSearchCriteriaTest, cls).resource_setup() |
| 379 | for name in cls.resource_names: |
| 380 | cls._create_subnetpool(name=name) |
| 381 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 382 | @decorators.idempotent_id('6e3f842e-6bfb-49cb-82d3-0026be4e8e04') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 383 | def test_list_sorts_asc(self): |
| 384 | self._test_list_sorts_asc() |
| 385 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 386 | @decorators.idempotent_id('f336859b-b868-438c-a6fc-2c06374115f2') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 387 | def test_list_sorts_desc(self): |
| 388 | self._test_list_sorts_desc() |
| 389 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 390 | @decorators.idempotent_id('1291fae7-c196-4372-ad59-ce7988518f7b') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 391 | def test_list_pagination(self): |
| 392 | self._test_list_pagination() |
| 393 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 394 | @decorators.idempotent_id('ddb20d14-1952-49b4-a17e-231cc2239a52') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 395 | def test_list_pagination_with_marker(self): |
| 396 | self._test_list_pagination_with_marker() |
| 397 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 398 | @decorators.idempotent_id('b3bd9665-2769-4a43-b50c-31b1add12891') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 399 | def test_list_pagination_with_href_links(self): |
| 400 | self._test_list_pagination_with_href_links() |
| 401 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 402 | @decorators.idempotent_id('1ec1f325-43b0-406e-96ce-20539e38a61d') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 403 | def test_list_pagination_page_reverse_asc(self): |
| 404 | self._test_list_pagination_page_reverse_asc() |
| 405 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 406 | @decorators.idempotent_id('f43a293e-4aaa-48f4-aeaf-de63a676357c') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 407 | def test_list_pagination_page_reverse_desc(self): |
| 408 | self._test_list_pagination_page_reverse_desc() |
| 409 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 410 | @decorators.idempotent_id('73511385-839c-4829-8ac1-b5ad992126c4') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 411 | def test_list_pagination_page_reverse_with_href_links(self): |
| 412 | self._test_list_pagination_page_reverse_with_href_links() |
| 413 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 414 | @decorators.idempotent_id('82a13efc-c18f-4249-b8ec-cec7cf26fbd6') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 415 | def test_list_no_pagination_limit_0(self): |
| 416 | self._test_list_no_pagination_limit_0() |
Victor Morales | 1be97b4 | 2016-09-05 08:50:06 -0500 | [diff] [blame] | 417 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 418 | @decorators.idempotent_id('27feb3f8-40f4-4e50-8cd2-7d0096a98682') |
Victor Morales | 1be97b4 | 2016-09-05 08:50:06 -0500 | [diff] [blame] | 419 | def test_list_validation_filters(self): |
Hongbin Lu | 54f5592 | 2018-07-12 19:05:39 +0000 | [diff] [blame] | 420 | self._test_list_validation_filters(self.list_kwargs) |
| 421 | self._test_list_validation_filters({ |
| 422 | 'unknown_filter': 'value'}, filter_is_valid=False) |
Igor Malinovskiy | 649c018 | 2020-03-06 17:30:47 +0200 | [diff] [blame^] | 423 | |
| 424 | |
| 425 | class RbacSubnetPoolTest(SubnetPoolsTestBase): |
| 426 | |
| 427 | force_tenant_isolation = True |
| 428 | credentials = ['primary', 'alt', 'admin'] |
| 429 | required_extensions = ['rbac-subnetpool'] |
| 430 | |
| 431 | @classmethod |
| 432 | def resource_setup(cls): |
| 433 | super(RbacSubnetPoolTest, cls).resource_setup() |
| 434 | cls.client2 = cls.os_alt.network_client |
| 435 | |
| 436 | def _make_admin_snp_shared_to_project_id(self, project_id): |
| 437 | snp = self._create_subnetpool(is_admin=True) |
| 438 | rbac_policy = self.admin_client.create_rbac_policy( |
| 439 | object_type='subnetpool', |
| 440 | object_id=snp['id'], |
| 441 | action='access_as_shared', |
| 442 | target_tenant=project_id, |
| 443 | )['rbac_policy'] |
| 444 | return {'subnetpool': snp, 'rbac_policy': rbac_policy} |
| 445 | |
| 446 | @decorators.idempotent_id('71b35ad0-51cd-40da-985d-89a51c95ec6a') |
| 447 | def test_policy_target_update(self): |
| 448 | res = self._make_admin_snp_shared_to_project_id( |
| 449 | self.client.tenant_id) |
| 450 | # change to client2 |
| 451 | update_res = self.admin_client.update_rbac_policy( |
| 452 | res['rbac_policy']['id'], target_tenant=self.client2.tenant_id) |
| 453 | self.assertEqual(self.client2.tenant_id, |
| 454 | update_res['rbac_policy']['target_tenant']) |
| 455 | # make sure everything else stayed the same |
| 456 | res['rbac_policy'].pop('target_tenant') |
| 457 | update_res['rbac_policy'].pop('target_tenant') |
| 458 | self.assertEqual(res['rbac_policy'], update_res['rbac_policy']) |
| 459 | |
| 460 | @decorators.idempotent_id('451d9d38-65a0-4916-a805-1460d6a938d1') |
| 461 | def test_subnet_presence_prevents_rbac_policy_deletion(self): |
| 462 | res = self._make_admin_snp_shared_to_project_id( |
| 463 | self.client2.tenant_id) |
| 464 | network = self.create_network(client=self.client2) |
| 465 | subnet = self.client2.create_subnet( |
| 466 | network_id=network['id'], |
| 467 | ip_version=4, |
| 468 | subnetpool_id=res['subnetpool']['id'], |
| 469 | name=data_utils.rand_name("rbac-subnetpool"), |
| 470 | )["subnet"] |
| 471 | self.addCleanup(self.client2.delete_network, network['id']) |
| 472 | self.addCleanup( |
| 473 | self.admin_client.delete_subnetpool, |
| 474 | res['subnetpool']['id'] |
| 475 | ) |
| 476 | self.addCleanup(self.client2.delete_subnet, subnet['id']) |
| 477 | |
| 478 | # a port with shared sg should prevent the deletion of an |
| 479 | # rbac-policy required for it to be shared |
| 480 | with testtools.ExpectedException(lib_exc.Conflict): |
| 481 | self.admin_client.delete_rbac_policy(res['rbac_policy']['id']) |
| 482 | |
| 483 | @decorators.idempotent_id('f74a71de-9abf-49c6-8199-4ac7f53e383b') |
| 484 | @utils.requires_ext(extension='rbac-address-scope', service='network') |
| 485 | def test_cannot_share_if_no_access_to_address_scope(self): |
| 486 | # Create Address Scope shared only to client but not to client2 |
| 487 | a_s = self.admin_client.create_address_scope( |
| 488 | name=data_utils.rand_name("rbac-subnetpool"), |
| 489 | ip_version=4 |
| 490 | )["address_scope"] |
| 491 | rbac_policy = self.admin_client.create_rbac_policy( |
| 492 | object_type='address_scope', object_id=a_s['id'], |
| 493 | action='access_as_shared', |
| 494 | target_tenant=self.client.tenant_id)['rbac_policy'] |
| 495 | |
| 496 | # Create subnet pool owned by client with shared AS |
| 497 | snp = self._create_subnetpool(address_scope_id=a_s["id"]) |
| 498 | |
| 499 | with testtools.ExpectedException(lib_exc.BadRequest): |
| 500 | self.client.create_rbac_policy( |
| 501 | object_type='subnetpool', object_id=snp['id'], |
| 502 | action='access_as_shared', |
| 503 | target_tenant=self.client2.tenant_id |
| 504 | ) |
| 505 | |
| 506 | # cleanup |
| 507 | self.client.delete_subnetpool(snp["id"]) |
| 508 | self.admin_client.delete_rbac_policy(rbac_policy['id']) |
| 509 | self.admin_client.delete_address_scope(a_s['id']) |
| 510 | |
| 511 | @decorators.idempotent_id('9cf8bba5-0163-4083-9397-678bb9b5f5a2') |
| 512 | def test_regular_client_shares_to_another_regular_client(self): |
| 513 | # owned by self.admin_client |
| 514 | snp = self._create_subnetpool(is_admin=True) |
| 515 | with testtools.ExpectedException(lib_exc.NotFound): |
| 516 | self.client.show_subnetpool(snp['id']) |
| 517 | rbac_policy = self.admin_client.create_rbac_policy( |
| 518 | object_type='subnetpool', object_id=snp['id'], |
| 519 | action='access_as_shared', |
| 520 | target_tenant=self.client.tenant_id)['rbac_policy'] |
| 521 | self.client.show_subnetpool(snp['id']) |
| 522 | |
| 523 | self.assertIn(rbac_policy, |
| 524 | self.admin_client.list_rbac_policies()['rbac_policies']) |
| 525 | # ensure that 'client2' can't see the rbac-policy sharing the |
| 526 | # as to it because the rbac-policy belongs to 'client' |
| 527 | self.assertNotIn(rbac_policy['id'], [p['id'] for p in |
| 528 | self.client2.list_rbac_policies()['rbac_policies']]) |
| 529 | |
| 530 | @decorators.idempotent_id('17b2b437-a5fa-4340-ad98-912a986d0d7c') |
| 531 | def test_filter_fields(self): |
| 532 | snp = self._create_subnetpool() |
| 533 | self.admin_client.create_rbac_policy( |
| 534 | object_type='subnetpool', object_id=snp['id'], |
| 535 | action='access_as_shared', target_tenant=self.client2.tenant_id) |
| 536 | field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'), |
| 537 | ('project_id', 'target_tenant')) |
| 538 | for fields in field_args: |
| 539 | res = self.admin_client.list_rbac_policies(fields=fields) |
| 540 | self.assertEqual(set(fields), set(res['rbac_policies'][0].keys())) |
| 541 | |
| 542 | @decorators.idempotent_id('e59e4502-4e6a-4e49-b446-a5d5642bbd69') |
| 543 | def test_rbac_policy_show(self): |
| 544 | res = self._make_admin_snp_shared_to_project_id( |
| 545 | self.client.tenant_id) |
| 546 | p1 = res['rbac_policy'] |
| 547 | p2 = self.admin_client.create_rbac_policy( |
| 548 | object_type='subnetpool', |
| 549 | object_id=res['subnetpool']['id'], |
| 550 | action='access_as_shared', |
| 551 | target_tenant='*')['rbac_policy'] |
| 552 | |
| 553 | self.assertEqual( |
| 554 | p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy']) |
| 555 | self.assertEqual( |
| 556 | p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy']) |
| 557 | |
| 558 | @decorators.idempotent_id('1c24c28c-eb1e-466e-af29-255cf127653a') |
| 559 | def test_filter_rbac_policies(self): |
| 560 | snp = self._create_subnetpool() |
| 561 | rbac_pol1 = self.admin_client.create_rbac_policy( |
| 562 | object_type='subnetpool', object_id=snp['id'], |
| 563 | action='access_as_shared', |
| 564 | target_tenant=self.client2.tenant_id)['rbac_policy'] |
| 565 | rbac_pol2 = self.admin_client.create_rbac_policy( |
| 566 | object_type='subnetpool', object_id=snp['id'], |
| 567 | action='access_as_shared', |
| 568 | target_tenant=self.admin_client.tenant_id)['rbac_policy'] |
| 569 | res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[ |
| 570 | 'rbac_policies'] |
| 571 | res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[ |
| 572 | 'rbac_policies'] |
| 573 | self.assertEqual(1, len(res1)) |
| 574 | self.assertEqual(1, len(res2)) |
| 575 | self.assertEqual(rbac_pol1['id'], res1[0]['id']) |
| 576 | self.assertEqual(rbac_pol2['id'], res2[0]['id']) |
| 577 | |
| 578 | @decorators.idempotent_id('63d9acbe-403c-4e77-9ffd-80e636a4621e') |
| 579 | def test_regular_client_blocked_from_sharing_anothers_policy(self): |
| 580 | snp = self._make_admin_snp_shared_to_project_id( |
| 581 | self.client.tenant_id)['subnetpool'] |
| 582 | with testtools.ExpectedException(lib_exc.BadRequest): |
| 583 | self.client.create_rbac_policy( |
| 584 | object_type='subnetpool', object_id=snp['id'], |
| 585 | action='access_as_shared', |
| 586 | target_tenant=self.client2.tenant_id) |
| 587 | |
| 588 | # make sure the rbac-policy is invisible to the tenant for which it's |
| 589 | # being shared |
| 590 | self.assertFalse(self.client.list_rbac_policies()['rbac_policies']) |