blob: 9ab7a49e3b3f91c5e0a2d40bf7b3d01566465dca [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.
Igor Malinovskiy649c0182020-03-06 17:30:47 +020015import testtools
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000016
Chandan Kumarc125fd12017-11-15 19:41:01 +053017from tempest.common import utils
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000018from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000019from tempest.lib import decorators
Igor Malinovskiy649c0182020-03-06 17:30:47 +020020from tempest.lib import exceptions as lib_exc
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000021
Chandan Kumar667d3d32017-09-22 12:24:06 +053022from neutron_tempest_plugin.api import base
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000023
24SUBNETPOOL_NAME = 'smoke-subnetpool'
25SUBNET_NAME = 'smoke-subnet'
26
27
28class SubnetPoolsTestBase(base.BaseAdminNetworkTest):
29
30 @classmethod
Ilya Menkov5cdb9d92020-05-06 11:52:44 +040031 def skip_checks(cls):
32 super(SubnetPoolsTestBase, cls).skip_checks()
33 if not utils.is_extension_enabled('default-subnetpools', 'network'):
34 msg = "default-subnetpools extension not enabled."
35 raise cls.skipException(msg)
36
37 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000038 def resource_setup(cls):
39 super(SubnetPoolsTestBase, cls).resource_setup()
40 min_prefixlen = '29'
41 prefixes = [u'10.11.12.0/24']
42 cls._subnetpool_data = {'prefixes': prefixes,
43 'min_prefixlen': min_prefixlen}
44
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +020045 @classmethod
46 def _create_subnetpool(cls, is_admin=False, **kwargs):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000047 if 'name' not in kwargs:
48 name = data_utils.rand_name(SUBNETPOOL_NAME)
49 else:
50 name = kwargs.pop('name')
51
52 if 'prefixes' not in kwargs:
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +020053 kwargs['prefixes'] = cls._subnetpool_data['prefixes']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000054
55 if 'min_prefixlen' not in kwargs:
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +020056 kwargs['min_prefixlen'] = cls._subnetpool_data['min_prefixlen']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000057
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +020058 return cls.create_subnetpool(name=name, is_admin=is_admin, **kwargs)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000059
60
61class SubnetPoolsTest(SubnetPoolsTestBase):
62
63 min_prefixlen = '28'
Lucas Alvares Gomes7ff60d82018-04-09 16:28:49 +010064 max_prefixlen = '30'
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000065 _ip_version = 4
Lucas Alvares Gomes7ff60d82018-04-09 16:28:49 +010066 subnet_cidr = u'10.11.12.0/29'
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000067 new_prefix = u'10.11.15.0/24'
68 larger_prefix = u'10.11.0.0/16'
69
Brian Haleyae328b92018-10-09 19:51:54 -040070 """Test Subnet Pools
71
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000072 Tests the following operations in the Neutron API using the REST client for
73 Neutron:
74
75 create a subnetpool for a tenant
76 list tenant's subnetpools
77 show a tenant subnetpool details
78 subnetpool update
79 delete a subnetpool
80
81 All subnetpool tests are run once with ipv4 and once with ipv6.
82
83 v2.0 of the Neutron API is assumed.
84
85 """
86
87 def _new_subnetpool_attributes(self):
88 new_name = data_utils.rand_name(SUBNETPOOL_NAME)
89 return {'name': new_name, 'min_prefixlen': self.min_prefixlen,
90 'max_prefixlen': self.max_prefixlen}
91
92 def _check_equality_updated_subnetpool(self, expected_values,
93 updated_pool):
94 self.assertEqual(expected_values['name'],
95 updated_pool['name'])
96 self.assertEqual(expected_values['min_prefixlen'],
97 updated_pool['min_prefixlen'])
98 self.assertEqual(expected_values['max_prefixlen'],
99 updated_pool['max_prefixlen'])
100 # expected_values may not contains all subnetpool values
101 if 'prefixes' in expected_values:
102 self.assertEqual(expected_values['prefixes'],
103 updated_pool['prefixes'])
104
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000105 @decorators.idempotent_id('6e1781ec-b45b-4042-aebe-f485c022996e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000106 def test_create_list_subnetpool(self):
107 created_subnetpool = self._create_subnetpool()
108 body = self.client.list_subnetpools()
109 subnetpools = body['subnetpools']
110 self.assertIn(created_subnetpool['id'],
111 [sp['id'] for sp in subnetpools],
112 "Created subnetpool id should be in the list")
113 self.assertIn(created_subnetpool['name'],
114 [sp['name'] for sp in subnetpools],
115 "Created subnetpool name should be in the list")
116
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000117 @decorators.idempotent_id('c72c1c0c-2193-4aca-ddd4-b1442640bbbb')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530118 @utils.requires_ext(extension="standard-attr-description",
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000119 service="network")
120 def test_create_update_subnetpool_description(self):
121 body = self._create_subnetpool(description='d1')
122 self.assertEqual('d1', body['description'])
123 sub_id = body['id']
Nguyen Phuong Anc486b972016-08-29 18:15:30 +0700124 subnet_pools = [x for x in
125 self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id]
126 body = subnet_pools[0]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000127 self.assertEqual('d1', body['description'])
128 body = self.client.update_subnetpool(sub_id, description='d2')
129 self.assertEqual('d2', body['subnetpool']['description'])
Nguyen Phuong Anc486b972016-08-29 18:15:30 +0700130 subnet_pools = [x for x in
131 self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id]
132 body = subnet_pools[0]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000133 self.assertEqual('d2', body['description'])
134
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000135 @decorators.idempotent_id('741d08c2-1e3f-42be-99c7-0ea93c5b728c')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000136 def test_get_subnetpool(self):
137 created_subnetpool = self._create_subnetpool()
138 prefixlen = self._subnetpool_data['min_prefixlen']
139 body = self.client.show_subnetpool(created_subnetpool['id'])
140 subnetpool = body['subnetpool']
141 self.assertEqual(created_subnetpool['name'], subnetpool['name'])
142 self.assertEqual(created_subnetpool['id'], subnetpool['id'])
143 self.assertEqual(prefixlen, subnetpool['min_prefixlen'])
144 self.assertEqual(prefixlen, subnetpool['default_prefixlen'])
145 self.assertFalse(subnetpool['shared'])
146
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000147 @decorators.idempotent_id('5bf9f1e2-efc8-4195-acf3-d12b2bd68dd3')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530148 @utils.requires_ext(extension="project-id", service="network")
Henry Gessaufa6c78d2016-10-09 19:56:09 -0400149 def test_show_subnetpool_has_project_id(self):
150 subnetpool = self._create_subnetpool()
151 body = self.client.show_subnetpool(subnetpool['id'])
152 show_subnetpool = body['subnetpool']
153 self.assertIn('project_id', show_subnetpool)
154 self.assertIn('tenant_id', show_subnetpool)
155 self.assertEqual(self.client.tenant_id, show_subnetpool['project_id'])
156 self.assertEqual(self.client.tenant_id, show_subnetpool['tenant_id'])
157
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000158 @decorators.idempotent_id('764f1b93-1c4a-4513-9e7b-6c2fc5e9270c')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000159 def test_tenant_update_subnetpool(self):
160 created_subnetpool = self._create_subnetpool()
161 pool_id = created_subnetpool['id']
162 subnetpool_data = self._new_subnetpool_attributes()
163 self.client.update_subnetpool(created_subnetpool['id'],
164 **subnetpool_data)
165
166 body = self.client.show_subnetpool(pool_id)
167 subnetpool = body['subnetpool']
168 self._check_equality_updated_subnetpool(subnetpool_data,
169 subnetpool)
170 self.assertFalse(subnetpool['shared'])
171
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000172 @decorators.idempotent_id('4b496082-c992-4319-90be-d4a7ce646290')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000173 def test_update_subnetpool_prefixes_append(self):
174 # We can append new prefixes to subnetpool
175 create_subnetpool = self._create_subnetpool()
176 pool_id = create_subnetpool['id']
177 old_prefixes = self._subnetpool_data['prefixes']
178 new_prefixes = old_prefixes[:]
179 new_prefixes.append(self.new_prefix)
180 subnetpool_data = {'prefixes': new_prefixes}
181 self.client.update_subnetpool(pool_id, **subnetpool_data)
182 body = self.client.show_subnetpool(pool_id)
183 prefixes = body['subnetpool']['prefixes']
184 self.assertIn(self.new_prefix, prefixes)
185 self.assertIn(old_prefixes[0], prefixes)
186
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000187 @decorators.idempotent_id('2cae5d6a-9d32-42d8-8067-f13970ae13bb')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000188 def test_update_subnetpool_prefixes_extend(self):
189 # We can extend current subnetpool prefixes
190 created_subnetpool = self._create_subnetpool()
191 pool_id = created_subnetpool['id']
192 old_prefixes = self._subnetpool_data['prefixes']
193 subnetpool_data = {'prefixes': [self.larger_prefix]}
194 self.client.update_subnetpool(pool_id, **subnetpool_data)
195 body = self.client.show_subnetpool(pool_id)
196 prefixes = body['subnetpool']['prefixes']
197 self.assertIn(self.larger_prefix, prefixes)
198 self.assertNotIn(old_prefixes[0], prefixes)
199
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000200 @decorators.idempotent_id('d70c6c35-913b-4f24-909f-14cd0d29b2d2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000201 def test_admin_create_shared_subnetpool(self):
202 created_subnetpool = self._create_subnetpool(is_admin=True,
203 shared=True)
204 pool_id = created_subnetpool['id']
205 # Shared subnetpool can be retrieved by tenant user.
206 body = self.client.show_subnetpool(pool_id)
207 subnetpool = body['subnetpool']
208 self.assertEqual(created_subnetpool['name'], subnetpool['name'])
209 self.assertTrue(subnetpool['shared'])
210
211 def _create_subnet_from_pool(self, subnet_values=None, pool_values=None):
212 if pool_values is None:
213 pool_values = {}
214
215 created_subnetpool = self._create_subnetpool(**pool_values)
216 pool_id = created_subnetpool['id']
217 subnet_name = data_utils.rand_name(SUBNETPOOL_NAME)
218 network = self.create_network()
219 subnet_kwargs = {'name': subnet_name,
220 'subnetpool_id': pool_id}
221 if subnet_values:
222 subnet_kwargs.update(subnet_values)
223 # not creating the subnet using the base.create_subnet because
224 # that function needs to be enhanced to support subnet_create when
225 # prefixlen and subnetpool_id is specified.
226 body = self.client.create_subnet(
227 network_id=network['id'],
228 ip_version=self._ip_version,
229 **subnet_kwargs)
230 subnet = body['subnet']
231 return pool_id, subnet
232
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000233 @decorators.idempotent_id('1362ed7d-3089-42eb-b3a5-d6cb8398ee77')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000234 def test_create_subnet_from_pool_with_prefixlen(self):
235 subnet_values = {"prefixlen": self.max_prefixlen}
236 pool_id, subnet = self._create_subnet_from_pool(
237 subnet_values=subnet_values)
238 cidr = str(subnet['cidr'])
239 self.assertEqual(pool_id, subnet['subnetpool_id'])
240 self.assertTrue(cidr.endswith(str(self.max_prefixlen)))
241
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000242 @decorators.idempotent_id('86b86189-9789-4582-9c3b-7e2bfe5735ee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000243 def test_create_subnet_from_pool_with_subnet_cidr(self):
244 subnet_values = {"cidr": self.subnet_cidr}
245 pool_id, subnet = self._create_subnet_from_pool(
246 subnet_values=subnet_values)
247 cidr = str(subnet['cidr'])
248 self.assertEqual(pool_id, subnet['subnetpool_id'])
249 self.assertEqual(cidr, self.subnet_cidr)
250
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000251 @decorators.idempotent_id('83f76e3a-9c40-40c2-a015-b7c5242178d8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000252 def test_create_subnet_from_pool_with_default_prefixlen(self):
253 # If neither cidr nor prefixlen is specified,
254 # subnet will use subnetpool default_prefixlen for cidr.
255 pool_id, subnet = self._create_subnet_from_pool()
256 cidr = str(subnet['cidr'])
257 self.assertEqual(pool_id, subnet['subnetpool_id'])
258 prefixlen = self._subnetpool_data['min_prefixlen']
259 self.assertTrue(cidr.endswith(str(prefixlen)))
260
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000261 @decorators.idempotent_id('a64af292-ec52-4bde-b654-a6984acaf477')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000262 def test_create_subnet_from_pool_with_quota(self):
263 pool_values = {'default_quota': 4}
264 subnet_values = {"prefixlen": self.max_prefixlen}
265 pool_id, subnet = self._create_subnet_from_pool(
266 subnet_values=subnet_values, pool_values=pool_values)
267 cidr = str(subnet['cidr'])
268 self.assertEqual(pool_id, subnet['subnetpool_id'])
269 self.assertTrue(cidr.endswith(str(self.max_prefixlen)))
270
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000271 @decorators.idempotent_id('49b44c64-1619-4b29-b527-ffc3c3115dc4')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530272 @utils.requires_ext(extension='address-scope', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000273 def test_create_subnetpool_associate_address_scope(self):
274 address_scope = self.create_address_scope(
275 name=data_utils.rand_name('smoke-address-scope'),
276 ip_version=self._ip_version)
277 created_subnetpool = self._create_subnetpool(
278 address_scope_id=address_scope['id'])
279 body = self.client.show_subnetpool(created_subnetpool['id'])
280 self.assertEqual(address_scope['id'],
281 body['subnetpool']['address_scope_id'])
282
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000283 @decorators.idempotent_id('910b6393-db24-4f6f-87dc-b36892ad6c8c')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530284 @utils.requires_ext(extension='address-scope', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000285 def test_update_subnetpool_associate_address_scope(self):
286 address_scope = self.create_address_scope(
287 name=data_utils.rand_name('smoke-address-scope'),
288 ip_version=self._ip_version)
289 created_subnetpool = self._create_subnetpool()
290 pool_id = created_subnetpool['id']
291 body = self.client.show_subnetpool(pool_id)
292 self.assertIsNone(body['subnetpool']['address_scope_id'])
293 self.client.update_subnetpool(pool_id,
294 address_scope_id=address_scope['id'])
295 body = self.client.show_subnetpool(pool_id)
296 self.assertEqual(address_scope['id'],
297 body['subnetpool']['address_scope_id'])
298
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000299 @decorators.idempotent_id('18302e80-46a3-4563-82ac-ccd1dd57f652')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530300 @utils.requires_ext(extension='address-scope', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000301 def test_update_subnetpool_associate_another_address_scope(self):
302 address_scope = self.create_address_scope(
303 name=data_utils.rand_name('smoke-address-scope'),
304 ip_version=self._ip_version)
305 another_address_scope = self.create_address_scope(
306 name=data_utils.rand_name('smoke-address-scope'),
307 ip_version=self._ip_version)
308 created_subnetpool = self._create_subnetpool(
309 address_scope_id=address_scope['id'])
310 pool_id = created_subnetpool['id']
311 body = self.client.show_subnetpool(pool_id)
312 self.assertEqual(address_scope['id'],
313 body['subnetpool']['address_scope_id'])
314 self.client.update_subnetpool(
315 pool_id, address_scope_id=another_address_scope['id'])
316 body = self.client.show_subnetpool(pool_id)
317 self.assertEqual(another_address_scope['id'],
318 body['subnetpool']['address_scope_id'])
319
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000320 @decorators.idempotent_id('f8970048-e41b-42d6-934b-a1297b07706a')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530321 @utils.requires_ext(extension='address-scope', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000322 def test_update_subnetpool_disassociate_address_scope(self):
323 address_scope = self.create_address_scope(
324 name=data_utils.rand_name('smoke-address-scope'),
325 ip_version=self._ip_version)
326 created_subnetpool = self._create_subnetpool(
327 address_scope_id=address_scope['id'])
328 pool_id = created_subnetpool['id']
329 body = self.client.show_subnetpool(pool_id)
330 self.assertEqual(address_scope['id'],
331 body['subnetpool']['address_scope_id'])
332 self.client.update_subnetpool(pool_id,
333 address_scope_id=None)
334 body = self.client.show_subnetpool(pool_id)
335 self.assertIsNone(body['subnetpool']['address_scope_id'])
336
Dongcan Ye2bc62bb2017-05-26 10:48:40 +0800337 @decorators.idempotent_id('4c6963c2-f54c-4347-b288-75d18421c4c4')
Dongcan Ye2bc62bb2017-05-26 10:48:40 +0800338 def test_tenant_create_non_default_subnetpool(self):
Brian Haleyae328b92018-10-09 19:51:54 -0400339 """Test creates a subnetpool, the "is_default" attribute is False."""
Dongcan Ye2bc62bb2017-05-26 10:48:40 +0800340 created_subnetpool = self._create_subnetpool()
341 self.assertFalse(created_subnetpool['is_default'])
342
343
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000344class SubnetPoolsTestV6(SubnetPoolsTest):
345
346 min_prefixlen = '48'
347 max_prefixlen = '64'
348 _ip_version = 6
349 subnet_cidr = '2001:db8:3::/64'
350 new_prefix = u'2001:db8:5::/64'
351 larger_prefix = u'2001:db8::/32'
352
353 @classmethod
354 def resource_setup(cls):
355 super(SubnetPoolsTestV6, cls).resource_setup()
356 min_prefixlen = '64'
357 prefixes = [u'2001:db8:3::/48']
358 cls._subnetpool_data = {'min_prefixlen': min_prefixlen,
359 'prefixes': prefixes}
360
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000361 @decorators.idempotent_id('f62d73dc-cf6f-4879-b94b-dab53982bf3b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000362 def test_create_dual_stack_subnets_from_subnetpools(self):
363 pool_id_v6, subnet_v6 = self._create_subnet_from_pool()
364 pool_values_v4 = {'prefixes': ['192.168.0.0/16'],
365 'min_prefixlen': 21,
366 'max_prefixlen': 32}
367 create_v4_subnetpool = self._create_subnetpool(**pool_values_v4)
368 pool_id_v4 = create_v4_subnetpool['id']
369 subnet_v4 = self.client.create_subnet(
370 network_id=subnet_v6['network_id'], ip_version=4,
371 subnetpool_id=pool_id_v4)['subnet']
372 self.assertEqual(subnet_v4['network_id'], subnet_v6['network_id'])
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200373
374
375class SubnetPoolsSearchCriteriaTest(base.BaseSearchCriteriaTest,
376 SubnetPoolsTestBase):
377
378 resource = 'subnetpool'
379
Ihar Hrachyshkaa9035b62016-06-13 11:21:38 +0200380 list_kwargs = {'shared': False}
381
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200382 @classmethod
383 def resource_setup(cls):
384 super(SubnetPoolsSearchCriteriaTest, cls).resource_setup()
385 for name in cls.resource_names:
386 cls._create_subnetpool(name=name)
387
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000388 @decorators.idempotent_id('6e3f842e-6bfb-49cb-82d3-0026be4e8e04')
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200389 def test_list_sorts_asc(self):
390 self._test_list_sorts_asc()
391
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000392 @decorators.idempotent_id('f336859b-b868-438c-a6fc-2c06374115f2')
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200393 def test_list_sorts_desc(self):
394 self._test_list_sorts_desc()
395
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000396 @decorators.idempotent_id('1291fae7-c196-4372-ad59-ce7988518f7b')
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200397 def test_list_pagination(self):
398 self._test_list_pagination()
399
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000400 @decorators.idempotent_id('ddb20d14-1952-49b4-a17e-231cc2239a52')
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200401 def test_list_pagination_with_marker(self):
402 self._test_list_pagination_with_marker()
403
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000404 @decorators.idempotent_id('b3bd9665-2769-4a43-b50c-31b1add12891')
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200405 def test_list_pagination_with_href_links(self):
406 self._test_list_pagination_with_href_links()
407
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000408 @decorators.idempotent_id('1ec1f325-43b0-406e-96ce-20539e38a61d')
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200409 def test_list_pagination_page_reverse_asc(self):
410 self._test_list_pagination_page_reverse_asc()
411
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000412 @decorators.idempotent_id('f43a293e-4aaa-48f4-aeaf-de63a676357c')
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200413 def test_list_pagination_page_reverse_desc(self):
414 self._test_list_pagination_page_reverse_desc()
415
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000416 @decorators.idempotent_id('73511385-839c-4829-8ac1-b5ad992126c4')
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200417 def test_list_pagination_page_reverse_with_href_links(self):
418 self._test_list_pagination_page_reverse_with_href_links()
419
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000420 @decorators.idempotent_id('82a13efc-c18f-4249-b8ec-cec7cf26fbd6')
Ihar Hrachyshkaeace1742016-06-08 15:07:35 +0200421 def test_list_no_pagination_limit_0(self):
422 self._test_list_no_pagination_limit_0()
Victor Morales1be97b42016-09-05 08:50:06 -0500423
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000424 @decorators.idempotent_id('27feb3f8-40f4-4e50-8cd2-7d0096a98682')
Victor Morales1be97b42016-09-05 08:50:06 -0500425 def test_list_validation_filters(self):
Hongbin Lu54f55922018-07-12 19:05:39 +0000426 self._test_list_validation_filters(self.list_kwargs)
427 self._test_list_validation_filters({
428 'unknown_filter': 'value'}, filter_is_valid=False)
Igor Malinovskiy649c0182020-03-06 17:30:47 +0200429
430
431class RbacSubnetPoolTest(SubnetPoolsTestBase):
432
433 force_tenant_isolation = True
434 credentials = ['primary', 'alt', 'admin']
435 required_extensions = ['rbac-subnetpool']
436
437 @classmethod
438 def resource_setup(cls):
439 super(RbacSubnetPoolTest, cls).resource_setup()
440 cls.client2 = cls.os_alt.network_client
441
442 def _make_admin_snp_shared_to_project_id(self, project_id):
443 snp = self._create_subnetpool(is_admin=True)
444 rbac_policy = self.admin_client.create_rbac_policy(
445 object_type='subnetpool',
446 object_id=snp['id'],
447 action='access_as_shared',
448 target_tenant=project_id,
449 )['rbac_policy']
450 return {'subnetpool': snp, 'rbac_policy': rbac_policy}
451
452 @decorators.idempotent_id('71b35ad0-51cd-40da-985d-89a51c95ec6a')
453 def test_policy_target_update(self):
454 res = self._make_admin_snp_shared_to_project_id(
455 self.client.tenant_id)
456 # change to client2
457 update_res = self.admin_client.update_rbac_policy(
458 res['rbac_policy']['id'], target_tenant=self.client2.tenant_id)
459 self.assertEqual(self.client2.tenant_id,
460 update_res['rbac_policy']['target_tenant'])
461 # make sure everything else stayed the same
462 res['rbac_policy'].pop('target_tenant')
463 update_res['rbac_policy'].pop('target_tenant')
464 self.assertEqual(res['rbac_policy'], update_res['rbac_policy'])
465
466 @decorators.idempotent_id('451d9d38-65a0-4916-a805-1460d6a938d1')
467 def test_subnet_presence_prevents_rbac_policy_deletion(self):
468 res = self._make_admin_snp_shared_to_project_id(
469 self.client2.tenant_id)
470 network = self.create_network(client=self.client2)
471 subnet = self.client2.create_subnet(
472 network_id=network['id'],
473 ip_version=4,
474 subnetpool_id=res['subnetpool']['id'],
475 name=data_utils.rand_name("rbac-subnetpool"),
476 )["subnet"]
477 self.addCleanup(self.client2.delete_network, network['id'])
478 self.addCleanup(
479 self.admin_client.delete_subnetpool,
480 res['subnetpool']['id']
481 )
482 self.addCleanup(self.client2.delete_subnet, subnet['id'])
483
484 # a port with shared sg should prevent the deletion of an
485 # rbac-policy required for it to be shared
486 with testtools.ExpectedException(lib_exc.Conflict):
487 self.admin_client.delete_rbac_policy(res['rbac_policy']['id'])
488
489 @decorators.idempotent_id('f74a71de-9abf-49c6-8199-4ac7f53e383b')
490 @utils.requires_ext(extension='rbac-address-scope', service='network')
491 def test_cannot_share_if_no_access_to_address_scope(self):
492 # Create Address Scope shared only to client but not to client2
493 a_s = self.admin_client.create_address_scope(
494 name=data_utils.rand_name("rbac-subnetpool"),
495 ip_version=4
496 )["address_scope"]
497 rbac_policy = self.admin_client.create_rbac_policy(
498 object_type='address_scope', object_id=a_s['id'],
499 action='access_as_shared',
500 target_tenant=self.client.tenant_id)['rbac_policy']
501
502 # Create subnet pool owned by client with shared AS
503 snp = self._create_subnetpool(address_scope_id=a_s["id"])
504
505 with testtools.ExpectedException(lib_exc.BadRequest):
506 self.client.create_rbac_policy(
507 object_type='subnetpool', object_id=snp['id'],
508 action='access_as_shared',
509 target_tenant=self.client2.tenant_id
510 )
511
512 # cleanup
513 self.client.delete_subnetpool(snp["id"])
514 self.admin_client.delete_rbac_policy(rbac_policy['id'])
515 self.admin_client.delete_address_scope(a_s['id'])
516
517 @decorators.idempotent_id('9cf8bba5-0163-4083-9397-678bb9b5f5a2')
518 def test_regular_client_shares_to_another_regular_client(self):
519 # owned by self.admin_client
520 snp = self._create_subnetpool(is_admin=True)
521 with testtools.ExpectedException(lib_exc.NotFound):
522 self.client.show_subnetpool(snp['id'])
523 rbac_policy = self.admin_client.create_rbac_policy(
524 object_type='subnetpool', object_id=snp['id'],
525 action='access_as_shared',
526 target_tenant=self.client.tenant_id)['rbac_policy']
527 self.client.show_subnetpool(snp['id'])
528
529 self.assertIn(rbac_policy,
530 self.admin_client.list_rbac_policies()['rbac_policies'])
531 # ensure that 'client2' can't see the rbac-policy sharing the
532 # as to it because the rbac-policy belongs to 'client'
533 self.assertNotIn(rbac_policy['id'], [p['id'] for p in
534 self.client2.list_rbac_policies()['rbac_policies']])
535
536 @decorators.idempotent_id('17b2b437-a5fa-4340-ad98-912a986d0d7c')
537 def test_filter_fields(self):
538 snp = self._create_subnetpool()
539 self.admin_client.create_rbac_policy(
540 object_type='subnetpool', object_id=snp['id'],
541 action='access_as_shared', target_tenant=self.client2.tenant_id)
542 field_args = (('id',), ('id', 'action'), ('object_type', 'object_id'),
543 ('project_id', 'target_tenant'))
544 for fields in field_args:
545 res = self.admin_client.list_rbac_policies(fields=fields)
546 self.assertEqual(set(fields), set(res['rbac_policies'][0].keys()))
547
548 @decorators.idempotent_id('e59e4502-4e6a-4e49-b446-a5d5642bbd69')
549 def test_rbac_policy_show(self):
550 res = self._make_admin_snp_shared_to_project_id(
551 self.client.tenant_id)
552 p1 = res['rbac_policy']
553 p2 = self.admin_client.create_rbac_policy(
554 object_type='subnetpool',
555 object_id=res['subnetpool']['id'],
556 action='access_as_shared',
557 target_tenant='*')['rbac_policy']
558
559 self.assertEqual(
560 p1, self.admin_client.show_rbac_policy(p1['id'])['rbac_policy'])
561 self.assertEqual(
562 p2, self.admin_client.show_rbac_policy(p2['id'])['rbac_policy'])
563
564 @decorators.idempotent_id('1c24c28c-eb1e-466e-af29-255cf127653a')
565 def test_filter_rbac_policies(self):
566 snp = self._create_subnetpool()
567 rbac_pol1 = self.admin_client.create_rbac_policy(
568 object_type='subnetpool', object_id=snp['id'],
569 action='access_as_shared',
570 target_tenant=self.client2.tenant_id)['rbac_policy']
571 rbac_pol2 = self.admin_client.create_rbac_policy(
572 object_type='subnetpool', object_id=snp['id'],
573 action='access_as_shared',
574 target_tenant=self.admin_client.tenant_id)['rbac_policy']
575 res1 = self.admin_client.list_rbac_policies(id=rbac_pol1['id'])[
576 'rbac_policies']
577 res2 = self.admin_client.list_rbac_policies(id=rbac_pol2['id'])[
578 'rbac_policies']
579 self.assertEqual(1, len(res1))
580 self.assertEqual(1, len(res2))
581 self.assertEqual(rbac_pol1['id'], res1[0]['id'])
582 self.assertEqual(rbac_pol2['id'], res2[0]['id'])
583
584 @decorators.idempotent_id('63d9acbe-403c-4e77-9ffd-80e636a4621e')
585 def test_regular_client_blocked_from_sharing_anothers_policy(self):
586 snp = self._make_admin_snp_shared_to_project_id(
587 self.client.tenant_id)['subnetpool']
588 with testtools.ExpectedException(lib_exc.BadRequest):
589 self.client.create_rbac_policy(
590 object_type='subnetpool', object_id=snp['id'],
591 action='access_as_shared',
592 target_tenant=self.client2.tenant_id)
593
594 # make sure the rbac-policy is invisible to the tenant for which it's
595 # being shared
596 self.assertFalse(self.client.list_rbac_policies()['rbac_policies'])