blob: 85b16cb988abe24bbfe9e7f8c5b57214b3ef17d0 [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)
Huifeng Le1c9f40b2018-11-07 01:14:21 +080050 cls.router = cls.create_router_by_client()
51 cls.create_router_interface(cls.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
Huifeng Le1c9f40b2018-11-07 01:14:21 +080098 def _create_server_with_network(self, network, use_advanced_image=False):
99 port = self.create_port(network, security_groups=[
100 self.secgroup['security_group']['id']])
101 server, fip = self._create_server_with_fip(
102 port['id'], use_advanced_image=use_advanced_image)
103 ssh_user = CONF.validation.image_ssh_user
104 if use_advanced_image:
105 ssh_user = CONF.neutron_plugin_options.advanced_image_ssh_user
106
107 server_ssh_client = ssh.Client(
108 fip['floating_ip_address'],
109 ssh_user,
110 pkey=self.keypair['private_key'])
111
112 return {
113 'server': server,
114 'fip': fip,
115 'ssh_client': server_ssh_client,
116 'port': port,
117 }
118
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200119 def _create_server_with_port_and_subport(self, vlan_network, vlan_tag,
120 use_advanced_image=False):
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500121 parent_port = self.create_port(self.network, security_groups=[
122 self.secgroup['security_group']['id']])
123 port_for_subport = self.create_port(
124 vlan_network,
125 security_groups=[self.secgroup['security_group']['id']],
126 mac_address=parent_port['mac_address'])
127 subport = {
128 'port_id': port_for_subport['id'],
129 'segmentation_type': 'vlan',
130 'segmentation_id': vlan_tag}
Huifeng Le1c9f40b2018-11-07 01:14:21 +0800131 trunk = self.create_trunk(parent_port, [subport])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500132
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200133 server, fip = self._create_server_with_fip(
134 parent_port['id'], use_advanced_image=use_advanced_image)
135
136 ssh_user = CONF.validation.image_ssh_user
137 if use_advanced_image:
138 ssh_user = CONF.neutron_plugin_options.advanced_image_ssh_user
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500139
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800140 server_ssh_client = ssh.Client(
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500141 fip['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200142 ssh_user,
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800143 pkey=self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500144
145 return {
146 'server': server,
147 'fip': fip,
148 'ssh_client': server_ssh_client,
149 'subport': port_for_subport,
Huifeng Le1c9f40b2018-11-07 01:14:21 +0800150 'parentport': parent_port,
151 'trunk': trunk,
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500152 }
153
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200154 def _wait_for_server(self, server, advanced_image=False):
155 ssh_user = CONF.validation.image_ssh_user
156 if advanced_image:
157 ssh_user = CONF.neutron_plugin_options.advanced_image_ssh_user
Brian Haleyf86ac2e2017-06-21 10:43:50 -0400158 waiters.wait_for_server_status(self.os_primary.servers_client,
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500159 server['server']['id'],
160 constants.SERVER_STATUS_ACTIVE)
161 self.check_connectivity(server['fip']['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200162 ssh_user,
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500163 self.keypair['private_key'])
164
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000165 @decorators.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e')
Kevin Bentona305d592016-09-19 04:26:10 -0700166 def test_trunk_subport_lifecycle(self):
167 """Test trunk creation and subport transition to ACTIVE status.
168
169 This is a basic test for the trunk extension to ensure that we
170 can create a trunk, attach it to a server, add/remove subports,
171 while ensuring the status transitions as appropriate.
172
173 This test does not assert any dataplane behavior for the subports.
174 It's just a high-level check to ensure the agents claim to have
175 wired the port correctly and that the trunk port itself maintains
176 connectivity.
177 """
178 server1 = self._create_server_with_trunk_port()
179 server2 = self._create_server_with_trunk_port()
180 for server in (server1, server2):
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500181 self._wait_for_server(server)
Kevin Bentona305d592016-09-19 04:26:10 -0700182 trunk1_id, trunk2_id = server1['trunk']['id'], server2['trunk']['id']
183 # trunks should transition to ACTIVE without any subports
184 utils.wait_until_true(
185 lambda: self._is_trunk_active(trunk1_id),
186 exception=RuntimeError("Timed out waiting for trunk %s to "
187 "transition to ACTIVE." % trunk1_id))
188 utils.wait_until_true(
189 lambda: self._is_trunk_active(trunk2_id),
190 exception=RuntimeError("Timed out waiting for trunk %s to "
191 "transition to ACTIVE." % trunk2_id))
192 # create a few more networks and ports for subports
Yariv Rachmanifed6f862017-12-19 11:55:25 +0200193 # check limit of networks per project
194 max_vlan = 3 + CONF.neutron_plugin_options.max_networks_per_project
195 allowed_vlans = range(3, max_vlan)
Kevin Bentona305d592016-09-19 04:26:10 -0700196 subports = [{'port_id': self.create_port(self.create_network())['id'],
197 'segmentation_type': 'vlan', 'segmentation_id': seg_id}
Yariv Rachmanifed6f862017-12-19 11:55:25 +0200198 for seg_id in allowed_vlans]
Kevin Bentona305d592016-09-19 04:26:10 -0700199 # add all subports to server1
200 self.client.add_subports(trunk1_id, subports)
201 # ensure trunk transitions to ACTIVE
202 utils.wait_until_true(
203 lambda: self._is_trunk_active(trunk1_id),
204 exception=RuntimeError("Timed out waiting for trunk %s to "
205 "transition to ACTIVE." % trunk1_id))
206 # ensure all underlying subports transitioned to ACTIVE
207 for s in subports:
208 utils.wait_until_true(lambda: self._is_port_active(s['port_id']))
209 # ensure main dataplane wasn't interrupted
210 self.check_connectivity(server1['fip']['floating_ip_address'],
211 CONF.validation.image_ssh_user,
212 self.keypair['private_key'])
213 # move subports over to other server
214 self.client.remove_subports(trunk1_id, subports)
215 # ensure all subports go down
216 for s in subports:
217 utils.wait_until_true(
218 lambda: self._is_port_down(s['port_id']),
219 exception=RuntimeError("Timed out waiting for subport %s to "
220 "transition to DOWN." % s['port_id']))
221 self.client.add_subports(trunk2_id, subports)
222 # wait for both trunks to go back to ACTIVE
223 utils.wait_until_true(
224 lambda: self._is_trunk_active(trunk1_id),
225 exception=RuntimeError("Timed out waiting for trunk %s to "
226 "transition to ACTIVE." % trunk1_id))
227 utils.wait_until_true(
228 lambda: self._is_trunk_active(trunk2_id),
229 exception=RuntimeError("Timed out waiting for trunk %s to "
230 "transition to ACTIVE." % trunk2_id))
231 # ensure subports come up on other trunk
232 for s in subports:
233 utils.wait_until_true(
234 lambda: self._is_port_active(s['port_id']),
235 exception=RuntimeError("Timed out waiting for subport %s to "
236 "transition to ACTIVE." % s['port_id']))
237 # final connectivity check
238 self.check_connectivity(server1['fip']['floating_ip_address'],
239 CONF.validation.image_ssh_user,
240 self.keypair['private_key'])
241 self.check_connectivity(server2['fip']['floating_ip_address'],
242 CONF.validation.image_ssh_user,
243 self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500244
Genadi Chereshnyae91b69c2017-07-16 09:51:58 +0300245 @testtools.skipUnless(
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200246 CONF.neutron_plugin_options.advanced_image_ref,
Genadi Chereshnyae91b69c2017-07-16 09:51:58 +0300247 "Advanced image is required to run this test.")
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000248 @decorators.idempotent_id('a8a02c9b-b453-49b5-89a2-cce7da66aafb')
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500249 def test_subport_connectivity(self):
250 vlan_tag = 10
251
252 vlan_network = self.create_network()
Sławek Kapłońskid98e27d2018-05-07 16:16:28 +0200253 self.create_subnet(vlan_network, gateway=None)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500254
255 servers = [
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200256 self._create_server_with_port_and_subport(
257 vlan_network, vlan_tag, use_advanced_image=True)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500258 for i in range(2)]
259
260 for server in servers:
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200261 self._wait_for_server(server, advanced_image=True)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500262 # Configure VLAN interfaces on server
263 command = CONFIGURE_VLAN_INTERFACE_COMMANDS % {'tag': vlan_tag}
264 server['ssh_client'].exec_command(command)
AlexSTafeyev0aa817c2017-05-08 10:57:37 +0000265 out = server['ssh_client'].exec_command(
266 'PATH=$PATH:/usr/sbin;ip addr list')
Kevin Benton07c90562017-02-27 01:53:16 -0800267 LOG.debug("Interfaces on server %s: %s", server, out)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500268
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800269 # Ping from server1 to server2 via VLAN interface should fail because
270 # we haven't allowed ICMP
271 self.check_remote_connectivity(
272 servers[0]['ssh_client'],
273 servers[1]['subport']['fixed_ips'][0]['ip_address'],
274 should_succeed=False
275 )
276 # allow intra-securitygroup traffic
277 self.client.create_security_group_rule(
278 security_group_id=self.secgroup['security_group']['id'],
279 direction='ingress', ethertype='IPv4', protocol='icmp',
280 remote_group_id=self.secgroup['security_group']['id'])
281 self.check_remote_connectivity(
282 servers[0]['ssh_client'],
283 servers[1]['subport']['fixed_ips'][0]['ip_address'],
284 should_succeed=True
285 )
Huifeng Le1c9f40b2018-11-07 01:14:21 +0800286
287 @testtools.skipUnless(
288 CONF.neutron_plugin_options.advanced_image_ref,
289 "Advanced image is required to run this test.")
290 @testtools.skipUnless(
291 CONF.neutron_plugin_options.q_agent == "linuxbridge",
292 "Linux bridge agent is required to run this test.")
293 @decorators.idempotent_id('d61cbdf6-1896-491c-b4b4-871caf7fbffe')
294 def test_parent_port_connectivity_after_trunk_deleted_lb(self):
295 vlan_tag = 10
296
297 vlan_network = self.create_network()
298 vlan_subnet = self.create_subnet(vlan_network)
299 self.create_router_interface(self.router['id'], vlan_subnet['id'])
300
301 trunk_network_server = self._create_server_with_port_and_subport(
302 vlan_network, vlan_tag, use_advanced_image=True)
303 normal_network_server = self._create_server_with_network(self.network)
304 vlan_network_server = self._create_server_with_network(vlan_network)
305
306 self._wait_for_server(trunk_network_server, advanced_image=True)
307 # Configure VLAN interfaces on server
308 command = CONFIGURE_VLAN_INTERFACE_COMMANDS % {'tag': vlan_tag}
309 trunk_network_server['ssh_client'].exec_command(command)
310 out = trunk_network_server['ssh_client'].exec_command(
311 'PATH=$PATH:/usr/sbin;ip addr list')
312 LOG.debug("Interfaces on server %s: %s", trunk_network_server, out)
313
314 self._wait_for_server(normal_network_server)
315 self._wait_for_server(vlan_network_server)
316
317 # allow intra-securitygroup traffic
318 rule = self.client.create_security_group_rule(
319 security_group_id=self.secgroup['security_group']['id'],
320 direction='ingress', ethertype='IPv4', protocol='icmp',
321 remote_group_id=self.secgroup['security_group']['id'])
322 self.addCleanup(self.client.delete_security_group_rule,
323 rule['security_group_rule']['id'])
324
325 # Ping from trunk_network_server to normal_network_server
326 # via parent port
327 self.check_remote_connectivity(
328 trunk_network_server['ssh_client'],
329 normal_network_server['port']['fixed_ips'][0]['ip_address'],
330 should_succeed=True
331 )
332
333 # Ping from trunk_network_server to vlan_network_server via VLAN
334 # interface should success
335 self.check_remote_connectivity(
336 trunk_network_server['ssh_client'],
337 vlan_network_server['port']['fixed_ips'][0]['ip_address'],
338 should_succeed=True
339 )
340
341 # Delete the trunk
342 self.delete_trunk(trunk_network_server['trunk'],
343 detach_parent_port=False)
344 LOG.debug("Trunk %s is deleted.", trunk_network_server['trunk']['id'])
345
346 # Ping from trunk_network_server to normal_network_server
347 # via parent port success after trunk deleted
348 self.check_remote_connectivity(
349 trunk_network_server['ssh_client'],
350 normal_network_server['port']['fixed_ips'][0]['ip_address'],
351 should_succeed=True
352 )
353
354 # Ping from trunk_network_server to vlan_network_server via VLAN
355 # interface should fail after trunk deleted
356 self.check_remote_connectivity(
357 trunk_network_server['ssh_client'],
358 vlan_network_server['port']['fixed_ips'][0]['ip_address'],
359 should_succeed=False
360 )