blob: f687b59a1c305096238a3a6f57019de60cce85a9 [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 Bentona305d592016-09-19 04:26:10 -070016from tempest.common import waiters
Kevin Benton6f1f9d52017-03-01 09:14:45 -080017from tempest.lib.common import ssh
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
Kevin Bentona305d592016-09-19 04:26:10 -070020from tempest import test
21
22from neutron.common import utils
23from neutron.tests.tempest import config
24from neutron.tests.tempest.scenario import base
25from neutron.tests.tempest.scenario import constants
26
27CONF = config.CONF
Kevin Bentona305d592016-09-19 04:26:10 -070028
Jakub Libosvar6d397d32016-12-30 10:57:52 -050029CONFIGURE_VLAN_INTERFACE_COMMANDS = (
AlexSTafeyev200b7672017-03-28 12:07:59 +030030 'IFACE=$(PATH=$PATH:/usr/sbin ip l | grep "^[0-9]*: e" |'
31 'cut -d \: -f 2) && '
Jakub Libosvar6d397d32016-12-30 10:57:52 -050032 'sudo su -c '
AlexSTafeyev200b7672017-03-28 12:07:59 +030033 '"ip l a link $IFACE name $IFACE.%(tag)d type vlan id %(tag)d &&'
Jakub Libosvar6d397d32016-12-30 10:57:52 -050034 'ip l s up dev $IFACE.%(tag)d && '
35 'dhclient $IFACE.%(tag)d"')
36
37
38def get_next_subnet(cidr):
39 return netaddr.IPNetwork(cidr).next()
40
Kevin Bentona305d592016-09-19 04:26:10 -070041
42class TrunkTest(base.BaseTempestTestCase):
43 credentials = ['primary']
44 force_tenant_isolation = False
45
46 @classmethod
47 @test.requires_ext(extension="trunk", service="network")
48 def resource_setup(cls):
49 super(TrunkTest, cls).resource_setup()
50 # setup basic topology for servers we can log into
51 cls.network = cls.create_network()
52 cls.subnet = cls.create_subnet(cls.network)
Genadi Chereshnyac0411e92016-07-11 16:59:42 +030053 router = cls.create_router_by_client()
54 cls.create_router_interface(router['id'], cls.subnet['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070055 cls.keypair = cls.create_keypair()
Itzik Brownbac51dc2016-10-31 12:25:04 +000056 cls.secgroup = cls.manager.network_client.create_security_group(
57 name=data_utils.rand_name('secgroup-'))
58 cls.security_groups.append(cls.secgroup['security_group'])
59 cls.create_loginable_secgroup_rule(
60 secgroup_id=cls.secgroup['security_group']['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070061
62 def _create_server_with_trunk_port(self):
Itzik Brownbac51dc2016-10-31 12:25:04 +000063 port = self.create_port(self.network, security_groups=[
64 self.secgroup['security_group']['id']])
Kevin Bentona305d592016-09-19 04:26:10 -070065 trunk = self.client.create_trunk(port['id'], subports=[])['trunk']
Jakub Libosvar6d397d32016-12-30 10:57:52 -050066 server, fip = self._create_server_with_fip(port['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070067 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
68 return {'port': port, 'trunk': trunk, 'fip': fip,
69 'server': server}
70
Jakub Libosvar6d397d32016-12-30 10:57:52 -050071 def _create_server_with_fip(self, port_id, **server_kwargs):
72 fip = self.create_and_associate_floatingip(port_id)
73 return (
74 self.create_server(
75 flavor_ref=CONF.compute.flavor_ref,
76 image_ref=CONF.compute.image_ref,
77 key_name=self.keypair['name'],
78 networks=[{'port': port_id}],
79 security_groups=[{'name': self.secgroup[
80 'security_group']['name']}],
81 **server_kwargs)['server'],
82 fip)
83
Kevin Bentona305d592016-09-19 04:26:10 -070084 def _detach_and_delete_trunk(self, server, trunk):
85 # we have to detach the interface from the server before
86 # the trunk can be deleted.
87 self.manager.compute.InterfacesClient().delete_interface(
88 server['id'], trunk['port_id'])
89
90 def is_port_detached():
91 p = self.client.show_port(trunk['port_id'])['port']
92 return p['device_id'] == ''
93 utils.wait_until_true(is_port_detached)
94 self.client.delete_trunk(trunk['id'])
95
96 def _is_port_down(self, port_id):
97 p = self.client.show_port(port_id)['port']
98 return p['status'] == 'DOWN'
99
100 def _is_port_active(self, port_id):
101 p = self.client.show_port(port_id)['port']
102 return p['status'] == 'ACTIVE'
103
104 def _is_trunk_active(self, trunk_id):
105 t = self.client.show_trunk(trunk_id)['trunk']
106 return t['status'] == 'ACTIVE'
107
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500108 def _create_server_with_port_and_subport(self, vlan_network, vlan_tag):
109 parent_port = self.create_port(self.network, security_groups=[
110 self.secgroup['security_group']['id']])
111 port_for_subport = self.create_port(
112 vlan_network,
113 security_groups=[self.secgroup['security_group']['id']],
114 mac_address=parent_port['mac_address'])
115 subport = {
116 'port_id': port_for_subport['id'],
117 'segmentation_type': 'vlan',
118 'segmentation_id': vlan_tag}
119 trunk = self.client.create_trunk(
120 parent_port['id'], subports=[subport])['trunk']
121
122 server, fip = self._create_server_with_fip(parent_port['id'])
123 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
124
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800125 server_ssh_client = ssh.Client(
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500126 fip['floating_ip_address'],
127 CONF.validation.image_ssh_user,
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800128 pkey=self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500129
130 return {
131 'server': server,
132 'fip': fip,
133 'ssh_client': server_ssh_client,
134 'subport': port_for_subport,
135 }
136
137 def _wait_for_server(self, server):
138 waiters.wait_for_server_status(self.manager.servers_client,
139 server['server']['id'],
140 constants.SERVER_STATUS_ACTIVE)
141 self.check_connectivity(server['fip']['floating_ip_address'],
142 CONF.validation.image_ssh_user,
143 self.keypair['private_key'])
144
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000145 @decorators.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e')
Kevin Bentona305d592016-09-19 04:26:10 -0700146 def test_trunk_subport_lifecycle(self):
147 """Test trunk creation and subport transition to ACTIVE status.
148
149 This is a basic test for the trunk extension to ensure that we
150 can create a trunk, attach it to a server, add/remove subports,
151 while ensuring the status transitions as appropriate.
152
153 This test does not assert any dataplane behavior for the subports.
154 It's just a high-level check to ensure the agents claim to have
155 wired the port correctly and that the trunk port itself maintains
156 connectivity.
157 """
158 server1 = self._create_server_with_trunk_port()
159 server2 = self._create_server_with_trunk_port()
160 for server in (server1, server2):
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500161 self._wait_for_server(server)
Kevin Bentona305d592016-09-19 04:26:10 -0700162 trunk1_id, trunk2_id = server1['trunk']['id'], server2['trunk']['id']
163 # trunks should transition to ACTIVE without any subports
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 utils.wait_until_true(
169 lambda: self._is_trunk_active(trunk2_id),
170 exception=RuntimeError("Timed out waiting for trunk %s to "
171 "transition to ACTIVE." % trunk2_id))
172 # create a few more networks and ports for subports
173 subports = [{'port_id': self.create_port(self.create_network())['id'],
174 'segmentation_type': 'vlan', 'segmentation_id': seg_id}
175 for seg_id in range(3, 7)]
176 # 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
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000222 @decorators.idempotent_id('a8a02c9b-b453-49b5-89a2-cce7da66aafb')
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500223 def test_subport_connectivity(self):
224 vlan_tag = 10
225
226 vlan_network = self.create_network()
227 new_subnet_cidr = get_next_subnet(
228 config.safe_get_config_value('network', 'project_network_cidr'))
229 self.create_subnet(vlan_network, cidr=new_subnet_cidr)
230
231 servers = [
232 self._create_server_with_port_and_subport(vlan_network, vlan_tag)
233 for i in range(2)]
234
235 for server in servers:
236 self._wait_for_server(server)
237 # Configure VLAN interfaces on server
238 command = CONFIGURE_VLAN_INTERFACE_COMMANDS % {'tag': vlan_tag}
239 server['ssh_client'].exec_command(command)
240
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800241 # Ping from server1 to server2 via VLAN interface should fail because
242 # we haven't allowed ICMP
243 self.check_remote_connectivity(
244 servers[0]['ssh_client'],
245 servers[1]['subport']['fixed_ips'][0]['ip_address'],
246 should_succeed=False
247 )
248 # allow intra-securitygroup traffic
249 self.client.create_security_group_rule(
250 security_group_id=self.secgroup['security_group']['id'],
251 direction='ingress', ethertype='IPv4', protocol='icmp',
252 remote_group_id=self.secgroup['security_group']['id'])
253 self.check_remote_connectivity(
254 servers[0]['ssh_client'],
255 servers[1]['subport']['fixed_ips'][0]['ip_address'],
256 should_succeed=True
257 )