blob: 44adb7e814b287e4993431ec5ab7cf440e5f05ec [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
Armando Migliacciod26a2742016-07-13 08:57:50 -070015from tempest.lib.common.utils import test_utils
Ryan Tidwell9b9be442016-02-18 17:34:43 +080016from tempest.lib import exceptions as lib_exc
17from tempest import test
18
19from neutron.tests.tempest.api import base
20
21
Armando Migliacciod26a2742016-07-13 08:57:50 -070022def trunks_cleanup(client, trunks):
23 for trunk in trunks:
Armando Migliaccio232642c2016-07-20 16:28:24 -070024 # NOTE(armax): deleting a trunk with subports is permitted, however
25 # for testing purposes it is safer to be explicit and clean all the
26 # resources associated with the trunk beforehand.
Armando Migliacciod26a2742016-07-13 08:57:50 -070027 subports = test_utils.call_and_ignore_notfound_exc(
28 client.get_subports, trunk['id'])
29 if subports:
30 client.remove_subports(
31 trunk['id'], subports['sub_ports'])
32 test_utils.call_and_ignore_notfound_exc(
33 client.delete_trunk, trunk['id'])
34
35
Ryan Tidwell9b9be442016-02-18 17:34:43 +080036class TrunkTestJSONBase(base.BaseAdminNetworkTest):
37
Armando Migliacciod26a2742016-07-13 08:57:50 -070038 extension = 'trunk'
39
40 def setUp(self):
41 self.addCleanup(self.resource_cleanup)
42 super(TrunkTestJSONBase, self).setUp()
43
44 @classmethod
45 def skip_checks(cls):
46 super(TrunkTestJSONBase, cls).skip_checks()
47 if not test.is_extension_enabled(cls.extension, 'network'):
48 msg = "%s extension not enabled." % cls.extension
49 raise cls.skipException(msg)
50
51 @classmethod
52 def resource_setup(cls):
53 super(TrunkTestJSONBase, cls).resource_setup()
54 cls.trunks = []
55
56 @classmethod
57 def resource_cleanup(cls):
58 trunks_cleanup(cls.client, cls.trunks)
59 super(TrunkTestJSONBase, cls).resource_cleanup()
60
Armando Migliaccio71d34702016-08-29 22:50:44 -070061 def _remove_timestamps(self, trunk):
62 # Let's make sure these fields exist, but let's not
63 # use them in the comparison, in case skews or
64 # roundups get in the way.
65 created_at = trunk.pop('created_at')
66 updated_at = trunk.pop('updated_at')
67 self.assertIsNotNone(created_at)
68 self.assertIsNotNone(updated_at)
69
Armando Migliaccio89a24f12016-07-12 11:59:02 -070070 def _create_trunk_with_network_and_parent(self, subports, **kwargs):
Ryan Tidwell9b9be442016-02-18 17:34:43 +080071 network = self.create_network()
72 parent_port = self.create_port(network)
Armando Migliaccio89a24f12016-07-12 11:59:02 -070073 trunk = self.client.create_trunk(parent_port['id'], subports, **kwargs)
Armando Migliacciod26a2742016-07-13 08:57:50 -070074 self.trunks.append(trunk['trunk'])
Armando Migliaccio71d34702016-08-29 22:50:44 -070075 self._remove_timestamps(trunk['trunk'])
Armando Migliacciod26a2742016-07-13 08:57:50 -070076 return trunk
Ryan Tidwell9b9be442016-02-18 17:34:43 +080077
Armando Migliaccio71d34702016-08-29 22:50:44 -070078 def _show_trunk(self, trunk_id):
79 trunk = self.client.show_trunk(trunk_id)
80 self._remove_timestamps(trunk['trunk'])
81 return trunk
82
83 def _list_trunks(self):
84 trunks = self.client.list_trunks()
85 for t in trunks['trunks']:
86 self._remove_timestamps(t)
87 return trunks
88
Ryan Tidwell9b9be442016-02-18 17:34:43 +080089
90class TrunkTestJSON(TrunkTestJSONBase):
91
Armando Migliaccio71d34702016-08-29 22:50:44 -070092 def _test_create_trunk(self, subports):
93 trunk = self._create_trunk_with_network_and_parent(subports)
94 observed_trunk = self._show_trunk(trunk['trunk']['id'])
95 self.assertEqual(trunk, observed_trunk)
96
Ryan Tidwell9b9be442016-02-18 17:34:43 +080097 @test.idempotent_id('e1a6355c-4768-41f3-9bf8-0f1d192bd501')
98 def test_create_trunk_empty_subports_list(self):
Armando Migliaccio71d34702016-08-29 22:50:44 -070099 self._test_create_trunk([])
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800100
101 @test.idempotent_id('382dfa39-ca03-4bd3-9a1c-91e36d2e3796')
102 def test_create_trunk_subports_not_specified(self):
Armando Migliaccio71d34702016-08-29 22:50:44 -0700103 self._test_create_trunk(None)
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800104
105 @test.idempotent_id('7de46c22-e2b6-4959-ac5a-0e624632ab32')
106 def test_create_show_delete_trunk(self):
107 trunk = self._create_trunk_with_network_and_parent(None)
108 trunk_id = trunk['trunk']['id']
109 parent_port_id = trunk['trunk']['port_id']
Armando Migliaccio71d34702016-08-29 22:50:44 -0700110 res = self._show_trunk(trunk_id)
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800111 self.assertEqual(trunk_id, res['trunk']['id'])
112 self.assertEqual(parent_port_id, res['trunk']['port_id'])
113 self.client.delete_trunk(trunk_id)
Armando Migliaccio71d34702016-08-29 22:50:44 -0700114 self.assertRaises(lib_exc.NotFound, self._show_trunk, trunk_id)
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800115
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700116 @test.idempotent_id('4ce46c22-a2b6-4659-bc5a-0ef2463cab32')
117 def test_create_update_trunk(self):
118 trunk = self._create_trunk_with_network_and_parent(None)
119 trunk_id = trunk['trunk']['id']
Armando Migliaccio71d34702016-08-29 22:50:44 -0700120 res = self._show_trunk(trunk_id)
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700121 self.assertTrue(res['trunk']['admin_state_up'])
122 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'])
128 # enable the trunk so that it can be managed
129 self.client.update_trunk(trunk_id, admin_state_up=True)
130
Armando Migliaccio42738312016-08-29 22:04:21 -0700131 @test.idempotent_id('5ff46c22-a2b6-5559-bc5a-0ef2463cab32')
132 def test_create_update_trunk_with_description(self):
133 trunk = self._create_trunk_with_network_and_parent(
134 None, description="foo description")
135 trunk_id = trunk['trunk']['id']
136 self.assertEqual("foo description", trunk['trunk']['description'])
137 trunk = self.client.update_trunk(trunk_id, description='')
138 self.assertEqual('', trunk['trunk']['description'])
139
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800140 @test.idempotent_id('73365f73-bed6-42cd-960b-ec04e0c99d85')
141 def test_list_trunks(self):
142 trunk1 = self._create_trunk_with_network_and_parent(None)
143 trunk2 = self._create_trunk_with_network_and_parent(None)
144 expected_trunks = {trunk1['trunk']['id']: trunk1['trunk'],
145 trunk2['trunk']['id']: trunk2['trunk']}
Armando Migliaccio71d34702016-08-29 22:50:44 -0700146 trunk_list = self._list_trunks()['trunks']
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800147 matched_trunks = [x for x in trunk_list if x['id'] in expected_trunks]
148 self.assertEqual(2, len(matched_trunks))
149 for trunk in matched_trunks:
150 self.assertEqual(expected_trunks[trunk['id']], trunk)
151
152 @test.idempotent_id('bb5fcead-09b5-484a-bbe6-46d1e06d6cc0')
153 def test_add_subport(self):
154 trunk = self._create_trunk_with_network_and_parent([])
155 network = self.create_network()
156 port = self.create_port(network)
157 subports = [{'port_id': port['id'],
158 'segmentation_type': 'vlan',
159 'segmentation_id': 2}]
160 self.client.add_subports(trunk['trunk']['id'], subports)
Armando Migliaccio71d34702016-08-29 22:50:44 -0700161 trunk = self._show_trunk(trunk['trunk']['id'])
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800162 observed_subports = trunk['trunk']['sub_ports']
163 self.assertEqual(1, len(observed_subports))
164 created_subport = observed_subports[0]
165 self.assertEqual(subports[0], created_subport)
166
Armando Migliaccio232642c2016-07-20 16:28:24 -0700167 @test.idempotent_id('ee5fcead-1abf-483a-bce6-43d1e06d6aa0')
168 def test_delete_trunk_with_subport_is_allowed(self):
169 network = self.create_network()
170 port = self.create_port(network)
171 subports = [{'port_id': port['id'],
172 'segmentation_type': 'vlan',
173 'segmentation_id': 2}]
174 trunk = self._create_trunk_with_network_and_parent(subports)
175 self.client.delete_trunk(trunk['trunk']['id'])
176
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800177 @test.idempotent_id('96eea398-a03c-4c3e-a99e-864392c2ca53')
178 def test_remove_subport(self):
179 subport_parent1 = self.create_port(self.create_network())
180 subport_parent2 = self.create_port(self.create_network())
181 subports = [{'port_id': subport_parent1['id'],
182 'segmentation_type': 'vlan',
183 'segmentation_id': 2},
184 {'port_id': subport_parent2['id'],
185 'segmentation_type': 'vlan',
186 'segmentation_id': 4}]
187 trunk = self._create_trunk_with_network_and_parent(subports)
188 removed_subport = trunk['trunk']['sub_ports'][0]
189 expected_subport = None
190
191 for subport in subports:
192 if subport['port_id'] != removed_subport['port_id']:
193 expected_subport = subport
194 break
195
196 # Remove the subport and validate PUT response
197 res = self.client.remove_subports(trunk['trunk']['id'],
198 [removed_subport])
199 self.assertEqual(1, len(res['sub_ports']))
200 self.assertEqual(expected_subport, res['sub_ports'][0])
201
202 # Validate the results of a subport list
Armando Migliaccio71d34702016-08-29 22:50:44 -0700203 trunk = self._show_trunk(trunk['trunk']['id'])
Ryan Tidwell9b9be442016-02-18 17:34:43 +0800204 observed_subports = trunk['trunk']['sub_ports']
205 self.assertEqual(1, len(observed_subports))
206 self.assertEqual(expected_subport, observed_subports[0])
207
208 @test.idempotent_id('bb5fcaad-09b5-484a-dde6-4cd1ea6d6ff0')
209 def test_get_subports(self):
210 network = self.create_network()
211 port = self.create_port(network)
212 subports = [{'port_id': port['id'],
213 'segmentation_type': 'vlan',
214 'segmentation_id': 2}]
215 trunk = self._create_trunk_with_network_and_parent(subports)
216 trunk = self.client.get_subports(trunk['trunk']['id'])
217 observed_subports = trunk['sub_ports']
218 self.assertEqual(1, len(observed_subports))
Armando Migliaccio57581c62016-07-01 10:13:19 -0700219
220
221class TrunksSearchCriteriaTest(base.BaseSearchCriteriaTest):
222
223 resource = 'trunk'
Armando Migliaccio57581c62016-07-01 10:13:19 -0700224
225 @classmethod
Armando Migliacciod26a2742016-07-13 08:57:50 -0700226 def skip_checks(cls):
227 super(TrunksSearchCriteriaTest, cls).skip_checks()
228 if not test.is_extension_enabled('trunk', 'network'):
229 msg = "trunk extension not enabled."
230 raise cls.skipException(msg)
231
232 @classmethod
Armando Migliaccio57581c62016-07-01 10:13:19 -0700233 def resource_setup(cls):
234 super(TrunksSearchCriteriaTest, cls).resource_setup()
Armando Migliacciod26a2742016-07-13 08:57:50 -0700235 cls.trunks = []
Armando Migliaccio57581c62016-07-01 10:13:19 -0700236 net = cls.create_network(network_name='trunk-search-test-net')
237 for name in cls.resource_names:
238 parent_port = cls.create_port(net)
Armando Migliaccio89a24f12016-07-12 11:59:02 -0700239 trunk = cls.client.create_trunk(parent_port['id'], [], name=name)
Armando Migliacciod26a2742016-07-13 08:57:50 -0700240 cls.trunks.append(trunk['trunk'])
241
242 @classmethod
243 def resource_cleanup(cls):
244 trunks_cleanup(cls.client, cls.trunks)
245 super(TrunksSearchCriteriaTest, cls).resource_cleanup()
Armando Migliaccio57581c62016-07-01 10:13:19 -0700246
247 @test.idempotent_id('fab73df4-960a-4ae3-87d3-60992b8d3e2d')
248 def test_list_sorts_asc(self):
249 self._test_list_sorts_asc()
250
251 @test.idempotent_id('a426671d-7270-430f-82ff-8f33eec93010')
252 def test_list_sorts_desc(self):
253 self._test_list_sorts_desc()
254
255 @test.idempotent_id('b202fdc8-6616-45df-b6a0-463932de6f94')
256 def test_list_pagination(self):
257 self._test_list_pagination()
258
259 @test.idempotent_id('c4723b8e-8186-4b9a-bf9e-57519967e048')
260 def test_list_pagination_with_marker(self):
261 self._test_list_pagination_with_marker()
262
263 @test.idempotent_id('dcd02a7a-f07e-4d5e-b0ca-b58e48927a9b')
264 def test_list_pagination_with_href_links(self):
265 self._test_list_pagination_with_href_links()
266
267 @test.idempotent_id('eafe7024-77ab-4cfe-824b-0b2bf4217727')
268 def test_list_no_pagination_limit_0(self):
269 self._test_list_no_pagination_limit_0()
270
271 @test.idempotent_id('f8857391-dc44-40cc-89b7-2800402e03ce')
272 def test_list_pagination_page_reverse_asc(self):
273 self._test_list_pagination_page_reverse_asc()
274
275 @test.idempotent_id('ae51e9c9-ceae-4ec0-afd4-147569247699')
276 def test_list_pagination_page_reverse_desc(self):
277 self._test_list_pagination_page_reverse_desc()
278
279 @test.idempotent_id('b4293e59-d794-4a93-be09-38667199ef68')
280 def test_list_pagination_page_reverse_with_href_links(self):
281 self._test_list_pagination_page_reverse_with_href_links()