blob: bb4266c2da659fe41a83400e3b7b929a72bf9c92 [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
Jakub Libosvar6d397d32016-12-30 10:57:52 -050015import netaddr
Kevin Benton07c90562017-02-27 01:53:16 -080016from oslo_log import log as logging
Chandan Kumarc125fd12017-11-15 19:41:01 +053017from tempest.common import utils as tutils
Kevin Bentona305d592016-09-19 04:26:10 -070018from tempest.common import waiters
Itzik Brownbac51dc2016-10-31 12:25:04 +000019from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000020from tempest.lib import decorators
Genadi Chereshnyae91b69c2017-07-16 09:51:58 +030021import testtools
Kevin Bentona305d592016-09-19 04:26:10 -070022
Chandan Kumar667d3d32017-09-22 12:24:06 +053023from neutron_tempest_plugin.common import ssh
24from neutron_tempest_plugin.common import utils
25from neutron_tempest_plugin import config
26from neutron_tempest_plugin.scenario import base
27from neutron_tempest_plugin.scenario import constants
Kevin Bentona305d592016-09-19 04:26:10 -070028
Kevin Benton07c90562017-02-27 01:53:16 -080029LOG = logging.getLogger(__name__)
Kevin Bentona305d592016-09-19 04:26:10 -070030CONF = config.CONF
Kevin Bentona305d592016-09-19 04:26:10 -070031
Jakub Libosvar6d397d32016-12-30 10:57:52 -050032CONFIGURE_VLAN_INTERFACE_COMMANDS = (
AlexSTafeyev200b7672017-03-28 12:07:59 +030033 'IFACE=$(PATH=$PATH:/usr/sbin ip l | grep "^[0-9]*: e" |'
34 'cut -d \: -f 2) && '
Jakub Libosvar6d397d32016-12-30 10:57:52 -050035 'sudo su -c '
AlexSTafeyev200b7672017-03-28 12:07:59 +030036 '"ip l a link $IFACE name $IFACE.%(tag)d type vlan id %(tag)d &&'
Jakub Libosvar6d397d32016-12-30 10:57:52 -050037 'ip l s up dev $IFACE.%(tag)d && '
38 'dhclient $IFACE.%(tag)d"')
39
40
41def get_next_subnet(cidr):
42 return netaddr.IPNetwork(cidr).next()
43
Kevin Bentona305d592016-09-19 04:26:10 -070044
45class TrunkTest(base.BaseTempestTestCase):
46 credentials = ['primary']
47 force_tenant_isolation = False
48
49 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053050 @tutils.requires_ext(extension="trunk", service="network")
Kevin Bentona305d592016-09-19 04:26:10 -070051 def resource_setup(cls):
52 super(TrunkTest, cls).resource_setup()
53 # setup basic topology for servers we can log into
54 cls.network = cls.create_network()
55 cls.subnet = cls.create_subnet(cls.network)
Genadi Chereshnyac0411e92016-07-11 16:59:42 +030056 router = cls.create_router_by_client()
57 cls.create_router_interface(router['id'], cls.subnet['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070058 cls.keypair = cls.create_keypair()
rajat294495c042017-06-28 15:37:16 +053059 cls.secgroup = cls.os_primary.network_client.create_security_group(
Chandan Kumarc125fd12017-11-15 19:41:01 +053060 name=data_utils.rand_name('secgroup'))
Itzik Brownbac51dc2016-10-31 12:25:04 +000061 cls.security_groups.append(cls.secgroup['security_group'])
62 cls.create_loginable_secgroup_rule(
63 secgroup_id=cls.secgroup['security_group']['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070064
65 def _create_server_with_trunk_port(self):
Itzik Brownbac51dc2016-10-31 12:25:04 +000066 port = self.create_port(self.network, security_groups=[
67 self.secgroup['security_group']['id']])
Kevin Bentona305d592016-09-19 04:26:10 -070068 trunk = self.client.create_trunk(port['id'], subports=[])['trunk']
Jakub Libosvar6d397d32016-12-30 10:57:52 -050069 server, fip = self._create_server_with_fip(port['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070070 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
71 return {'port': port, 'trunk': trunk, 'fip': fip,
72 'server': server}
73
Jakub Libosvar6d397d32016-12-30 10:57:52 -050074 def _create_server_with_fip(self, port_id, **server_kwargs):
75 fip = self.create_and_associate_floatingip(port_id)
76 return (
77 self.create_server(
78 flavor_ref=CONF.compute.flavor_ref,
79 image_ref=CONF.compute.image_ref,
80 key_name=self.keypair['name'],
81 networks=[{'port': port_id}],
82 security_groups=[{'name': self.secgroup[
83 'security_group']['name']}],
84 **server_kwargs)['server'],
85 fip)
86
Kevin Bentona305d592016-09-19 04:26:10 -070087 def _detach_and_delete_trunk(self, server, trunk):
88 # we have to detach the interface from the server before
89 # the trunk can be deleted.
Brian Haleyf86ac2e2017-06-21 10:43:50 -040090 self.os_primary.compute.InterfacesClient().delete_interface(
Kevin Bentona305d592016-09-19 04:26:10 -070091 server['id'], trunk['port_id'])
92
93 def is_port_detached():
94 p = self.client.show_port(trunk['port_id'])['port']
95 return p['device_id'] == ''
96 utils.wait_until_true(is_port_detached)
97 self.client.delete_trunk(trunk['id'])
98
99 def _is_port_down(self, port_id):
100 p = self.client.show_port(port_id)['port']
101 return p['status'] == 'DOWN'
102
103 def _is_port_active(self, port_id):
104 p = self.client.show_port(port_id)['port']
105 return p['status'] == 'ACTIVE'
106
107 def _is_trunk_active(self, trunk_id):
108 t = self.client.show_trunk(trunk_id)['trunk']
109 return t['status'] == 'ACTIVE'
110
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500111 def _create_server_with_port_and_subport(self, vlan_network, vlan_tag):
112 parent_port = self.create_port(self.network, security_groups=[
113 self.secgroup['security_group']['id']])
114 port_for_subport = self.create_port(
115 vlan_network,
116 security_groups=[self.secgroup['security_group']['id']],
117 mac_address=parent_port['mac_address'])
118 subport = {
119 'port_id': port_for_subport['id'],
120 'segmentation_type': 'vlan',
121 'segmentation_id': vlan_tag}
122 trunk = self.client.create_trunk(
123 parent_port['id'], subports=[subport])['trunk']
124
125 server, fip = self._create_server_with_fip(parent_port['id'])
126 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
127
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800128 server_ssh_client = ssh.Client(
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500129 fip['floating_ip_address'],
130 CONF.validation.image_ssh_user,
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800131 pkey=self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500132
133 return {
134 'server': server,
135 'fip': fip,
136 'ssh_client': server_ssh_client,
137 'subport': port_for_subport,
138 }
139
140 def _wait_for_server(self, server):
Brian Haleyf86ac2e2017-06-21 10:43:50 -0400141 waiters.wait_for_server_status(self.os_primary.servers_client,
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500142 server['server']['id'],
143 constants.SERVER_STATUS_ACTIVE)
144 self.check_connectivity(server['fip']['floating_ip_address'],
145 CONF.validation.image_ssh_user,
146 self.keypair['private_key'])
147
Jakub Libosvarb2a04ef2018-01-02 15:54:00 +0000148 @utils.unstable_test("bug 1740885")
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000149 @decorators.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e')
Kevin Bentona305d592016-09-19 04:26:10 -0700150 def test_trunk_subport_lifecycle(self):
151 """Test trunk creation and subport transition to ACTIVE status.
152
153 This is a basic test for the trunk extension to ensure that we
154 can create a trunk, attach it to a server, add/remove subports,
155 while ensuring the status transitions as appropriate.
156
157 This test does not assert any dataplane behavior for the subports.
158 It's just a high-level check to ensure the agents claim to have
159 wired the port correctly and that the trunk port itself maintains
160 connectivity.
161 """
162 server1 = self._create_server_with_trunk_port()
163 server2 = self._create_server_with_trunk_port()
164 for server in (server1, server2):
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500165 self._wait_for_server(server)
Kevin Bentona305d592016-09-19 04:26:10 -0700166 trunk1_id, trunk2_id = server1['trunk']['id'], server2['trunk']['id']
167 # trunks should transition to ACTIVE without any subports
168 utils.wait_until_true(
169 lambda: self._is_trunk_active(trunk1_id),
170 exception=RuntimeError("Timed out waiting for trunk %s to "
171 "transition to ACTIVE." % trunk1_id))
172 utils.wait_until_true(
173 lambda: self._is_trunk_active(trunk2_id),
174 exception=RuntimeError("Timed out waiting for trunk %s to "
175 "transition to ACTIVE." % trunk2_id))
176 # create a few more networks and ports for subports
Yariv Rachmanifed6f862017-12-19 11:55:25 +0200177 # check limit of networks per project
178 max_vlan = 3 + CONF.neutron_plugin_options.max_networks_per_project
179 allowed_vlans = range(3, max_vlan)
Kevin Bentona305d592016-09-19 04:26:10 -0700180 subports = [{'port_id': self.create_port(self.create_network())['id'],
181 'segmentation_type': 'vlan', 'segmentation_id': seg_id}
Yariv Rachmanifed6f862017-12-19 11:55:25 +0200182 for seg_id in allowed_vlans]
Kevin Bentona305d592016-09-19 04:26:10 -0700183 # add all subports to server1
184 self.client.add_subports(trunk1_id, subports)
185 # ensure trunk transitions to ACTIVE
186 utils.wait_until_true(
187 lambda: self._is_trunk_active(trunk1_id),
188 exception=RuntimeError("Timed out waiting for trunk %s to "
189 "transition to ACTIVE." % trunk1_id))
190 # ensure all underlying subports transitioned to ACTIVE
191 for s in subports:
192 utils.wait_until_true(lambda: self._is_port_active(s['port_id']))
193 # ensure main dataplane wasn't interrupted
194 self.check_connectivity(server1['fip']['floating_ip_address'],
195 CONF.validation.image_ssh_user,
196 self.keypair['private_key'])
197 # move subports over to other server
198 self.client.remove_subports(trunk1_id, subports)
199 # ensure all subports go down
200 for s in subports:
201 utils.wait_until_true(
202 lambda: self._is_port_down(s['port_id']),
203 exception=RuntimeError("Timed out waiting for subport %s to "
204 "transition to DOWN." % s['port_id']))
205 self.client.add_subports(trunk2_id, subports)
206 # wait for both trunks to go back to ACTIVE
207 utils.wait_until_true(
208 lambda: self._is_trunk_active(trunk1_id),
209 exception=RuntimeError("Timed out waiting for trunk %s to "
210 "transition to ACTIVE." % trunk1_id))
211 utils.wait_until_true(
212 lambda: self._is_trunk_active(trunk2_id),
213 exception=RuntimeError("Timed out waiting for trunk %s to "
214 "transition to ACTIVE." % trunk2_id))
215 # ensure subports come up on other trunk
216 for s in subports:
217 utils.wait_until_true(
218 lambda: self._is_port_active(s['port_id']),
219 exception=RuntimeError("Timed out waiting for subport %s to "
220 "transition to ACTIVE." % s['port_id']))
221 # final connectivity check
222 self.check_connectivity(server1['fip']['floating_ip_address'],
223 CONF.validation.image_ssh_user,
224 self.keypair['private_key'])
225 self.check_connectivity(server2['fip']['floating_ip_address'],
226 CONF.validation.image_ssh_user,
227 self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500228
Genadi Chereshnyae91b69c2017-07-16 09:51:58 +0300229 @testtools.skipUnless(
230 CONF.neutron_plugin_options.image_is_advanced,
231 "Advanced image is required to run this test.")
Jakub Libosvarb2a04ef2018-01-02 15:54:00 +0000232 @utils.unstable_test("bug 1740885")
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000233 @decorators.idempotent_id('a8a02c9b-b453-49b5-89a2-cce7da66aafb')
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500234 def test_subport_connectivity(self):
235 vlan_tag = 10
236
237 vlan_network = self.create_network()
238 new_subnet_cidr = get_next_subnet(
239 config.safe_get_config_value('network', 'project_network_cidr'))
AlexSTafeyev5d704992017-04-23 10:59:12 +0000240 self.create_subnet(vlan_network, gateway=None, cidr=new_subnet_cidr)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500241
242 servers = [
243 self._create_server_with_port_and_subport(vlan_network, vlan_tag)
244 for i in range(2)]
245
246 for server in servers:
247 self._wait_for_server(server)
248 # Configure VLAN interfaces on server
249 command = CONFIGURE_VLAN_INTERFACE_COMMANDS % {'tag': vlan_tag}
250 server['ssh_client'].exec_command(command)
AlexSTafeyev0aa817c2017-05-08 10:57:37 +0000251 out = server['ssh_client'].exec_command(
252 'PATH=$PATH:/usr/sbin;ip addr list')
Kevin Benton07c90562017-02-27 01:53:16 -0800253 LOG.debug("Interfaces on server %s: %s", server, out)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500254
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800255 # Ping from server1 to server2 via VLAN interface should fail because
256 # we haven't allowed ICMP
257 self.check_remote_connectivity(
258 servers[0]['ssh_client'],
259 servers[1]['subport']['fixed_ips'][0]['ip_address'],
260 should_succeed=False
261 )
262 # allow intra-securitygroup traffic
263 self.client.create_security_group_rule(
264 security_group_id=self.secgroup['security_group']['id'],
265 direction='ingress', ethertype='IPv4', protocol='icmp',
266 remote_group_id=self.secgroup['security_group']['id'])
267 self.check_remote_connectivity(
268 servers[0]['ssh_client'],
269 servers[1]['subport']['fixed_ips'][0]['ip_address'],
270 should_succeed=True
271 )