blob: 6f4fd80986d0feece3dba8d05893ecb32b20bfd2 [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
Roman Safronov561cf622019-03-04 18:56:49 +020017from oslo_log import log
Yariv Rachmani94970882018-03-04 11:35:17 +020018from oslo_serialization import jsonutils
Chandan Kumarc125fd12017-11-15 19:41:01 +053019from tempest.common import utils
20from tempest.common import waiters
Dongcan Yeee300042018-01-10 05:38:35 +000021from tempest.lib.common.utils import data_utils
Chandan Kumarc125fd12017-11-15 19:41:01 +053022from tempest.lib import decorators
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +020023import testtools
Chandan Kumarc125fd12017-11-15 19:41:01 +053024
25from neutron_tempest_plugin.common import ssh
26from neutron_tempest_plugin import config
27from neutron_tempest_plugin.scenario import base
28from neutron_tempest_plugin.scenario import constants
29
30CONF = config.CONF
Roman Safronov561cf622019-03-04 18:56:49 +020031LOG = log.getLogger(__name__)
Chandan Kumarc125fd12017-11-15 19:41:01 +053032
33
34class NetworkMtuBaseTest(base.BaseTempestTestCase):
Chandan Kumarc125fd12017-11-15 19:41:01 +053035
36 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053037 def resource_setup(cls):
38 super(NetworkMtuBaseTest, cls).resource_setup()
39 # setup basic topology for servers we can log into it
40 cls.router = cls.create_router_by_client()
41 cls.keypair = cls.create_keypair()
42 cls.secgroup = cls.os_primary.network_client.create_security_group(
43 name='secgroup_mtu')
44 cls.security_groups.append(cls.secgroup['security_group'])
45 cls.create_loginable_secgroup_rule(
46 secgroup_id=cls.secgroup['security_group']['id'])
47 cls.create_pingable_secgroup_rule(
48 secgroup_id=cls.secgroup['security_group']['id'])
Renjing Xiaoe6e4b892025-12-23 12:46:10 +000049 cls.setup_advanced_image()
Chandan Kumarc125fd12017-11-15 19:41:01 +053050
Dongcan Yeee300042018-01-10 05:38:35 +000051 def create_pingable_vm(self, net, keypair, secgroup):
52 server = self.create_server(
Renjing Xiaoe6e4b892025-12-23 12:46:10 +000053 flavor_ref=self.flavor_ref,
54 image_ref=self.image_ref,
Dongcan Yeee300042018-01-10 05:38:35 +000055 key_name=keypair['name'],
56 networks=[{'uuid': net['id']}],
57 security_groups=[{'name': secgroup[
58 'security_group']['name']}])
59 waiters.wait_for_server_status(
60 self.os_primary.servers_client, server['server']['id'],
61 constants.SERVER_STATUS_ACTIVE)
62 port = self.client.list_ports(
63 network_id=net['id'], device_id=server['server']['id'])['ports'][0]
Federico Ressi3dfa94c2018-07-06 09:46:39 +020064 fip = self.create_floatingip(port=port)
Dongcan Yeee300042018-01-10 05:38:35 +000065 return server, fip
66
Yariv Rachmani94970882018-03-04 11:35:17 +020067 def _get_network_params(self):
68 return jsonutils.loads(CONF.neutron_plugin_options.test_mtu_networks)
69
Dongcan Yeee300042018-01-10 05:38:35 +000070
71class NetworkMtuTest(NetworkMtuBaseTest):
72 credentials = ['primary', 'admin']
73 servers = []
74 networks = []
75
76 @classmethod
77 def skip_checks(cls):
78 super(NetworkMtuTest, cls).skip_checks()
79 if ("vxlan" not in
Brian Haley33ef4602018-04-26 14:37:49 -040080 config.CONF.neutron_plugin_options.available_type_drivers or
81 "gre" not in
Dongcan Yeee300042018-01-10 05:38:35 +000082 config.CONF.neutron_plugin_options.available_type_drivers):
83 raise cls.skipException("GRE or VXLAN type_driver is not enabled")
84
85 @classmethod
86 @utils.requires_ext(extension=provider_net.ALIAS, service="network")
87 def resource_setup(cls):
88 super(NetworkMtuTest, cls).resource_setup()
89
Chandan Kumarc125fd12017-11-15 19:41:01 +053090 def _create_setup(self):
91 self.admin_client = self.os_admin.network_client
Takashi Kajinamida451772023-03-22 00:19:39 +090092 net_kwargs = {'tenant_id': self.client.project_id}
Federico Ressi0ddc93b2018-04-09 12:01:48 +020093 for net_type in ['vxlan', 'gre']:
Chandan Kumarc125fd12017-11-15 19:41:01 +053094 net_kwargs['name'] = '-'.join([net_type, 'net'])
95 net_kwargs['provider:network_type'] = net_type
96 network = self.admin_client.create_network(**net_kwargs)[
97 'network']
98 self.networks.append(network)
99 self.addCleanup(self.admin_client.delete_network, network['id'])
Federico Ressi0ddc93b2018-04-09 12:01:48 +0200100 subnet = self.create_subnet(network)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530101 self.create_router_interface(self.router['id'], subnet['id'])
102 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
103 self.router['id'], subnet['id'])
104 # check that MTUs are different for 2 networks
105 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
106 self.networks.sort(key=lambda net: net['mtu'])
Dongcan Yeee300042018-01-10 05:38:35 +0000107 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200108 self.keypair, self.secgroup)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530109 server_ssh_client1 = ssh.Client(
110 self.floating_ips[0]['floating_ip_address'],
Yariv Rachmanifa1081a2018-11-21 12:46:57 +0200111 self.username, pkey=self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000112 server2, fip2 = self.create_pingable_vm(self.networks[1],
Yariv Rachmani94970882018-03-04 11:35:17 +0200113 self.keypair, self.secgroup)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530114 server_ssh_client2 = ssh.Client(
115 self.floating_ips[0]['floating_ip_address'],
Yariv Rachmanifa1081a2018-11-21 12:46:57 +0200116 self.username, pkey=self.keypair['private_key'])
Chandan Kumarc125fd12017-11-15 19:41:01 +0530117 for fip in (fip1, fip2):
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200118 self.check_connectivity(
119 fip['floating_ip_address'],
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100120 self.username, self.keypair['private_key'],
121 servers=[server1, server2])
Chandan Kumarc125fd12017-11-15 19:41:01 +0530122 return server_ssh_client1, fip1, server_ssh_client2, fip2
123
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200124 @testtools.skipUnless(
Yariv Rachmanifa1081a2018-11-21 12:46:57 +0200125 (CONF.neutron_plugin_options.advanced_image_ref or
126 CONF.neutron_plugin_options.default_image_is_advanced),
127 "Advanced image is required to run this test.")
Chandan Kumarc125fd12017-11-15 19:41:01 +0530128 @decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a273d9d344')
129 def test_connectivity_min_max_mtu(self):
130 server_ssh_client, _, _, fip2 = self._create_setup()
131 # ping with min mtu of 2 networks succeeds even when
132 # fragmentation is disabled
133 self.check_remote_connectivity(
134 server_ssh_client, fip2['fixed_ip_address'],
135 mtu=self.networks[0]['mtu'], fragmentation=False)
136
137 # ping with the size above min mtu of 2 networks
138 # 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[0]['mtu'] + 1, fragmentation=False)
142
143 # ping with max mtu of 2 networks succeeds when
144 # fragmentation is enabled
145 self.check_remote_connectivity(
146 server_ssh_client, fip2['fixed_ip_address'],
147 mtu=self.networks[1]['mtu'])
148
149 # ping with max mtu of 2 networks fails when fragmentation is disabled
150 self.check_remote_connectivity(
151 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
152 mtu=self.networks[1]['mtu'], fragmentation=False)
Dongcan Yeee300042018-01-10 05:38:35 +0000153
154
155class NetworkWritableMtuTest(NetworkMtuBaseTest):
156 credentials = ['primary', 'admin']
157 servers = []
158 networks = []
159
160 @classmethod
Dongcan Yeee300042018-01-10 05:38:35 +0000161 @utils.requires_ext(extension="net-mtu-writable", service="network")
162 def resource_setup(cls):
163 super(NetworkWritableMtuTest, cls).resource_setup()
Roman Safronov9be93752024-09-17 14:57:48 +0300164 if cls.is_driver_ovn:
165 raise cls.skipException("East/west icmp fragmentation is not "
166 "supported with ML2/OVN")
Dongcan Yeee300042018-01-10 05:38:35 +0000167
168 def _create_setup(self):
169 self.admin_client = self.os_admin.network_client
Yariv Rachmani94970882018-03-04 11:35:17 +0200170 for test_net in self._get_network_params():
Takashi Kajinamida451772023-03-22 00:19:39 +0900171 test_net['tenant_id'] = self.client.project_id
Yariv Rachmani94970882018-03-04 11:35:17 +0200172 test_net['name'] = data_utils.rand_name('net')
173 cidr = None if 'cidr' not in test_net else test_net.pop('cidr')
174 network = self.admin_client.create_network(**test_net)[
Dongcan Yeee300042018-01-10 05:38:35 +0000175 'network']
176 self.networks.append(network)
177 self.addCleanup(self.admin_client.delete_network, network['id'])
Yariv Rachmani94970882018-03-04 11:35:17 +0200178 subnet = self.create_subnet(network, cidr=cidr)
Dongcan Yeee300042018-01-10 05:38:35 +0000179 self.create_router_interface(self.router['id'], subnet['id'])
180 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
181 self.router['id'], subnet['id'])
182
Yariv Rachmani94970882018-03-04 11:35:17 +0200183 # update network mtu
Dongcan Yeee300042018-01-10 05:38:35 +0000184 net_mtu = self.admin_client.show_network(
185 self.networks[0]['id'])['network']['mtu']
186 self.admin_client.update_network(self.networks[0]['id'],
Yariv Rachmani94970882018-03-04 11:35:17 +0200187 mtu=(net_mtu - 1))
Dongcan Yeee300042018-01-10 05:38:35 +0000188 self.networks[0]['mtu'] = (
189 self.admin_client.show_network(
190 self.networks[0]['id'])['network']['mtu'])
191
192 # check that MTUs are different for 2 networks
193 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
194 self.networks.sort(key=lambda net: net['mtu'])
195 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200196 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000197 server_ssh_client1 = ssh.Client(
198 self.floating_ips[0]['floating_ip_address'],
Yariv Rachmanifa1081a2018-11-21 12:46:57 +0200199 self.username, pkey=self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000200 server2, fip2 = self.create_pingable_vm(self.networks[1],
Yariv Rachmani94970882018-03-04 11:35:17 +0200201 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000202 server_ssh_client2 = ssh.Client(
203 self.floating_ips[0]['floating_ip_address'],
Yariv Rachmanifa1081a2018-11-21 12:46:57 +0200204 self.username, pkey=self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000205 for fip in (fip1, fip2):
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200206 self.check_connectivity(
207 fip['floating_ip_address'],
Yariv Rachmanifa1081a2018-11-21 12:46:57 +0200208 self.username, self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000209 return server_ssh_client1, fip1, server_ssh_client2, fip2
210
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200211 @testtools.skipUnless(
Yariv Rachmanifa1081a2018-11-21 12:46:57 +0200212 (CONF.neutron_plugin_options.advanced_image_ref or
213 CONF.neutron_plugin_options.default_image_is_advanced),
214 "Advanced image is required to run this test.")
Dongcan Yeee300042018-01-10 05:38:35 +0000215 @decorators.idempotent_id('bc470200-d8f4-4f07-b294-1b4cbaaa35b9')
216 def test_connectivity_min_max_mtu(self):
217 server_ssh_client, _, _, fip2 = self._create_setup()
Takashi Kajinami435ff6f2024-11-16 15:33:27 +0900218 log_msg = ("Ping with %(mtu_size)s MTU of 2 networks. "
219 "Fragmentation is %(fragmentation_state)s. "
220 "Expected result: ping %(ping_status)s")
Roman Safronov561cf622019-03-04 18:56:49 +0200221
Dongcan Yeee300042018-01-10 05:38:35 +0000222 # ping with min mtu of 2 networks succeeds even when
223 # fragmentation is disabled
Takashi Kajinami435ff6f2024-11-16 15:33:27 +0900224 LOG.debug(log_msg, mtu_size='minimal',
225 fragmentation_state='disabled', ping_status='succeeded')
Dongcan Yeee300042018-01-10 05:38:35 +0000226 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
Takashi Kajinami435ff6f2024-11-16 15:33:27 +0900232 LOG.debug(log_msg, mtu_size='size above minimal',
233 fragmentation_state='disabled', ping_status='failed')
Dongcan Yeee300042018-01-10 05:38:35 +0000234 self.check_remote_connectivity(
235 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
236 mtu=self.networks[0]['mtu'] + 2, fragmentation=False)
237
238 # ping with max mtu of 2 networks succeeds when
239 # fragmentation is enabled
Takashi Kajinami435ff6f2024-11-16 15:33:27 +0900240 LOG.debug(log_msg, mtu_size='maximal',
241 fragmentation_state='enabled', ping_status='succeeded')
Dongcan Yeee300042018-01-10 05:38:35 +0000242 self.check_remote_connectivity(
243 server_ssh_client, fip2['fixed_ip_address'],
244 mtu=self.networks[1]['mtu'])
245
246 # ping with max mtu of 2 networks fails when fragmentation is disabled
Takashi Kajinami435ff6f2024-11-16 15:33:27 +0900247 LOG.debug(log_msg, mtu_size='maximal',
248 fragmentation_state='disabled', ping_status='failed')
Dongcan Yeee300042018-01-10 05:38:35 +0000249 self.check_remote_connectivity(
250 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
251 mtu=self.networks[1]['mtu'], fragmentation=False)