blob: 3dc8f0d9739f68ae8c01d4a6e314ce9e0964b80d [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
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700103 @test.idempotent_id('4ce46c22-a2b6-4659-bc5a-0ef2463cab32')
104 def test_create_update_trunk(self):
105 trunk = self._create_trunk_with_network_and_parent(None)
Armando Migliaccio13adb742016-09-02 18:27:38 -0700106 self.assertEqual(1, trunk['trunk']['revision_number'])
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700107 trunk_id = trunk['trunk']['id']
Armando Migliaccio71d34702016-08-29 22:50:44 -0700108 res = self._show_trunk(trunk_id)
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700109 self.assertTrue(res['trunk']['admin_state_up'])
Armando Migliaccio13adb742016-09-02 18:27:38 -0700110 self.assertEqual(1, res['trunk']['revision_number'])
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700111 self.assertEqual("", res['trunk']['name'])
Armando Migliaccio42738312016-08-29 22:04:21 -0700112 self.assertEqual("", res['trunk']['description'])
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700113 res = self.client.update_trunk(
114 trunk_id, name='foo', admin_state_up=False)
115 self.assertFalse(res['trunk']['admin_state_up'])
116 self.assertEqual("foo", res['trunk']['name'])
Armando Migliaccio13adb742016-09-02 18:27:38 -0700117 self.assertGreater(res['trunk']['revision_number'], 1)
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700118 # enable the trunk so that it can be managed
119 self.client.update_trunk(trunk_id, admin_state_up=True)
120
Armando Migliaccio42738312016-08-29 22:04:21 -0700121 @test.idempotent_id('5ff46c22-a2b6-5559-bc5a-0ef2463cab32')
122 def test_create_update_trunk_with_description(self):
123 trunk = self._create_trunk_with_network_and_parent(
124 None, description="foo description")
125 trunk_id = trunk['trunk']['id']
126 self.assertEqual("foo description", trunk['trunk']['description'])
127 trunk = self.client.update_trunk(trunk_id, description='')
128 self.assertEqual('', trunk['trunk']['description'])
129
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800130 @test.idempotent_id('73365f73-bed6-42cd-960b-ec04e0c99d85')
131 def test_list_trunks(self):
132 trunk1 = self._create_trunk_with_network_and_parent(None)
133 trunk2 = self._create_trunk_with_network_and_parent(None)
134 expected_trunks = {trunk1['trunk']['id']: trunk1['trunk'],
135 trunk2['trunk']['id']: trunk2['trunk']}
Armando Migliaccio71d34702016-08-29 22:50:44 -0700136 trunk_list = self._list_trunks()['trunks']
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800137 matched_trunks = [x for x in trunk_list if x['id'] in expected_trunks]
138 self.assertEqual(2, len(matched_trunks))
139 for trunk in matched_trunks:
140 self.assertEqual(expected_trunks[trunk['id']], trunk)
141
142 @test.idempotent_id('bb5fcead-09b5-484a-bbe6-46d1e06d6cc0')
143 def test_add_subport(self):
144 trunk = self._create_trunk_with_network_and_parent([])
145 network = self.create_network()
146 port = self.create_port(network)
147 subports = [{'port_id': port['id'],
148 'segmentation_type': 'vlan',
149 'segmentation_id': 2}]
150 self.client.add_subports(trunk['trunk']['id'], subports)
Armando Migliaccio71d34702016-08-29 22:50:44 -0700151 trunk = self._show_trunk(trunk['trunk']['id'])
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800152 observed_subports = trunk['trunk']['sub_ports']
153 self.assertEqual(1, len(observed_subports))
154 created_subport = observed_subports[0]
155 self.assertEqual(subports[0], created_subport)
156
Armando Migliaccio232642c2016-07-20 16:28:24 -0700157 @test.idempotent_id('ee5fcead-1abf-483a-bce6-43d1e06d6aa0')
158 def test_delete_trunk_with_subport_is_allowed(self):
159 network = self.create_network()
160 port = self.create_port(network)
161 subports = [{'port_id': port['id'],
162 'segmentation_type': 'vlan',
163 'segmentation_id': 2}]
164 trunk = self._create_trunk_with_network_and_parent(subports)
165 self.client.delete_trunk(trunk['trunk']['id'])
166
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800167 @test.idempotent_id('96eea398-a03c-4c3e-a99e-864392c2ca53')
168 def test_remove_subport(self):
169 subport_parent1 = self.create_port(self.create_network())
170 subport_parent2 = self.create_port(self.create_network())
171 subports = [{'port_id': subport_parent1['id'],
172 'segmentation_type': 'vlan',
173 'segmentation_id': 2},
174 {'port_id': subport_parent2['id'],
175 'segmentation_type': 'vlan',
176 'segmentation_id': 4}]
177 trunk = self._create_trunk_with_network_and_parent(subports)
178 removed_subport = trunk['trunk']['sub_ports'][0]
179 expected_subport = None
180
181 for subport in subports:
182 if subport['port_id'] != removed_subport['port_id']:
183 expected_subport = subport
184 break
185
186 # Remove the subport and validate PUT response
187 res = self.client.remove_subports(trunk['trunk']['id'],
188 [removed_subport])
189 self.assertEqual(1, len(res['sub_ports']))
190 self.assertEqual(expected_subport, res['sub_ports'][0])
191
192 # Validate the results of a subport list
Armando Migliaccio71d34702016-08-29 22:50:44 -0700193 trunk = self._show_trunk(trunk['trunk']['id'])
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800194 observed_subports = trunk['trunk']['sub_ports']
195 self.assertEqual(1, len(observed_subports))
196 self.assertEqual(expected_subport, observed_subports[0])
197
198 @test.idempotent_id('bb5fcaad-09b5-484a-dde6-4cd1ea6d6ff0')
199 def test_get_subports(self):
200 network = self.create_network()
201 port = self.create_port(network)
202 subports = [{'port_id': port['id'],
203 'segmentation_type': 'vlan',
204 'segmentation_id': 2}]
205 trunk = self._create_trunk_with_network_and_parent(subports)
206 trunk = self.client.get_subports(trunk['trunk']['id'])
207 observed_subports = trunk['sub_ports']
208 self.assertEqual(1, len(observed_subports))
Armando Migliaccio57581c62016-07-01 10:13:19 -0700209
210
Hynek Mlnarikc5106762016-09-01 11:47:31 +0200211class TrunkTestMtusJSONBase(TrunkTestJSONBase):
212
213 required_extensions = ['provider', 'trunk']
214
215 @classmethod
216 def skip_checks(cls):
217 super(TrunkTestMtusJSONBase, cls).skip_checks()
218 for ext in cls.required_extensions:
219 if not test.is_extension_enabled(ext, 'network'):
220 msg = "%s extension not enabled." % ext
221 raise cls.skipException(msg)
222
223 if any(t
224 not in config.CONF.neutron_plugin_options.available_type_drivers
225 for t in ['gre', 'vxlan']):
226 msg = "Either vxlan or gre type driver not enabled."
227 raise cls.skipException(msg)
228
229 def setUp(self):
230 super(TrunkTestMtusJSONBase, self).setUp()
231
232 # VXLAN autocomputed MTU (1450) is smaller than that of GRE (1458)
233 vxlan_kwargs = {'network_name': data_utils.rand_name('vxlan-net-'),
234 'provider:network_type': 'vxlan'}
235 self.smaller_mtu_net = self.create_shared_network(**vxlan_kwargs)
236
237 gre_kwargs = {'network_name': data_utils.rand_name('gre-net-'),
238 'provider:network_type': 'gre'}
239 self.larger_mtu_net = self.create_shared_network(**gre_kwargs)
240
241 self.smaller_mtu_port = self.create_port(self.smaller_mtu_net)
242 self.smaller_mtu_port_2 = self.create_port(self.smaller_mtu_net)
243 self.larger_mtu_port = self.create_port(self.larger_mtu_net)
244
245
246class TrunkTestMtusJSON(TrunkTestMtusJSONBase):
247
248 @test.idempotent_id('0f05d98e-41f5-4629-ac29-9aee269c9602')
249 def test_create_trunk_with_mtu_greater_than_subport(self):
250 subports = [{'port_id': self.smaller_mtu_port['id'],
251 'segmentation_type': 'vlan',
252 'segmentation_id': 2}]
253
254 trunk = self.client.create_trunk(self.larger_mtu_port['id'], subports)
255 self.trunks.append(trunk['trunk'])
256
257 @test.idempotent_id('2004c5c6-e557-4c43-8100-c820ad4953e8')
258 def test_add_subport_with_mtu_smaller_than_trunk(self):
259 subports = [{'port_id': self.smaller_mtu_port['id'],
260 'segmentation_type': 'vlan',
261 'segmentation_id': 2}]
262
263 trunk = self.client.create_trunk(self.larger_mtu_port['id'], None)
264 self.trunks.append(trunk['trunk'])
265
266 self.client.add_subports(trunk['trunk']['id'], subports)
267
268 @test.idempotent_id('22725101-f4bc-4e00-84ec-4e02cd7e0500')
269 def test_create_trunk_with_mtu_equal_to_subport(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.smaller_mtu_port_2['id'],
275 subports)
276 self.trunks.append(trunk['trunk'])
277
278 @test.idempotent_id('175b05ae-66ad-44c7-857a-a12d16f1058f')
279 def test_add_subport_with_mtu_equal_to_trunk(self):
280 subports = [{'port_id': self.smaller_mtu_port['id'],
281 'segmentation_type': 'vlan',
282 'segmentation_id': 2}]
283
284 trunk = self.client.create_trunk(self.smaller_mtu_port_2['id'], None)
285 self.trunks.append(trunk['trunk'])
286
287 self.client.add_subports(trunk['trunk']['id'], subports)
288
289
Armando Migliaccio57581c62016-07-01 10:13:19 -0700290class TrunksSearchCriteriaTest(base.BaseSearchCriteriaTest):
291
292 resource = 'trunk'
Armando Migliaccio57581c62016-07-01 10:13:19 -0700293
294 @classmethod
Armando Migliacciod26a2742016-07-13 08:57:50 -0700295 def skip_checks(cls):
296 super(TrunksSearchCriteriaTest, cls).skip_checks()
297 if not test.is_extension_enabled('trunk', 'network'):
298 msg = "trunk extension not enabled."
299 raise cls.skipException(msg)
300
301 @classmethod
Armando Migliaccio57581c62016-07-01 10:13:19 -0700302 def resource_setup(cls):
303 super(TrunksSearchCriteriaTest, cls).resource_setup()
Armando Migliacciod26a2742016-07-13 08:57:50 -0700304 cls.trunks = []
Armando Migliaccio57581c62016-07-01 10:13:19 -0700305 net = cls.create_network(network_name='trunk-search-test-net')
306 for name in cls.resource_names:
307 parent_port = cls.create_port(net)
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700308 trunk = cls.client.create_trunk(parent_port['id'], [], name=name)
Armando Migliacciod26a2742016-07-13 08:57:50 -0700309 cls.trunks.append(trunk['trunk'])
310
311 @classmethod
312 def resource_cleanup(cls):
313 trunks_cleanup(cls.client, cls.trunks)
314 super(TrunksSearchCriteriaTest, cls).resource_cleanup()
Armando Migliaccio57581c62016-07-01 10:13:19 -0700315
316 @test.idempotent_id('fab73df4-960a-4ae3-87d3-60992b8d3e2d')
317 def test_list_sorts_asc(self):
318 self._test_list_sorts_asc()
319
320 @test.idempotent_id('a426671d-7270-430f-82ff-8f33eec93010')
321 def test_list_sorts_desc(self):
322 self._test_list_sorts_desc()
323
324 @test.idempotent_id('b202fdc8-6616-45df-b6a0-463932de6f94')
325 def test_list_pagination(self):
326 self._test_list_pagination()
327
328 @test.idempotent_id('c4723b8e-8186-4b9a-bf9e-57519967e048')
329 def test_list_pagination_with_marker(self):
330 self._test_list_pagination_with_marker()
331
332 @test.idempotent_id('dcd02a7a-f07e-4d5e-b0ca-b58e48927a9b')
333 def test_list_pagination_with_href_links(self):
334 self._test_list_pagination_with_href_links()
335
336 @test.idempotent_id('eafe7024-77ab-4cfe-824b-0b2bf4217727')
337 def test_list_no_pagination_limit_0(self):
338 self._test_list_no_pagination_limit_0()
339
340 @test.idempotent_id('f8857391-dc44-40cc-89b7-2800402e03ce')
341 def test_list_pagination_page_reverse_asc(self):
342 self._test_list_pagination_page_reverse_asc()
343
344 @test.idempotent_id('ae51e9c9-ceae-4ec0-afd4-147569247699')
345 def test_list_pagination_page_reverse_desc(self):
346 self._test_list_pagination_page_reverse_desc()
347
348 @test.idempotent_id('b4293e59-d794-4a93-be09-38667199ef68')
349 def test_list_pagination_page_reverse_with_href_links(self):
350 self._test_list_pagination_page_reverse_with_href_links()