blob: 77a2844af2da4acef7919e237dbae64106b7055b [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 = (
AlexSTafeyev200b7672017-03-28 12:07:59 +030032 'IFACE=$(PATH=$PATH:/usr/sbin ip l | grep "^[0-9]*: e" |'
33 'cut -d \: -f 2) && '
Jakub Libosvar6d397d32016-12-30 10:57:52 -050034 'sudo su -c '
AlexSTafeyev200b7672017-03-28 12:07:59 +030035 '"ip l a link $IFACE name $IFACE.%(tag)d type vlan id %(tag)d &&'
Jakub Libosvar6d397d32016-12-30 10:57:52 -050036 'ip l s up dev $IFACE.%(tag)d && '
37 'dhclient $IFACE.%(tag)d"')
38
39
Kevin Bentona305d592016-09-19 04:26:10 -070040class TrunkTest(base.BaseTempestTestCase):
41 credentials = ['primary']
42 force_tenant_isolation = False
43
44 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053045 @tutils.requires_ext(extension="trunk", service="network")
Kevin Bentona305d592016-09-19 04:26:10 -070046 def resource_setup(cls):
47 super(TrunkTest, cls).resource_setup()
48 # setup basic topology for servers we can log into
49 cls.network = cls.create_network()
50 cls.subnet = cls.create_subnet(cls.network)
Genadi Chereshnyac0411e92016-07-11 16:59:42 +030051 router = cls.create_router_by_client()
52 cls.create_router_interface(router['id'], cls.subnet['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070053 cls.keypair = cls.create_keypair()
rajat294495c042017-06-28 15:37:16 +053054 cls.secgroup = cls.os_primary.network_client.create_security_group(
Chandan Kumarc125fd12017-11-15 19:41:01 +053055 name=data_utils.rand_name('secgroup'))
Itzik Brownbac51dc2016-10-31 12:25:04 +000056 cls.security_groups.append(cls.secgroup['security_group'])
57 cls.create_loginable_secgroup_rule(
58 secgroup_id=cls.secgroup['security_group']['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070059
60 def _create_server_with_trunk_port(self):
Itzik Brownbac51dc2016-10-31 12:25:04 +000061 port = self.create_port(self.network, security_groups=[
62 self.secgroup['security_group']['id']])
Kevin Bentona305d592016-09-19 04:26:10 -070063 trunk = self.client.create_trunk(port['id'], subports=[])['trunk']
Jakub Libosvar6d397d32016-12-30 10:57:52 -050064 server, fip = self._create_server_with_fip(port['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070065 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
66 return {'port': port, 'trunk': trunk, 'fip': fip,
67 'server': server}
68
Jakub Libosvar6d397d32016-12-30 10:57:52 -050069 def _create_server_with_fip(self, port_id, **server_kwargs):
70 fip = self.create_and_associate_floatingip(port_id)
71 return (
72 self.create_server(
73 flavor_ref=CONF.compute.flavor_ref,
74 image_ref=CONF.compute.image_ref,
75 key_name=self.keypair['name'],
76 networks=[{'port': port_id}],
77 security_groups=[{'name': self.secgroup[
78 'security_group']['name']}],
79 **server_kwargs)['server'],
80 fip)
81
Kevin Bentona305d592016-09-19 04:26:10 -070082 def _detach_and_delete_trunk(self, server, trunk):
83 # we have to detach the interface from the server before
84 # the trunk can be deleted.
Brian Haleyf86ac2e2017-06-21 10:43:50 -040085 self.os_primary.compute.InterfacesClient().delete_interface(
Kevin Bentona305d592016-09-19 04:26:10 -070086 server['id'], trunk['port_id'])
87
88 def is_port_detached():
89 p = self.client.show_port(trunk['port_id'])['port']
90 return p['device_id'] == ''
91 utils.wait_until_true(is_port_detached)
92 self.client.delete_trunk(trunk['id'])
93
94 def _is_port_down(self, port_id):
95 p = self.client.show_port(port_id)['port']
96 return p['status'] == 'DOWN'
97
98 def _is_port_active(self, port_id):
99 p = self.client.show_port(port_id)['port']
100 return p['status'] == 'ACTIVE'
101
102 def _is_trunk_active(self, trunk_id):
103 t = self.client.show_trunk(trunk_id)['trunk']
104 return t['status'] == 'ACTIVE'
105
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500106 def _create_server_with_port_and_subport(self, vlan_network, vlan_tag):
107 parent_port = self.create_port(self.network, security_groups=[
108 self.secgroup['security_group']['id']])
109 port_for_subport = self.create_port(
110 vlan_network,
111 security_groups=[self.secgroup['security_group']['id']],
112 mac_address=parent_port['mac_address'])
113 subport = {
114 'port_id': port_for_subport['id'],
115 'segmentation_type': 'vlan',
116 'segmentation_id': vlan_tag}
117 trunk = self.client.create_trunk(
118 parent_port['id'], subports=[subport])['trunk']
119
120 server, fip = self._create_server_with_fip(parent_port['id'])
121 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
122
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800123 server_ssh_client = ssh.Client(
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500124 fip['floating_ip_address'],
125 CONF.validation.image_ssh_user,
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800126 pkey=self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500127
128 return {
129 'server': server,
130 'fip': fip,
131 'ssh_client': server_ssh_client,
132 'subport': port_for_subport,
133 }
134
135 def _wait_for_server(self, server):
Brian Haleyf86ac2e2017-06-21 10:43:50 -0400136 waiters.wait_for_server_status(self.os_primary.servers_client,
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500137 server['server']['id'],
138 constants.SERVER_STATUS_ACTIVE)
139 self.check_connectivity(server['fip']['floating_ip_address'],
140 CONF.validation.image_ssh_user,
141 self.keypair['private_key'])
142
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000143 @decorators.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e')
Kevin Bentona305d592016-09-19 04:26:10 -0700144 def test_trunk_subport_lifecycle(self):
145 """Test trunk creation and subport transition to ACTIVE status.
146
147 This is a basic test for the trunk extension to ensure that we
148 can create a trunk, attach it to a server, add/remove subports,
149 while ensuring the status transitions as appropriate.
150
151 This test does not assert any dataplane behavior for the subports.
152 It's just a high-level check to ensure the agents claim to have
153 wired the port correctly and that the trunk port itself maintains
154 connectivity.
155 """
156 server1 = self._create_server_with_trunk_port()
157 server2 = self._create_server_with_trunk_port()
158 for server in (server1, server2):
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500159 self._wait_for_server(server)
Kevin Bentona305d592016-09-19 04:26:10 -0700160 trunk1_id, trunk2_id = server1['trunk']['id'], server2['trunk']['id']
161 # trunks should transition to ACTIVE without any subports
162 utils.wait_until_true(
163 lambda: self._is_trunk_active(trunk1_id),
164 exception=RuntimeError("Timed out waiting for trunk %s to "
165 "transition to ACTIVE." % trunk1_id))
166 utils.wait_until_true(
167 lambda: self._is_trunk_active(trunk2_id),
168 exception=RuntimeError("Timed out waiting for trunk %s to "
169 "transition to ACTIVE." % trunk2_id))
170 # create a few more networks and ports for subports
Yariv Rachmanifed6f862017-12-19 11:55:25 +0200171 # check limit of networks per project
172 max_vlan = 3 + CONF.neutron_plugin_options.max_networks_per_project
173 allowed_vlans = range(3, max_vlan)
Kevin Bentona305d592016-09-19 04:26:10 -0700174 subports = [{'port_id': self.create_port(self.create_network())['id'],
175 'segmentation_type': 'vlan', 'segmentation_id': seg_id}
Yariv Rachmanifed6f862017-12-19 11:55:25 +0200176 for seg_id in allowed_vlans]
Kevin Bentona305d592016-09-19 04:26:10 -0700177 # add all subports to server1
178 self.client.add_subports(trunk1_id, subports)
179 # ensure trunk transitions to ACTIVE
180 utils.wait_until_true(
181 lambda: self._is_trunk_active(trunk1_id),
182 exception=RuntimeError("Timed out waiting for trunk %s to "
183 "transition to ACTIVE." % trunk1_id))
184 # ensure all underlying subports transitioned to ACTIVE
185 for s in subports:
186 utils.wait_until_true(lambda: self._is_port_active(s['port_id']))
187 # ensure main dataplane wasn't interrupted
188 self.check_connectivity(server1['fip']['floating_ip_address'],
189 CONF.validation.image_ssh_user,
190 self.keypair['private_key'])
191 # move subports over to other server
192 self.client.remove_subports(trunk1_id, subports)
193 # ensure all subports go down
194 for s in subports:
195 utils.wait_until_true(
196 lambda: self._is_port_down(s['port_id']),
197 exception=RuntimeError("Timed out waiting for subport %s to "
198 "transition to DOWN." % s['port_id']))
199 self.client.add_subports(trunk2_id, subports)
200 # wait for both trunks to go back to ACTIVE
201 utils.wait_until_true(
202 lambda: self._is_trunk_active(trunk1_id),
203 exception=RuntimeError("Timed out waiting for trunk %s to "
204 "transition to ACTIVE." % trunk1_id))
205 utils.wait_until_true(
206 lambda: self._is_trunk_active(trunk2_id),
207 exception=RuntimeError("Timed out waiting for trunk %s to "
208 "transition to ACTIVE." % trunk2_id))
209 # ensure subports come up on other trunk
210 for s in subports:
211 utils.wait_until_true(
212 lambda: self._is_port_active(s['port_id']),
213 exception=RuntimeError("Timed out waiting for subport %s to "
214 "transition to ACTIVE." % s['port_id']))
215 # final connectivity check
216 self.check_connectivity(server1['fip']['floating_ip_address'],
217 CONF.validation.image_ssh_user,
218 self.keypair['private_key'])
219 self.check_connectivity(server2['fip']['floating_ip_address'],
220 CONF.validation.image_ssh_user,
221 self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500222
Genadi Chereshnyae91b69c2017-07-16 09:51:58 +0300223 @testtools.skipUnless(
224 CONF.neutron_plugin_options.image_is_advanced,
225 "Advanced image is required to run this test.")
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000226 @decorators.idempotent_id('a8a02c9b-b453-49b5-89a2-cce7da66aafb')
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500227 def test_subport_connectivity(self):
228 vlan_tag = 10
229
230 vlan_network = self.create_network()
Federico Ressi0ddc93b2018-04-09 12:01:48 +0200231 self.create_subnet(vlan_network)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500232
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)
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 )