blob: 7a9f9691fe61c4d53ffc2b7c210661777e5ef691 [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
Yariv Rachmani94970882018-03-04 11:35:17 +020017from oslo_serialization import jsonutils
Chandan Kumarc125fd12017-11-15 19:41:01 +053018from tempest.common import utils
19from tempest.common import waiters
Dongcan Yeee300042018-01-10 05:38:35 +000020from tempest.lib.common.utils import data_utils
Chandan Kumarc125fd12017-11-15 19:41:01 +053021from tempest.lib import decorators
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +020022import testtools
Chandan Kumarc125fd12017-11-15 19:41:01 +053023
24from neutron_tempest_plugin.common import ssh
25from neutron_tempest_plugin import config
26from neutron_tempest_plugin.scenario import base
27from neutron_tempest_plugin.scenario import constants
28
29CONF = config.CONF
30
31
32class NetworkMtuBaseTest(base.BaseTempestTestCase):
Chandan Kumarc125fd12017-11-15 19:41:01 +053033
34 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053035 def resource_setup(cls):
36 super(NetworkMtuBaseTest, cls).resource_setup()
37 # setup basic topology for servers we can log into it
38 cls.router = cls.create_router_by_client()
39 cls.keypair = cls.create_keypair()
40 cls.secgroup = cls.os_primary.network_client.create_security_group(
41 name='secgroup_mtu')
42 cls.security_groups.append(cls.secgroup['security_group'])
43 cls.create_loginable_secgroup_rule(
44 secgroup_id=cls.secgroup['security_group']['id'])
45 cls.create_pingable_secgroup_rule(
46 secgroup_id=cls.secgroup['security_group']['id'])
47
Dongcan Yeee300042018-01-10 05:38:35 +000048 def create_pingable_vm(self, net, keypair, secgroup):
49 server = self.create_server(
50 flavor_ref=CONF.compute.flavor_ref,
51 image_ref=CONF.compute.image_ref,
52 key_name=keypair['name'],
53 networks=[{'uuid': net['id']}],
54 security_groups=[{'name': secgroup[
55 'security_group']['name']}])
56 waiters.wait_for_server_status(
57 self.os_primary.servers_client, server['server']['id'],
58 constants.SERVER_STATUS_ACTIVE)
59 port = self.client.list_ports(
60 network_id=net['id'], device_id=server['server']['id'])['ports'][0]
Federico Ressi3dfa94c2018-07-06 09:46:39 +020061 fip = self.create_floatingip(port=port)
Dongcan Yeee300042018-01-10 05:38:35 +000062 return server, fip
63
Yariv Rachmani94970882018-03-04 11:35:17 +020064 def _get_network_params(self):
65 return jsonutils.loads(CONF.neutron_plugin_options.test_mtu_networks)
66
Dongcan Yeee300042018-01-10 05:38:35 +000067
68class NetworkMtuTest(NetworkMtuBaseTest):
69 credentials = ['primary', 'admin']
70 servers = []
71 networks = []
72
73 @classmethod
74 def skip_checks(cls):
75 super(NetworkMtuTest, cls).skip_checks()
76 if ("vxlan" not in
Brian Haley33ef4602018-04-26 14:37:49 -040077 config.CONF.neutron_plugin_options.available_type_drivers or
78 "gre" not in
Dongcan Yeee300042018-01-10 05:38:35 +000079 config.CONF.neutron_plugin_options.available_type_drivers):
80 raise cls.skipException("GRE or VXLAN type_driver is not enabled")
81
82 @classmethod
83 @utils.requires_ext(extension=provider_net.ALIAS, service="network")
84 def resource_setup(cls):
85 super(NetworkMtuTest, cls).resource_setup()
86
Chandan Kumarc125fd12017-11-15 19:41:01 +053087 def _create_setup(self):
88 self.admin_client = self.os_admin.network_client
89 net_kwargs = {'tenant_id': self.client.tenant_id}
Federico Ressi0ddc93b2018-04-09 12:01:48 +020090 for net_type in ['vxlan', 'gre']:
Chandan Kumarc125fd12017-11-15 19:41:01 +053091 net_kwargs['name'] = '-'.join([net_type, 'net'])
92 net_kwargs['provider:network_type'] = net_type
93 network = self.admin_client.create_network(**net_kwargs)[
94 'network']
95 self.networks.append(network)
96 self.addCleanup(self.admin_client.delete_network, network['id'])
Federico Ressi0ddc93b2018-04-09 12:01:48 +020097 subnet = self.create_subnet(network)
Chandan Kumarc125fd12017-11-15 19:41:01 +053098 self.create_router_interface(self.router['id'], subnet['id'])
99 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
100 self.router['id'], subnet['id'])
101 # check that MTUs are different for 2 networks
102 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
103 self.networks.sort(key=lambda net: net['mtu'])
Dongcan Yeee300042018-01-10 05:38:35 +0000104 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200105 self.keypair, self.secgroup)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530106 server_ssh_client1 = ssh.Client(
107 self.floating_ips[0]['floating_ip_address'],
108 CONF.validation.image_ssh_user,
109 pkey=self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000110 server2, fip2 = self.create_pingable_vm(self.networks[1],
Yariv Rachmani94970882018-03-04 11:35:17 +0200111 self.keypair, self.secgroup)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530112 server_ssh_client2 = ssh.Client(
113 self.floating_ips[0]['floating_ip_address'],
114 CONF.validation.image_ssh_user,
115 pkey=self.keypair['private_key'])
116 for fip in (fip1, fip2):
117 self.check_connectivity(fip['floating_ip_address'],
118 CONF.validation.image_ssh_user,
119 self.keypair['private_key'])
120 return server_ssh_client1, fip1, server_ssh_client2, fip2
121
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200122 @testtools.skipUnless(
123 CONF.neutron_plugin_options.image_is_advanced,
124 "Advanced image is required to run this test.")
Chandan Kumarc125fd12017-11-15 19:41:01 +0530125 @decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a273d9d344')
126 def test_connectivity_min_max_mtu(self):
127 server_ssh_client, _, _, fip2 = self._create_setup()
128 # ping with min mtu of 2 networks succeeds even when
129 # fragmentation is disabled
130 self.check_remote_connectivity(
131 server_ssh_client, fip2['fixed_ip_address'],
132 mtu=self.networks[0]['mtu'], fragmentation=False)
133
134 # ping with the size above min mtu of 2 networks
135 # fails when fragmentation is disabled
136 self.check_remote_connectivity(
137 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
138 mtu=self.networks[0]['mtu'] + 1, fragmentation=False)
139
140 # ping with max mtu of 2 networks succeeds when
141 # fragmentation is enabled
142 self.check_remote_connectivity(
143 server_ssh_client, fip2['fixed_ip_address'],
144 mtu=self.networks[1]['mtu'])
145
146 # ping with max mtu of 2 networks fails when fragmentation is disabled
147 self.check_remote_connectivity(
148 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
149 mtu=self.networks[1]['mtu'], fragmentation=False)
Dongcan Yeee300042018-01-10 05:38:35 +0000150
151
152class NetworkWritableMtuTest(NetworkMtuBaseTest):
153 credentials = ['primary', 'admin']
154 servers = []
155 networks = []
156
157 @classmethod
158 def skip_checks(cls):
159 super(NetworkWritableMtuTest, cls).skip_checks()
160 if ("vxlan" not in
Yariv Rachmani94970882018-03-04 11:35:17 +0200161 config.CONF.neutron_plugin_options.available_type_drivers):
Dongcan Yeee300042018-01-10 05:38:35 +0000162 raise cls.skipException("VXLAN type_driver is not enabled")
163
164 @classmethod
165 @utils.requires_ext(extension="net-mtu-writable", service="network")
166 def resource_setup(cls):
167 super(NetworkWritableMtuTest, cls).resource_setup()
168
169 def _create_setup(self):
170 self.admin_client = self.os_admin.network_client
Yariv Rachmani94970882018-03-04 11:35:17 +0200171 for test_net in self._get_network_params():
172 test_net['tenant_id'] = self.client.tenant_id
173 test_net['name'] = data_utils.rand_name('net')
174 cidr = None if 'cidr' not in test_net else test_net.pop('cidr')
175 network = self.admin_client.create_network(**test_net)[
Dongcan Yeee300042018-01-10 05:38:35 +0000176 'network']
177 self.networks.append(network)
178 self.addCleanup(self.admin_client.delete_network, network['id'])
Yariv Rachmani94970882018-03-04 11:35:17 +0200179 subnet = self.create_subnet(network, cidr=cidr)
Dongcan Yeee300042018-01-10 05:38:35 +0000180 self.create_router_interface(self.router['id'], subnet['id'])
181 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
182 self.router['id'], subnet['id'])
183
Yariv Rachmani94970882018-03-04 11:35:17 +0200184 # update network mtu
Dongcan Yeee300042018-01-10 05:38:35 +0000185 net_mtu = self.admin_client.show_network(
186 self.networks[0]['id'])['network']['mtu']
187 self.admin_client.update_network(self.networks[0]['id'],
Yariv Rachmani94970882018-03-04 11:35:17 +0200188 mtu=(net_mtu - 1))
Dongcan Yeee300042018-01-10 05:38:35 +0000189 self.networks[0]['mtu'] = (
190 self.admin_client.show_network(
191 self.networks[0]['id'])['network']['mtu'])
192
193 # check that MTUs are different for 2 networks
194 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
195 self.networks.sort(key=lambda net: net['mtu'])
196 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200197 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000198 server_ssh_client1 = ssh.Client(
199 self.floating_ips[0]['floating_ip_address'],
200 CONF.validation.image_ssh_user,
201 pkey=self.keypair['private_key'])
202 server2, fip2 = self.create_pingable_vm(self.networks[1],
Yariv Rachmani94970882018-03-04 11:35:17 +0200203 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000204 server_ssh_client2 = ssh.Client(
205 self.floating_ips[0]['floating_ip_address'],
206 CONF.validation.image_ssh_user,
207 pkey=self.keypair['private_key'])
208 for fip in (fip1, fip2):
209 self.check_connectivity(fip['floating_ip_address'],
210 CONF.validation.image_ssh_user,
211 self.keypair['private_key'])
212 return server_ssh_client1, fip1, server_ssh_client2, fip2
213
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200214 @testtools.skipUnless(
215 CONF.neutron_plugin_options.image_is_advanced,
216 "Advanced image is required to run this test.")
Dongcan Yeee300042018-01-10 05:38:35 +0000217 @decorators.idempotent_id('bc470200-d8f4-4f07-b294-1b4cbaaa35b9')
218 def test_connectivity_min_max_mtu(self):
219 server_ssh_client, _, _, fip2 = self._create_setup()
220 # ping with min mtu of 2 networks succeeds even when
221 # fragmentation is disabled
222 self.check_remote_connectivity(
223 server_ssh_client, fip2['fixed_ip_address'],
224 mtu=self.networks[0]['mtu'], fragmentation=False)
225
226 # ping with the size above min mtu of 2 networks
227 # 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[0]['mtu'] + 2, fragmentation=False)
231
232 # ping with max mtu of 2 networks succeeds when
233 # fragmentation is enabled
234 self.check_remote_connectivity(
235 server_ssh_client, fip2['fixed_ip_address'],
236 mtu=self.networks[1]['mtu'])
237
238 # ping with max mtu of 2 networks fails when fragmentation is disabled
239 self.check_remote_connectivity(
240 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
241 mtu=self.networks[1]['mtu'], fragmentation=False)