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