blob: 763d06c3ef3e11def781b93959d020ac8d22e996 [file] [log] [blame]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001# 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
16from tempest.lib.common.utils import data_utils
17from tempest import test
18
19from neutron.tests.tempest.api import base
20
21SUBNETPOOL_NAME = 'smoke-subnetpool'
22SUBNET_NAME = 'smoke-subnet'
23
24
25class SubnetPoolsTestBase(base.BaseAdminNetworkTest):
26
27 @classmethod
28 def resource_setup(cls):
29 super(SubnetPoolsTestBase, cls).resource_setup()
30 min_prefixlen = '29'
31 prefixes = [u'10.11.12.0/24']
32 cls._subnetpool_data = {'prefixes': prefixes,
33 'min_prefixlen': min_prefixlen}
34
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +020035 @classmethod
36 def _create_subnetpool(cls, is_admin=False, **kwargs):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000037 if 'name' not in kwargs:
38 name = data_utils.rand_name(SUBNETPOOL_NAME)
39 else:
40 name = kwargs.pop('name')
41
42 if 'prefixes' not in kwargs:
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +020043 kwargs['prefixes'] = cls._subnetpool_data['prefixes']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000044
45 if 'min_prefixlen' not in kwargs:
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +020046 kwargs['min_prefixlen'] = cls._subnetpool_data['min_prefixlen']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000047
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +020048 return cls.create_subnetpool(name=name, is_admin=is_admin, **kwargs)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000049
50
51class SubnetPoolsTest(SubnetPoolsTestBase):
52
53 min_prefixlen = '28'
54 max_prefixlen = '31'
55 _ip_version = 4
56 subnet_cidr = u'10.11.12.0/31'
57 new_prefix = u'10.11.15.0/24'
58 larger_prefix = u'10.11.0.0/16'
59
60 """
61 Tests the following operations in the Neutron API using the REST client for
62 Neutron:
63
64 create a subnetpool for a tenant
65 list tenant's subnetpools
66 show a tenant subnetpool details
67 subnetpool update
68 delete a subnetpool
69
70 All subnetpool tests are run once with ipv4 and once with ipv6.
71
72 v2.0 of the Neutron API is assumed.
73
74 """
75
76 def _new_subnetpool_attributes(self):
77 new_name = data_utils.rand_name(SUBNETPOOL_NAME)
78 return {'name': new_name, 'min_prefixlen': self.min_prefixlen,
79 'max_prefixlen': self.max_prefixlen}
80
81 def _check_equality_updated_subnetpool(self, expected_values,
82 updated_pool):
83 self.assertEqual(expected_values['name'],
84 updated_pool['name'])
85 self.assertEqual(expected_values['min_prefixlen'],
86 updated_pool['min_prefixlen'])
87 self.assertEqual(expected_values['max_prefixlen'],
88 updated_pool['max_prefixlen'])
89 # expected_values may not contains all subnetpool values
90 if 'prefixes' in expected_values:
91 self.assertEqual(expected_values['prefixes'],
92 updated_pool['prefixes'])
93
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000094 @test.idempotent_id('6e1781ec-b45b-4042-aebe-f485c022996e')
95 def test_create_list_subnetpool(self):
96 created_subnetpool = self._create_subnetpool()
97 body = self.client.list_subnetpools()
98 subnetpools = body['subnetpools']
99 self.assertIn(created_subnetpool['id'],
100 [sp['id'] for sp in subnetpools],
101 "Created subnetpool id should be in the list")
102 self.assertIn(created_subnetpool['name'],
103 [sp['name'] for sp in subnetpools],
104 "Created subnetpool name should be in the list")
105
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000106 @test.idempotent_id('c72c1c0c-2193-4aca-ddd4-b1442640bbbb')
107 @test.requires_ext(extension="standard-attr-description",
108 service="network")
109 def test_create_update_subnetpool_description(self):
110 body = self._create_subnetpool(description='d1')
111 self.assertEqual('d1', body['description'])
112 sub_id = body['id']
Nguyen Phuong Anc486b972016-08-29 18:15:30 +0700113 subnet_pools = [x for x in
114 self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id]
115 body = subnet_pools[0]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000116 self.assertEqual('d1', body['description'])
117 body = self.client.update_subnetpool(sub_id, description='d2')
118 self.assertEqual('d2', body['subnetpool']['description'])
Nguyen Phuong Anc486b972016-08-29 18:15:30 +0700119 subnet_pools = [x for x in
120 self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id]
121 body = subnet_pools[0]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000122 self.assertEqual('d2', body['description'])
123
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000124 @test.idempotent_id('741d08c2-1e3f-42be-99c7-0ea93c5b728c')
125 def test_get_subnetpool(self):
126 created_subnetpool = self._create_subnetpool()
127 prefixlen = self._subnetpool_data['min_prefixlen']
128 body = self.client.show_subnetpool(created_subnetpool['id'])
129 subnetpool = body['subnetpool']
130 self.assertEqual(created_subnetpool['name'], subnetpool['name'])
131 self.assertEqual(created_subnetpool['id'], subnetpool['id'])
132 self.assertEqual(prefixlen, subnetpool['min_prefixlen'])
133 self.assertEqual(prefixlen, subnetpool['default_prefixlen'])
134 self.assertFalse(subnetpool['shared'])
135
Henry Gessaufa6c78d2016-10-09 19:56:09 -0400136 @test.idempotent_id('5bf9f1e2-efc8-4195-acf3-d12b2bd68dd3')
137 @test.requires_ext(extension="project-id", service="network")
138 def test_show_subnetpool_has_project_id(self):
139 subnetpool = self._create_subnetpool()
140 body = self.client.show_subnetpool(subnetpool['id'])
141 show_subnetpool = body['subnetpool']
142 self.assertIn('project_id', show_subnetpool)
143 self.assertIn('tenant_id', show_subnetpool)
144 self.assertEqual(self.client.tenant_id, show_subnetpool['project_id'])
145 self.assertEqual(self.client.tenant_id, show_subnetpool['tenant_id'])
146
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000147 @test.idempotent_id('764f1b93-1c4a-4513-9e7b-6c2fc5e9270c')
148 def test_tenant_update_subnetpool(self):
149 created_subnetpool = self._create_subnetpool()
150 pool_id = created_subnetpool['id']
151 subnetpool_data = self._new_subnetpool_attributes()
152 self.client.update_subnetpool(created_subnetpool['id'],
153 **subnetpool_data)
154
155 body = self.client.show_subnetpool(pool_id)
156 subnetpool = body['subnetpool']
157 self._check_equality_updated_subnetpool(subnetpool_data,
158 subnetpool)
159 self.assertFalse(subnetpool['shared'])
160
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000161 @test.idempotent_id('4b496082-c992-4319-90be-d4a7ce646290')
162 def test_update_subnetpool_prefixes_append(self):
163 # We can append new prefixes to subnetpool
164 create_subnetpool = self._create_subnetpool()
165 pool_id = create_subnetpool['id']
166 old_prefixes = self._subnetpool_data['prefixes']
167 new_prefixes = old_prefixes[:]
168 new_prefixes.append(self.new_prefix)
169 subnetpool_data = {'prefixes': new_prefixes}
170 self.client.update_subnetpool(pool_id, **subnetpool_data)
171 body = self.client.show_subnetpool(pool_id)
172 prefixes = body['subnetpool']['prefixes']
173 self.assertIn(self.new_prefix, prefixes)
174 self.assertIn(old_prefixes[0], prefixes)
175
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000176 @test.idempotent_id('2cae5d6a-9d32-42d8-8067-f13970ae13bb')
177 def test_update_subnetpool_prefixes_extend(self):
178 # We can extend current subnetpool prefixes
179 created_subnetpool = self._create_subnetpool()
180 pool_id = created_subnetpool['id']
181 old_prefixes = self._subnetpool_data['prefixes']
182 subnetpool_data = {'prefixes': [self.larger_prefix]}
183 self.client.update_subnetpool(pool_id, **subnetpool_data)
184 body = self.client.show_subnetpool(pool_id)
185 prefixes = body['subnetpool']['prefixes']
186 self.assertIn(self.larger_prefix, prefixes)
187 self.assertNotIn(old_prefixes[0], prefixes)
188
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000189 @test.idempotent_id('d70c6c35-913b-4f24-909f-14cd0d29b2d2')
190 def test_admin_create_shared_subnetpool(self):
191 created_subnetpool = self._create_subnetpool(is_admin=True,
192 shared=True)
193 pool_id = created_subnetpool['id']
194 # Shared subnetpool can be retrieved by tenant user.
195 body = self.client.show_subnetpool(pool_id)
196 subnetpool = body['subnetpool']
197 self.assertEqual(created_subnetpool['name'], subnetpool['name'])
198 self.assertTrue(subnetpool['shared'])
199
200 def _create_subnet_from_pool(self, subnet_values=None, pool_values=None):
201 if pool_values is None:
202 pool_values = {}
203
204 created_subnetpool = self._create_subnetpool(**pool_values)
205 pool_id = created_subnetpool['id']
206 subnet_name = data_utils.rand_name(SUBNETPOOL_NAME)
207 network = self.create_network()
208 subnet_kwargs = {'name': subnet_name,
209 'subnetpool_id': pool_id}
210 if subnet_values:
211 subnet_kwargs.update(subnet_values)
212 # not creating the subnet using the base.create_subnet because
213 # that function needs to be enhanced to support subnet_create when
214 # prefixlen and subnetpool_id is specified.
215 body = self.client.create_subnet(
216 network_id=network['id'],
217 ip_version=self._ip_version,
218 **subnet_kwargs)
219 subnet = body['subnet']
220 return pool_id, subnet
221
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000222 @test.idempotent_id('1362ed7d-3089-42eb-b3a5-d6cb8398ee77')
223 def test_create_subnet_from_pool_with_prefixlen(self):
224 subnet_values = {"prefixlen": self.max_prefixlen}
225 pool_id, subnet = self._create_subnet_from_pool(
226 subnet_values=subnet_values)
227 cidr = str(subnet['cidr'])
228 self.assertEqual(pool_id, subnet['subnetpool_id'])
229 self.assertTrue(cidr.endswith(str(self.max_prefixlen)))
230
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000231 @test.idempotent_id('86b86189-9789-4582-9c3b-7e2bfe5735ee')
232 def test_create_subnet_from_pool_with_subnet_cidr(self):
233 subnet_values = {"cidr": self.subnet_cidr}
234 pool_id, subnet = self._create_subnet_from_pool(
235 subnet_values=subnet_values)
236 cidr = str(subnet['cidr'])
237 self.assertEqual(pool_id, subnet['subnetpool_id'])
238 self.assertEqual(cidr, self.subnet_cidr)
239
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000240 @test.idempotent_id('83f76e3a-9c40-40c2-a015-b7c5242178d8')
241 def test_create_subnet_from_pool_with_default_prefixlen(self):
242 # If neither cidr nor prefixlen is specified,
243 # subnet will use subnetpool default_prefixlen for cidr.
244 pool_id, subnet = self._create_subnet_from_pool()
245 cidr = str(subnet['cidr'])
246 self.assertEqual(pool_id, subnet['subnetpool_id'])
247 prefixlen = self._subnetpool_data['min_prefixlen']
248 self.assertTrue(cidr.endswith(str(prefixlen)))
249
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000250 @test.idempotent_id('a64af292-ec52-4bde-b654-a6984acaf477')
251 def test_create_subnet_from_pool_with_quota(self):
252 pool_values = {'default_quota': 4}
253 subnet_values = {"prefixlen": self.max_prefixlen}
254 pool_id, subnet = self._create_subnet_from_pool(
255 subnet_values=subnet_values, pool_values=pool_values)
256 cidr = str(subnet['cidr'])
257 self.assertEqual(pool_id, subnet['subnetpool_id'])
258 self.assertTrue(cidr.endswith(str(self.max_prefixlen)))
259
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000260 @test.idempotent_id('49b44c64-1619-4b29-b527-ffc3c3115dc4')
261 @test.requires_ext(extension='address-scope', service='network')
262 def test_create_subnetpool_associate_address_scope(self):
263 address_scope = self.create_address_scope(
264 name=data_utils.rand_name('smoke-address-scope'),
265 ip_version=self._ip_version)
266 created_subnetpool = self._create_subnetpool(
267 address_scope_id=address_scope['id'])
268 body = self.client.show_subnetpool(created_subnetpool['id'])
269 self.assertEqual(address_scope['id'],
270 body['subnetpool']['address_scope_id'])
271
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000272 @test.idempotent_id('910b6393-db24-4f6f-87dc-b36892ad6c8c')
273 @test.requires_ext(extension='address-scope', service='network')
274 def test_update_subnetpool_associate_address_scope(self):
275 address_scope = self.create_address_scope(
276 name=data_utils.rand_name('smoke-address-scope'),
277 ip_version=self._ip_version)
278 created_subnetpool = self._create_subnetpool()
279 pool_id = created_subnetpool['id']
280 body = self.client.show_subnetpool(pool_id)
281 self.assertIsNone(body['subnetpool']['address_scope_id'])
282 self.client.update_subnetpool(pool_id,
283 address_scope_id=address_scope['id'])
284 body = self.client.show_subnetpool(pool_id)
285 self.assertEqual(address_scope['id'],
286 body['subnetpool']['address_scope_id'])
287
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000288 @test.idempotent_id('18302e80-46a3-4563-82ac-ccd1dd57f652')
289 @test.requires_ext(extension='address-scope', service='network')
290 def test_update_subnetpool_associate_another_address_scope(self):
291 address_scope = self.create_address_scope(
292 name=data_utils.rand_name('smoke-address-scope'),
293 ip_version=self._ip_version)
294 another_address_scope = self.create_address_scope(
295 name=data_utils.rand_name('smoke-address-scope'),
296 ip_version=self._ip_version)
297 created_subnetpool = self._create_subnetpool(
298 address_scope_id=address_scope['id'])
299 pool_id = created_subnetpool['id']
300 body = self.client.show_subnetpool(pool_id)
301 self.assertEqual(address_scope['id'],
302 body['subnetpool']['address_scope_id'])
303 self.client.update_subnetpool(
304 pool_id, address_scope_id=another_address_scope['id'])
305 body = self.client.show_subnetpool(pool_id)
306 self.assertEqual(another_address_scope['id'],
307 body['subnetpool']['address_scope_id'])
308
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000309 @test.idempotent_id('f8970048-e41b-42d6-934b-a1297b07706a')
310 @test.requires_ext(extension='address-scope', service='network')
311 def test_update_subnetpool_disassociate_address_scope(self):
312 address_scope = self.create_address_scope(
313 name=data_utils.rand_name('smoke-address-scope'),
314 ip_version=self._ip_version)
315 created_subnetpool = self._create_subnetpool(
316 address_scope_id=address_scope['id'])
317 pool_id = created_subnetpool['id']
318 body = self.client.show_subnetpool(pool_id)
319 self.assertEqual(address_scope['id'],
320 body['subnetpool']['address_scope_id'])
321 self.client.update_subnetpool(pool_id,
322 address_scope_id=None)
323 body = self.client.show_subnetpool(pool_id)
324 self.assertIsNone(body['subnetpool']['address_scope_id'])
325
326
327class SubnetPoolsTestV6(SubnetPoolsTest):
328
329 min_prefixlen = '48'
330 max_prefixlen = '64'
331 _ip_version = 6
332 subnet_cidr = '2001:db8:3::/64'
333 new_prefix = u'2001:db8:5::/64'
334 larger_prefix = u'2001:db8::/32'
335
336 @classmethod
337 def resource_setup(cls):
338 super(SubnetPoolsTestV6, cls).resource_setup()
339 min_prefixlen = '64'
340 prefixes = [u'2001:db8:3::/48']
341 cls._subnetpool_data = {'min_prefixlen': min_prefixlen,
342 'prefixes': prefixes}
343
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000344 @test.idempotent_id('f62d73dc-cf6f-4879-b94b-dab53982bf3b')
345 def test_create_dual_stack_subnets_from_subnetpools(self):
346 pool_id_v6, subnet_v6 = self._create_subnet_from_pool()
347 pool_values_v4 = {'prefixes': ['192.168.0.0/16'],
348 'min_prefixlen': 21,
349 'max_prefixlen': 32}
350 create_v4_subnetpool = self._create_subnetpool(**pool_values_v4)
351 pool_id_v4 = create_v4_subnetpool['id']
352 subnet_v4 = self.client.create_subnet(
353 network_id=subnet_v6['network_id'], ip_version=4,
354 subnetpool_id=pool_id_v4)['subnet']
355 self.assertEqual(subnet_v4['network_id'], subnet_v6['network_id'])
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200356
357
358class SubnetPoolsSearchCriteriaTest(base.BaseSearchCriteriaTest,
359 SubnetPoolsTestBase):
360
361 resource = 'subnetpool'
362
Ihar Hrachyshkaa9035b62016-06-13 11:21:38 +0200363 list_kwargs = {'shared': False}
364
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200365 @classmethod
366 def resource_setup(cls):
367 super(SubnetPoolsSearchCriteriaTest, cls).resource_setup()
368 for name in cls.resource_names:
369 cls._create_subnetpool(name=name)
370
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200371 @test.idempotent_id('6e3f842e-6bfb-49cb-82d3-0026be4e8e04')
372 def test_list_sorts_asc(self):
373 self._test_list_sorts_asc()
374
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200375 @test.idempotent_id('f336859b-b868-438c-a6fc-2c06374115f2')
376 def test_list_sorts_desc(self):
377 self._test_list_sorts_desc()
378
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200379 @test.idempotent_id('1291fae7-c196-4372-ad59-ce7988518f7b')
380 def test_list_pagination(self):
381 self._test_list_pagination()
382
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200383 @test.idempotent_id('ddb20d14-1952-49b4-a17e-231cc2239a52')
384 def test_list_pagination_with_marker(self):
385 self._test_list_pagination_with_marker()
386
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200387 @test.idempotent_id('b3bd9665-2769-4a43-b50c-31b1add12891')
388 def test_list_pagination_with_href_links(self):
389 self._test_list_pagination_with_href_links()
390
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200391 @test.idempotent_id('1ec1f325-43b0-406e-96ce-20539e38a61d')
392 def test_list_pagination_page_reverse_asc(self):
393 self._test_list_pagination_page_reverse_asc()
394
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200395 @test.idempotent_id('f43a293e-4aaa-48f4-aeaf-de63a676357c')
396 def test_list_pagination_page_reverse_desc(self):
397 self._test_list_pagination_page_reverse_desc()
398
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200399 @test.idempotent_id('73511385-839c-4829-8ac1-b5ad992126c4')
400 def test_list_pagination_page_reverse_with_href_links(self):
401 self._test_list_pagination_page_reverse_with_href_links()
402
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200403 @test.idempotent_id('82a13efc-c18f-4249-b8ec-cec7cf26fbd6')
404 def test_list_no_pagination_limit_0(self):
405 self._test_list_no_pagination_limit_0()
Victor Morales1be97b42016-09-05 08:50:06 -0500406
407 @test.idempotent_id('27feb3f8-40f4-4e50-8cd2-7d0096a98682')
408 def test_list_validation_filters(self):
409 self._test_list_validation_filters()