blob: a7a523eae944c1a01e061428625acbc07f904da0 [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
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000136 @test.idempotent_id('764f1b93-1c4a-4513-9e7b-6c2fc5e9270c')
137 def test_tenant_update_subnetpool(self):
138 created_subnetpool = self._create_subnetpool()
139 pool_id = created_subnetpool['id']
140 subnetpool_data = self._new_subnetpool_attributes()
141 self.client.update_subnetpool(created_subnetpool['id'],
142 **subnetpool_data)
143
144 body = self.client.show_subnetpool(pool_id)
145 subnetpool = body['subnetpool']
146 self._check_equality_updated_subnetpool(subnetpool_data,
147 subnetpool)
148 self.assertFalse(subnetpool['shared'])
149
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000150 @test.idempotent_id('4b496082-c992-4319-90be-d4a7ce646290')
151 def test_update_subnetpool_prefixes_append(self):
152 # We can append new prefixes to subnetpool
153 create_subnetpool = self._create_subnetpool()
154 pool_id = create_subnetpool['id']
155 old_prefixes = self._subnetpool_data['prefixes']
156 new_prefixes = old_prefixes[:]
157 new_prefixes.append(self.new_prefix)
158 subnetpool_data = {'prefixes': new_prefixes}
159 self.client.update_subnetpool(pool_id, **subnetpool_data)
160 body = self.client.show_subnetpool(pool_id)
161 prefixes = body['subnetpool']['prefixes']
162 self.assertIn(self.new_prefix, prefixes)
163 self.assertIn(old_prefixes[0], prefixes)
164
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000165 @test.idempotent_id('2cae5d6a-9d32-42d8-8067-f13970ae13bb')
166 def test_update_subnetpool_prefixes_extend(self):
167 # We can extend current subnetpool prefixes
168 created_subnetpool = self._create_subnetpool()
169 pool_id = created_subnetpool['id']
170 old_prefixes = self._subnetpool_data['prefixes']
171 subnetpool_data = {'prefixes': [self.larger_prefix]}
172 self.client.update_subnetpool(pool_id, **subnetpool_data)
173 body = self.client.show_subnetpool(pool_id)
174 prefixes = body['subnetpool']['prefixes']
175 self.assertIn(self.larger_prefix, prefixes)
176 self.assertNotIn(old_prefixes[0], prefixes)
177
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000178 @test.idempotent_id('d70c6c35-913b-4f24-909f-14cd0d29b2d2')
179 def test_admin_create_shared_subnetpool(self):
180 created_subnetpool = self._create_subnetpool(is_admin=True,
181 shared=True)
182 pool_id = created_subnetpool['id']
183 # Shared subnetpool can be retrieved by tenant user.
184 body = self.client.show_subnetpool(pool_id)
185 subnetpool = body['subnetpool']
186 self.assertEqual(created_subnetpool['name'], subnetpool['name'])
187 self.assertTrue(subnetpool['shared'])
188
189 def _create_subnet_from_pool(self, subnet_values=None, pool_values=None):
190 if pool_values is None:
191 pool_values = {}
192
193 created_subnetpool = self._create_subnetpool(**pool_values)
194 pool_id = created_subnetpool['id']
195 subnet_name = data_utils.rand_name(SUBNETPOOL_NAME)
196 network = self.create_network()
197 subnet_kwargs = {'name': subnet_name,
198 'subnetpool_id': pool_id}
199 if subnet_values:
200 subnet_kwargs.update(subnet_values)
201 # not creating the subnet using the base.create_subnet because
202 # that function needs to be enhanced to support subnet_create when
203 # prefixlen and subnetpool_id is specified.
204 body = self.client.create_subnet(
205 network_id=network['id'],
206 ip_version=self._ip_version,
207 **subnet_kwargs)
208 subnet = body['subnet']
209 return pool_id, subnet
210
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000211 @test.idempotent_id('1362ed7d-3089-42eb-b3a5-d6cb8398ee77')
212 def test_create_subnet_from_pool_with_prefixlen(self):
213 subnet_values = {"prefixlen": self.max_prefixlen}
214 pool_id, subnet = self._create_subnet_from_pool(
215 subnet_values=subnet_values)
216 cidr = str(subnet['cidr'])
217 self.assertEqual(pool_id, subnet['subnetpool_id'])
218 self.assertTrue(cidr.endswith(str(self.max_prefixlen)))
219
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000220 @test.idempotent_id('86b86189-9789-4582-9c3b-7e2bfe5735ee')
221 def test_create_subnet_from_pool_with_subnet_cidr(self):
222 subnet_values = {"cidr": self.subnet_cidr}
223 pool_id, subnet = self._create_subnet_from_pool(
224 subnet_values=subnet_values)
225 cidr = str(subnet['cidr'])
226 self.assertEqual(pool_id, subnet['subnetpool_id'])
227 self.assertEqual(cidr, self.subnet_cidr)
228
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000229 @test.idempotent_id('83f76e3a-9c40-40c2-a015-b7c5242178d8')
230 def test_create_subnet_from_pool_with_default_prefixlen(self):
231 # If neither cidr nor prefixlen is specified,
232 # subnet will use subnetpool default_prefixlen for cidr.
233 pool_id, subnet = self._create_subnet_from_pool()
234 cidr = str(subnet['cidr'])
235 self.assertEqual(pool_id, subnet['subnetpool_id'])
236 prefixlen = self._subnetpool_data['min_prefixlen']
237 self.assertTrue(cidr.endswith(str(prefixlen)))
238
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000239 @test.idempotent_id('a64af292-ec52-4bde-b654-a6984acaf477')
240 def test_create_subnet_from_pool_with_quota(self):
241 pool_values = {'default_quota': 4}
242 subnet_values = {"prefixlen": self.max_prefixlen}
243 pool_id, subnet = self._create_subnet_from_pool(
244 subnet_values=subnet_values, pool_values=pool_values)
245 cidr = str(subnet['cidr'])
246 self.assertEqual(pool_id, subnet['subnetpool_id'])
247 self.assertTrue(cidr.endswith(str(self.max_prefixlen)))
248
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000249 @test.idempotent_id('49b44c64-1619-4b29-b527-ffc3c3115dc4')
250 @test.requires_ext(extension='address-scope', service='network')
251 def test_create_subnetpool_associate_address_scope(self):
252 address_scope = self.create_address_scope(
253 name=data_utils.rand_name('smoke-address-scope'),
254 ip_version=self._ip_version)
255 created_subnetpool = self._create_subnetpool(
256 address_scope_id=address_scope['id'])
257 body = self.client.show_subnetpool(created_subnetpool['id'])
258 self.assertEqual(address_scope['id'],
259 body['subnetpool']['address_scope_id'])
260
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000261 @test.idempotent_id('910b6393-db24-4f6f-87dc-b36892ad6c8c')
262 @test.requires_ext(extension='address-scope', service='network')
263 def test_update_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 pool_id = created_subnetpool['id']
269 body = self.client.show_subnetpool(pool_id)
270 self.assertIsNone(body['subnetpool']['address_scope_id'])
271 self.client.update_subnetpool(pool_id,
272 address_scope_id=address_scope['id'])
273 body = self.client.show_subnetpool(pool_id)
274 self.assertEqual(address_scope['id'],
275 body['subnetpool']['address_scope_id'])
276
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000277 @test.idempotent_id('18302e80-46a3-4563-82ac-ccd1dd57f652')
278 @test.requires_ext(extension='address-scope', service='network')
279 def test_update_subnetpool_associate_another_address_scope(self):
280 address_scope = self.create_address_scope(
281 name=data_utils.rand_name('smoke-address-scope'),
282 ip_version=self._ip_version)
283 another_address_scope = self.create_address_scope(
284 name=data_utils.rand_name('smoke-address-scope'),
285 ip_version=self._ip_version)
286 created_subnetpool = self._create_subnetpool(
287 address_scope_id=address_scope['id'])
288 pool_id = created_subnetpool['id']
289 body = self.client.show_subnetpool(pool_id)
290 self.assertEqual(address_scope['id'],
291 body['subnetpool']['address_scope_id'])
292 self.client.update_subnetpool(
293 pool_id, address_scope_id=another_address_scope['id'])
294 body = self.client.show_subnetpool(pool_id)
295 self.assertEqual(another_address_scope['id'],
296 body['subnetpool']['address_scope_id'])
297
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000298 @test.idempotent_id('f8970048-e41b-42d6-934b-a1297b07706a')
299 @test.requires_ext(extension='address-scope', service='network')
300 def test_update_subnetpool_disassociate_address_scope(self):
301 address_scope = self.create_address_scope(
302 name=data_utils.rand_name('smoke-address-scope'),
303 ip_version=self._ip_version)
304 created_subnetpool = self._create_subnetpool(
305 address_scope_id=address_scope['id'])
306 pool_id = created_subnetpool['id']
307 body = self.client.show_subnetpool(pool_id)
308 self.assertEqual(address_scope['id'],
309 body['subnetpool']['address_scope_id'])
310 self.client.update_subnetpool(pool_id,
311 address_scope_id=None)
312 body = self.client.show_subnetpool(pool_id)
313 self.assertIsNone(body['subnetpool']['address_scope_id'])
314
315
316class SubnetPoolsTestV6(SubnetPoolsTest):
317
318 min_prefixlen = '48'
319 max_prefixlen = '64'
320 _ip_version = 6
321 subnet_cidr = '2001:db8:3::/64'
322 new_prefix = u'2001:db8:5::/64'
323 larger_prefix = u'2001:db8::/32'
324
325 @classmethod
326 def resource_setup(cls):
327 super(SubnetPoolsTestV6, cls).resource_setup()
328 min_prefixlen = '64'
329 prefixes = [u'2001:db8:3::/48']
330 cls._subnetpool_data = {'min_prefixlen': min_prefixlen,
331 'prefixes': prefixes}
332
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000333 @test.idempotent_id('f62d73dc-cf6f-4879-b94b-dab53982bf3b')
334 def test_create_dual_stack_subnets_from_subnetpools(self):
335 pool_id_v6, subnet_v6 = self._create_subnet_from_pool()
336 pool_values_v4 = {'prefixes': ['192.168.0.0/16'],
337 'min_prefixlen': 21,
338 'max_prefixlen': 32}
339 create_v4_subnetpool = self._create_subnetpool(**pool_values_v4)
340 pool_id_v4 = create_v4_subnetpool['id']
341 subnet_v4 = self.client.create_subnet(
342 network_id=subnet_v6['network_id'], ip_version=4,
343 subnetpool_id=pool_id_v4)['subnet']
344 self.assertEqual(subnet_v4['network_id'], subnet_v6['network_id'])
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200345
346
347class SubnetPoolsSearchCriteriaTest(base.BaseSearchCriteriaTest,
348 SubnetPoolsTestBase):
349
350 resource = 'subnetpool'
351
Ihar Hrachyshkaa9035b62016-06-13 11:21:38 +0200352 list_kwargs = {'shared': False}
353
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200354 @classmethod
355 def resource_setup(cls):
356 super(SubnetPoolsSearchCriteriaTest, cls).resource_setup()
357 for name in cls.resource_names:
358 cls._create_subnetpool(name=name)
359
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200360 @test.idempotent_id('6e3f842e-6bfb-49cb-82d3-0026be4e8e04')
361 def test_list_sorts_asc(self):
362 self._test_list_sorts_asc()
363
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200364 @test.idempotent_id('f336859b-b868-438c-a6fc-2c06374115f2')
365 def test_list_sorts_desc(self):
366 self._test_list_sorts_desc()
367
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200368 @test.idempotent_id('1291fae7-c196-4372-ad59-ce7988518f7b')
369 def test_list_pagination(self):
370 self._test_list_pagination()
371
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200372 @test.idempotent_id('ddb20d14-1952-49b4-a17e-231cc2239a52')
373 def test_list_pagination_with_marker(self):
374 self._test_list_pagination_with_marker()
375
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200376 @test.idempotent_id('b3bd9665-2769-4a43-b50c-31b1add12891')
377 def test_list_pagination_with_href_links(self):
378 self._test_list_pagination_with_href_links()
379
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200380 @test.idempotent_id('1ec1f325-43b0-406e-96ce-20539e38a61d')
381 def test_list_pagination_page_reverse_asc(self):
382 self._test_list_pagination_page_reverse_asc()
383
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200384 @test.idempotent_id('f43a293e-4aaa-48f4-aeaf-de63a676357c')
385 def test_list_pagination_page_reverse_desc(self):
386 self._test_list_pagination_page_reverse_desc()
387
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200388 @test.idempotent_id('73511385-839c-4829-8ac1-b5ad992126c4')
389 def test_list_pagination_page_reverse_with_href_links(self):
390 self._test_list_pagination_page_reverse_with_href_links()
391
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200392 @test.idempotent_id('82a13efc-c18f-4249-b8ec-cec7cf26fbd6')
393 def test_list_no_pagination_limit_0(self):
394 self._test_list_no_pagination_limit_0()