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. |
| 15 | |
| 16 | from tempest.lib.common.utils import data_utils |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 17 | from tempest.lib import decorators |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 18 | from tempest import test |
| 19 | |
Chandan Kumar | 667d3d3 | 2017-09-22 12:24:06 +0530 | [diff] [blame^] | 20 | from neutron_tempest_plugin.api import base |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 21 | |
| 22 | SUBNETPOOL_NAME = 'smoke-subnetpool' |
| 23 | SUBNET_NAME = 'smoke-subnet' |
| 24 | |
| 25 | |
| 26 | class SubnetPoolsTestBase(base.BaseAdminNetworkTest): |
| 27 | |
| 28 | @classmethod |
| 29 | def resource_setup(cls): |
| 30 | super(SubnetPoolsTestBase, cls).resource_setup() |
| 31 | min_prefixlen = '29' |
| 32 | prefixes = [u'10.11.12.0/24'] |
| 33 | cls._subnetpool_data = {'prefixes': prefixes, |
| 34 | 'min_prefixlen': min_prefixlen} |
| 35 | |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 36 | @classmethod |
| 37 | def _create_subnetpool(cls, is_admin=False, **kwargs): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 38 | if 'name' not in kwargs: |
| 39 | name = data_utils.rand_name(SUBNETPOOL_NAME) |
| 40 | else: |
| 41 | name = kwargs.pop('name') |
| 42 | |
| 43 | if 'prefixes' not in kwargs: |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 44 | kwargs['prefixes'] = cls._subnetpool_data['prefixes'] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 45 | |
| 46 | if 'min_prefixlen' not in kwargs: |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 47 | kwargs['min_prefixlen'] = cls._subnetpool_data['min_prefixlen'] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 48 | |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 49 | return cls.create_subnetpool(name=name, is_admin=is_admin, **kwargs) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | class SubnetPoolsTest(SubnetPoolsTestBase): |
| 53 | |
| 54 | min_prefixlen = '28' |
| 55 | max_prefixlen = '31' |
| 56 | _ip_version = 4 |
| 57 | subnet_cidr = u'10.11.12.0/31' |
| 58 | new_prefix = u'10.11.15.0/24' |
| 59 | larger_prefix = u'10.11.0.0/16' |
| 60 | |
| 61 | """ |
| 62 | Tests the following operations in the Neutron API using the REST client for |
| 63 | Neutron: |
| 64 | |
| 65 | create a subnetpool for a tenant |
| 66 | list tenant's subnetpools |
| 67 | show a tenant subnetpool details |
| 68 | subnetpool update |
| 69 | delete a subnetpool |
| 70 | |
| 71 | All subnetpool tests are run once with ipv4 and once with ipv6. |
| 72 | |
| 73 | v2.0 of the Neutron API is assumed. |
| 74 | |
| 75 | """ |
| 76 | |
| 77 | def _new_subnetpool_attributes(self): |
| 78 | new_name = data_utils.rand_name(SUBNETPOOL_NAME) |
| 79 | return {'name': new_name, 'min_prefixlen': self.min_prefixlen, |
| 80 | 'max_prefixlen': self.max_prefixlen} |
| 81 | |
| 82 | def _check_equality_updated_subnetpool(self, expected_values, |
| 83 | updated_pool): |
| 84 | self.assertEqual(expected_values['name'], |
| 85 | updated_pool['name']) |
| 86 | self.assertEqual(expected_values['min_prefixlen'], |
| 87 | updated_pool['min_prefixlen']) |
| 88 | self.assertEqual(expected_values['max_prefixlen'], |
| 89 | updated_pool['max_prefixlen']) |
| 90 | # expected_values may not contains all subnetpool values |
| 91 | if 'prefixes' in expected_values: |
| 92 | self.assertEqual(expected_values['prefixes'], |
| 93 | updated_pool['prefixes']) |
| 94 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 95 | @decorators.idempotent_id('6e1781ec-b45b-4042-aebe-f485c022996e') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 96 | def test_create_list_subnetpool(self): |
| 97 | created_subnetpool = self._create_subnetpool() |
| 98 | body = self.client.list_subnetpools() |
| 99 | subnetpools = body['subnetpools'] |
| 100 | self.assertIn(created_subnetpool['id'], |
| 101 | [sp['id'] for sp in subnetpools], |
| 102 | "Created subnetpool id should be in the list") |
| 103 | self.assertIn(created_subnetpool['name'], |
| 104 | [sp['name'] for sp in subnetpools], |
| 105 | "Created subnetpool name should be in the list") |
| 106 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 107 | @decorators.idempotent_id('c72c1c0c-2193-4aca-ddd4-b1442640bbbb') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 108 | @test.requires_ext(extension="standard-attr-description", |
| 109 | service="network") |
| 110 | def test_create_update_subnetpool_description(self): |
| 111 | body = self._create_subnetpool(description='d1') |
| 112 | self.assertEqual('d1', body['description']) |
| 113 | sub_id = body['id'] |
Nguyen Phuong An | c486b97 | 2016-08-29 18:15:30 +0700 | [diff] [blame] | 114 | subnet_pools = [x for x in |
| 115 | self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id] |
| 116 | body = subnet_pools[0] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 117 | self.assertEqual('d1', body['description']) |
| 118 | body = self.client.update_subnetpool(sub_id, description='d2') |
| 119 | self.assertEqual('d2', body['subnetpool']['description']) |
Nguyen Phuong An | c486b97 | 2016-08-29 18:15:30 +0700 | [diff] [blame] | 120 | subnet_pools = [x for x in |
| 121 | self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id] |
| 122 | body = subnet_pools[0] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 123 | self.assertEqual('d2', body['description']) |
| 124 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 125 | @decorators.idempotent_id('741d08c2-1e3f-42be-99c7-0ea93c5b728c') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 126 | def test_get_subnetpool(self): |
| 127 | created_subnetpool = self._create_subnetpool() |
| 128 | prefixlen = self._subnetpool_data['min_prefixlen'] |
| 129 | body = self.client.show_subnetpool(created_subnetpool['id']) |
| 130 | subnetpool = body['subnetpool'] |
| 131 | self.assertEqual(created_subnetpool['name'], subnetpool['name']) |
| 132 | self.assertEqual(created_subnetpool['id'], subnetpool['id']) |
| 133 | self.assertEqual(prefixlen, subnetpool['min_prefixlen']) |
| 134 | self.assertEqual(prefixlen, subnetpool['default_prefixlen']) |
| 135 | self.assertFalse(subnetpool['shared']) |
| 136 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 137 | @decorators.idempotent_id('5bf9f1e2-efc8-4195-acf3-d12b2bd68dd3') |
Henry Gessau | fa6c78d | 2016-10-09 19:56:09 -0400 | [diff] [blame] | 138 | @test.requires_ext(extension="project-id", service="network") |
| 139 | def test_show_subnetpool_has_project_id(self): |
| 140 | subnetpool = self._create_subnetpool() |
| 141 | body = self.client.show_subnetpool(subnetpool['id']) |
| 142 | show_subnetpool = body['subnetpool'] |
| 143 | self.assertIn('project_id', show_subnetpool) |
| 144 | self.assertIn('tenant_id', show_subnetpool) |
| 145 | self.assertEqual(self.client.tenant_id, show_subnetpool['project_id']) |
| 146 | self.assertEqual(self.client.tenant_id, show_subnetpool['tenant_id']) |
| 147 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 148 | @decorators.idempotent_id('764f1b93-1c4a-4513-9e7b-6c2fc5e9270c') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 149 | def test_tenant_update_subnetpool(self): |
| 150 | created_subnetpool = self._create_subnetpool() |
| 151 | pool_id = created_subnetpool['id'] |
| 152 | subnetpool_data = self._new_subnetpool_attributes() |
| 153 | self.client.update_subnetpool(created_subnetpool['id'], |
| 154 | **subnetpool_data) |
| 155 | |
| 156 | body = self.client.show_subnetpool(pool_id) |
| 157 | subnetpool = body['subnetpool'] |
| 158 | self._check_equality_updated_subnetpool(subnetpool_data, |
| 159 | subnetpool) |
| 160 | self.assertFalse(subnetpool['shared']) |
| 161 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 162 | @decorators.idempotent_id('4b496082-c992-4319-90be-d4a7ce646290') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 163 | def test_update_subnetpool_prefixes_append(self): |
| 164 | # We can append new prefixes to subnetpool |
| 165 | create_subnetpool = self._create_subnetpool() |
| 166 | pool_id = create_subnetpool['id'] |
| 167 | old_prefixes = self._subnetpool_data['prefixes'] |
| 168 | new_prefixes = old_prefixes[:] |
| 169 | new_prefixes.append(self.new_prefix) |
| 170 | subnetpool_data = {'prefixes': new_prefixes} |
| 171 | self.client.update_subnetpool(pool_id, **subnetpool_data) |
| 172 | body = self.client.show_subnetpool(pool_id) |
| 173 | prefixes = body['subnetpool']['prefixes'] |
| 174 | self.assertIn(self.new_prefix, prefixes) |
| 175 | self.assertIn(old_prefixes[0], prefixes) |
| 176 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 177 | @decorators.idempotent_id('2cae5d6a-9d32-42d8-8067-f13970ae13bb') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 178 | def test_update_subnetpool_prefixes_extend(self): |
| 179 | # We can extend current subnetpool prefixes |
| 180 | created_subnetpool = self._create_subnetpool() |
| 181 | pool_id = created_subnetpool['id'] |
| 182 | old_prefixes = self._subnetpool_data['prefixes'] |
| 183 | subnetpool_data = {'prefixes': [self.larger_prefix]} |
| 184 | self.client.update_subnetpool(pool_id, **subnetpool_data) |
| 185 | body = self.client.show_subnetpool(pool_id) |
| 186 | prefixes = body['subnetpool']['prefixes'] |
| 187 | self.assertIn(self.larger_prefix, prefixes) |
| 188 | self.assertNotIn(old_prefixes[0], prefixes) |
| 189 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 190 | @decorators.idempotent_id('d70c6c35-913b-4f24-909f-14cd0d29b2d2') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 191 | def test_admin_create_shared_subnetpool(self): |
| 192 | created_subnetpool = self._create_subnetpool(is_admin=True, |
| 193 | shared=True) |
| 194 | pool_id = created_subnetpool['id'] |
| 195 | # Shared subnetpool can be retrieved by tenant user. |
| 196 | body = self.client.show_subnetpool(pool_id) |
| 197 | subnetpool = body['subnetpool'] |
| 198 | self.assertEqual(created_subnetpool['name'], subnetpool['name']) |
| 199 | self.assertTrue(subnetpool['shared']) |
| 200 | |
| 201 | def _create_subnet_from_pool(self, subnet_values=None, pool_values=None): |
| 202 | if pool_values is None: |
| 203 | pool_values = {} |
| 204 | |
| 205 | created_subnetpool = self._create_subnetpool(**pool_values) |
| 206 | pool_id = created_subnetpool['id'] |
| 207 | subnet_name = data_utils.rand_name(SUBNETPOOL_NAME) |
| 208 | network = self.create_network() |
| 209 | subnet_kwargs = {'name': subnet_name, |
| 210 | 'subnetpool_id': pool_id} |
| 211 | if subnet_values: |
| 212 | subnet_kwargs.update(subnet_values) |
| 213 | # not creating the subnet using the base.create_subnet because |
| 214 | # that function needs to be enhanced to support subnet_create when |
| 215 | # prefixlen and subnetpool_id is specified. |
| 216 | body = self.client.create_subnet( |
| 217 | network_id=network['id'], |
| 218 | ip_version=self._ip_version, |
| 219 | **subnet_kwargs) |
| 220 | subnet = body['subnet'] |
| 221 | return pool_id, subnet |
| 222 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 223 | @decorators.idempotent_id('1362ed7d-3089-42eb-b3a5-d6cb8398ee77') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 224 | def test_create_subnet_from_pool_with_prefixlen(self): |
| 225 | subnet_values = {"prefixlen": self.max_prefixlen} |
| 226 | pool_id, subnet = self._create_subnet_from_pool( |
| 227 | subnet_values=subnet_values) |
| 228 | cidr = str(subnet['cidr']) |
| 229 | self.assertEqual(pool_id, subnet['subnetpool_id']) |
| 230 | self.assertTrue(cidr.endswith(str(self.max_prefixlen))) |
| 231 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 232 | @decorators.idempotent_id('86b86189-9789-4582-9c3b-7e2bfe5735ee') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 233 | def test_create_subnet_from_pool_with_subnet_cidr(self): |
| 234 | subnet_values = {"cidr": self.subnet_cidr} |
| 235 | pool_id, subnet = self._create_subnet_from_pool( |
| 236 | subnet_values=subnet_values) |
| 237 | cidr = str(subnet['cidr']) |
| 238 | self.assertEqual(pool_id, subnet['subnetpool_id']) |
| 239 | self.assertEqual(cidr, self.subnet_cidr) |
| 240 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 241 | @decorators.idempotent_id('83f76e3a-9c40-40c2-a015-b7c5242178d8') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 242 | def test_create_subnet_from_pool_with_default_prefixlen(self): |
| 243 | # If neither cidr nor prefixlen is specified, |
| 244 | # subnet will use subnetpool default_prefixlen for cidr. |
| 245 | pool_id, subnet = self._create_subnet_from_pool() |
| 246 | cidr = str(subnet['cidr']) |
| 247 | self.assertEqual(pool_id, subnet['subnetpool_id']) |
| 248 | prefixlen = self._subnetpool_data['min_prefixlen'] |
| 249 | self.assertTrue(cidr.endswith(str(prefixlen))) |
| 250 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 251 | @decorators.idempotent_id('a64af292-ec52-4bde-b654-a6984acaf477') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 252 | def test_create_subnet_from_pool_with_quota(self): |
| 253 | pool_values = {'default_quota': 4} |
| 254 | subnet_values = {"prefixlen": self.max_prefixlen} |
| 255 | pool_id, subnet = self._create_subnet_from_pool( |
| 256 | subnet_values=subnet_values, pool_values=pool_values) |
| 257 | cidr = str(subnet['cidr']) |
| 258 | self.assertEqual(pool_id, subnet['subnetpool_id']) |
| 259 | self.assertTrue(cidr.endswith(str(self.max_prefixlen))) |
| 260 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 261 | @decorators.idempotent_id('49b44c64-1619-4b29-b527-ffc3c3115dc4') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 262 | @test.requires_ext(extension='address-scope', service='network') |
| 263 | def test_create_subnetpool_associate_address_scope(self): |
| 264 | address_scope = self.create_address_scope( |
| 265 | name=data_utils.rand_name('smoke-address-scope'), |
| 266 | ip_version=self._ip_version) |
| 267 | created_subnetpool = self._create_subnetpool( |
| 268 | address_scope_id=address_scope['id']) |
| 269 | body = self.client.show_subnetpool(created_subnetpool['id']) |
| 270 | self.assertEqual(address_scope['id'], |
| 271 | body['subnetpool']['address_scope_id']) |
| 272 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 273 | @decorators.idempotent_id('910b6393-db24-4f6f-87dc-b36892ad6c8c') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 274 | @test.requires_ext(extension='address-scope', service='network') |
| 275 | def test_update_subnetpool_associate_address_scope(self): |
| 276 | address_scope = self.create_address_scope( |
| 277 | name=data_utils.rand_name('smoke-address-scope'), |
| 278 | ip_version=self._ip_version) |
| 279 | created_subnetpool = self._create_subnetpool() |
| 280 | pool_id = created_subnetpool['id'] |
| 281 | body = self.client.show_subnetpool(pool_id) |
| 282 | self.assertIsNone(body['subnetpool']['address_scope_id']) |
| 283 | self.client.update_subnetpool(pool_id, |
| 284 | address_scope_id=address_scope['id']) |
| 285 | body = self.client.show_subnetpool(pool_id) |
| 286 | self.assertEqual(address_scope['id'], |
| 287 | body['subnetpool']['address_scope_id']) |
| 288 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 289 | @decorators.idempotent_id('18302e80-46a3-4563-82ac-ccd1dd57f652') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 290 | @test.requires_ext(extension='address-scope', service='network') |
| 291 | def test_update_subnetpool_associate_another_address_scope(self): |
| 292 | address_scope = self.create_address_scope( |
| 293 | name=data_utils.rand_name('smoke-address-scope'), |
| 294 | ip_version=self._ip_version) |
| 295 | another_address_scope = self.create_address_scope( |
| 296 | name=data_utils.rand_name('smoke-address-scope'), |
| 297 | ip_version=self._ip_version) |
| 298 | created_subnetpool = self._create_subnetpool( |
| 299 | address_scope_id=address_scope['id']) |
| 300 | pool_id = created_subnetpool['id'] |
| 301 | body = self.client.show_subnetpool(pool_id) |
| 302 | self.assertEqual(address_scope['id'], |
| 303 | body['subnetpool']['address_scope_id']) |
| 304 | self.client.update_subnetpool( |
| 305 | pool_id, address_scope_id=another_address_scope['id']) |
| 306 | body = self.client.show_subnetpool(pool_id) |
| 307 | self.assertEqual(another_address_scope['id'], |
| 308 | body['subnetpool']['address_scope_id']) |
| 309 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 310 | @decorators.idempotent_id('f8970048-e41b-42d6-934b-a1297b07706a') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 311 | @test.requires_ext(extension='address-scope', service='network') |
| 312 | def test_update_subnetpool_disassociate_address_scope(self): |
| 313 | address_scope = self.create_address_scope( |
| 314 | name=data_utils.rand_name('smoke-address-scope'), |
| 315 | ip_version=self._ip_version) |
| 316 | created_subnetpool = self._create_subnetpool( |
| 317 | address_scope_id=address_scope['id']) |
| 318 | pool_id = created_subnetpool['id'] |
| 319 | body = self.client.show_subnetpool(pool_id) |
| 320 | self.assertEqual(address_scope['id'], |
| 321 | body['subnetpool']['address_scope_id']) |
| 322 | self.client.update_subnetpool(pool_id, |
| 323 | address_scope_id=None) |
| 324 | body = self.client.show_subnetpool(pool_id) |
| 325 | self.assertIsNone(body['subnetpool']['address_scope_id']) |
| 326 | |
Dongcan Ye | 2bc62bb | 2017-05-26 10:48:40 +0800 | [diff] [blame] | 327 | @decorators.idempotent_id('4c6963c2-f54c-4347-b288-75d18421c4c4') |
| 328 | @test.requires_ext(extension='default-subnetpools', service='network') |
| 329 | def test_tenant_create_non_default_subnetpool(self): |
| 330 | """ |
| 331 | Test creates a subnetpool, the "is_default" attribute is False. |
| 332 | """ |
| 333 | created_subnetpool = self._create_subnetpool() |
| 334 | self.assertFalse(created_subnetpool['is_default']) |
| 335 | |
| 336 | |
| 337 | class DefaultSubnetPoolsTest(SubnetPoolsTestBase): |
| 338 | |
Jakub Libosvar | 0e45ffc | 2017-08-10 17:04:45 +0000 | [diff] [blame] | 339 | def setUp(self): |
| 340 | self.addCleanup(self.resource_cleanup) |
| 341 | super(DefaultSubnetPoolsTest, self).setUp() |
| 342 | |
Dongcan Ye | 2bc62bb | 2017-05-26 10:48:40 +0800 | [diff] [blame] | 343 | @classmethod |
| 344 | def resource_setup(cls): |
| 345 | super(DefaultSubnetPoolsTest, cls).resource_setup() |
| 346 | body = cls.admin_client.list_subnetpools() |
| 347 | subnetpools = body['subnetpools'] |
| 348 | for subnetpool in subnetpools: |
| 349 | if subnetpool.get('is_default'): |
| 350 | msg = 'Default subnetpool already exists. Only one is allowed.' |
| 351 | raise cls.skipException(msg) |
| 352 | |
| 353 | @decorators.idempotent_id('cb839106-6184-4332-b292-5d07c074de4f') |
| 354 | @test.requires_ext(extension='default-subnetpools', service='network') |
| 355 | def test_admin_create_default_subnetpool(self): |
| 356 | """ |
| 357 | Test uses administrative credentials to create a default subnetpool, |
| 358 | using the is_default=True. |
| 359 | """ |
| 360 | created_subnetpool = self._create_subnetpool(is_admin=True, |
| 361 | is_default=True) |
| 362 | self.assertTrue(created_subnetpool['is_default']) |
| 363 | |
| 364 | @decorators.idempotent_id('9e79730c-29b6-44a4-9504-bf3c7cedc56c') |
| 365 | @test.requires_ext(extension='default-subnetpools', service='network') |
| 366 | def test_convert_subnetpool_to_default_subnetpool(self): |
| 367 | """ |
| 368 | Test creates a subnetpool, which is non default subnetpool. |
| 369 | Then it will update to a default subnetpool, by setting "is_default" |
| 370 | attribute to True. |
| 371 | """ |
| 372 | created_subnetpool = self._create_subnetpool() |
| 373 | subnetpool_id = created_subnetpool['id'] |
| 374 | self.assertFalse(created_subnetpool['is_default']) |
| 375 | subnetpool_data = {'is_default': True} |
| 376 | self.admin_client.update_subnetpool(subnetpool_id, |
| 377 | **subnetpool_data) |
| 378 | show_body = self.client.show_subnetpool(subnetpool_id) |
| 379 | self.assertTrue(show_body['subnetpool']['is_default']) |
| 380 | |
| 381 | @decorators.idempotent_id('39687561-7a37-47b8-91ce-f9143ae26969') |
| 382 | @test.requires_ext(extension='default-subnetpools', service='network') |
| 383 | def test_convert_default_subnetpool_to_non_default(self): |
| 384 | """ |
| 385 | Test uses administrative credentials to create a default subnetpool, |
| 386 | using the is_default=True. |
| 387 | Then it will update "is_default" attribute to False. |
| 388 | """ |
| 389 | created_subnetpool = self._create_subnetpool(is_admin=True, |
| 390 | is_default=True) |
| 391 | subnetpool_id = created_subnetpool['id'] |
| 392 | self.assertTrue(created_subnetpool['is_default']) |
| 393 | subnetpool_data = {'is_default': False} |
| 394 | self.admin_client.update_subnetpool(subnetpool_id, |
| 395 | **subnetpool_data) |
Itzik Brown | 76f5d15 | 2017-08-10 15:44:18 +0300 | [diff] [blame] | 396 | show_body = self.admin_client.show_subnetpool(subnetpool_id) |
Dongcan Ye | 2bc62bb | 2017-05-26 10:48:40 +0800 | [diff] [blame] | 397 | self.assertFalse(show_body['subnetpool']['is_default']) |
| 398 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 399 | |
| 400 | class SubnetPoolsTestV6(SubnetPoolsTest): |
| 401 | |
| 402 | min_prefixlen = '48' |
| 403 | max_prefixlen = '64' |
| 404 | _ip_version = 6 |
| 405 | subnet_cidr = '2001:db8:3::/64' |
| 406 | new_prefix = u'2001:db8:5::/64' |
| 407 | larger_prefix = u'2001:db8::/32' |
| 408 | |
| 409 | @classmethod |
| 410 | def resource_setup(cls): |
| 411 | super(SubnetPoolsTestV6, cls).resource_setup() |
| 412 | min_prefixlen = '64' |
| 413 | prefixes = [u'2001:db8:3::/48'] |
| 414 | cls._subnetpool_data = {'min_prefixlen': min_prefixlen, |
| 415 | 'prefixes': prefixes} |
| 416 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 417 | @decorators.idempotent_id('f62d73dc-cf6f-4879-b94b-dab53982bf3b') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 418 | def test_create_dual_stack_subnets_from_subnetpools(self): |
| 419 | pool_id_v6, subnet_v6 = self._create_subnet_from_pool() |
| 420 | pool_values_v4 = {'prefixes': ['192.168.0.0/16'], |
| 421 | 'min_prefixlen': 21, |
| 422 | 'max_prefixlen': 32} |
| 423 | create_v4_subnetpool = self._create_subnetpool(**pool_values_v4) |
| 424 | pool_id_v4 = create_v4_subnetpool['id'] |
| 425 | subnet_v4 = self.client.create_subnet( |
| 426 | network_id=subnet_v6['network_id'], ip_version=4, |
| 427 | subnetpool_id=pool_id_v4)['subnet'] |
| 428 | self.assertEqual(subnet_v4['network_id'], subnet_v6['network_id']) |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 429 | |
| 430 | |
| 431 | class SubnetPoolsSearchCriteriaTest(base.BaseSearchCriteriaTest, |
| 432 | SubnetPoolsTestBase): |
| 433 | |
| 434 | resource = 'subnetpool' |
| 435 | |
Ihar Hrachyshka | a9035b6 | 2016-06-13 11:21:38 +0200 | [diff] [blame] | 436 | list_kwargs = {'shared': False} |
| 437 | |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 438 | @classmethod |
| 439 | def resource_setup(cls): |
| 440 | super(SubnetPoolsSearchCriteriaTest, cls).resource_setup() |
| 441 | for name in cls.resource_names: |
| 442 | cls._create_subnetpool(name=name) |
| 443 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 444 | @decorators.idempotent_id('6e3f842e-6bfb-49cb-82d3-0026be4e8e04') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 445 | def test_list_sorts_asc(self): |
| 446 | self._test_list_sorts_asc() |
| 447 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 448 | @decorators.idempotent_id('f336859b-b868-438c-a6fc-2c06374115f2') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 449 | def test_list_sorts_desc(self): |
| 450 | self._test_list_sorts_desc() |
| 451 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 452 | @decorators.idempotent_id('1291fae7-c196-4372-ad59-ce7988518f7b') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 453 | def test_list_pagination(self): |
| 454 | self._test_list_pagination() |
| 455 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 456 | @decorators.idempotent_id('ddb20d14-1952-49b4-a17e-231cc2239a52') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 457 | def test_list_pagination_with_marker(self): |
| 458 | self._test_list_pagination_with_marker() |
| 459 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 460 | @decorators.idempotent_id('b3bd9665-2769-4a43-b50c-31b1add12891') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 461 | def test_list_pagination_with_href_links(self): |
| 462 | self._test_list_pagination_with_href_links() |
| 463 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 464 | @decorators.idempotent_id('1ec1f325-43b0-406e-96ce-20539e38a61d') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 465 | def test_list_pagination_page_reverse_asc(self): |
| 466 | self._test_list_pagination_page_reverse_asc() |
| 467 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 468 | @decorators.idempotent_id('f43a293e-4aaa-48f4-aeaf-de63a676357c') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 469 | def test_list_pagination_page_reverse_desc(self): |
| 470 | self._test_list_pagination_page_reverse_desc() |
| 471 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 472 | @decorators.idempotent_id('73511385-839c-4829-8ac1-b5ad992126c4') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 473 | def test_list_pagination_page_reverse_with_href_links(self): |
| 474 | self._test_list_pagination_page_reverse_with_href_links() |
| 475 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 476 | @decorators.idempotent_id('82a13efc-c18f-4249-b8ec-cec7cf26fbd6') |
Ihar Hrachyshka | eace174 | 2016-06-08 15:07:35 +0200 | [diff] [blame] | 477 | def test_list_no_pagination_limit_0(self): |
| 478 | self._test_list_no_pagination_limit_0() |
Victor Morales | 1be97b4 | 2016-09-05 08:50:06 -0500 | [diff] [blame] | 479 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 480 | @decorators.idempotent_id('27feb3f8-40f4-4e50-8cd2-7d0096a98682') |
Victor Morales | 1be97b4 | 2016-09-05 08:50:06 -0500 | [diff] [blame] | 481 | def test_list_validation_filters(self): |
| 482 | self._test_list_validation_filters() |