blob: 87d5c0563d8ac96d3ef5b20b4ecaabcc9f9f9e7c [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']
113 body = filter(lambda x: x['id'] == sub_id,
114 self.client.list_subnetpools()['subnetpools'])[0]
115 self.assertEqual('d1', body['description'])
116 body = self.client.update_subnetpool(sub_id, description='d2')
117 self.assertEqual('d2', body['subnetpool']['description'])
118 body = filter(lambda x: x['id'] == sub_id,
119 self.client.list_subnetpools()['subnetpools'])[0]
120 self.assertEqual('d2', body['description'])
121
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000122 @test.idempotent_id('741d08c2-1e3f-42be-99c7-0ea93c5b728c')
123 def test_get_subnetpool(self):
124 created_subnetpool = self._create_subnetpool()
125 prefixlen = self._subnetpool_data['min_prefixlen']
126 body = self.client.show_subnetpool(created_subnetpool['id'])
127 subnetpool = body['subnetpool']
128 self.assertEqual(created_subnetpool['name'], subnetpool['name'])
129 self.assertEqual(created_subnetpool['id'], subnetpool['id'])
130 self.assertEqual(prefixlen, subnetpool['min_prefixlen'])
131 self.assertEqual(prefixlen, subnetpool['default_prefixlen'])
132 self.assertFalse(subnetpool['shared'])
133
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000134 @test.idempotent_id('764f1b93-1c4a-4513-9e7b-6c2fc5e9270c')
135 def test_tenant_update_subnetpool(self):
136 created_subnetpool = self._create_subnetpool()
137 pool_id = created_subnetpool['id']
138 subnetpool_data = self._new_subnetpool_attributes()
139 self.client.update_subnetpool(created_subnetpool['id'],
140 **subnetpool_data)
141
142 body = self.client.show_subnetpool(pool_id)
143 subnetpool = body['subnetpool']
144 self._check_equality_updated_subnetpool(subnetpool_data,
145 subnetpool)
146 self.assertFalse(subnetpool['shared'])
147
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000148 @test.idempotent_id('4b496082-c992-4319-90be-d4a7ce646290')
149 def test_update_subnetpool_prefixes_append(self):
150 # We can append new prefixes to subnetpool
151 create_subnetpool = self._create_subnetpool()
152 pool_id = create_subnetpool['id']
153 old_prefixes = self._subnetpool_data['prefixes']
154 new_prefixes = old_prefixes[:]
155 new_prefixes.append(self.new_prefix)
156 subnetpool_data = {'prefixes': new_prefixes}
157 self.client.update_subnetpool(pool_id, **subnetpool_data)
158 body = self.client.show_subnetpool(pool_id)
159 prefixes = body['subnetpool']['prefixes']
160 self.assertIn(self.new_prefix, prefixes)
161 self.assertIn(old_prefixes[0], prefixes)
162
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000163 @test.idempotent_id('2cae5d6a-9d32-42d8-8067-f13970ae13bb')
164 def test_update_subnetpool_prefixes_extend(self):
165 # We can extend current subnetpool prefixes
166 created_subnetpool = self._create_subnetpool()
167 pool_id = created_subnetpool['id']
168 old_prefixes = self._subnetpool_data['prefixes']
169 subnetpool_data = {'prefixes': [self.larger_prefix]}
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.larger_prefix, prefixes)
174 self.assertNotIn(old_prefixes[0], prefixes)
175
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000176 @test.idempotent_id('d70c6c35-913b-4f24-909f-14cd0d29b2d2')
177 def test_admin_create_shared_subnetpool(self):
178 created_subnetpool = self._create_subnetpool(is_admin=True,
179 shared=True)
180 pool_id = created_subnetpool['id']
181 # Shared subnetpool can be retrieved by tenant user.
182 body = self.client.show_subnetpool(pool_id)
183 subnetpool = body['subnetpool']
184 self.assertEqual(created_subnetpool['name'], subnetpool['name'])
185 self.assertTrue(subnetpool['shared'])
186
187 def _create_subnet_from_pool(self, subnet_values=None, pool_values=None):
188 if pool_values is None:
189 pool_values = {}
190
191 created_subnetpool = self._create_subnetpool(**pool_values)
192 pool_id = created_subnetpool['id']
193 subnet_name = data_utils.rand_name(SUBNETPOOL_NAME)
194 network = self.create_network()
195 subnet_kwargs = {'name': subnet_name,
196 'subnetpool_id': pool_id}
197 if subnet_values:
198 subnet_kwargs.update(subnet_values)
199 # not creating the subnet using the base.create_subnet because
200 # that function needs to be enhanced to support subnet_create when
201 # prefixlen and subnetpool_id is specified.
202 body = self.client.create_subnet(
203 network_id=network['id'],
204 ip_version=self._ip_version,
205 **subnet_kwargs)
206 subnet = body['subnet']
207 return pool_id, subnet
208
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000209 @test.idempotent_id('1362ed7d-3089-42eb-b3a5-d6cb8398ee77')
210 def test_create_subnet_from_pool_with_prefixlen(self):
211 subnet_values = {"prefixlen": self.max_prefixlen}
212 pool_id, subnet = self._create_subnet_from_pool(
213 subnet_values=subnet_values)
214 cidr = str(subnet['cidr'])
215 self.assertEqual(pool_id, subnet['subnetpool_id'])
216 self.assertTrue(cidr.endswith(str(self.max_prefixlen)))
217
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000218 @test.idempotent_id('86b86189-9789-4582-9c3b-7e2bfe5735ee')
219 def test_create_subnet_from_pool_with_subnet_cidr(self):
220 subnet_values = {"cidr": self.subnet_cidr}
221 pool_id, subnet = self._create_subnet_from_pool(
222 subnet_values=subnet_values)
223 cidr = str(subnet['cidr'])
224 self.assertEqual(pool_id, subnet['subnetpool_id'])
225 self.assertEqual(cidr, self.subnet_cidr)
226
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000227 @test.idempotent_id('83f76e3a-9c40-40c2-a015-b7c5242178d8')
228 def test_create_subnet_from_pool_with_default_prefixlen(self):
229 # If neither cidr nor prefixlen is specified,
230 # subnet will use subnetpool default_prefixlen for cidr.
231 pool_id, subnet = self._create_subnet_from_pool()
232 cidr = str(subnet['cidr'])
233 self.assertEqual(pool_id, subnet['subnetpool_id'])
234 prefixlen = self._subnetpool_data['min_prefixlen']
235 self.assertTrue(cidr.endswith(str(prefixlen)))
236
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000237 @test.idempotent_id('a64af292-ec52-4bde-b654-a6984acaf477')
238 def test_create_subnet_from_pool_with_quota(self):
239 pool_values = {'default_quota': 4}
240 subnet_values = {"prefixlen": self.max_prefixlen}
241 pool_id, subnet = self._create_subnet_from_pool(
242 subnet_values=subnet_values, pool_values=pool_values)
243 cidr = str(subnet['cidr'])
244 self.assertEqual(pool_id, subnet['subnetpool_id'])
245 self.assertTrue(cidr.endswith(str(self.max_prefixlen)))
246
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000247 @test.idempotent_id('49b44c64-1619-4b29-b527-ffc3c3115dc4')
248 @test.requires_ext(extension='address-scope', service='network')
249 def test_create_subnetpool_associate_address_scope(self):
250 address_scope = self.create_address_scope(
251 name=data_utils.rand_name('smoke-address-scope'),
252 ip_version=self._ip_version)
253 created_subnetpool = self._create_subnetpool(
254 address_scope_id=address_scope['id'])
255 body = self.client.show_subnetpool(created_subnetpool['id'])
256 self.assertEqual(address_scope['id'],
257 body['subnetpool']['address_scope_id'])
258
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000259 @test.idempotent_id('910b6393-db24-4f6f-87dc-b36892ad6c8c')
260 @test.requires_ext(extension='address-scope', service='network')
261 def test_update_subnetpool_associate_address_scope(self):
262 address_scope = self.create_address_scope(
263 name=data_utils.rand_name('smoke-address-scope'),
264 ip_version=self._ip_version)
265 created_subnetpool = self._create_subnetpool()
266 pool_id = created_subnetpool['id']
267 body = self.client.show_subnetpool(pool_id)
268 self.assertIsNone(body['subnetpool']['address_scope_id'])
269 self.client.update_subnetpool(pool_id,
270 address_scope_id=address_scope['id'])
271 body = self.client.show_subnetpool(pool_id)
272 self.assertEqual(address_scope['id'],
273 body['subnetpool']['address_scope_id'])
274
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000275 @test.idempotent_id('18302e80-46a3-4563-82ac-ccd1dd57f652')
276 @test.requires_ext(extension='address-scope', service='network')
277 def test_update_subnetpool_associate_another_address_scope(self):
278 address_scope = self.create_address_scope(
279 name=data_utils.rand_name('smoke-address-scope'),
280 ip_version=self._ip_version)
281 another_address_scope = self.create_address_scope(
282 name=data_utils.rand_name('smoke-address-scope'),
283 ip_version=self._ip_version)
284 created_subnetpool = self._create_subnetpool(
285 address_scope_id=address_scope['id'])
286 pool_id = created_subnetpool['id']
287 body = self.client.show_subnetpool(pool_id)
288 self.assertEqual(address_scope['id'],
289 body['subnetpool']['address_scope_id'])
290 self.client.update_subnetpool(
291 pool_id, address_scope_id=another_address_scope['id'])
292 body = self.client.show_subnetpool(pool_id)
293 self.assertEqual(another_address_scope['id'],
294 body['subnetpool']['address_scope_id'])
295
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000296 @test.idempotent_id('f8970048-e41b-42d6-934b-a1297b07706a')
297 @test.requires_ext(extension='address-scope', service='network')
298 def test_update_subnetpool_disassociate_address_scope(self):
299 address_scope = self.create_address_scope(
300 name=data_utils.rand_name('smoke-address-scope'),
301 ip_version=self._ip_version)
302 created_subnetpool = self._create_subnetpool(
303 address_scope_id=address_scope['id'])
304 pool_id = created_subnetpool['id']
305 body = self.client.show_subnetpool(pool_id)
306 self.assertEqual(address_scope['id'],
307 body['subnetpool']['address_scope_id'])
308 self.client.update_subnetpool(pool_id,
309 address_scope_id=None)
310 body = self.client.show_subnetpool(pool_id)
311 self.assertIsNone(body['subnetpool']['address_scope_id'])
312
313
314class SubnetPoolsTestV6(SubnetPoolsTest):
315
316 min_prefixlen = '48'
317 max_prefixlen = '64'
318 _ip_version = 6
319 subnet_cidr = '2001:db8:3::/64'
320 new_prefix = u'2001:db8:5::/64'
321 larger_prefix = u'2001:db8::/32'
322
323 @classmethod
324 def resource_setup(cls):
325 super(SubnetPoolsTestV6, cls).resource_setup()
326 min_prefixlen = '64'
327 prefixes = [u'2001:db8:3::/48']
328 cls._subnetpool_data = {'min_prefixlen': min_prefixlen,
329 'prefixes': prefixes}
330
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000331 @test.idempotent_id('f62d73dc-cf6f-4879-b94b-dab53982bf3b')
332 def test_create_dual_stack_subnets_from_subnetpools(self):
333 pool_id_v6, subnet_v6 = self._create_subnet_from_pool()
334 pool_values_v4 = {'prefixes': ['192.168.0.0/16'],
335 'min_prefixlen': 21,
336 'max_prefixlen': 32}
337 create_v4_subnetpool = self._create_subnetpool(**pool_values_v4)
338 pool_id_v4 = create_v4_subnetpool['id']
339 subnet_v4 = self.client.create_subnet(
340 network_id=subnet_v6['network_id'], ip_version=4,
341 subnetpool_id=pool_id_v4)['subnet']
342 self.assertEqual(subnet_v4['network_id'], subnet_v6['network_id'])
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200343
344
345class SubnetPoolsSearchCriteriaTest(base.BaseSearchCriteriaTest,
346 SubnetPoolsTestBase):
347
348 resource = 'subnetpool'
349
350 @classmethod
351 def resource_setup(cls):
352 super(SubnetPoolsSearchCriteriaTest, cls).resource_setup()
353 for name in cls.resource_names:
354 cls._create_subnetpool(name=name)
355
356 @test.attr(type='smoke')
357 @test.idempotent_id('6e3f842e-6bfb-49cb-82d3-0026be4e8e04')
358 def test_list_sorts_asc(self):
359 self._test_list_sorts_asc()
360
361 @test.attr(type='smoke')
362 @test.idempotent_id('f336859b-b868-438c-a6fc-2c06374115f2')
363 def test_list_sorts_desc(self):
364 self._test_list_sorts_desc()
365
366 @test.attr(type='smoke')
367 @test.idempotent_id('1291fae7-c196-4372-ad59-ce7988518f7b')
368 def test_list_pagination(self):
369 self._test_list_pagination()
370
371 @test.attr(type='smoke')
372 @test.idempotent_id('ddb20d14-1952-49b4-a17e-231cc2239a52')
373 def test_list_pagination_with_marker(self):
374 self._test_list_pagination_with_marker()
375
376 @test.attr(type='smoke')
377 @test.idempotent_id('b3bd9665-2769-4a43-b50c-31b1add12891')
378 def test_list_pagination_with_href_links(self):
379 self._test_list_pagination_with_href_links()
380
381 @test.attr(type='smoke')
382 @test.idempotent_id('1ec1f325-43b0-406e-96ce-20539e38a61d')
383 def test_list_pagination_page_reverse_asc(self):
384 self._test_list_pagination_page_reverse_asc()
385
386 @test.attr(type='smoke')
387 @test.idempotent_id('f43a293e-4aaa-48f4-aeaf-de63a676357c')
388 def test_list_pagination_page_reverse_desc(self):
389 self._test_list_pagination_page_reverse_desc()
390
391 @test.attr(type='smoke')
392 @test.idempotent_id('73511385-839c-4829-8ac1-b5ad992126c4')
393 def test_list_pagination_page_reverse_with_href_links(self):
394 self._test_list_pagination_page_reverse_with_href_links()
395
396 @test.attr(type='smoke')
397 @test.idempotent_id('82a13efc-c18f-4249-b8ec-cec7cf26fbd6')
398 def test_list_no_pagination_limit_0(self):
399 self._test_list_no_pagination_limit_0()