blob: 3b49e3932d78afeb514bc6d31276f0ee3735288b [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
Kevin Bentona305d592016-09-19 04:26:10 -070017from tempest.common import waiters
Kevin Benton6f1f9d52017-03-01 09:14:45 -080018from tempest.lib.common import ssh
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
Kevin Bentona305d592016-09-19 04:26:10 -070021from tempest import test
22
23from neutron.common import utils
24from neutron.tests.tempest import config
25from neutron.tests.tempest.scenario import base
26from neutron.tests.tempest.scenario import constants
27
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 = (
32 'IFACE=$(ip l | grep "^[0-9]*: e" | cut -d \: -f 2) && '
33 'sudo su -c '
34 '"ip l a link $IFACE name $IFACE.%(tag)d type vlan id %(tag)d && '
35 'ip l s up dev $IFACE.%(tag)d && '
36 'dhclient $IFACE.%(tag)d"')
37
38
39def get_next_subnet(cidr):
40 return netaddr.IPNetwork(cidr).next()
41
Kevin Bentona305d592016-09-19 04:26:10 -070042
43class TrunkTest(base.BaseTempestTestCase):
44 credentials = ['primary']
45 force_tenant_isolation = False
46
47 @classmethod
48 @test.requires_ext(extension="trunk", service="network")
49 def resource_setup(cls):
50 super(TrunkTest, cls).resource_setup()
51 # setup basic topology for servers we can log into
52 cls.network = cls.create_network()
53 cls.subnet = cls.create_subnet(cls.network)
Genadi Chereshnyac0411e92016-07-11 16:59:42 +030054 router = cls.create_router_by_client()
55 cls.create_router_interface(router['id'], cls.subnet['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070056 cls.keypair = cls.create_keypair()
Itzik Brownbac51dc2016-10-31 12:25:04 +000057 cls.secgroup = cls.manager.network_client.create_security_group(
58 name=data_utils.rand_name('secgroup-'))
59 cls.security_groups.append(cls.secgroup['security_group'])
60 cls.create_loginable_secgroup_rule(
61 secgroup_id=cls.secgroup['security_group']['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070062
63 def _create_server_with_trunk_port(self):
Itzik Brownbac51dc2016-10-31 12:25:04 +000064 port = self.create_port(self.network, security_groups=[
65 self.secgroup['security_group']['id']])
Kevin Bentona305d592016-09-19 04:26:10 -070066 trunk = self.client.create_trunk(port['id'], subports=[])['trunk']
Jakub Libosvar6d397d32016-12-30 10:57:52 -050067 server, fip = self._create_server_with_fip(port['id'])
Kevin Bentona305d592016-09-19 04:26:10 -070068 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
69 return {'port': port, 'trunk': trunk, 'fip': fip,
70 'server': server}
71
Jakub Libosvar6d397d32016-12-30 10:57:52 -050072 def _create_server_with_fip(self, port_id, **server_kwargs):
73 fip = self.create_and_associate_floatingip(port_id)
74 return (
75 self.create_server(
76 flavor_ref=CONF.compute.flavor_ref,
77 image_ref=CONF.compute.image_ref,
78 key_name=self.keypair['name'],
79 networks=[{'port': port_id}],
80 security_groups=[{'name': self.secgroup[
81 'security_group']['name']}],
82 **server_kwargs)['server'],
83 fip)
84
Kevin Bentona305d592016-09-19 04:26:10 -070085 def _detach_and_delete_trunk(self, server, trunk):
86 # we have to detach the interface from the server before
87 # the trunk can be deleted.
88 self.manager.compute.InterfacesClient().delete_interface(
89 server['id'], trunk['port_id'])
90
91 def is_port_detached():
92 p = self.client.show_port(trunk['port_id'])['port']
93 return p['device_id'] == ''
94 utils.wait_until_true(is_port_detached)
95 self.client.delete_trunk(trunk['id'])
96
97 def _is_port_down(self, port_id):
98 p = self.client.show_port(port_id)['port']
99 return p['status'] == 'DOWN'
100
101 def _is_port_active(self, port_id):
102 p = self.client.show_port(port_id)['port']
103 return p['status'] == 'ACTIVE'
104
105 def _is_trunk_active(self, trunk_id):
106 t = self.client.show_trunk(trunk_id)['trunk']
107 return t['status'] == 'ACTIVE'
108
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500109 def _create_server_with_port_and_subport(self, vlan_network, vlan_tag):
110 parent_port = self.create_port(self.network, security_groups=[
111 self.secgroup['security_group']['id']])
112 port_for_subport = self.create_port(
113 vlan_network,
114 security_groups=[self.secgroup['security_group']['id']],
115 mac_address=parent_port['mac_address'])
116 subport = {
117 'port_id': port_for_subport['id'],
118 'segmentation_type': 'vlan',
119 'segmentation_id': vlan_tag}
120 trunk = self.client.create_trunk(
121 parent_port['id'], subports=[subport])['trunk']
122
123 server, fip = self._create_server_with_fip(parent_port['id'])
124 self.addCleanup(self._detach_and_delete_trunk, server, trunk)
125
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800126 server_ssh_client = ssh.Client(
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500127 fip['floating_ip_address'],
128 CONF.validation.image_ssh_user,
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800129 pkey=self.keypair['private_key'])
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500130
131 return {
132 'server': server,
133 'fip': fip,
134 'ssh_client': server_ssh_client,
135 'subport': port_for_subport,
136 }
137
138 def _wait_for_server(self, server):
139 waiters.wait_for_server_status(self.manager.servers_client,
140 server['server']['id'],
141 constants.SERVER_STATUS_ACTIVE)
142 self.check_connectivity(server['fip']['floating_ip_address'],
143 CONF.validation.image_ssh_user,
144 self.keypair['private_key'])
145
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000146 @decorators.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e')
Kevin Bentona305d592016-09-19 04:26:10 -0700147 def test_trunk_subport_lifecycle(self):
148 """Test trunk creation and subport transition to ACTIVE status.
149
150 This is a basic test for the trunk extension to ensure that we
151 can create a trunk, attach it to a server, add/remove subports,
152 while ensuring the status transitions as appropriate.
153
154 This test does not assert any dataplane behavior for the subports.
155 It's just a high-level check to ensure the agents claim to have
156 wired the port correctly and that the trunk port itself maintains
157 connectivity.
158 """
159 server1 = self._create_server_with_trunk_port()
160 server2 = self._create_server_with_trunk_port()
161 for server in (server1, server2):
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500162 self._wait_for_server(server)
Kevin Bentona305d592016-09-19 04:26:10 -0700163 trunk1_id, trunk2_id = server1['trunk']['id'], server2['trunk']['id']
164 # trunks should transition to ACTIVE without any subports
165 utils.wait_until_true(
166 lambda: self._is_trunk_active(trunk1_id),
167 exception=RuntimeError("Timed out waiting for trunk %s to "
168 "transition to ACTIVE." % trunk1_id))
169 utils.wait_until_true(
170 lambda: self._is_trunk_active(trunk2_id),
171 exception=RuntimeError("Timed out waiting for trunk %s to "
172 "transition to ACTIVE." % trunk2_id))
173 # create a few more networks and ports for subports
174 subports = [{'port_id': self.create_port(self.create_network())['id'],
175 'segmentation_type': 'vlan', 'segmentation_id': seg_id}
176 for seg_id in range(3, 7)]
177 # 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
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000223 @decorators.idempotent_id('a8a02c9b-b453-49b5-89a2-cce7da66aafb')
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500224 def test_subport_connectivity(self):
225 vlan_tag = 10
226
227 vlan_network = self.create_network()
228 new_subnet_cidr = get_next_subnet(
229 config.safe_get_config_value('network', 'project_network_cidr'))
AlexSTafeyev5d704992017-04-23 10:59:12 +0000230 self.create_subnet(vlan_network, gateway=None, cidr=new_subnet_cidr)
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)
Kevin Benton07c90562017-02-27 01:53:16 -0800241 out = server['ssh_client'].exec_command('ip addr list')
242 LOG.debug("Interfaces on server %s: %s", server, out)
Jakub Libosvar6d397d32016-12-30 10:57:52 -0500243
Kevin Benton6f1f9d52017-03-01 09:14:45 -0800244 # Ping from server1 to server2 via VLAN interface should fail because
245 # we haven't allowed ICMP
246 self.check_remote_connectivity(
247 servers[0]['ssh_client'],
248 servers[1]['subport']['fixed_ips'][0]['ip_address'],
249 should_succeed=False
250 )
251 # allow intra-securitygroup traffic
252 self.client.create_security_group_rule(
253 security_group_id=self.secgroup['security_group']['id'],
254 direction='ingress', ethertype='IPv4', protocol='icmp',
255 remote_group_id=self.secgroup['security_group']['id'])
256 self.check_remote_connectivity(
257 servers[0]['ssh_client'],
258 servers[1]['subport']['fixed_ips'][0]['ip_address'],
259 should_succeed=True
260 )