Ryan Tidwell | 9b9be44 | 2016-02-18 17:34:43 +0800 | [diff] [blame] | 1 | # 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 Migliaccio | d26a274 | 2016-07-13 08:57:50 -0700 | [diff] [blame] | 15 | from tempest.lib.common.utils import test_utils |
Ryan Tidwell | 9b9be44 | 2016-02-18 17:34:43 +0800 | [diff] [blame] | 16 | from tempest.lib import exceptions as lib_exc |
| 17 | from tempest import test |
| 18 | |
| 19 | from neutron.tests.tempest.api import base |
| 20 | |
| 21 | |
Armando Migliaccio | d26a274 | 2016-07-13 08:57:50 -0700 | [diff] [blame] | 22 | def trunks_cleanup(client, trunks): |
| 23 | for trunk in trunks: |
Armando Migliaccio | 232642c | 2016-07-20 16:28:24 -0700 | [diff] [blame^] | 24 | # 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 Migliaccio | d26a274 | 2016-07-13 08:57:50 -0700 | [diff] [blame] | 27 | 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 Tidwell | 9b9be44 | 2016-02-18 17:34:43 +0800 | [diff] [blame] | 36 | class TrunkTestJSONBase(base.BaseAdminNetworkTest): |
| 37 | |
Armando Migliaccio | d26a274 | 2016-07-13 08:57:50 -0700 | [diff] [blame] | 38 | 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 Migliaccio | 89a24f1 | 2016-07-12 11:59:02 -0700 | [diff] [blame] | 61 | def _create_trunk_with_network_and_parent(self, subports, **kwargs): |
Ryan Tidwell | 9b9be44 | 2016-02-18 17:34:43 +0800 | [diff] [blame] | 62 | network = self.create_network() |
| 63 | parent_port = self.create_port(network) |
Armando Migliaccio | 89a24f1 | 2016-07-12 11:59:02 -0700 | [diff] [blame] | 64 | trunk = self.client.create_trunk(parent_port['id'], subports, **kwargs) |
Armando Migliaccio | d26a274 | 2016-07-13 08:57:50 -0700 | [diff] [blame] | 65 | self.trunks.append(trunk['trunk']) |
| 66 | return trunk |
Ryan Tidwell | 9b9be44 | 2016-02-18 17:34:43 +0800 | [diff] [blame] | 67 | |
| 68 | |
| 69 | class TrunkTestJSON(TrunkTestJSONBase): |
| 70 | |
Ryan Tidwell | 9b9be44 | 2016-02-18 17:34:43 +0800 | [diff] [blame] | 71 | @test.idempotent_id('e1a6355c-4768-41f3-9bf8-0f1d192bd501') |
| 72 | def test_create_trunk_empty_subports_list(self): |
| 73 | trunk = self._create_trunk_with_network_and_parent([]) |
| 74 | observed_trunk = self.client.show_trunk(trunk['trunk']['id']) |
| 75 | self.assertEqual(trunk, observed_trunk) |
| 76 | |
| 77 | @test.idempotent_id('382dfa39-ca03-4bd3-9a1c-91e36d2e3796') |
| 78 | def test_create_trunk_subports_not_specified(self): |
| 79 | trunk = self._create_trunk_with_network_and_parent(None) |
| 80 | observed_trunk = self.client.show_trunk(trunk['trunk']['id']) |
| 81 | self.assertEqual(trunk, observed_trunk) |
| 82 | |
| 83 | @test.idempotent_id('7de46c22-e2b6-4959-ac5a-0e624632ab32') |
| 84 | def test_create_show_delete_trunk(self): |
| 85 | trunk = self._create_trunk_with_network_and_parent(None) |
| 86 | trunk_id = trunk['trunk']['id'] |
| 87 | parent_port_id = trunk['trunk']['port_id'] |
| 88 | res = self.client.show_trunk(trunk_id) |
| 89 | self.assertEqual(trunk_id, res['trunk']['id']) |
| 90 | self.assertEqual(parent_port_id, res['trunk']['port_id']) |
| 91 | self.client.delete_trunk(trunk_id) |
| 92 | self.assertRaises(lib_exc.NotFound, self.client.show_trunk, trunk_id) |
| 93 | |
Armando Migliaccio | 89a24f1 | 2016-07-12 11:59:02 -0700 | [diff] [blame] | 94 | @test.idempotent_id('4ce46c22-a2b6-4659-bc5a-0ef2463cab32') |
| 95 | def test_create_update_trunk(self): |
| 96 | trunk = self._create_trunk_with_network_and_parent(None) |
| 97 | trunk_id = trunk['trunk']['id'] |
| 98 | res = self.client.show_trunk(trunk_id) |
| 99 | self.assertTrue(res['trunk']['admin_state_up']) |
| 100 | self.assertEqual("", res['trunk']['name']) |
| 101 | res = self.client.update_trunk( |
| 102 | trunk_id, name='foo', admin_state_up=False) |
| 103 | self.assertFalse(res['trunk']['admin_state_up']) |
| 104 | self.assertEqual("foo", res['trunk']['name']) |
| 105 | # enable the trunk so that it can be managed |
| 106 | self.client.update_trunk(trunk_id, admin_state_up=True) |
| 107 | |
Ryan Tidwell | 9b9be44 | 2016-02-18 17:34:43 +0800 | [diff] [blame] | 108 | @test.idempotent_id('73365f73-bed6-42cd-960b-ec04e0c99d85') |
| 109 | def test_list_trunks(self): |
| 110 | trunk1 = self._create_trunk_with_network_and_parent(None) |
| 111 | trunk2 = self._create_trunk_with_network_and_parent(None) |
| 112 | expected_trunks = {trunk1['trunk']['id']: trunk1['trunk'], |
| 113 | trunk2['trunk']['id']: trunk2['trunk']} |
| 114 | trunk_list = self.client.list_trunks()['trunks'] |
| 115 | matched_trunks = [x for x in trunk_list if x['id'] in expected_trunks] |
| 116 | self.assertEqual(2, len(matched_trunks)) |
| 117 | for trunk in matched_trunks: |
| 118 | self.assertEqual(expected_trunks[trunk['id']], trunk) |
| 119 | |
| 120 | @test.idempotent_id('bb5fcead-09b5-484a-bbe6-46d1e06d6cc0') |
| 121 | def test_add_subport(self): |
| 122 | trunk = self._create_trunk_with_network_and_parent([]) |
| 123 | network = self.create_network() |
| 124 | port = self.create_port(network) |
| 125 | subports = [{'port_id': port['id'], |
| 126 | 'segmentation_type': 'vlan', |
| 127 | 'segmentation_id': 2}] |
| 128 | self.client.add_subports(trunk['trunk']['id'], subports) |
| 129 | trunk = self.client.show_trunk(trunk['trunk']['id']) |
| 130 | observed_subports = trunk['trunk']['sub_ports'] |
| 131 | self.assertEqual(1, len(observed_subports)) |
| 132 | created_subport = observed_subports[0] |
| 133 | self.assertEqual(subports[0], created_subport) |
| 134 | |
Armando Migliaccio | 232642c | 2016-07-20 16:28:24 -0700 | [diff] [blame^] | 135 | @test.idempotent_id('ee5fcead-1abf-483a-bce6-43d1e06d6aa0') |
| 136 | def test_delete_trunk_with_subport_is_allowed(self): |
| 137 | network = self.create_network() |
| 138 | port = self.create_port(network) |
| 139 | subports = [{'port_id': port['id'], |
| 140 | 'segmentation_type': 'vlan', |
| 141 | 'segmentation_id': 2}] |
| 142 | trunk = self._create_trunk_with_network_and_parent(subports) |
| 143 | self.client.delete_trunk(trunk['trunk']['id']) |
| 144 | |
Ryan Tidwell | 9b9be44 | 2016-02-18 17:34:43 +0800 | [diff] [blame] | 145 | @test.idempotent_id('96eea398-a03c-4c3e-a99e-864392c2ca53') |
| 146 | def test_remove_subport(self): |
| 147 | subport_parent1 = self.create_port(self.create_network()) |
| 148 | subport_parent2 = self.create_port(self.create_network()) |
| 149 | subports = [{'port_id': subport_parent1['id'], |
| 150 | 'segmentation_type': 'vlan', |
| 151 | 'segmentation_id': 2}, |
| 152 | {'port_id': subport_parent2['id'], |
| 153 | 'segmentation_type': 'vlan', |
| 154 | 'segmentation_id': 4}] |
| 155 | trunk = self._create_trunk_with_network_and_parent(subports) |
| 156 | removed_subport = trunk['trunk']['sub_ports'][0] |
| 157 | expected_subport = None |
| 158 | |
| 159 | for subport in subports: |
| 160 | if subport['port_id'] != removed_subport['port_id']: |
| 161 | expected_subport = subport |
| 162 | break |
| 163 | |
| 164 | # Remove the subport and validate PUT response |
| 165 | res = self.client.remove_subports(trunk['trunk']['id'], |
| 166 | [removed_subport]) |
| 167 | self.assertEqual(1, len(res['sub_ports'])) |
| 168 | self.assertEqual(expected_subport, res['sub_ports'][0]) |
| 169 | |
| 170 | # Validate the results of a subport list |
| 171 | trunk = self.client.show_trunk(trunk['trunk']['id']) |
| 172 | observed_subports = trunk['trunk']['sub_ports'] |
| 173 | self.assertEqual(1, len(observed_subports)) |
| 174 | self.assertEqual(expected_subport, observed_subports[0]) |
| 175 | |
| 176 | @test.idempotent_id('bb5fcaad-09b5-484a-dde6-4cd1ea6d6ff0') |
| 177 | def test_get_subports(self): |
| 178 | network = self.create_network() |
| 179 | port = self.create_port(network) |
| 180 | subports = [{'port_id': port['id'], |
| 181 | 'segmentation_type': 'vlan', |
| 182 | 'segmentation_id': 2}] |
| 183 | trunk = self._create_trunk_with_network_and_parent(subports) |
| 184 | trunk = self.client.get_subports(trunk['trunk']['id']) |
| 185 | observed_subports = trunk['sub_ports'] |
| 186 | self.assertEqual(1, len(observed_subports)) |
Armando Migliaccio | 57581c6 | 2016-07-01 10:13:19 -0700 | [diff] [blame] | 187 | |
| 188 | |
| 189 | class TrunksSearchCriteriaTest(base.BaseSearchCriteriaTest): |
| 190 | |
| 191 | resource = 'trunk' |
Armando Migliaccio | 57581c6 | 2016-07-01 10:13:19 -0700 | [diff] [blame] | 192 | |
| 193 | @classmethod |
Armando Migliaccio | d26a274 | 2016-07-13 08:57:50 -0700 | [diff] [blame] | 194 | def skip_checks(cls): |
| 195 | super(TrunksSearchCriteriaTest, cls).skip_checks() |
| 196 | if not test.is_extension_enabled('trunk', 'network'): |
| 197 | msg = "trunk extension not enabled." |
| 198 | raise cls.skipException(msg) |
| 199 | |
| 200 | @classmethod |
Armando Migliaccio | 57581c6 | 2016-07-01 10:13:19 -0700 | [diff] [blame] | 201 | def resource_setup(cls): |
| 202 | super(TrunksSearchCriteriaTest, cls).resource_setup() |
Armando Migliaccio | d26a274 | 2016-07-13 08:57:50 -0700 | [diff] [blame] | 203 | cls.trunks = [] |
Armando Migliaccio | 57581c6 | 2016-07-01 10:13:19 -0700 | [diff] [blame] | 204 | net = cls.create_network(network_name='trunk-search-test-net') |
| 205 | for name in cls.resource_names: |
| 206 | parent_port = cls.create_port(net) |
Armando Migliaccio | 89a24f1 | 2016-07-12 11:59:02 -0700 | [diff] [blame] | 207 | trunk = cls.client.create_trunk(parent_port['id'], [], name=name) |
Armando Migliaccio | d26a274 | 2016-07-13 08:57:50 -0700 | [diff] [blame] | 208 | cls.trunks.append(trunk['trunk']) |
| 209 | |
| 210 | @classmethod |
| 211 | def resource_cleanup(cls): |
| 212 | trunks_cleanup(cls.client, cls.trunks) |
| 213 | super(TrunksSearchCriteriaTest, cls).resource_cleanup() |
Armando Migliaccio | 57581c6 | 2016-07-01 10:13:19 -0700 | [diff] [blame] | 214 | |
| 215 | @test.idempotent_id('fab73df4-960a-4ae3-87d3-60992b8d3e2d') |
| 216 | def test_list_sorts_asc(self): |
| 217 | self._test_list_sorts_asc() |
| 218 | |
| 219 | @test.idempotent_id('a426671d-7270-430f-82ff-8f33eec93010') |
| 220 | def test_list_sorts_desc(self): |
| 221 | self._test_list_sorts_desc() |
| 222 | |
| 223 | @test.idempotent_id('b202fdc8-6616-45df-b6a0-463932de6f94') |
| 224 | def test_list_pagination(self): |
| 225 | self._test_list_pagination() |
| 226 | |
| 227 | @test.idempotent_id('c4723b8e-8186-4b9a-bf9e-57519967e048') |
| 228 | def test_list_pagination_with_marker(self): |
| 229 | self._test_list_pagination_with_marker() |
| 230 | |
| 231 | @test.idempotent_id('dcd02a7a-f07e-4d5e-b0ca-b58e48927a9b') |
| 232 | def test_list_pagination_with_href_links(self): |
| 233 | self._test_list_pagination_with_href_links() |
| 234 | |
| 235 | @test.idempotent_id('eafe7024-77ab-4cfe-824b-0b2bf4217727') |
| 236 | def test_list_no_pagination_limit_0(self): |
| 237 | self._test_list_no_pagination_limit_0() |
| 238 | |
| 239 | @test.idempotent_id('f8857391-dc44-40cc-89b7-2800402e03ce') |
| 240 | def test_list_pagination_page_reverse_asc(self): |
| 241 | self._test_list_pagination_page_reverse_asc() |
| 242 | |
| 243 | @test.idempotent_id('ae51e9c9-ceae-4ec0-afd4-147569247699') |
| 244 | def test_list_pagination_page_reverse_desc(self): |
| 245 | self._test_list_pagination_page_reverse_desc() |
| 246 | |
| 247 | @test.idempotent_id('b4293e59-d794-4a93-be09-38667199ef68') |
| 248 | def test_list_pagination_page_reverse_with_href_links(self): |
| 249 | self._test_list_pagination_page_reverse_with_href_links() |