blob: fa6bc62970629935f17b0f250497e04a5dd37c16 [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()
Roman Safronova92aa4e2019-02-19 18:51:53 +0200161 supported_type_drivers = ['vxlan', 'geneve']
162 if not any(type_driver in supported_type_drivers for type_driver in
163 config.CONF.neutron_plugin_options.available_type_drivers):
164 raise cls.skipException(
165 "Neither VXLAN nor GENEVE type_driver is enabled")
Dongcan Yeee300042018-01-10 05:38:35 +0000166
167 @classmethod
168 @utils.requires_ext(extension="net-mtu-writable", service="network")
169 def resource_setup(cls):
170 super(NetworkWritableMtuTest, cls).resource_setup()
171
172 def _create_setup(self):
173 self.admin_client = self.os_admin.network_client
Yariv Rachmani94970882018-03-04 11:35:17 +0200174 for test_net in self._get_network_params():
175 test_net['tenant_id'] = self.client.tenant_id
176 test_net['name'] = data_utils.rand_name('net')
177 cidr = None if 'cidr' not in test_net else test_net.pop('cidr')
178 network = self.admin_client.create_network(**test_net)[
Dongcan Yeee300042018-01-10 05:38:35 +0000179 'network']
180 self.networks.append(network)
181 self.addCleanup(self.admin_client.delete_network, network['id'])
Yariv Rachmani94970882018-03-04 11:35:17 +0200182 subnet = self.create_subnet(network, cidr=cidr)
Dongcan Yeee300042018-01-10 05:38:35 +0000183 self.create_router_interface(self.router['id'], subnet['id'])
184 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
185 self.router['id'], subnet['id'])
186
Yariv Rachmani94970882018-03-04 11:35:17 +0200187 # update network mtu
Dongcan Yeee300042018-01-10 05:38:35 +0000188 net_mtu = self.admin_client.show_network(
189 self.networks[0]['id'])['network']['mtu']
190 self.admin_client.update_network(self.networks[0]['id'],
Yariv Rachmani94970882018-03-04 11:35:17 +0200191 mtu=(net_mtu - 1))
Dongcan Yeee300042018-01-10 05:38:35 +0000192 self.networks[0]['mtu'] = (
193 self.admin_client.show_network(
194 self.networks[0]['id'])['network']['mtu'])
195
196 # check that MTUs are different for 2 networks
197 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
198 self.networks.sort(key=lambda net: net['mtu'])
199 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200200 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000201 server_ssh_client1 = ssh.Client(
202 self.floating_ips[0]['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200203 CONF.neutron_plugin_options.advanced_image_ssh_user,
Dongcan Yeee300042018-01-10 05:38:35 +0000204 pkey=self.keypair['private_key'])
205 server2, fip2 = self.create_pingable_vm(self.networks[1],
Yariv Rachmani94970882018-03-04 11:35:17 +0200206 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000207 server_ssh_client2 = ssh.Client(
208 self.floating_ips[0]['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200209 CONF.neutron_plugin_options.advanced_image_ssh_user,
Dongcan Yeee300042018-01-10 05:38:35 +0000210 pkey=self.keypair['private_key'])
211 for fip in (fip1, fip2):
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200212 self.check_connectivity(
213 fip['floating_ip_address'],
214 CONF.neutron_plugin_options.advanced_image_ssh_user,
215 self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000216 return server_ssh_client1, fip1, server_ssh_client2, fip2
217
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200218 @testtools.skipUnless(
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200219 CONF.neutron_plugin_options.advanced_image_ref,
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200220 "Advanced image is required to run this test.")
Dongcan Yeee300042018-01-10 05:38:35 +0000221 @decorators.idempotent_id('bc470200-d8f4-4f07-b294-1b4cbaaa35b9')
222 def test_connectivity_min_max_mtu(self):
223 server_ssh_client, _, _, fip2 = self._create_setup()
224 # ping with min mtu of 2 networks succeeds even when
225 # fragmentation is disabled
226 self.check_remote_connectivity(
227 server_ssh_client, fip2['fixed_ip_address'],
228 mtu=self.networks[0]['mtu'], fragmentation=False)
229
230 # ping with the size above min mtu of 2 networks
231 # fails when fragmentation is disabled
232 self.check_remote_connectivity(
233 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
234 mtu=self.networks[0]['mtu'] + 2, fragmentation=False)
235
236 # ping with max mtu of 2 networks succeeds when
237 # fragmentation is enabled
238 self.check_remote_connectivity(
239 server_ssh_client, fip2['fixed_ip_address'],
240 mtu=self.networks[1]['mtu'])
241
242 # ping with max mtu of 2 networks fails when fragmentation is disabled
243 self.check_remote_connectivity(
244 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
245 mtu=self.networks[1]['mtu'], fragmentation=False)