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 | |
| 15 | from tempest.lib import exceptions as lib_exc |
| 16 | from tempest import test |
| 17 | |
| 18 | from neutron.tests.tempest.api import base |
| 19 | |
| 20 | |
| 21 | class TrunkTestJSONBase(base.BaseAdminNetworkTest): |
| 22 | |
| 23 | def _create_trunk_with_network_and_parent(self, subports): |
| 24 | network = self.create_network() |
| 25 | parent_port = self.create_port(network) |
| 26 | return self.client.create_trunk(parent_port['id'], subports) |
| 27 | |
| 28 | |
| 29 | class TrunkTestJSON(TrunkTestJSONBase): |
| 30 | |
| 31 | @classmethod |
| 32 | @test.requires_ext(extension="trunk", service="network") |
| 33 | def resource_setup(cls): |
| 34 | super(TrunkTestJSON, cls).resource_setup() |
| 35 | |
| 36 | def tearDown(self): |
| 37 | # NOTE(tidwellr) These tests create networks and ports, clean them up |
| 38 | # after each test to avoid hitting quota limits |
| 39 | self.resource_cleanup() |
| 40 | super(TrunkTestJSON, self).tearDown() |
| 41 | |
| 42 | @test.idempotent_id('e1a6355c-4768-41f3-9bf8-0f1d192bd501') |
| 43 | def test_create_trunk_empty_subports_list(self): |
| 44 | trunk = self._create_trunk_with_network_and_parent([]) |
| 45 | observed_trunk = self.client.show_trunk(trunk['trunk']['id']) |
| 46 | self.assertEqual(trunk, observed_trunk) |
| 47 | |
| 48 | @test.idempotent_id('382dfa39-ca03-4bd3-9a1c-91e36d2e3796') |
| 49 | def test_create_trunk_subports_not_specified(self): |
| 50 | trunk = self._create_trunk_with_network_and_parent(None) |
| 51 | observed_trunk = self.client.show_trunk(trunk['trunk']['id']) |
| 52 | self.assertEqual(trunk, observed_trunk) |
| 53 | |
| 54 | @test.idempotent_id('7de46c22-e2b6-4959-ac5a-0e624632ab32') |
| 55 | def test_create_show_delete_trunk(self): |
| 56 | trunk = self._create_trunk_with_network_and_parent(None) |
| 57 | trunk_id = trunk['trunk']['id'] |
| 58 | parent_port_id = trunk['trunk']['port_id'] |
| 59 | res = self.client.show_trunk(trunk_id) |
| 60 | self.assertEqual(trunk_id, res['trunk']['id']) |
| 61 | self.assertEqual(parent_port_id, res['trunk']['port_id']) |
| 62 | self.client.delete_trunk(trunk_id) |
| 63 | self.assertRaises(lib_exc.NotFound, self.client.show_trunk, trunk_id) |
| 64 | |
| 65 | @test.idempotent_id('73365f73-bed6-42cd-960b-ec04e0c99d85') |
| 66 | def test_list_trunks(self): |
| 67 | trunk1 = self._create_trunk_with_network_and_parent(None) |
| 68 | trunk2 = self._create_trunk_with_network_and_parent(None) |
| 69 | expected_trunks = {trunk1['trunk']['id']: trunk1['trunk'], |
| 70 | trunk2['trunk']['id']: trunk2['trunk']} |
| 71 | trunk_list = self.client.list_trunks()['trunks'] |
| 72 | matched_trunks = [x for x in trunk_list if x['id'] in expected_trunks] |
| 73 | self.assertEqual(2, len(matched_trunks)) |
| 74 | for trunk in matched_trunks: |
| 75 | self.assertEqual(expected_trunks[trunk['id']], trunk) |
| 76 | |
| 77 | @test.idempotent_id('bb5fcead-09b5-484a-bbe6-46d1e06d6cc0') |
| 78 | def test_add_subport(self): |
| 79 | trunk = self._create_trunk_with_network_and_parent([]) |
| 80 | network = self.create_network() |
| 81 | port = self.create_port(network) |
| 82 | subports = [{'port_id': port['id'], |
| 83 | 'segmentation_type': 'vlan', |
| 84 | 'segmentation_id': 2}] |
| 85 | self.client.add_subports(trunk['trunk']['id'], subports) |
| 86 | trunk = self.client.show_trunk(trunk['trunk']['id']) |
| 87 | observed_subports = trunk['trunk']['sub_ports'] |
| 88 | self.assertEqual(1, len(observed_subports)) |
| 89 | created_subport = observed_subports[0] |
| 90 | self.assertEqual(subports[0], created_subport) |
| 91 | |
| 92 | @test.idempotent_id('96eea398-a03c-4c3e-a99e-864392c2ca53') |
| 93 | def test_remove_subport(self): |
| 94 | subport_parent1 = self.create_port(self.create_network()) |
| 95 | subport_parent2 = self.create_port(self.create_network()) |
| 96 | subports = [{'port_id': subport_parent1['id'], |
| 97 | 'segmentation_type': 'vlan', |
| 98 | 'segmentation_id': 2}, |
| 99 | {'port_id': subport_parent2['id'], |
| 100 | 'segmentation_type': 'vlan', |
| 101 | 'segmentation_id': 4}] |
| 102 | trunk = self._create_trunk_with_network_and_parent(subports) |
| 103 | removed_subport = trunk['trunk']['sub_ports'][0] |
| 104 | expected_subport = None |
| 105 | |
| 106 | for subport in subports: |
| 107 | if subport['port_id'] != removed_subport['port_id']: |
| 108 | expected_subport = subport |
| 109 | break |
| 110 | |
| 111 | # Remove the subport and validate PUT response |
| 112 | res = self.client.remove_subports(trunk['trunk']['id'], |
| 113 | [removed_subport]) |
| 114 | self.assertEqual(1, len(res['sub_ports'])) |
| 115 | self.assertEqual(expected_subport, res['sub_ports'][0]) |
| 116 | |
| 117 | # Validate the results of a subport list |
| 118 | trunk = self.client.show_trunk(trunk['trunk']['id']) |
| 119 | observed_subports = trunk['trunk']['sub_ports'] |
| 120 | self.assertEqual(1, len(observed_subports)) |
| 121 | self.assertEqual(expected_subport, observed_subports[0]) |
| 122 | |
| 123 | @test.idempotent_id('bb5fcaad-09b5-484a-dde6-4cd1ea6d6ff0') |
| 124 | def test_get_subports(self): |
| 125 | network = self.create_network() |
| 126 | port = self.create_port(network) |
| 127 | subports = [{'port_id': port['id'], |
| 128 | 'segmentation_type': 'vlan', |
| 129 | 'segmentation_id': 2}] |
| 130 | trunk = self._create_trunk_with_network_and_parent(subports) |
| 131 | trunk = self.client.get_subports(trunk['trunk']['id']) |
| 132 | observed_subports = trunk['sub_ports'] |
| 133 | self.assertEqual(1, len(observed_subports)) |