blob: 9a92b38825309bfd5d4f29e504e60e7533c16c47 [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
Jakub Libosvar6d397d32016-12-30 10:57:52 -050067 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 Bentona305d592016-09-19 04:26:10 -070080 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 Libosvar6d397d32016-12-30 10:57:52 -050092 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 Ressic9f5ec52018-07-05 13:10:42 +0200103 self.create_trunk(parent_port, [subport])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500104
105 server, fip = self._create_server_with_fip(parent_port['id'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500106
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800107 server_ssh_client = ssh.Client(
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500108 fip['floating_ip_address'],
109 CONF.validation.image_ssh_user,
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800110 pkey=self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500111
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 Haleyf86ac2e2017-06-21 10:43:50 -0400120 waiters.wait_for_server_status(self.os_primary.servers_client,
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500121 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ńskic0caa2e2017-02-25 10:11:32 +0000127 @decorators.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e')
Kevin Bentona305d592016-09-19 04:26:10 -0700128 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 Libosvar6d397d32016-12-30 10:57:52 -0500143 self._wait_for_server(server)
Kevin Bentona305d592016-09-19 04:26:10 -0700144 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 Rachmanifed6f862017-12-19 11:55:25 +0200155 # 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 Bentona305d592016-09-19 04:26:10 -0700158 subports = [{'port_id': self.create_port(self.create_network())['id'],
159 'segmentation_type': 'vlan', 'segmentation_id': seg_id}
Yariv Rachmanifed6f862017-12-19 11:55:25 +0200160 for seg_id in allowed_vlans]
Kevin Bentona305d592016-09-19 04:26:10 -0700161 # 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 Libosvar6d397d32016-12-30 10:57:52 -0500206
Genadi Chereshnyae91b69c2017-07-16 09:51:58 +0300207 @testtools.skipUnless(
208 CONF.neutron_plugin_options.image_is_advanced,
209 "Advanced image is required to run this test.")
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000210 @decorators.idempotent_id('a8a02c9b-b453-49b5-89a2-cce7da66aafb')
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500211 def test_subport_connectivity(self):
212 vlan_tag = 10
213
214 vlan_network = self.create_network()
Sławek Kapłońskid98e27d2018-05-07 16:16:28 +0200215 self.create_subnet(vlan_network, gateway=None)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500216
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)
AlexSTafeyev0aa817c2017-05-08 10:57:37 +0000226 out = server['ssh_client'].exec_command(
227 'PATH=$PATH:/usr/sbin;ip addr list')
Kevin Benton07c90562017-02-27 01:53:16 -0800228 LOG.debug("Interfaces on server %s: %s", server, out)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500229
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800230 # 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 )