Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 1 | # All Rights Reserved. |
| 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 | |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 15 | import netaddr |
Kevin Benton | 07c9056 | 2017-02-27 01:53:16 -0800 | [diff] [blame] | 16 | from oslo_log import log as logging |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 17 | from tempest.common import waiters |
Itzik Brown | bac51dc | 2016-10-31 12:25:04 +0000 | [diff] [blame] | 18 | from tempest.lib.common.utils import data_utils |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 19 | from tempest.lib import decorators |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 20 | from tempest import test |
| 21 | |
| 22 | from neutron.common import utils |
Jakub Libosvar | 7c58cb2 | 2017-05-03 09:00:14 +0000 | [diff] [blame] | 23 | from neutron.tests.tempest.common import ssh |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 24 | from neutron.tests.tempest import config |
| 25 | from neutron.tests.tempest.scenario import base |
| 26 | from neutron.tests.tempest.scenario import constants |
| 27 | |
Kevin Benton | 07c9056 | 2017-02-27 01:53:16 -0800 | [diff] [blame] | 28 | LOG = logging.getLogger(__name__) |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 29 | CONF = config.CONF |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 30 | |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 31 | CONFIGURE_VLAN_INTERFACE_COMMANDS = ( |
AlexSTafeyev | 200b767 | 2017-03-28 12:07:59 +0300 | [diff] [blame] | 32 | 'IFACE=$(PATH=$PATH:/usr/sbin ip l | grep "^[0-9]*: e" |' |
| 33 | 'cut -d \: -f 2) && ' |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 34 | 'sudo su -c ' |
AlexSTafeyev | 200b767 | 2017-03-28 12:07:59 +0300 | [diff] [blame] | 35 | '"ip l a link $IFACE name $IFACE.%(tag)d type vlan id %(tag)d &&' |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 36 | 'ip l s up dev $IFACE.%(tag)d && ' |
| 37 | 'dhclient $IFACE.%(tag)d"') |
| 38 | |
| 39 | |
| 40 | def get_next_subnet(cidr): |
| 41 | return netaddr.IPNetwork(cidr).next() |
| 42 | |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 43 | |
| 44 | class TrunkTest(base.BaseTempestTestCase): |
| 45 | credentials = ['primary'] |
| 46 | force_tenant_isolation = False |
| 47 | |
| 48 | @classmethod |
| 49 | @test.requires_ext(extension="trunk", service="network") |
| 50 | def resource_setup(cls): |
| 51 | super(TrunkTest, cls).resource_setup() |
| 52 | # setup basic topology for servers we can log into |
| 53 | cls.network = cls.create_network() |
| 54 | cls.subnet = cls.create_subnet(cls.network) |
Genadi Chereshnya | c0411e9 | 2016-07-11 16:59:42 +0300 | [diff] [blame] | 55 | router = cls.create_router_by_client() |
| 56 | cls.create_router_interface(router['id'], cls.subnet['id']) |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 57 | cls.keypair = cls.create_keypair() |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame^] | 58 | cls.secgroup = cls.os_primary.network_client.create_security_group( |
Itzik Brown | bac51dc | 2016-10-31 12:25:04 +0000 | [diff] [blame] | 59 | name=data_utils.rand_name('secgroup-')) |
| 60 | cls.security_groups.append(cls.secgroup['security_group']) |
| 61 | cls.create_loginable_secgroup_rule( |
| 62 | secgroup_id=cls.secgroup['security_group']['id']) |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 63 | |
| 64 | def _create_server_with_trunk_port(self): |
Itzik Brown | bac51dc | 2016-10-31 12:25:04 +0000 | [diff] [blame] | 65 | port = self.create_port(self.network, security_groups=[ |
| 66 | self.secgroup['security_group']['id']]) |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 67 | trunk = self.client.create_trunk(port['id'], subports=[])['trunk'] |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 68 | server, fip = self._create_server_with_fip(port['id']) |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 69 | self.addCleanup(self._detach_and_delete_trunk, server, trunk) |
| 70 | return {'port': port, 'trunk': trunk, 'fip': fip, |
| 71 | 'server': server} |
| 72 | |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 73 | def _create_server_with_fip(self, port_id, **server_kwargs): |
| 74 | fip = self.create_and_associate_floatingip(port_id) |
| 75 | return ( |
| 76 | self.create_server( |
| 77 | flavor_ref=CONF.compute.flavor_ref, |
| 78 | image_ref=CONF.compute.image_ref, |
| 79 | key_name=self.keypair['name'], |
| 80 | networks=[{'port': port_id}], |
| 81 | security_groups=[{'name': self.secgroup[ |
| 82 | 'security_group']['name']}], |
| 83 | **server_kwargs)['server'], |
| 84 | fip) |
| 85 | |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 86 | def _detach_and_delete_trunk(self, server, trunk): |
| 87 | # we have to detach the interface from the server before |
| 88 | # the trunk can be deleted. |
Brian Haley | f86ac2e | 2017-06-21 10:43:50 -0400 | [diff] [blame] | 89 | self.os_primary.compute.InterfacesClient().delete_interface( |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 90 | server['id'], trunk['port_id']) |
| 91 | |
| 92 | def is_port_detached(): |
| 93 | p = self.client.show_port(trunk['port_id'])['port'] |
| 94 | return p['device_id'] == '' |
| 95 | utils.wait_until_true(is_port_detached) |
| 96 | self.client.delete_trunk(trunk['id']) |
| 97 | |
| 98 | def _is_port_down(self, port_id): |
| 99 | p = self.client.show_port(port_id)['port'] |
| 100 | return p['status'] == 'DOWN' |
| 101 | |
| 102 | def _is_port_active(self, port_id): |
| 103 | p = self.client.show_port(port_id)['port'] |
| 104 | return p['status'] == 'ACTIVE' |
| 105 | |
| 106 | def _is_trunk_active(self, trunk_id): |
| 107 | t = self.client.show_trunk(trunk_id)['trunk'] |
| 108 | return t['status'] == 'ACTIVE' |
| 109 | |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 110 | def _create_server_with_port_and_subport(self, vlan_network, vlan_tag): |
| 111 | parent_port = self.create_port(self.network, security_groups=[ |
| 112 | self.secgroup['security_group']['id']]) |
| 113 | port_for_subport = self.create_port( |
| 114 | vlan_network, |
| 115 | security_groups=[self.secgroup['security_group']['id']], |
| 116 | mac_address=parent_port['mac_address']) |
| 117 | subport = { |
| 118 | 'port_id': port_for_subport['id'], |
| 119 | 'segmentation_type': 'vlan', |
| 120 | 'segmentation_id': vlan_tag} |
| 121 | trunk = self.client.create_trunk( |
| 122 | parent_port['id'], subports=[subport])['trunk'] |
| 123 | |
| 124 | server, fip = self._create_server_with_fip(parent_port['id']) |
| 125 | self.addCleanup(self._detach_and_delete_trunk, server, trunk) |
| 126 | |
Kevin Benton | 6f1f9d5 | 2017-03-01 09:14:45 -0800 | [diff] [blame] | 127 | server_ssh_client = ssh.Client( |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 128 | fip['floating_ip_address'], |
| 129 | CONF.validation.image_ssh_user, |
Kevin Benton | 6f1f9d5 | 2017-03-01 09:14:45 -0800 | [diff] [blame] | 130 | pkey=self.keypair['private_key']) |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 131 | |
| 132 | return { |
| 133 | 'server': server, |
| 134 | 'fip': fip, |
| 135 | 'ssh_client': server_ssh_client, |
| 136 | 'subport': port_for_subport, |
| 137 | } |
| 138 | |
| 139 | def _wait_for_server(self, server): |
Brian Haley | f86ac2e | 2017-06-21 10:43:50 -0400 | [diff] [blame] | 140 | waiters.wait_for_server_status(self.os_primary.servers_client, |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 141 | server['server']['id'], |
| 142 | constants.SERVER_STATUS_ACTIVE) |
| 143 | self.check_connectivity(server['fip']['floating_ip_address'], |
| 144 | CONF.validation.image_ssh_user, |
| 145 | self.keypair['private_key']) |
| 146 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 147 | @decorators.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e') |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 148 | def test_trunk_subport_lifecycle(self): |
| 149 | """Test trunk creation and subport transition to ACTIVE status. |
| 150 | |
| 151 | This is a basic test for the trunk extension to ensure that we |
| 152 | can create a trunk, attach it to a server, add/remove subports, |
| 153 | while ensuring the status transitions as appropriate. |
| 154 | |
| 155 | This test does not assert any dataplane behavior for the subports. |
| 156 | It's just a high-level check to ensure the agents claim to have |
| 157 | wired the port correctly and that the trunk port itself maintains |
| 158 | connectivity. |
| 159 | """ |
| 160 | server1 = self._create_server_with_trunk_port() |
| 161 | server2 = self._create_server_with_trunk_port() |
| 162 | for server in (server1, server2): |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 163 | self._wait_for_server(server) |
Kevin Benton | a305d59 | 2016-09-19 04:26:10 -0700 | [diff] [blame] | 164 | trunk1_id, trunk2_id = server1['trunk']['id'], server2['trunk']['id'] |
| 165 | # trunks should transition to ACTIVE without any subports |
| 166 | utils.wait_until_true( |
| 167 | lambda: self._is_trunk_active(trunk1_id), |
| 168 | exception=RuntimeError("Timed out waiting for trunk %s to " |
| 169 | "transition to ACTIVE." % trunk1_id)) |
| 170 | utils.wait_until_true( |
| 171 | lambda: self._is_trunk_active(trunk2_id), |
| 172 | exception=RuntimeError("Timed out waiting for trunk %s to " |
| 173 | "transition to ACTIVE." % trunk2_id)) |
| 174 | # create a few more networks and ports for subports |
| 175 | subports = [{'port_id': self.create_port(self.create_network())['id'], |
| 176 | 'segmentation_type': 'vlan', 'segmentation_id': seg_id} |
| 177 | for seg_id in range(3, 7)] |
| 178 | # add all subports to server1 |
| 179 | self.client.add_subports(trunk1_id, subports) |
| 180 | # ensure trunk transitions to ACTIVE |
| 181 | utils.wait_until_true( |
| 182 | lambda: self._is_trunk_active(trunk1_id), |
| 183 | exception=RuntimeError("Timed out waiting for trunk %s to " |
| 184 | "transition to ACTIVE." % trunk1_id)) |
| 185 | # ensure all underlying subports transitioned to ACTIVE |
| 186 | for s in subports: |
| 187 | utils.wait_until_true(lambda: self._is_port_active(s['port_id'])) |
| 188 | # ensure main dataplane wasn't interrupted |
| 189 | self.check_connectivity(server1['fip']['floating_ip_address'], |
| 190 | CONF.validation.image_ssh_user, |
| 191 | self.keypair['private_key']) |
| 192 | # move subports over to other server |
| 193 | self.client.remove_subports(trunk1_id, subports) |
| 194 | # ensure all subports go down |
| 195 | for s in subports: |
| 196 | utils.wait_until_true( |
| 197 | lambda: self._is_port_down(s['port_id']), |
| 198 | exception=RuntimeError("Timed out waiting for subport %s to " |
| 199 | "transition to DOWN." % s['port_id'])) |
| 200 | self.client.add_subports(trunk2_id, subports) |
| 201 | # wait for both trunks to go back to ACTIVE |
| 202 | utils.wait_until_true( |
| 203 | lambda: self._is_trunk_active(trunk1_id), |
| 204 | exception=RuntimeError("Timed out waiting for trunk %s to " |
| 205 | "transition to ACTIVE." % trunk1_id)) |
| 206 | utils.wait_until_true( |
| 207 | lambda: self._is_trunk_active(trunk2_id), |
| 208 | exception=RuntimeError("Timed out waiting for trunk %s to " |
| 209 | "transition to ACTIVE." % trunk2_id)) |
| 210 | # ensure subports come up on other trunk |
| 211 | for s in subports: |
| 212 | utils.wait_until_true( |
| 213 | lambda: self._is_port_active(s['port_id']), |
| 214 | exception=RuntimeError("Timed out waiting for subport %s to " |
| 215 | "transition to ACTIVE." % s['port_id'])) |
| 216 | # final connectivity check |
| 217 | self.check_connectivity(server1['fip']['floating_ip_address'], |
| 218 | CONF.validation.image_ssh_user, |
| 219 | self.keypair['private_key']) |
| 220 | self.check_connectivity(server2['fip']['floating_ip_address'], |
| 221 | CONF.validation.image_ssh_user, |
| 222 | self.keypair['private_key']) |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 223 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 224 | @decorators.idempotent_id('a8a02c9b-b453-49b5-89a2-cce7da66aafb') |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 225 | def test_subport_connectivity(self): |
| 226 | vlan_tag = 10 |
| 227 | |
| 228 | vlan_network = self.create_network() |
| 229 | new_subnet_cidr = get_next_subnet( |
| 230 | config.safe_get_config_value('network', 'project_network_cidr')) |
AlexSTafeyev | 5d70499 | 2017-04-23 10:59:12 +0000 | [diff] [blame] | 231 | self.create_subnet(vlan_network, gateway=None, cidr=new_subnet_cidr) |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 232 | |
| 233 | servers = [ |
| 234 | self._create_server_with_port_and_subport(vlan_network, vlan_tag) |
| 235 | for i in range(2)] |
| 236 | |
| 237 | for server in servers: |
| 238 | self._wait_for_server(server) |
| 239 | # Configure VLAN interfaces on server |
| 240 | command = CONFIGURE_VLAN_INTERFACE_COMMANDS % {'tag': vlan_tag} |
| 241 | server['ssh_client'].exec_command(command) |
AlexSTafeyev | 0aa817c | 2017-05-08 10:57:37 +0000 | [diff] [blame] | 242 | out = server['ssh_client'].exec_command( |
| 243 | 'PATH=$PATH:/usr/sbin;ip addr list') |
Kevin Benton | 07c9056 | 2017-02-27 01:53:16 -0800 | [diff] [blame] | 244 | LOG.debug("Interfaces on server %s: %s", server, out) |
Jakub Libosvar | 6d397d3 | 2016-12-30 10:57:52 -0500 | [diff] [blame] | 245 | |
Kevin Benton | 6f1f9d5 | 2017-03-01 09:14:45 -0800 | [diff] [blame] | 246 | # Ping from server1 to server2 via VLAN interface should fail because |
| 247 | # we haven't allowed ICMP |
| 248 | self.check_remote_connectivity( |
| 249 | servers[0]['ssh_client'], |
| 250 | servers[1]['subport']['fixed_ips'][0]['ip_address'], |
| 251 | should_succeed=False |
| 252 | ) |
| 253 | # allow intra-securitygroup traffic |
| 254 | self.client.create_security_group_rule( |
| 255 | security_group_id=self.secgroup['security_group']['id'], |
| 256 | direction='ingress', ethertype='IPv4', protocol='icmp', |
| 257 | remote_group_id=self.secgroup['security_group']['id']) |
| 258 | self.check_remote_connectivity( |
| 259 | servers[0]['ssh_client'], |
| 260 | servers[1]['subport']['fixed_ips'][0]['ip_address'], |
| 261 | should_succeed=True |
| 262 | ) |