Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 1 | # 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 15 | |
| 16 | from neutron_lib.api.definitions import provider_net |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 17 | from oslo_serialization import jsonutils |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 18 | from tempest.common import utils |
| 19 | from tempest.common import waiters |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 20 | from tempest.lib.common.utils import data_utils |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 21 | from tempest.lib import decorators |
Slawek Kaplonski | 1cd4fb4 | 2018-08-10 15:03:32 +0200 | [diff] [blame] | 22 | import testtools |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 23 | |
| 24 | from neutron_tempest_plugin.common import ssh |
| 25 | from neutron_tempest_plugin import config |
| 26 | from neutron_tempest_plugin.scenario import base |
| 27 | from neutron_tempest_plugin.scenario import constants |
| 28 | |
| 29 | CONF = config.CONF |
| 30 | |
| 31 | |
| 32 | class NetworkMtuBaseTest(base.BaseTempestTestCase): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 33 | |
| 34 | @classmethod |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 35 | 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 Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 48 | def create_pingable_vm(self, net, keypair, secgroup): |
| 49 | server = self.create_server( |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame^] | 50 | flavor_ref=CONF.neutron_plugin_options.advanced_image_flavor_ref, |
| 51 | image_ref=CONF.neutron_plugin_options.advanced_image_ref, |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 52 | 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 Ressi | 3dfa94c | 2018-07-06 09:46:39 +0200 | [diff] [blame] | 61 | fip = self.create_floatingip(port=port) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 62 | return server, fip |
| 63 | |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 64 | def _get_network_params(self): |
| 65 | return jsonutils.loads(CONF.neutron_plugin_options.test_mtu_networks) |
| 66 | |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 67 | |
| 68 | class 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 Haley | 33ef460 | 2018-04-26 14:37:49 -0400 | [diff] [blame] | 77 | config.CONF.neutron_plugin_options.available_type_drivers or |
| 78 | "gre" not in |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 79 | 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 87 | def _create_setup(self): |
| 88 | self.admin_client = self.os_admin.network_client |
| 89 | net_kwargs = {'tenant_id': self.client.tenant_id} |
Federico Ressi | 0ddc93b | 2018-04-09 12:01:48 +0200 | [diff] [blame] | 90 | for net_type in ['vxlan', 'gre']: |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 91 | 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 Ressi | 0ddc93b | 2018-04-09 12:01:48 +0200 | [diff] [blame] | 97 | subnet = self.create_subnet(network) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 98 | 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 Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 104 | server1, fip1 = self.create_pingable_vm(self.networks[0], |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 105 | self.keypair, self.secgroup) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 106 | server_ssh_client1 = ssh.Client( |
| 107 | self.floating_ips[0]['floating_ip_address'], |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame^] | 108 | CONF.neutron_plugin_options.advanced_image_ssh_user, |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 109 | pkey=self.keypair['private_key']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 110 | server2, fip2 = self.create_pingable_vm(self.networks[1], |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 111 | self.keypair, self.secgroup) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 112 | server_ssh_client2 = ssh.Client( |
| 113 | self.floating_ips[0]['floating_ip_address'], |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame^] | 114 | CONF.neutron_plugin_options.advanced_image_ssh_user, |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 115 | pkey=self.keypair['private_key']) |
| 116 | for fip in (fip1, fip2): |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame^] | 117 | self.check_connectivity( |
| 118 | fip['floating_ip_address'], |
| 119 | CONF.neutron_plugin_options.advanced_image_ssh_user, |
| 120 | self.keypair['private_key']) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 121 | return server_ssh_client1, fip1, server_ssh_client2, fip2 |
| 122 | |
Slawek Kaplonski | 1cd4fb4 | 2018-08-10 15:03:32 +0200 | [diff] [blame] | 123 | @testtools.skipUnless( |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame^] | 124 | CONF.neutron_plugin_options.advanced_image_ref, |
Slawek Kaplonski | 1cd4fb4 | 2018-08-10 15:03:32 +0200 | [diff] [blame] | 125 | "Advanced image is required to run this test.") |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 126 | @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 Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 151 | |
| 152 | |
| 153 | class 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 Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 162 | config.CONF.neutron_plugin_options.available_type_drivers): |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 163 | 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 Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 172 | 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 Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 177 | 'network'] |
| 178 | self.networks.append(network) |
| 179 | self.addCleanup(self.admin_client.delete_network, network['id']) |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 180 | subnet = self.create_subnet(network, cidr=cidr) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 181 | 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 Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 185 | # update network mtu |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 186 | 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 Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 189 | mtu=(net_mtu - 1)) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 190 | 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 Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 198 | self.keypair, self.secgroup) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 199 | server_ssh_client1 = ssh.Client( |
| 200 | self.floating_ips[0]['floating_ip_address'], |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame^] | 201 | CONF.neutron_plugin_options.advanced_image_ssh_user, |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 202 | pkey=self.keypair['private_key']) |
| 203 | server2, fip2 = self.create_pingable_vm(self.networks[1], |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 204 | self.keypair, self.secgroup) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 205 | server_ssh_client2 = ssh.Client( |
| 206 | self.floating_ips[0]['floating_ip_address'], |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame^] | 207 | CONF.neutron_plugin_options.advanced_image_ssh_user, |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 208 | pkey=self.keypair['private_key']) |
| 209 | for fip in (fip1, fip2): |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame^] | 210 | self.check_connectivity( |
| 211 | fip['floating_ip_address'], |
| 212 | CONF.neutron_plugin_options.advanced_image_ssh_user, |
| 213 | self.keypair['private_key']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 214 | return server_ssh_client1, fip1, server_ssh_client2, fip2 |
| 215 | |
Slawek Kaplonski | 1cd4fb4 | 2018-08-10 15:03:32 +0200 | [diff] [blame] | 216 | @testtools.skipUnless( |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame^] | 217 | CONF.neutron_plugin_options.advanced_image_ref, |
Slawek Kaplonski | 1cd4fb4 | 2018-08-10 15:03:32 +0200 | [diff] [blame] | 218 | "Advanced image is required to run this test.") |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 219 | @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) |