blob: b38d770663e71f1f9931352038c909ecb9a0bf6c [file] [log] [blame]
Chandan Kumarc125fd12017-11-15 19:41:01 +05301# Copyright 2016 Red Hat, Inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
Chandan Kumarc125fd12017-11-15 19:41:01 +053015
16from neutron_lib.api.definitions import provider_net
17from tempest.common import utils
18from tempest.common import waiters
Dongcan Yeee300042018-01-10 05:38:35 +000019from tempest.lib.common.utils import data_utils
Chandan Kumarc125fd12017-11-15 19:41:01 +053020from tempest.lib import decorators
21
22from neutron_tempest_plugin.common import ssh
23from neutron_tempest_plugin import config
24from neutron_tempest_plugin.scenario import base
25from neutron_tempest_plugin.scenario import constants
26
27CONF = config.CONF
28
29
30class NetworkMtuBaseTest(base.BaseTempestTestCase):
Chandan Kumarc125fd12017-11-15 19:41:01 +053031
32 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053033 def resource_setup(cls):
34 super(NetworkMtuBaseTest, cls).resource_setup()
35 # setup basic topology for servers we can log into it
36 cls.router = cls.create_router_by_client()
37 cls.keypair = cls.create_keypair()
38 cls.secgroup = cls.os_primary.network_client.create_security_group(
39 name='secgroup_mtu')
40 cls.security_groups.append(cls.secgroup['security_group'])
41 cls.create_loginable_secgroup_rule(
42 secgroup_id=cls.secgroup['security_group']['id'])
43 cls.create_pingable_secgroup_rule(
44 secgroup_id=cls.secgroup['security_group']['id'])
45
Dongcan Yeee300042018-01-10 05:38:35 +000046 def create_pingable_vm(self, net, keypair, secgroup):
47 server = self.create_server(
48 flavor_ref=CONF.compute.flavor_ref,
49 image_ref=CONF.compute.image_ref,
50 key_name=keypair['name'],
51 networks=[{'uuid': net['id']}],
52 security_groups=[{'name': secgroup[
53 'security_group']['name']}])
54 waiters.wait_for_server_status(
55 self.os_primary.servers_client, server['server']['id'],
56 constants.SERVER_STATUS_ACTIVE)
57 port = self.client.list_ports(
58 network_id=net['id'], device_id=server['server']['id'])['ports'][0]
59 fip = self.create_and_associate_floatingip(port['id'])
60 return server, fip
61
62
63class NetworkMtuTest(NetworkMtuBaseTest):
64 credentials = ['primary', 'admin']
65 servers = []
66 networks = []
67
68 @classmethod
69 def skip_checks(cls):
70 super(NetworkMtuTest, cls).skip_checks()
71 if ("vxlan" not in
Brian Haley33ef4602018-04-26 14:37:49 -040072 config.CONF.neutron_plugin_options.available_type_drivers or
73 "gre" not in
Dongcan Yeee300042018-01-10 05:38:35 +000074 config.CONF.neutron_plugin_options.available_type_drivers):
75 raise cls.skipException("GRE or VXLAN type_driver is not enabled")
76
77 @classmethod
78 @utils.requires_ext(extension=provider_net.ALIAS, service="network")
79 def resource_setup(cls):
80 super(NetworkMtuTest, cls).resource_setup()
81
Chandan Kumarc125fd12017-11-15 19:41:01 +053082 def _create_setup(self):
83 self.admin_client = self.os_admin.network_client
84 net_kwargs = {'tenant_id': self.client.tenant_id}
Federico Ressi0ddc93b2018-04-09 12:01:48 +020085 for net_type in ['vxlan', 'gre']:
Chandan Kumarc125fd12017-11-15 19:41:01 +053086 net_kwargs['name'] = '-'.join([net_type, 'net'])
87 net_kwargs['provider:network_type'] = net_type
88 network = self.admin_client.create_network(**net_kwargs)[
89 'network']
90 self.networks.append(network)
91 self.addCleanup(self.admin_client.delete_network, network['id'])
Federico Ressi0ddc93b2018-04-09 12:01:48 +020092 subnet = self.create_subnet(network)
Chandan Kumarc125fd12017-11-15 19:41:01 +053093 self.create_router_interface(self.router['id'], subnet['id'])
94 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
95 self.router['id'], subnet['id'])
96 # check that MTUs are different for 2 networks
97 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
98 self.networks.sort(key=lambda net: net['mtu'])
Dongcan Yeee300042018-01-10 05:38:35 +000099 server1, fip1 = self.create_pingable_vm(self.networks[0],
100 self.keypair, self.secgroup)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530101 server_ssh_client1 = ssh.Client(
102 self.floating_ips[0]['floating_ip_address'],
103 CONF.validation.image_ssh_user,
104 pkey=self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000105 server2, fip2 = self.create_pingable_vm(self.networks[1],
106 self.keypair, self.secgroup)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530107 server_ssh_client2 = ssh.Client(
108 self.floating_ips[0]['floating_ip_address'],
109 CONF.validation.image_ssh_user,
110 pkey=self.keypair['private_key'])
111 for fip in (fip1, fip2):
112 self.check_connectivity(fip['floating_ip_address'],
113 CONF.validation.image_ssh_user,
114 self.keypair['private_key'])
115 return server_ssh_client1, fip1, server_ssh_client2, fip2
116
Chandan Kumarc125fd12017-11-15 19:41:01 +0530117 @decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a273d9d344')
118 def test_connectivity_min_max_mtu(self):
119 server_ssh_client, _, _, fip2 = self._create_setup()
120 # ping with min mtu of 2 networks succeeds even when
121 # fragmentation is disabled
122 self.check_remote_connectivity(
123 server_ssh_client, fip2['fixed_ip_address'],
124 mtu=self.networks[0]['mtu'], fragmentation=False)
125
126 # ping with the size above min mtu of 2 networks
127 # fails when fragmentation is disabled
128 self.check_remote_connectivity(
129 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
130 mtu=self.networks[0]['mtu'] + 1, fragmentation=False)
131
132 # ping with max mtu of 2 networks succeeds when
133 # fragmentation is enabled
134 self.check_remote_connectivity(
135 server_ssh_client, fip2['fixed_ip_address'],
136 mtu=self.networks[1]['mtu'])
137
138 # ping with max mtu of 2 networks fails when fragmentation is disabled
139 self.check_remote_connectivity(
140 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
141 mtu=self.networks[1]['mtu'], fragmentation=False)
Dongcan Yeee300042018-01-10 05:38:35 +0000142
143
144class NetworkWritableMtuTest(NetworkMtuBaseTest):
145 credentials = ['primary', 'admin']
146 servers = []
147 networks = []
148
149 @classmethod
150 def skip_checks(cls):
151 super(NetworkWritableMtuTest, cls).skip_checks()
152 if ("vxlan" not in
153 config.CONF.neutron_plugin_options.available_type_drivers):
154 raise cls.skipException("VXLAN type_driver is not enabled")
155
156 @classmethod
157 @utils.requires_ext(extension="net-mtu-writable", service="network")
158 def resource_setup(cls):
159 super(NetworkWritableMtuTest, cls).resource_setup()
160
161 def _create_setup(self):
162 self.admin_client = self.os_admin.network_client
163 net_kwargs = {'tenant_id': self.client.tenant_id,
164 'provider:network_type': 'vxlan'}
Federico Ressi0ddc93b2018-04-09 12:01:48 +0200165 for _ in range(2):
Dongcan Yeee300042018-01-10 05:38:35 +0000166 net_kwargs['name'] = data_utils.rand_name('net')
167 network = self.admin_client.create_network(**net_kwargs)[
168 'network']
169 self.networks.append(network)
170 self.addCleanup(self.admin_client.delete_network, network['id'])
Federico Ressi0ddc93b2018-04-09 12:01:48 +0200171 subnet = self.create_subnet(network)
Dongcan Yeee300042018-01-10 05:38:35 +0000172 self.create_router_interface(self.router['id'], subnet['id'])
173 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
174 self.router['id'], subnet['id'])
175
176 # Update network mtu.
177 net_mtu = self.admin_client.show_network(
178 self.networks[0]['id'])['network']['mtu']
179 self.admin_client.update_network(self.networks[0]['id'],
180 mtu=(net_mtu - 1))
181 self.networks[0]['mtu'] = (
182 self.admin_client.show_network(
183 self.networks[0]['id'])['network']['mtu'])
184
185 # check that MTUs are different for 2 networks
186 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
187 self.networks.sort(key=lambda net: net['mtu'])
188 server1, fip1 = self.create_pingable_vm(self.networks[0],
189 self.keypair, self.secgroup)
190 server_ssh_client1 = ssh.Client(
191 self.floating_ips[0]['floating_ip_address'],
192 CONF.validation.image_ssh_user,
193 pkey=self.keypair['private_key'])
194 server2, fip2 = self.create_pingable_vm(self.networks[1],
195 self.keypair, self.secgroup)
196 server_ssh_client2 = ssh.Client(
197 self.floating_ips[0]['floating_ip_address'],
198 CONF.validation.image_ssh_user,
199 pkey=self.keypair['private_key'])
200 for fip in (fip1, fip2):
201 self.check_connectivity(fip['floating_ip_address'],
202 CONF.validation.image_ssh_user,
203 self.keypair['private_key'])
204 return server_ssh_client1, fip1, server_ssh_client2, fip2
205
206 @decorators.idempotent_id('bc470200-d8f4-4f07-b294-1b4cbaaa35b9')
207 def test_connectivity_min_max_mtu(self):
208 server_ssh_client, _, _, fip2 = self._create_setup()
209 # ping with min mtu of 2 networks succeeds even when
210 # fragmentation is disabled
211 self.check_remote_connectivity(
212 server_ssh_client, fip2['fixed_ip_address'],
213 mtu=self.networks[0]['mtu'], fragmentation=False)
214
215 # ping with the size above min mtu of 2 networks
216 # fails when fragmentation is disabled
217 self.check_remote_connectivity(
218 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
219 mtu=self.networks[0]['mtu'] + 2, fragmentation=False)
220
221 # ping with max mtu of 2 networks succeeds when
222 # fragmentation is enabled
223 self.check_remote_connectivity(
224 server_ssh_client, fip2['fixed_ip_address'],
225 mtu=self.networks[1]['mtu'])
226
227 # ping with max mtu of 2 networks fails when fragmentation is disabled
228 self.check_remote_connectivity(
229 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
230 mtu=self.networks[1]['mtu'], fragmentation=False)