blob: 71a77f4d09c07fa6bb5678cbf4978c1806bc431b [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'])
49
Dongcan Yeee300042018-01-10 05:38:35 +000050 def create_pingable_vm(self, net, keypair, secgroup):
51 server = self.create_server(
Slawek Kaplonskida17f002018-10-11 18:35:23 +020052 flavor_ref=CONF.neutron_plugin_options.advanced_image_flavor_ref,
53 image_ref=CONF.neutron_plugin_options.advanced_image_ref,
Dongcan Yeee300042018-01-10 05:38:35 +000054 key_name=keypair['name'],
55 networks=[{'uuid': net['id']}],
56 security_groups=[{'name': secgroup[
57 'security_group']['name']}])
58 waiters.wait_for_server_status(
59 self.os_primary.servers_client, server['server']['id'],
60 constants.SERVER_STATUS_ACTIVE)
61 port = self.client.list_ports(
62 network_id=net['id'], device_id=server['server']['id'])['ports'][0]
Federico Ressi3dfa94c2018-07-06 09:46:39 +020063 fip = self.create_floatingip(port=port)
Dongcan Yeee300042018-01-10 05:38:35 +000064 return server, fip
65
Yariv Rachmani94970882018-03-04 11:35:17 +020066 def _get_network_params(self):
67 return jsonutils.loads(CONF.neutron_plugin_options.test_mtu_networks)
68
Dongcan Yeee300042018-01-10 05:38:35 +000069
70class NetworkMtuTest(NetworkMtuBaseTest):
71 credentials = ['primary', 'admin']
72 servers = []
73 networks = []
74
75 @classmethod
76 def skip_checks(cls):
77 super(NetworkMtuTest, cls).skip_checks()
78 if ("vxlan" not in
Brian Haley33ef4602018-04-26 14:37:49 -040079 config.CONF.neutron_plugin_options.available_type_drivers or
80 "gre" not in
Dongcan Yeee300042018-01-10 05:38:35 +000081 config.CONF.neutron_plugin_options.available_type_drivers):
82 raise cls.skipException("GRE or VXLAN type_driver is not enabled")
83
84 @classmethod
85 @utils.requires_ext(extension=provider_net.ALIAS, service="network")
86 def resource_setup(cls):
87 super(NetworkMtuTest, cls).resource_setup()
88
Chandan Kumarc125fd12017-11-15 19:41:01 +053089 def _create_setup(self):
90 self.admin_client = self.os_admin.network_client
91 net_kwargs = {'tenant_id': self.client.tenant_id}
Federico Ressi0ddc93b2018-04-09 12:01:48 +020092 for net_type in ['vxlan', 'gre']:
Chandan Kumarc125fd12017-11-15 19:41:01 +053093 net_kwargs['name'] = '-'.join([net_type, 'net'])
94 net_kwargs['provider:network_type'] = net_type
95 network = self.admin_client.create_network(**net_kwargs)[
96 'network']
97 self.networks.append(network)
98 self.addCleanup(self.admin_client.delete_network, network['id'])
Federico Ressi0ddc93b2018-04-09 12:01:48 +020099 subnet = self.create_subnet(network)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530100 self.create_router_interface(self.router['id'], subnet['id'])
101 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
102 self.router['id'], subnet['id'])
103 # check that MTUs are different for 2 networks
104 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
105 self.networks.sort(key=lambda net: net['mtu'])
Dongcan Yeee300042018-01-10 05:38:35 +0000106 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200107 self.keypair, self.secgroup)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530108 server_ssh_client1 = ssh.Client(
109 self.floating_ips[0]['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200110 CONF.neutron_plugin_options.advanced_image_ssh_user,
Chandan Kumarc125fd12017-11-15 19:41:01 +0530111 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'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200116 CONF.neutron_plugin_options.advanced_image_ssh_user,
Chandan Kumarc125fd12017-11-15 19:41:01 +0530117 pkey=self.keypair['private_key'])
118 for fip in (fip1, fip2):
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200119 self.check_connectivity(
120 fip['floating_ip_address'],
121 CONF.neutron_plugin_options.advanced_image_ssh_user,
122 self.keypair['private_key'])
Chandan Kumarc125fd12017-11-15 19:41:01 +0530123 return server_ssh_client1, fip1, server_ssh_client2, fip2
124
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200125 @testtools.skipUnless(
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200126 CONF.neutron_plugin_options.advanced_image_ref,
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200127 "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
161 def skip_checks(cls):
162 super(NetworkWritableMtuTest, cls).skip_checks()
Roman Safronova92aa4e2019-02-19 18:51:53 +0200163 supported_type_drivers = ['vxlan', 'geneve']
164 if not any(type_driver in supported_type_drivers for type_driver in
165 config.CONF.neutron_plugin_options.available_type_drivers):
166 raise cls.skipException(
167 "Neither VXLAN nor GENEVE type_driver is enabled")
Dongcan Yeee300042018-01-10 05:38:35 +0000168
169 @classmethod
170 @utils.requires_ext(extension="net-mtu-writable", service="network")
171 def resource_setup(cls):
172 super(NetworkWritableMtuTest, cls).resource_setup()
173
174 def _create_setup(self):
175 self.admin_client = self.os_admin.network_client
Yariv Rachmani94970882018-03-04 11:35:17 +0200176 for test_net in self._get_network_params():
177 test_net['tenant_id'] = self.client.tenant_id
178 test_net['name'] = data_utils.rand_name('net')
179 cidr = None if 'cidr' not in test_net else test_net.pop('cidr')
180 network = self.admin_client.create_network(**test_net)[
Dongcan Yeee300042018-01-10 05:38:35 +0000181 'network']
182 self.networks.append(network)
183 self.addCleanup(self.admin_client.delete_network, network['id'])
Yariv Rachmani94970882018-03-04 11:35:17 +0200184 subnet = self.create_subnet(network, cidr=cidr)
Dongcan Yeee300042018-01-10 05:38:35 +0000185 self.create_router_interface(self.router['id'], subnet['id'])
186 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
187 self.router['id'], subnet['id'])
188
Yariv Rachmani94970882018-03-04 11:35:17 +0200189 # update network mtu
Dongcan Yeee300042018-01-10 05:38:35 +0000190 net_mtu = self.admin_client.show_network(
191 self.networks[0]['id'])['network']['mtu']
192 self.admin_client.update_network(self.networks[0]['id'],
Yariv Rachmani94970882018-03-04 11:35:17 +0200193 mtu=(net_mtu - 1))
Dongcan Yeee300042018-01-10 05:38:35 +0000194 self.networks[0]['mtu'] = (
195 self.admin_client.show_network(
196 self.networks[0]['id'])['network']['mtu'])
197
198 # check that MTUs are different for 2 networks
199 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
200 self.networks.sort(key=lambda net: net['mtu'])
201 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200202 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000203 server_ssh_client1 = ssh.Client(
204 self.floating_ips[0]['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200205 CONF.neutron_plugin_options.advanced_image_ssh_user,
Dongcan Yeee300042018-01-10 05:38:35 +0000206 pkey=self.keypair['private_key'])
207 server2, fip2 = self.create_pingable_vm(self.networks[1],
Yariv Rachmani94970882018-03-04 11:35:17 +0200208 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000209 server_ssh_client2 = ssh.Client(
210 self.floating_ips[0]['floating_ip_address'],
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200211 CONF.neutron_plugin_options.advanced_image_ssh_user,
Dongcan Yeee300042018-01-10 05:38:35 +0000212 pkey=self.keypair['private_key'])
213 for fip in (fip1, fip2):
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200214 self.check_connectivity(
215 fip['floating_ip_address'],
216 CONF.neutron_plugin_options.advanced_image_ssh_user,
217 self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000218 return server_ssh_client1, fip1, server_ssh_client2, fip2
219
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200220 @testtools.skipUnless(
Slawek Kaplonskida17f002018-10-11 18:35:23 +0200221 CONF.neutron_plugin_options.advanced_image_ref,
Slawek Kaplonski1cd4fb42018-08-10 15:03:32 +0200222 "Advanced image is required to run this test.")
Dongcan Yeee300042018-01-10 05:38:35 +0000223 @decorators.idempotent_id('bc470200-d8f4-4f07-b294-1b4cbaaa35b9')
224 def test_connectivity_min_max_mtu(self):
225 server_ssh_client, _, _, fip2 = self._create_setup()
Roman Safronov561cf622019-03-04 18:56:49 +0200226 log_msg = ("Ping with {mtu_size} MTU of 2 networks. Fragmentation is "
227 "{fragmentation_state}. Expected result: ping "
228 "{ping_status}")
229
Dongcan Yeee300042018-01-10 05:38:35 +0000230 # ping with min mtu of 2 networks succeeds even when
231 # fragmentation is disabled
Roman Safronov561cf622019-03-04 18:56:49 +0200232 LOG.debug(log_msg.format(mtu_size='minimal',
233 fragmentation_state='disabled', ping_status='succeeded'))
Dongcan Yeee300042018-01-10 05:38:35 +0000234 self.check_remote_connectivity(
235 server_ssh_client, fip2['fixed_ip_address'],
236 mtu=self.networks[0]['mtu'], fragmentation=False)
237
238 # ping with the size above min mtu of 2 networks
239 # fails when fragmentation is disabled
Roman Safronov561cf622019-03-04 18:56:49 +0200240 LOG.debug(log_msg.format(mtu_size='size above minimal',
241 fragmentation_state='disabled', ping_status='failed'))
Dongcan Yeee300042018-01-10 05:38:35 +0000242 self.check_remote_connectivity(
243 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
244 mtu=self.networks[0]['mtu'] + 2, fragmentation=False)
245
246 # ping with max mtu of 2 networks succeeds when
247 # fragmentation is enabled
Roman Safronov561cf622019-03-04 18:56:49 +0200248 LOG.debug(log_msg.format(mtu_size='maximal',
249 fragmentation_state='enabled', ping_status='succeeded'))
Dongcan Yeee300042018-01-10 05:38:35 +0000250 self.check_remote_connectivity(
251 server_ssh_client, fip2['fixed_ip_address'],
252 mtu=self.networks[1]['mtu'])
253
254 # ping with max mtu of 2 networks fails when fragmentation is disabled
Roman Safronov561cf622019-03-04 18:56:49 +0200255 LOG.debug(log_msg.format(mtu_size='maximal',
256 fragmentation_state='disabled', ping_status='failed'))
Dongcan Yeee300042018-01-10 05:38:35 +0000257 self.check_remote_connectivity(
258 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
259 mtu=self.networks[1]['mtu'], fragmentation=False)