blob: 67635178d1c2ea986f6ad6d71ef0a707909ffb02 [file] [log] [blame]
Ryan Tidwell9b9be442016-02-18 17:34:43 +08001# Copyright 2016 Hewlett Packard Enterprise Development Company LP
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Hynek Mlnarikc5106762016-09-01 11:47:31 +020015from tempest.lib.common.utils import data_utils
Armando Migliacciod26a2742016-07-13 08:57:50 -070016from tempest.lib.common.utils import test_utils
Ryan Tidwell9b9be442016-02-18 17:34:43 +080017from tempest.lib import exceptions as lib_exc
18from tempest import test
19
20from neutron.tests.tempest.api import base
Hynek Mlnarikc5106762016-09-01 11:47:31 +020021from neutron.tests.tempest import config
Ryan Tidwell9b9be442016-02-18 17:34:43 +080022
23
Armando Migliacciod26a2742016-07-13 08:57:50 -070024def trunks_cleanup(client, trunks):
25 for trunk in trunks:
Armando Migliaccio232642c2016-07-20 16:28:24 -070026 # NOTE(armax): deleting a trunk with subports is permitted, however
27 # for testing purposes it is safer to be explicit and clean all the
28 # resources associated with the trunk beforehand.
Armando Migliacciod26a2742016-07-13 08:57:50 -070029 subports = test_utils.call_and_ignore_notfound_exc(
30 client.get_subports, trunk['id'])
31 if subports:
32 client.remove_subports(
33 trunk['id'], subports['sub_ports'])
34 test_utils.call_and_ignore_notfound_exc(
35 client.delete_trunk, trunk['id'])
36
37
Ryan Tidwell9b9be442016-02-18 17:34:43 +080038class TrunkTestJSONBase(base.BaseAdminNetworkTest):
39
Armando Migliacciod26a2742016-07-13 08:57:50 -070040 extension = 'trunk'
41
42 def setUp(self):
43 self.addCleanup(self.resource_cleanup)
44 super(TrunkTestJSONBase, self).setUp()
45
46 @classmethod
47 def skip_checks(cls):
48 super(TrunkTestJSONBase, cls).skip_checks()
49 if not test.is_extension_enabled(cls.extension, 'network'):
50 msg = "%s extension not enabled." % cls.extension
51 raise cls.skipException(msg)
52
53 @classmethod
54 def resource_setup(cls):
55 super(TrunkTestJSONBase, cls).resource_setup()
56 cls.trunks = []
57
58 @classmethod
59 def resource_cleanup(cls):
60 trunks_cleanup(cls.client, cls.trunks)
61 super(TrunkTestJSONBase, cls).resource_cleanup()
62
Armando Migliaccio89a24f12016-07-12 11:59:02 -070063 def _create_trunk_with_network_and_parent(self, subports, **kwargs):
Ryan Tidwell9b9be442016-02-18 17:34:43 +080064 network = self.create_network()
65 parent_port = self.create_port(network)
Armando Migliaccio89a24f12016-07-12 11:59:02 -070066 trunk = self.client.create_trunk(parent_port['id'], subports, **kwargs)
Armando Migliacciod26a2742016-07-13 08:57:50 -070067 self.trunks.append(trunk['trunk'])
68 return trunk
Ryan Tidwell9b9be442016-02-18 17:34:43 +080069
Armando Migliaccio71d34702016-08-29 22:50:44 -070070 def _show_trunk(self, trunk_id):
Armando Migliaccio5b606642016-09-02 11:45:56 -070071 return self.client.show_trunk(trunk_id)
Armando Migliaccio71d34702016-08-29 22:50:44 -070072
73 def _list_trunks(self):
Armando Migliaccio5b606642016-09-02 11:45:56 -070074 return self.client.list_trunks()
Armando Migliaccio71d34702016-08-29 22:50:44 -070075
Ryan Tidwell9b9be442016-02-18 17:34:43 +080076
77class TrunkTestJSON(TrunkTestJSONBase):
78
Armando Migliaccio71d34702016-08-29 22:50:44 -070079 def _test_create_trunk(self, subports):
80 trunk = self._create_trunk_with_network_and_parent(subports)
81 observed_trunk = self._show_trunk(trunk['trunk']['id'])
82 self.assertEqual(trunk, observed_trunk)
83
Ryan Tidwell9b9be442016-02-18 17:34:43 +080084 @test.idempotent_id('e1a6355c-4768-41f3-9bf8-0f1d192bd501')
85 def test_create_trunk_empty_subports_list(self):
Armando Migliaccio71d34702016-08-29 22:50:44 -070086 self._test_create_trunk([])
Ryan Tidwell9b9be442016-02-18 17:34:43 +080087
88 @test.idempotent_id('382dfa39-ca03-4bd3-9a1c-91e36d2e3796')
89 def test_create_trunk_subports_not_specified(self):
Armando Migliaccio71d34702016-08-29 22:50:44 -070090 self._test_create_trunk(None)
Ryan Tidwell9b9be442016-02-18 17:34:43 +080091
92 @test.idempotent_id('7de46c22-e2b6-4959-ac5a-0e624632ab32')
93 def test_create_show_delete_trunk(self):
94 trunk = self._create_trunk_with_network_and_parent(None)
95 trunk_id = trunk['trunk']['id']
96 parent_port_id = trunk['trunk']['port_id']
Armando Migliaccio71d34702016-08-29 22:50:44 -070097 res = self._show_trunk(trunk_id)
Ryan Tidwell9b9be442016-02-18 17:34:43 +080098 self.assertEqual(trunk_id, res['trunk']['id'])
99 self.assertEqual(parent_port_id, res['trunk']['port_id'])
100 self.client.delete_trunk(trunk_id)
Armando Migliaccio71d34702016-08-29 22:50:44 -0700101 self.assertRaises(lib_exc.NotFound, self._show_trunk, trunk_id)
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800102
Henry Gessaufa6c78d2016-10-09 19:56:09 -0400103 @test.idempotent_id('8d83a6ca-662d-45b8-8062-d513077296aa')
104 @test.requires_ext(extension="project-id", service="network")
105 def test_show_trunk_has_project_id(self):
106 trunk = self._create_trunk_with_network_and_parent(None)
107 body = self._show_trunk(trunk['trunk']['id'])
108 show_trunk = body['trunk']
109 self.assertIn('project_id', show_trunk)
110 self.assertIn('tenant_id', show_trunk)
111 self.assertEqual(self.client.tenant_id, show_trunk['project_id'])
112 self.assertEqual(self.client.tenant_id, show_trunk['tenant_id'])
113
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700114 @test.idempotent_id('4ce46c22-a2b6-4659-bc5a-0ef2463cab32')
115 def test_create_update_trunk(self):
116 trunk = self._create_trunk_with_network_and_parent(None)
Armando Migliaccio13adb742016-09-02 18:27:38 -0700117 self.assertEqual(1, trunk['trunk']['revision_number'])
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700118 trunk_id = trunk['trunk']['id']
Armando Migliaccio71d34702016-08-29 22:50:44 -0700119 res = self._show_trunk(trunk_id)
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700120 self.assertTrue(res['trunk']['admin_state_up'])
Armando Migliaccio13adb742016-09-02 18:27:38 -0700121 self.assertEqual(1, res['trunk']['revision_number'])
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700122 self.assertEqual("", res['trunk']['name'])
Armando Migliaccio42738312016-08-29 22:04:21 -0700123 self.assertEqual("", res['trunk']['description'])
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700124 res = self.client.update_trunk(
125 trunk_id, name='foo', admin_state_up=False)
126 self.assertFalse(res['trunk']['admin_state_up'])
127 self.assertEqual("foo", res['trunk']['name'])
Armando Migliaccio13adb742016-09-02 18:27:38 -0700128 self.assertGreater(res['trunk']['revision_number'], 1)
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700129 # enable the trunk so that it can be managed
130 self.client.update_trunk(trunk_id, admin_state_up=True)
131
Armando Migliaccio42738312016-08-29 22:04:21 -0700132 @test.idempotent_id('5ff46c22-a2b6-5559-bc5a-0ef2463cab32')
133 def test_create_update_trunk_with_description(self):
134 trunk = self._create_trunk_with_network_and_parent(
135 None, description="foo description")
136 trunk_id = trunk['trunk']['id']
137 self.assertEqual("foo description", trunk['trunk']['description'])
138 trunk = self.client.update_trunk(trunk_id, description='')
139 self.assertEqual('', trunk['trunk']['description'])
140
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800141 @test.idempotent_id('73365f73-bed6-42cd-960b-ec04e0c99d85')
142 def test_list_trunks(self):
143 trunk1 = self._create_trunk_with_network_and_parent(None)
144 trunk2 = self._create_trunk_with_network_and_parent(None)
145 expected_trunks = {trunk1['trunk']['id']: trunk1['trunk'],
146 trunk2['trunk']['id']: trunk2['trunk']}
Armando Migliaccio71d34702016-08-29 22:50:44 -0700147 trunk_list = self._list_trunks()['trunks']
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800148 matched_trunks = [x for x in trunk_list if x['id'] in expected_trunks]
149 self.assertEqual(2, len(matched_trunks))
150 for trunk in matched_trunks:
151 self.assertEqual(expected_trunks[trunk['id']], trunk)
152
153 @test.idempotent_id('bb5fcead-09b5-484a-bbe6-46d1e06d6cc0')
154 def test_add_subport(self):
155 trunk = self._create_trunk_with_network_and_parent([])
156 network = self.create_network()
157 port = self.create_port(network)
158 subports = [{'port_id': port['id'],
159 'segmentation_type': 'vlan',
160 'segmentation_id': 2}]
161 self.client.add_subports(trunk['trunk']['id'], subports)
Armando Migliaccio71d34702016-08-29 22:50:44 -0700162 trunk = self._show_trunk(trunk['trunk']['id'])
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800163 observed_subports = trunk['trunk']['sub_ports']
164 self.assertEqual(1, len(observed_subports))
165 created_subport = observed_subports[0]
166 self.assertEqual(subports[0], created_subport)
167
Armando Migliaccio232642c2016-07-20 16:28:24 -0700168 @test.idempotent_id('ee5fcead-1abf-483a-bce6-43d1e06d6aa0')
169 def test_delete_trunk_with_subport_is_allowed(self):
170 network = self.create_network()
171 port = self.create_port(network)
172 subports = [{'port_id': port['id'],
173 'segmentation_type': 'vlan',
174 'segmentation_id': 2}]
175 trunk = self._create_trunk_with_network_and_parent(subports)
176 self.client.delete_trunk(trunk['trunk']['id'])
177
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800178 @test.idempotent_id('96eea398-a03c-4c3e-a99e-864392c2ca53')
179 def test_remove_subport(self):
180 subport_parent1 = self.create_port(self.create_network())
181 subport_parent2 = self.create_port(self.create_network())
182 subports = [{'port_id': subport_parent1['id'],
183 'segmentation_type': 'vlan',
184 'segmentation_id': 2},
185 {'port_id': subport_parent2['id'],
186 'segmentation_type': 'vlan',
187 'segmentation_id': 4}]
188 trunk = self._create_trunk_with_network_and_parent(subports)
189 removed_subport = trunk['trunk']['sub_ports'][0]
190 expected_subport = None
191
192 for subport in subports:
193 if subport['port_id'] != removed_subport['port_id']:
194 expected_subport = subport
195 break
196
197 # Remove the subport and validate PUT response
198 res = self.client.remove_subports(trunk['trunk']['id'],
199 [removed_subport])
200 self.assertEqual(1, len(res['sub_ports']))
201 self.assertEqual(expected_subport, res['sub_ports'][0])
202
203 # Validate the results of a subport list
Armando Migliaccio71d34702016-08-29 22:50:44 -0700204 trunk = self._show_trunk(trunk['trunk']['id'])
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800205 observed_subports = trunk['trunk']['sub_ports']
206 self.assertEqual(1, len(observed_subports))
207 self.assertEqual(expected_subport, observed_subports[0])
208
209 @test.idempotent_id('bb5fcaad-09b5-484a-dde6-4cd1ea6d6ff0')
210 def test_get_subports(self):
211 network = self.create_network()
212 port = self.create_port(network)
213 subports = [{'port_id': port['id'],
214 'segmentation_type': 'vlan',
215 'segmentation_id': 2}]
216 trunk = self._create_trunk_with_network_and_parent(subports)
217 trunk = self.client.get_subports(trunk['trunk']['id'])
218 observed_subports = trunk['sub_ports']
219 self.assertEqual(1, len(observed_subports))
Armando Migliaccio57581c62016-07-01 10:13:19 -0700220
221
Hynek Mlnarikc5106762016-09-01 11:47:31 +0200222class TrunkTestMtusJSONBase(TrunkTestJSONBase):
223
224 required_extensions = ['provider', 'trunk']
225
226 @classmethod
227 def skip_checks(cls):
228 super(TrunkTestMtusJSONBase, cls).skip_checks()
229 for ext in cls.required_extensions:
230 if not test.is_extension_enabled(ext, 'network'):
231 msg = "%s extension not enabled." % ext
232 raise cls.skipException(msg)
233
234 if any(t
235 not in config.CONF.neutron_plugin_options.available_type_drivers
236 for t in ['gre', 'vxlan']):
237 msg = "Either vxlan or gre type driver not enabled."
238 raise cls.skipException(msg)
239
240 def setUp(self):
241 super(TrunkTestMtusJSONBase, self).setUp()
242
243 # VXLAN autocomputed MTU (1450) is smaller than that of GRE (1458)
244 vxlan_kwargs = {'network_name': data_utils.rand_name('vxlan-net-'),
245 'provider:network_type': 'vxlan'}
246 self.smaller_mtu_net = self.create_shared_network(**vxlan_kwargs)
247
248 gre_kwargs = {'network_name': data_utils.rand_name('gre-net-'),
249 'provider:network_type': 'gre'}
250 self.larger_mtu_net = self.create_shared_network(**gre_kwargs)
251
252 self.smaller_mtu_port = self.create_port(self.smaller_mtu_net)
253 self.smaller_mtu_port_2 = self.create_port(self.smaller_mtu_net)
254 self.larger_mtu_port = self.create_port(self.larger_mtu_net)
255
256
257class TrunkTestMtusJSON(TrunkTestMtusJSONBase):
258
259 @test.idempotent_id('0f05d98e-41f5-4629-ac29-9aee269c9602')
260 def test_create_trunk_with_mtu_greater_than_subport(self):
261 subports = [{'port_id': self.smaller_mtu_port['id'],
262 'segmentation_type': 'vlan',
263 'segmentation_id': 2}]
264
265 trunk = self.client.create_trunk(self.larger_mtu_port['id'], subports)
266 self.trunks.append(trunk['trunk'])
267
268 @test.idempotent_id('2004c5c6-e557-4c43-8100-c820ad4953e8')
269 def test_add_subport_with_mtu_smaller_than_trunk(self):
270 subports = [{'port_id': self.smaller_mtu_port['id'],
271 'segmentation_type': 'vlan',
272 'segmentation_id': 2}]
273
274 trunk = self.client.create_trunk(self.larger_mtu_port['id'], None)
275 self.trunks.append(trunk['trunk'])
276
277 self.client.add_subports(trunk['trunk']['id'], subports)
278
279 @test.idempotent_id('22725101-f4bc-4e00-84ec-4e02cd7e0500')
280 def test_create_trunk_with_mtu_equal_to_subport(self):
281 subports = [{'port_id': self.smaller_mtu_port['id'],
282 'segmentation_type': 'vlan',
283 'segmentation_id': 2}]
284
285 trunk = self.client.create_trunk(self.smaller_mtu_port_2['id'],
286 subports)
287 self.trunks.append(trunk['trunk'])
288
289 @test.idempotent_id('175b05ae-66ad-44c7-857a-a12d16f1058f')
290 def test_add_subport_with_mtu_equal_to_trunk(self):
291 subports = [{'port_id': self.smaller_mtu_port['id'],
292 'segmentation_type': 'vlan',
293 'segmentation_id': 2}]
294
295 trunk = self.client.create_trunk(self.smaller_mtu_port_2['id'], None)
296 self.trunks.append(trunk['trunk'])
297
298 self.client.add_subports(trunk['trunk']['id'], subports)
299
300
Armando Migliaccio57581c62016-07-01 10:13:19 -0700301class TrunksSearchCriteriaTest(base.BaseSearchCriteriaTest):
302
303 resource = 'trunk'
Armando Migliaccio57581c62016-07-01 10:13:19 -0700304
305 @classmethod
Armando Migliacciod26a2742016-07-13 08:57:50 -0700306 def skip_checks(cls):
307 super(TrunksSearchCriteriaTest, cls).skip_checks()
308 if not test.is_extension_enabled('trunk', 'network'):
309 msg = "trunk extension not enabled."
310 raise cls.skipException(msg)
311
312 @classmethod
Armando Migliaccio57581c62016-07-01 10:13:19 -0700313 def resource_setup(cls):
314 super(TrunksSearchCriteriaTest, cls).resource_setup()
Armando Migliacciod26a2742016-07-13 08:57:50 -0700315 cls.trunks = []
Armando Migliaccio57581c62016-07-01 10:13:19 -0700316 net = cls.create_network(network_name='trunk-search-test-net')
317 for name in cls.resource_names:
318 parent_port = cls.create_port(net)
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700319 trunk = cls.client.create_trunk(parent_port['id'], [], name=name)
Armando Migliacciod26a2742016-07-13 08:57:50 -0700320 cls.trunks.append(trunk['trunk'])
321
322 @classmethod
323 def resource_cleanup(cls):
324 trunks_cleanup(cls.client, cls.trunks)
325 super(TrunksSearchCriteriaTest, cls).resource_cleanup()
Armando Migliaccio57581c62016-07-01 10:13:19 -0700326
327 @test.idempotent_id('fab73df4-960a-4ae3-87d3-60992b8d3e2d')
328 def test_list_sorts_asc(self):
329 self._test_list_sorts_asc()
330
331 @test.idempotent_id('a426671d-7270-430f-82ff-8f33eec93010')
332 def test_list_sorts_desc(self):
333 self._test_list_sorts_desc()
334
335 @test.idempotent_id('b202fdc8-6616-45df-b6a0-463932de6f94')
336 def test_list_pagination(self):
337 self._test_list_pagination()
338
339 @test.idempotent_id('c4723b8e-8186-4b9a-bf9e-57519967e048')
340 def test_list_pagination_with_marker(self):
341 self._test_list_pagination_with_marker()
342
343 @test.idempotent_id('dcd02a7a-f07e-4d5e-b0ca-b58e48927a9b')
344 def test_list_pagination_with_href_links(self):
345 self._test_list_pagination_with_href_links()
346
347 @test.idempotent_id('eafe7024-77ab-4cfe-824b-0b2bf4217727')
348 def test_list_no_pagination_limit_0(self):
349 self._test_list_no_pagination_limit_0()
350
351 @test.idempotent_id('f8857391-dc44-40cc-89b7-2800402e03ce')
352 def test_list_pagination_page_reverse_asc(self):
353 self._test_list_pagination_page_reverse_asc()
354
355 @test.idempotent_id('ae51e9c9-ceae-4ec0-afd4-147569247699')
356 def test_list_pagination_page_reverse_desc(self):
357 self._test_list_pagination_page_reverse_desc()
358
359 @test.idempotent_id('b4293e59-d794-4a93-be09-38667199ef68')
360 def test_list_pagination_page_reverse_with_href_links(self):
361 self._test_list_pagination_page_reverse_with_href_links()