blob: 941d499e021ada718546d8be6ff91011650b6211 [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(
Slawek Kaplonskida17f002018-10-11 18:35:23 +020050 flavor_ref=CONF.neutron_plugin_options.advanced_image_flavor_ref,
51 image_ref=CONF.neutron_plugin_options.advanced_image_ref,
Dongcan Yeee300042018-01-10 05:38:35 +000052 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'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200108 CONF.neutron_plugin_options.advanced_image_ssh_user,
Chandan Kumarc125fd12017-11-15 19:41:01 +0530109 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'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200114 CONF.neutron_plugin_options.advanced_image_ssh_user,
Chandan Kumarc125fd12017-11-15 19:41:01 +0530115 pkey=self.keypair['private_key'])
116 for fip in (fip1, fip2):
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200117 self.check_connectivity(
118 fip['floating_ip_address'],
119 CONF.neutron_plugin_options.advanced_image_ssh_user,
120 self.keypair['private_key'])
Chandan Kumarc125fd12017-11-15 19:41:01 +0530121 return server_ssh_client1, fip1, server_ssh_client2, fip2
122
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200123 @testtools.skipUnless(
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200124 CONF.neutron_plugin_options.advanced_image_ref,
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200125 "Advanced image is required to run this test.")
Chandan Kumarc125fd12017-11-15 19:41:01 +0530126 @decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a273d9d344')
127 def test_connectivity_min_max_mtu(self):
128 server_ssh_client, _, _, fip2 = self._create_setup()
129 # ping with min mtu of 2 networks succeeds even when
130 # fragmentation is disabled
131 self.check_remote_connectivity(
132 server_ssh_client, fip2['fixed_ip_address'],
133 mtu=self.networks[0]['mtu'], fragmentation=False)
134
135 # ping with the size above min mtu of 2 networks
136 # fails when fragmentation is disabled
137 self.check_remote_connectivity(
138 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
139 mtu=self.networks[0]['mtu'] + 1, fragmentation=False)
140
141 # ping with max mtu of 2 networks succeeds when
142 # fragmentation is enabled
143 self.check_remote_connectivity(
144 server_ssh_client, fip2['fixed_ip_address'],
145 mtu=self.networks[1]['mtu'])
146
147 # ping with max mtu of 2 networks fails when fragmentation is disabled
148 self.check_remote_connectivity(
149 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
150 mtu=self.networks[1]['mtu'], fragmentation=False)
Dongcan Yeee300042018-01-10 05:38:35 +0000151
152
153class NetworkWritableMtuTest(NetworkMtuBaseTest):
154 credentials = ['primary', 'admin']
155 servers = []
156 networks = []
157
158 @classmethod
159 def skip_checks(cls):
160 super(NetworkWritableMtuTest, cls).skip_checks()
161 if ("vxlan" not in
Yariv Rachmani94970882018-03-04 11:35:17 +0200162 config.CONF.neutron_plugin_options.available_type_drivers):
Dongcan Yeee300042018-01-10 05:38:35 +0000163 raise cls.skipException("VXLAN type_driver is not enabled")
164
165 @classmethod
166 @utils.requires_ext(extension="net-mtu-writable", service="network")
167 def resource_setup(cls):
168 super(NetworkWritableMtuTest, cls).resource_setup()
169
170 def _create_setup(self):
171 self.admin_client = self.os_admin.network_client
Yariv Rachmani94970882018-03-04 11:35:17 +0200172 for test_net in self._get_network_params():
173 test_net['tenant_id'] = self.client.tenant_id
174 test_net['name'] = data_utils.rand_name('net')
175 cidr = None if 'cidr' not in test_net else test_net.pop('cidr')
176 network = self.admin_client.create_network(**test_net)[
Dongcan Yeee300042018-01-10 05:38:35 +0000177 'network']
178 self.networks.append(network)
179 self.addCleanup(self.admin_client.delete_network, network['id'])
Yariv Rachmani94970882018-03-04 11:35:17 +0200180 subnet = self.create_subnet(network, cidr=cidr)
Dongcan Yeee300042018-01-10 05:38:35 +0000181 self.create_router_interface(self.router['id'], subnet['id'])
182 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
183 self.router['id'], subnet['id'])
184
Yariv Rachmani94970882018-03-04 11:35:17 +0200185 # update network mtu
Dongcan Yeee300042018-01-10 05:38:35 +0000186 net_mtu = self.admin_client.show_network(
187 self.networks[0]['id'])['network']['mtu']
188 self.admin_client.update_network(self.networks[0]['id'],
Yariv Rachmani94970882018-03-04 11:35:17 +0200189 mtu=(net_mtu - 1))
Dongcan Yeee300042018-01-10 05:38:35 +0000190 self.networks[0]['mtu'] = (
191 self.admin_client.show_network(
192 self.networks[0]['id'])['network']['mtu'])
193
194 # check that MTUs are different for 2 networks
195 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
196 self.networks.sort(key=lambda net: net['mtu'])
197 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200198 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000199 server_ssh_client1 = ssh.Client(
200 self.floating_ips[0]['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200201 CONF.neutron_plugin_options.advanced_image_ssh_user,
Dongcan Yeee300042018-01-10 05:38:35 +0000202 pkey=self.keypair['private_key'])
203 server2, fip2 = self.create_pingable_vm(self.networks[1],
Yariv Rachmani94970882018-03-04 11:35:17 +0200204 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000205 server_ssh_client2 = ssh.Client(
206 self.floating_ips[0]['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200207 CONF.neutron_plugin_options.advanced_image_ssh_user,
Dongcan Yeee300042018-01-10 05:38:35 +0000208 pkey=self.keypair['private_key'])
209 for fip in (fip1, fip2):
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200210 self.check_connectivity(
211 fip['floating_ip_address'],
212 CONF.neutron_plugin_options.advanced_image_ssh_user,
213 self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000214 return server_ssh_client1, fip1, server_ssh_client2, fip2
215
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200216 @testtools.skipUnless(
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200217 CONF.neutron_plugin_options.advanced_image_ref,
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200218 "Advanced image is required to run this test.")
Dongcan Yeee300042018-01-10 05:38:35 +0000219 @decorators.idempotent_id('bc470200-d8f4-4f07-b294-1b4cbaaa35b9')
220 def test_connectivity_min_max_mtu(self):
221 server_ssh_client, _, _, fip2 = self._create_setup()
222 # ping with min mtu of 2 networks succeeds even when
223 # fragmentation is disabled
224 self.check_remote_connectivity(
225 server_ssh_client, fip2['fixed_ip_address'],
226 mtu=self.networks[0]['mtu'], fragmentation=False)
227
228 # ping with the size above min mtu of 2 networks
229 # fails when fragmentation is disabled
230 self.check_remote_connectivity(
231 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
232 mtu=self.networks[0]['mtu'] + 2, fragmentation=False)
233
234 # ping with max mtu of 2 networks succeeds when
235 # fragmentation is enabled
236 self.check_remote_connectivity(
237 server_ssh_client, fip2['fixed_ip_address'],
238 mtu=self.networks[1]['mtu'])
239
240 # ping with max mtu of 2 networks fails when fragmentation is disabled
241 self.check_remote_connectivity(
242 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
243 mtu=self.networks[1]['mtu'], fragmentation=False)