blob: 0e3afe9d45a8f5eac90895e74f47a53d18b9c563 [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
22
23from neutron_tempest_plugin.common import ssh
24from neutron_tempest_plugin import config
25from neutron_tempest_plugin.scenario import base
26from neutron_tempest_plugin.scenario import constants
27
28CONF = config.CONF
29
30
31class NetworkMtuBaseTest(base.BaseTempestTestCase):
Chandan Kumarc125fd12017-11-15 19:41:01 +053032
33 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053034 def resource_setup(cls):
35 super(NetworkMtuBaseTest, cls).resource_setup()
36 # setup basic topology for servers we can log into it
37 cls.router = cls.create_router_by_client()
38 cls.keypair = cls.create_keypair()
39 cls.secgroup = cls.os_primary.network_client.create_security_group(
40 name='secgroup_mtu')
41 cls.security_groups.append(cls.secgroup['security_group'])
42 cls.create_loginable_secgroup_rule(
43 secgroup_id=cls.secgroup['security_group']['id'])
44 cls.create_pingable_secgroup_rule(
45 secgroup_id=cls.secgroup['security_group']['id'])
46
Dongcan Yeee300042018-01-10 05:38:35 +000047 def create_pingable_vm(self, net, keypair, secgroup):
48 server = self.create_server(
49 flavor_ref=CONF.compute.flavor_ref,
50 image_ref=CONF.compute.image_ref,
51 key_name=keypair['name'],
52 networks=[{'uuid': net['id']}],
53 security_groups=[{'name': secgroup[
54 'security_group']['name']}])
55 waiters.wait_for_server_status(
56 self.os_primary.servers_client, server['server']['id'],
57 constants.SERVER_STATUS_ACTIVE)
58 port = self.client.list_ports(
59 network_id=net['id'], device_id=server['server']['id'])['ports'][0]
60 fip = self.create_and_associate_floatingip(port['id'])
61 return server, fip
62
Yariv Rachmani94970882018-03-04 11:35:17 +020063 def _get_network_params(self):
64 return jsonutils.loads(CONF.neutron_plugin_options.test_mtu_networks)
65
Dongcan Yeee300042018-01-10 05:38:35 +000066
67class NetworkMtuTest(NetworkMtuBaseTest):
68 credentials = ['primary', 'admin']
69 servers = []
70 networks = []
71
72 @classmethod
73 def skip_checks(cls):
74 super(NetworkMtuTest, cls).skip_checks()
75 if ("vxlan" not in
Brian Haley33ef4602018-04-26 14:37:49 -040076 config.CONF.neutron_plugin_options.available_type_drivers or
77 "gre" not in
Dongcan Yeee300042018-01-10 05:38:35 +000078 config.CONF.neutron_plugin_options.available_type_drivers):
79 raise cls.skipException("GRE or VXLAN type_driver is not enabled")
80
81 @classmethod
82 @utils.requires_ext(extension=provider_net.ALIAS, service="network")
83 def resource_setup(cls):
84 super(NetworkMtuTest, cls).resource_setup()
85
Chandan Kumarc125fd12017-11-15 19:41:01 +053086 def _create_setup(self):
87 self.admin_client = self.os_admin.network_client
88 net_kwargs = {'tenant_id': self.client.tenant_id}
Federico Ressi0ddc93b2018-04-09 12:01:48 +020089 for net_type in ['vxlan', 'gre']:
Chandan Kumarc125fd12017-11-15 19:41:01 +053090 net_kwargs['name'] = '-'.join([net_type, 'net'])
91 net_kwargs['provider:network_type'] = net_type
92 network = self.admin_client.create_network(**net_kwargs)[
93 'network']
94 self.networks.append(network)
95 self.addCleanup(self.admin_client.delete_network, network['id'])
Federico Ressi0ddc93b2018-04-09 12:01:48 +020096 subnet = self.create_subnet(network)
Chandan Kumarc125fd12017-11-15 19:41:01 +053097 self.create_router_interface(self.router['id'], subnet['id'])
98 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
99 self.router['id'], subnet['id'])
100 # check that MTUs are different for 2 networks
101 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
102 self.networks.sort(key=lambda net: net['mtu'])
Dongcan Yeee300042018-01-10 05:38:35 +0000103 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200104 self.keypair, self.secgroup)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530105 server_ssh_client1 = ssh.Client(
106 self.floating_ips[0]['floating_ip_address'],
107 CONF.validation.image_ssh_user,
108 pkey=self.keypair['private_key'])
Dongcan Yeee300042018-01-10 05:38:35 +0000109 server2, fip2 = self.create_pingable_vm(self.networks[1],
Yariv Rachmani94970882018-03-04 11:35:17 +0200110 self.keypair, self.secgroup)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530111 server_ssh_client2 = ssh.Client(
112 self.floating_ips[0]['floating_ip_address'],
113 CONF.validation.image_ssh_user,
114 pkey=self.keypair['private_key'])
115 for fip in (fip1, fip2):
116 self.check_connectivity(fip['floating_ip_address'],
117 CONF.validation.image_ssh_user,
118 self.keypair['private_key'])
119 return server_ssh_client1, fip1, server_ssh_client2, fip2
120
Chandan Kumarc125fd12017-11-15 19:41:01 +0530121 @decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a273d9d344')
122 def test_connectivity_min_max_mtu(self):
123 server_ssh_client, _, _, fip2 = self._create_setup()
124 # ping with min mtu of 2 networks succeeds even when
125 # fragmentation is disabled
126 self.check_remote_connectivity(
127 server_ssh_client, fip2['fixed_ip_address'],
128 mtu=self.networks[0]['mtu'], fragmentation=False)
129
130 # ping with the size above min mtu of 2 networks
131 # fails when fragmentation is disabled
132 self.check_remote_connectivity(
133 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
134 mtu=self.networks[0]['mtu'] + 1, fragmentation=False)
135
136 # ping with max mtu of 2 networks succeeds when
137 # fragmentation is enabled
138 self.check_remote_connectivity(
139 server_ssh_client, fip2['fixed_ip_address'],
140 mtu=self.networks[1]['mtu'])
141
142 # ping with max mtu of 2 networks fails when fragmentation is disabled
143 self.check_remote_connectivity(
144 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
145 mtu=self.networks[1]['mtu'], fragmentation=False)
Dongcan Yeee300042018-01-10 05:38:35 +0000146
147
148class NetworkWritableMtuTest(NetworkMtuBaseTest):
149 credentials = ['primary', 'admin']
150 servers = []
151 networks = []
152
153 @classmethod
154 def skip_checks(cls):
155 super(NetworkWritableMtuTest, cls).skip_checks()
156 if ("vxlan" not in
Yariv Rachmani94970882018-03-04 11:35:17 +0200157 config.CONF.neutron_plugin_options.available_type_drivers):
Dongcan Yeee300042018-01-10 05:38:35 +0000158 raise cls.skipException("VXLAN type_driver is not enabled")
159
160 @classmethod
161 @utils.requires_ext(extension="net-mtu-writable", service="network")
162 def resource_setup(cls):
163 super(NetworkWritableMtuTest, cls).resource_setup()
164
165 def _create_setup(self):
166 self.admin_client = self.os_admin.network_client
Yariv Rachmani94970882018-03-04 11:35:17 +0200167 for test_net in self._get_network_params():
168 test_net['tenant_id'] = self.client.tenant_id
169 test_net['name'] = data_utils.rand_name('net')
170 cidr = None if 'cidr' not in test_net else test_net.pop('cidr')
171 network = self.admin_client.create_network(**test_net)[
Dongcan Yeee300042018-01-10 05:38:35 +0000172 'network']
173 self.networks.append(network)
174 self.addCleanup(self.admin_client.delete_network, network['id'])
Yariv Rachmani94970882018-03-04 11:35:17 +0200175 subnet = self.create_subnet(network, cidr=cidr)
Dongcan Yeee300042018-01-10 05:38:35 +0000176 self.create_router_interface(self.router['id'], subnet['id'])
177 self.addCleanup(self.client.remove_router_interface_with_subnet_id,
178 self.router['id'], subnet['id'])
179
Yariv Rachmani94970882018-03-04 11:35:17 +0200180 # update network mtu
Dongcan Yeee300042018-01-10 05:38:35 +0000181 net_mtu = self.admin_client.show_network(
182 self.networks[0]['id'])['network']['mtu']
183 self.admin_client.update_network(self.networks[0]['id'],
Yariv Rachmani94970882018-03-04 11:35:17 +0200184 mtu=(net_mtu - 1))
Dongcan Yeee300042018-01-10 05:38:35 +0000185 self.networks[0]['mtu'] = (
186 self.admin_client.show_network(
187 self.networks[0]['id'])['network']['mtu'])
188
189 # check that MTUs are different for 2 networks
190 self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu'])
191 self.networks.sort(key=lambda net: net['mtu'])
192 server1, fip1 = self.create_pingable_vm(self.networks[0],
Yariv Rachmani94970882018-03-04 11:35:17 +0200193 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000194 server_ssh_client1 = ssh.Client(
195 self.floating_ips[0]['floating_ip_address'],
196 CONF.validation.image_ssh_user,
197 pkey=self.keypair['private_key'])
198 server2, fip2 = self.create_pingable_vm(self.networks[1],
Yariv Rachmani94970882018-03-04 11:35:17 +0200199 self.keypair, self.secgroup)
Dongcan Yeee300042018-01-10 05:38:35 +0000200 server_ssh_client2 = ssh.Client(
201 self.floating_ips[0]['floating_ip_address'],
202 CONF.validation.image_ssh_user,
203 pkey=self.keypair['private_key'])
204 for fip in (fip1, fip2):
205 self.check_connectivity(fip['floating_ip_address'],
206 CONF.validation.image_ssh_user,
207 self.keypair['private_key'])
208 return server_ssh_client1, fip1, server_ssh_client2, fip2
209
210 @decorators.idempotent_id('bc470200-d8f4-4f07-b294-1b4cbaaa35b9')
211 def test_connectivity_min_max_mtu(self):
212 server_ssh_client, _, _, fip2 = self._create_setup()
213 # ping with min mtu of 2 networks succeeds even when
214 # fragmentation is disabled
215 self.check_remote_connectivity(
216 server_ssh_client, fip2['fixed_ip_address'],
217 mtu=self.networks[0]['mtu'], fragmentation=False)
218
219 # ping with the size above min mtu of 2 networks
220 # fails when fragmentation is disabled
221 self.check_remote_connectivity(
222 server_ssh_client, fip2['fixed_ip_address'], should_succeed=False,
223 mtu=self.networks[0]['mtu'] + 2, fragmentation=False)
224
225 # ping with max mtu of 2 networks succeeds when
226 # fragmentation is enabled
227 self.check_remote_connectivity(
228 server_ssh_client, fip2['fixed_ip_address'],
229 mtu=self.networks[1]['mtu'])
230
231 # ping with max mtu of 2 networks 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[1]['mtu'], fragmentation=False)