blob: f7568c59496a7e78620c9f19bf9a56847ec2aaef [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']])
Kevin Bentona305d592016-09-19 04:26:10 -070062 trunk = self.client.create_trunk(port['id'], subports=[])['trunk']
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 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
65 return {'port': port, 'trunk': trunk, 'fip': fip,
66 'server': server}
67
Jakub Libosvar6d397d32016-12-30 10:57:52 -050068 def _create_server_with_fip(self, port_id, **server_kwargs):
69 fip = self.create_and_associate_floatingip(port_id)
70 return (
71 self.create_server(
72 flavor_ref=CONF.compute.flavor_ref,
73 image_ref=CONF.compute.image_ref,
74 key_name=self.keypair['name'],
75 networks=[{'port': port_id}],
76 security_groups=[{'name': self.secgroup[
77 'security_group']['name']}],
78 **server_kwargs)['server'],
79 fip)
80
Kevin Bentona305d592016-09-19 04:26:10 -070081 def _detach_and_delete_trunk(self, server, trunk):
82 # we have to detach the interface from the server before
83 # the trunk can be deleted.
Brian Haleyf86ac2e2017-06-21 10:43:50 -040084 self.os_primary.compute.InterfacesClient().delete_interface(
Kevin Bentona305d592016-09-19 04:26:10 -070085 server['id'], trunk['port_id'])
86
87 def is_port_detached():
88 p = self.client.show_port(trunk['port_id'])['port']
89 return p['device_id'] == ''
90 utils.wait_until_true(is_port_detached)
91 self.client.delete_trunk(trunk['id'])
92
93 def _is_port_down(self, port_id):
94 p = self.client.show_port(port_id)['port']
95 return p['status'] == 'DOWN'
96
97 def _is_port_active(self, port_id):
98 p = self.client.show_port(port_id)['port']
99 return p['status'] == 'ACTIVE'
100
101 def _is_trunk_active(self, trunk_id):
102 t = self.client.show_trunk(trunk_id)['trunk']
103 return t['status'] == 'ACTIVE'
104
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500105 def _create_server_with_port_and_subport(self, vlan_network, vlan_tag):
106 parent_port = self.create_port(self.network, security_groups=[
107 self.secgroup['security_group']['id']])
108 port_for_subport = self.create_port(
109 vlan_network,
110 security_groups=[self.secgroup['security_group']['id']],
111 mac_address=parent_port['mac_address'])
112 subport = {
113 'port_id': port_for_subport['id'],
114 'segmentation_type': 'vlan',
115 'segmentation_id': vlan_tag}
116 trunk = self.client.create_trunk(
117 parent_port['id'], subports=[subport])['trunk']
118
119 server, fip = self._create_server_with_fip(parent_port['id'])
120 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
121
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800122 server_ssh_client = ssh.Client(
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500123 fip['floating_ip_address'],
124 CONF.validation.image_ssh_user,
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800125 pkey=self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500126
127 return {
128 'server': server,
129 'fip': fip,
130 'ssh_client': server_ssh_client,
131 'subport': port_for_subport,
132 }
133
134 def _wait_for_server(self, server):
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'],
139 CONF.validation.image_ssh_user,
140 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(
223 CONF.neutron_plugin_options.image_is_advanced,
224 "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 = [
233 self._create_server_with_port_and_subport(vlan_network, vlan_tag)
234 for i in range(2)]
235
236 for server in servers:
237 self._wait_for_server(server)
238 # Configure VLAN interfaces on server
239 command = CONFIGURE_VLAN_INTERFACE_COMMANDS % {'tag': vlan_tag}
240 server['ssh_client'].exec_command(command)
AlexSTafeyev0aa817c2017-05-08 10:57:37 +0000241 out = server['ssh_client'].exec_command(
242 'PATH=$PATH:/usr/sbin;ip addr list')
Kevin Benton07c90562017-02-27 01:53:16 -0800243 LOG.debug("Interfaces on server %s: %s", server, out)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500244
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800245 # Ping from server1 to server2 via VLAN interface should fail because
246 # we haven't allowed ICMP
247 self.check_remote_connectivity(
248 servers[0]['ssh_client'],
249 servers[1]['subport']['fixed_ips'][0]['ip_address'],
250 should_succeed=False
251 )
252 # allow intra-securitygroup traffic
253 self.client.create_security_group_rule(
254 security_group_id=self.secgroup['security_group']['id'],
255 direction='ingress', ethertype='IPv4', protocol='icmp',
256 remote_group_id=self.secgroup['security_group']['id'])
257 self.check_remote_connectivity(
258 servers[0]['ssh_client'],
259 servers[1]['subport']['fixed_ips'][0]['ip_address'],
260 should_succeed=True
261 )