blob: d1fa32599135ca67c31f3fe42a0b7f565a466521 [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:
24 subports = test_utils.call_and_ignore_notfound_exc(
25 client.get_subports, trunk['id'])
26 if subports:
27 client.remove_subports(
28 trunk['id'], subports['sub_ports'])
29 test_utils.call_and_ignore_notfound_exc(
30 client.delete_trunk, trunk['id'])
31
32
Ryan Tidwell9b9be442016-02-18 17:34:43 +080033class TrunkTestJSONBase(base.BaseAdminNetworkTest):
34
Armando Migliacciod26a2742016-07-13 08:57:50 -070035 extension = 'trunk'
36
37 def setUp(self):
38 self.addCleanup(self.resource_cleanup)
39 super(TrunkTestJSONBase, self).setUp()
40
41 @classmethod
42 def skip_checks(cls):
43 super(TrunkTestJSONBase, cls).skip_checks()
44 if not test.is_extension_enabled(cls.extension, 'network'):
45 msg = "%s extension not enabled." % cls.extension
46 raise cls.skipException(msg)
47
48 @classmethod
49 def resource_setup(cls):
50 super(TrunkTestJSONBase, cls).resource_setup()
51 cls.trunks = []
52
53 @classmethod
54 def resource_cleanup(cls):
55 trunks_cleanup(cls.client, cls.trunks)
56 super(TrunkTestJSONBase, cls).resource_cleanup()
57
Ryan Tidwell9b9be442016-02-18 17:34:43 +080058 def _create_trunk_with_network_and_parent(self, subports):
59 network = self.create_network()
60 parent_port = self.create_port(network)
Armando Migliacciod26a2742016-07-13 08:57:50 -070061 trunk = self.client.create_trunk(parent_port['id'], subports)
62 self.trunks.append(trunk['trunk'])
63 return trunk
Ryan Tidwell9b9be442016-02-18 17:34:43 +080064
65
66class TrunkTestJSON(TrunkTestJSONBase):
67
Ryan Tidwell9b9be442016-02-18 17:34:43 +080068 @test.idempotent_id('e1a6355c-4768-41f3-9bf8-0f1d192bd501')
69 def test_create_trunk_empty_subports_list(self):
70 trunk = self._create_trunk_with_network_and_parent([])
71 observed_trunk = self.client.show_trunk(trunk['trunk']['id'])
72 self.assertEqual(trunk, observed_trunk)
73
74 @test.idempotent_id('382dfa39-ca03-4bd3-9a1c-91e36d2e3796')
75 def test_create_trunk_subports_not_specified(self):
76 trunk = self._create_trunk_with_network_and_parent(None)
77 observed_trunk = self.client.show_trunk(trunk['trunk']['id'])
78 self.assertEqual(trunk, observed_trunk)
79
80 @test.idempotent_id('7de46c22-e2b6-4959-ac5a-0e624632ab32')
81 def test_create_show_delete_trunk(self):
82 trunk = self._create_trunk_with_network_and_parent(None)
83 trunk_id = trunk['trunk']['id']
84 parent_port_id = trunk['trunk']['port_id']
85 res = self.client.show_trunk(trunk_id)
86 self.assertEqual(trunk_id, res['trunk']['id'])
87 self.assertEqual(parent_port_id, res['trunk']['port_id'])
88 self.client.delete_trunk(trunk_id)
89 self.assertRaises(lib_exc.NotFound, self.client.show_trunk, trunk_id)
90
91 @test.idempotent_id('73365f73-bed6-42cd-960b-ec04e0c99d85')
92 def test_list_trunks(self):
93 trunk1 = self._create_trunk_with_network_and_parent(None)
94 trunk2 = self._create_trunk_with_network_and_parent(None)
95 expected_trunks = {trunk1['trunk']['id']: trunk1['trunk'],
96 trunk2['trunk']['id']: trunk2['trunk']}
97 trunk_list = self.client.list_trunks()['trunks']
98 matched_trunks = [x for x in trunk_list if x['id'] in expected_trunks]
99 self.assertEqual(2, len(matched_trunks))
100 for trunk in matched_trunks:
101 self.assertEqual(expected_trunks[trunk['id']], trunk)
102
103 @test.idempotent_id('bb5fcead-09b5-484a-bbe6-46d1e06d6cc0')
104 def test_add_subport(self):
105 trunk = self._create_trunk_with_network_and_parent([])
106 network = self.create_network()
107 port = self.create_port(network)
108 subports = [{'port_id': port['id'],
109 'segmentation_type': 'vlan',
110 'segmentation_id': 2}]
111 self.client.add_subports(trunk['trunk']['id'], subports)
112 trunk = self.client.show_trunk(trunk['trunk']['id'])
113 observed_subports = trunk['trunk']['sub_ports']
114 self.assertEqual(1, len(observed_subports))
115 created_subport = observed_subports[0]
116 self.assertEqual(subports[0], created_subport)
117
118 @test.idempotent_id('96eea398-a03c-4c3e-a99e-864392c2ca53')
119 def test_remove_subport(self):
120 subport_parent1 = self.create_port(self.create_network())
121 subport_parent2 = self.create_port(self.create_network())
122 subports = [{'port_id': subport_parent1['id'],
123 'segmentation_type': 'vlan',
124 'segmentation_id': 2},
125 {'port_id': subport_parent2['id'],
126 'segmentation_type': 'vlan',
127 'segmentation_id': 4}]
128 trunk = self._create_trunk_with_network_and_parent(subports)
129 removed_subport = trunk['trunk']['sub_ports'][0]
130 expected_subport = None
131
132 for subport in subports:
133 if subport['port_id'] != removed_subport['port_id']:
134 expected_subport = subport
135 break
136
137 # Remove the subport and validate PUT response
138 res = self.client.remove_subports(trunk['trunk']['id'],
139 [removed_subport])
140 self.assertEqual(1, len(res['sub_ports']))
141 self.assertEqual(expected_subport, res['sub_ports'][0])
142
143 # Validate the results of a subport list
144 trunk = self.client.show_trunk(trunk['trunk']['id'])
145 observed_subports = trunk['trunk']['sub_ports']
146 self.assertEqual(1, len(observed_subports))
147 self.assertEqual(expected_subport, observed_subports[0])
148
149 @test.idempotent_id('bb5fcaad-09b5-484a-dde6-4cd1ea6d6ff0')
150 def test_get_subports(self):
151 network = self.create_network()
152 port = self.create_port(network)
153 subports = [{'port_id': port['id'],
154 'segmentation_type': 'vlan',
155 'segmentation_id': 2}]
156 trunk = self._create_trunk_with_network_and_parent(subports)
157 trunk = self.client.get_subports(trunk['trunk']['id'])
158 observed_subports = trunk['sub_ports']
159 self.assertEqual(1, len(observed_subports))
Armando Migliaccio57581c62016-07-01 10:13:19 -0700160
161
162class TrunksSearchCriteriaTest(base.BaseSearchCriteriaTest):
163
164 resource = 'trunk'
165 field = 'id'
166
167 @classmethod
Armando Migliacciod26a2742016-07-13 08:57:50 -0700168 def skip_checks(cls):
169 super(TrunksSearchCriteriaTest, cls).skip_checks()
170 if not test.is_extension_enabled('trunk', 'network'):
171 msg = "trunk extension not enabled."
172 raise cls.skipException(msg)
173
174 @classmethod
Armando Migliaccio57581c62016-07-01 10:13:19 -0700175 def resource_setup(cls):
176 super(TrunksSearchCriteriaTest, cls).resource_setup()
Armando Migliacciod26a2742016-07-13 08:57:50 -0700177 cls.trunks = []
Armando Migliaccio57581c62016-07-01 10:13:19 -0700178 net = cls.create_network(network_name='trunk-search-test-net')
179 for name in cls.resource_names:
180 parent_port = cls.create_port(net)
Armando Migliacciod26a2742016-07-13 08:57:50 -0700181 trunk = cls.client.create_trunk(parent_port['id'], [])
182 cls.trunks.append(trunk['trunk'])
183
184 @classmethod
185 def resource_cleanup(cls):
186 trunks_cleanup(cls.client, cls.trunks)
187 super(TrunksSearchCriteriaTest, cls).resource_cleanup()
Armando Migliaccio57581c62016-07-01 10:13:19 -0700188
189 @test.idempotent_id('fab73df4-960a-4ae3-87d3-60992b8d3e2d')
190 def test_list_sorts_asc(self):
191 self._test_list_sorts_asc()
192
193 @test.idempotent_id('a426671d-7270-430f-82ff-8f33eec93010')
194 def test_list_sorts_desc(self):
195 self._test_list_sorts_desc()
196
197 @test.idempotent_id('b202fdc8-6616-45df-b6a0-463932de6f94')
198 def test_list_pagination(self):
199 self._test_list_pagination()
200
201 @test.idempotent_id('c4723b8e-8186-4b9a-bf9e-57519967e048')
202 def test_list_pagination_with_marker(self):
203 self._test_list_pagination_with_marker()
204
205 @test.idempotent_id('dcd02a7a-f07e-4d5e-b0ca-b58e48927a9b')
206 def test_list_pagination_with_href_links(self):
207 self._test_list_pagination_with_href_links()
208
209 @test.idempotent_id('eafe7024-77ab-4cfe-824b-0b2bf4217727')
210 def test_list_no_pagination_limit_0(self):
211 self._test_list_no_pagination_limit_0()
212
213 @test.idempotent_id('f8857391-dc44-40cc-89b7-2800402e03ce')
214 def test_list_pagination_page_reverse_asc(self):
215 self._test_list_pagination_page_reverse_asc()
216
217 @test.idempotent_id('ae51e9c9-ceae-4ec0-afd4-147569247699')
218 def test_list_pagination_page_reverse_desc(self):
219 self._test_list_pagination_page_reverse_desc()
220
221 @test.idempotent_id('b4293e59-d794-4a93-be09-38667199ef68')
222 def test_list_pagination_page_reverse_with_href_links(self):
223 self._test_list_pagination_page_reverse_with_href_links()