blob: 1903180a4cf225bee1df26ce8aee9c22728dad7c [file] [log] [blame]
Kevin Bentona305d592016-09-19 04:26:10 -07001# 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 Benton07c90562017-02-27 01:53:16 -080015from oslo_log import log as logging
Chandan Kumarc125fd12017-11-15 19:41:01 +053016from tempest.common import utils as tutils
Kevin Bentona305d592016-09-19 04:26:10 -070017from tempest.common import waiters
Itzik Brownbac51dc2016-10-31 12:25:04 +000018from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000019from tempest.lib import decorators
Genadi Chereshnyae91b69c2017-07-16 09:51:58 +030020import testtools
Kevin Bentona305d592016-09-19 04:26:10 -070021
Chandan Kumar667d3d32017-09-22 12:24:06 +053022from neutron_tempest_plugin.common import ssh
23from neutron_tempest_plugin.common import utils
24from neutron_tempest_plugin import config
25from neutron_tempest_plugin.scenario import base
26from neutron_tempest_plugin.scenario import constants
Kevin Bentona305d592016-09-19 04:26:10 -070027
Kevin Benton07c90562017-02-27 01:53:16 -080028LOG = logging.getLogger(__name__)
Kevin Bentona305d592016-09-19 04:26:10 -070029CONF = config.CONF
Kevin Bentona305d592016-09-19 04:26:10 -070030
Jakub Libosvar6d397d32016-12-30 10:57:52 -050031CONFIGURE_VLAN_INTERFACE_COMMANDS = (
Slawek Kaplonski6bf840f2018-09-12 02:01:31 +020032 '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 Libosvar6d397d32016-12-30 10:57:52 -050037
38
Kevin Bentona305d592016-09-19 04:26:10 -070039class TrunkTest(base.BaseTempestTestCase):
40 credentials = ['primary']
41 force_tenant_isolation = False
42
43 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053044 @tutils.requires_ext(extension="trunk", service="network")
Kevin Bentona305d592016-09-19 04:26:10 -070045 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 Chereshnyac0411e92016-07-11 16:59:42 +030050 router = cls.create_router_by_client()
51 cls.create_router_interface(router['id'], cls.subnet['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070052 cls.keypair = cls.create_keypair()
rajat294495c042017-06-28 15:37:16 +053053 cls.secgroup = cls.os_primary.network_client.create_security_group(
Chandan Kumarc125fd12017-11-15 19:41:01 +053054 name=data_utils.rand_name('secgroup'))
Itzik Brownbac51dc2016-10-31 12:25:04 +000055 cls.security_groups.append(cls.secgroup['security_group'])
56 cls.create_loginable_secgroup_rule(
57 secgroup_id=cls.secgroup['security_group']['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070058
59 def _create_server_with_trunk_port(self):
Itzik Brownbac51dc2016-10-31 12:25:04 +000060 port = self.create_port(self.network, security_groups=[
61 self.secgroup['security_group']['id']])
Federico Ressic9f5ec52018-07-05 13:10:42 +020062 trunk = self.create_trunk(port)
Jakub Libosvar6d397d32016-12-30 10:57:52 -050063 server, fip = self._create_server_with_fip(port['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070064 return {'port': port, 'trunk': trunk, 'fip': fip,
65 'server': server}
66
Slawek Kaplonskida17f002018-10-11 18:35:23 +020067 def _create_server_with_fip(self, port_id, use_advanced_image=False,
68 **server_kwargs):
Federico Ressi3dfa94c2018-07-06 09:46:39 +020069 fip = self.create_floatingip(port_id=port_id)
Slawek Kaplonskida17f002018-10-11 18:35:23 +020070 flavor_ref = CONF.compute.flavor_ref
71 image_ref = CONF.compute.image_ref
72 if use_advanced_image:
73 flavor_ref = CONF.neutron_plugin_options.advanced_image_flavor_ref
74 image_ref = CONF.neutron_plugin_options.advanced_image_ref
Jakub Libosvar6d397d32016-12-30 10:57:52 -050075 return (
76 self.create_server(
Slawek Kaplonskida17f002018-10-11 18:35:23 +020077 flavor_ref=flavor_ref,
78 image_ref=image_ref,
Jakub Libosvar6d397d32016-12-30 10:57:52 -050079 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 Bentona305d592016-09-19 04:26:10 -070086 def _is_port_down(self, port_id):
87 p = self.client.show_port(port_id)['port']
88 return p['status'] == 'DOWN'
89
90 def _is_port_active(self, port_id):
91 p = self.client.show_port(port_id)['port']
92 return p['status'] == 'ACTIVE'
93
94 def _is_trunk_active(self, trunk_id):
95 t = self.client.show_trunk(trunk_id)['trunk']
96 return t['status'] == 'ACTIVE'
97
Slawek Kaplonskida17f002018-10-11 18:35:23 +020098 def _create_server_with_port_and_subport(self, vlan_network, vlan_tag,
99 use_advanced_image=False):
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500100 parent_port = self.create_port(self.network, security_groups=[
101 self.secgroup['security_group']['id']])
102 port_for_subport = self.create_port(
103 vlan_network,
104 security_groups=[self.secgroup['security_group']['id']],
105 mac_address=parent_port['mac_address'])
106 subport = {
107 'port_id': port_for_subport['id'],
108 'segmentation_type': 'vlan',
109 'segmentation_id': vlan_tag}
Federico Ressic9f5ec52018-07-05 13:10:42 +0200110 self.create_trunk(parent_port, [subport])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500111
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200112 server, fip = self._create_server_with_fip(
113 parent_port['id'], use_advanced_image=use_advanced_image)
114
115 ssh_user = CONF.validation.image_ssh_user
116 if use_advanced_image:
117 ssh_user = CONF.neutron_plugin_options.advanced_image_ssh_user
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500118
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800119 server_ssh_client = ssh.Client(
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500120 fip['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200121 ssh_user,
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800122 pkey=self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500123
124 return {
125 'server': server,
126 'fip': fip,
127 'ssh_client': server_ssh_client,
128 'subport': port_for_subport,
129 }
130
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200131 def _wait_for_server(self, server, advanced_image=False):
132 ssh_user = CONF.validation.image_ssh_user
133 if advanced_image:
134 ssh_user = CONF.neutron_plugin_options.advanced_image_ssh_user
Brian Haleyf86ac2e2017-06-21 10:43:50 -0400135 waiters.wait_for_server_status(self.os_primary.servers_client,
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500136 server['server']['id'],
137 constants.SERVER_STATUS_ACTIVE)
138 self.check_connectivity(server['fip']['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200139 ssh_user,
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500140 self.keypair['private_key'])
141
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000142 @decorators.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e')
Kevin Bentona305d592016-09-19 04:26:10 -0700143 def test_trunk_subport_lifecycle(self):
144 """Test trunk creation and subport transition to ACTIVE status.
145
146 This is a basic test for the trunk extension to ensure that we
147 can create a trunk, attach it to a server, add/remove subports,
148 while ensuring the status transitions as appropriate.
149
150 This test does not assert any dataplane behavior for the subports.
151 It's just a high-level check to ensure the agents claim to have
152 wired the port correctly and that the trunk port itself maintains
153 connectivity.
154 """
155 server1 = self._create_server_with_trunk_port()
156 server2 = self._create_server_with_trunk_port()
157 for server in (server1, server2):
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500158 self._wait_for_server(server)
Kevin Bentona305d592016-09-19 04:26:10 -0700159 trunk1_id, trunk2_id = server1['trunk']['id'], server2['trunk']['id']
160 # trunks should transition to ACTIVE without any subports
161 utils.wait_until_true(
162 lambda: self._is_trunk_active(trunk1_id),
163 exception=RuntimeError("Timed out waiting for trunk %s to "
164 "transition to ACTIVE." % trunk1_id))
165 utils.wait_until_true(
166 lambda: self._is_trunk_active(trunk2_id),
167 exception=RuntimeError("Timed out waiting for trunk %s to "
168 "transition to ACTIVE." % trunk2_id))
169 # create a few more networks and ports for subports
Yariv Rachmanifed6f862017-12-19 11:55:25 +0200170 # check limit of networks per project
171 max_vlan = 3 + CONF.neutron_plugin_options.max_networks_per_project
172 allowed_vlans = range(3, max_vlan)
Kevin Bentona305d592016-09-19 04:26:10 -0700173 subports = [{'port_id': self.create_port(self.create_network())['id'],
174 'segmentation_type': 'vlan', 'segmentation_id': seg_id}
Yariv Rachmanifed6f862017-12-19 11:55:25 +0200175 for seg_id in allowed_vlans]
Kevin Bentona305d592016-09-19 04:26:10 -0700176 # add all subports to server1
177 self.client.add_subports(trunk1_id, subports)
178 # ensure trunk transitions to ACTIVE
179 utils.wait_until_true(
180 lambda: self._is_trunk_active(trunk1_id),
181 exception=RuntimeError("Timed out waiting for trunk %s to "
182 "transition to ACTIVE." % trunk1_id))
183 # ensure all underlying subports transitioned to ACTIVE
184 for s in subports:
185 utils.wait_until_true(lambda: self._is_port_active(s['port_id']))
186 # ensure main dataplane wasn't interrupted
187 self.check_connectivity(server1['fip']['floating_ip_address'],
188 CONF.validation.image_ssh_user,
189 self.keypair['private_key'])
190 # move subports over to other server
191 self.client.remove_subports(trunk1_id, subports)
192 # ensure all subports go down
193 for s in subports:
194 utils.wait_until_true(
195 lambda: self._is_port_down(s['port_id']),
196 exception=RuntimeError("Timed out waiting for subport %s to "
197 "transition to DOWN." % s['port_id']))
198 self.client.add_subports(trunk2_id, subports)
199 # wait for both trunks to go back to ACTIVE
200 utils.wait_until_true(
201 lambda: self._is_trunk_active(trunk1_id),
202 exception=RuntimeError("Timed out waiting for trunk %s to "
203 "transition to ACTIVE." % trunk1_id))
204 utils.wait_until_true(
205 lambda: self._is_trunk_active(trunk2_id),
206 exception=RuntimeError("Timed out waiting for trunk %s to "
207 "transition to ACTIVE." % trunk2_id))
208 # ensure subports come up on other trunk
209 for s in subports:
210 utils.wait_until_true(
211 lambda: self._is_port_active(s['port_id']),
212 exception=RuntimeError("Timed out waiting for subport %s to "
213 "transition to ACTIVE." % s['port_id']))
214 # final connectivity check
215 self.check_connectivity(server1['fip']['floating_ip_address'],
216 CONF.validation.image_ssh_user,
217 self.keypair['private_key'])
218 self.check_connectivity(server2['fip']['floating_ip_address'],
219 CONF.validation.image_ssh_user,
220 self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500221
Genadi Chereshnyae91b69c2017-07-16 09:51:58 +0300222 @testtools.skipUnless(
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200223 CONF.neutron_plugin_options.advanced_image_ref,
Genadi Chereshnyae91b69c2017-07-16 09:51:58 +0300224 "Advanced image is required to run this test.")
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000225 @decorators.idempotent_id('a8a02c9b-b453-49b5-89a2-cce7da66aafb')
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500226 def test_subport_connectivity(self):
227 vlan_tag = 10
228
229 vlan_network = self.create_network()
Sławek Kapłońskid98e27d2018-05-07 16:16:28 +0200230 self.create_subnet(vlan_network, gateway=None)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500231
232 servers = [
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200233 self._create_server_with_port_and_subport(
234 vlan_network, vlan_tag, use_advanced_image=True)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500235 for i in range(2)]
236
237 for server in servers:
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200238 self._wait_for_server(server, advanced_image=True)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500239 # Configure VLAN interfaces on server
240 command = CONFIGURE_VLAN_INTERFACE_COMMANDS % {'tag': vlan_tag}
241 server['ssh_client'].exec_command(command)
AlexSTafeyev0aa817c2017-05-08 10:57:37 +0000242 out = server['ssh_client'].exec_command(
243 'PATH=$PATH:/usr/sbin;ip addr list')
Kevin Benton07c90562017-02-27 01:53:16 -0800244 LOG.debug("Interfaces on server %s: %s", server, out)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500245
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800246 # 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 )