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 |
| 17 | from tempest.common import utils |
| 18 | from tempest.common import waiters |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 19 | from tempest.lib.common.utils import data_utils |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 20 | from tempest.lib import decorators |
| 21 | |
| 22 | from neutron_tempest_plugin.common import ssh |
| 23 | from neutron_tempest_plugin import config |
| 24 | from neutron_tempest_plugin.scenario import base |
| 25 | from neutron_tempest_plugin.scenario import constants |
| 26 | |
| 27 | CONF = config.CONF |
| 28 | |
| 29 | |
| 30 | class NetworkMtuBaseTest(base.BaseTempestTestCase): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 31 | |
| 32 | @classmethod |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 33 | def resource_setup(cls): |
| 34 | super(NetworkMtuBaseTest, cls).resource_setup() |
| 35 | # setup basic topology for servers we can log into it |
| 36 | cls.router = cls.create_router_by_client() |
| 37 | cls.keypair = cls.create_keypair() |
| 38 | cls.secgroup = cls.os_primary.network_client.create_security_group( |
| 39 | name='secgroup_mtu') |
| 40 | cls.security_groups.append(cls.secgroup['security_group']) |
| 41 | cls.create_loginable_secgroup_rule( |
| 42 | secgroup_id=cls.secgroup['security_group']['id']) |
| 43 | cls.create_pingable_secgroup_rule( |
| 44 | secgroup_id=cls.secgroup['security_group']['id']) |
| 45 | |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 46 | def create_pingable_vm(self, net, keypair, secgroup): |
| 47 | server = self.create_server( |
| 48 | flavor_ref=CONF.compute.flavor_ref, |
| 49 | image_ref=CONF.compute.image_ref, |
| 50 | key_name=keypair['name'], |
| 51 | networks=[{'uuid': net['id']}], |
| 52 | security_groups=[{'name': secgroup[ |
| 53 | 'security_group']['name']}]) |
| 54 | waiters.wait_for_server_status( |
| 55 | self.os_primary.servers_client, server['server']['id'], |
| 56 | constants.SERVER_STATUS_ACTIVE) |
| 57 | port = self.client.list_ports( |
| 58 | network_id=net['id'], device_id=server['server']['id'])['ports'][0] |
| 59 | fip = self.create_and_associate_floatingip(port['id']) |
| 60 | return server, fip |
| 61 | |
| 62 | |
| 63 | class NetworkMtuTest(NetworkMtuBaseTest): |
| 64 | credentials = ['primary', 'admin'] |
| 65 | servers = [] |
| 66 | networks = [] |
| 67 | |
| 68 | @classmethod |
| 69 | def skip_checks(cls): |
| 70 | super(NetworkMtuTest, cls).skip_checks() |
| 71 | if ("vxlan" not in |
Brian Haley | 33ef460 | 2018-04-26 14:37:49 -0400 | [diff] [blame^] | 72 | config.CONF.neutron_plugin_options.available_type_drivers or |
| 73 | "gre" not in |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 74 | config.CONF.neutron_plugin_options.available_type_drivers): |
| 75 | raise cls.skipException("GRE or VXLAN type_driver is not enabled") |
| 76 | |
| 77 | @classmethod |
| 78 | @utils.requires_ext(extension=provider_net.ALIAS, service="network") |
| 79 | def resource_setup(cls): |
| 80 | super(NetworkMtuTest, cls).resource_setup() |
| 81 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 82 | def _create_setup(self): |
| 83 | self.admin_client = self.os_admin.network_client |
| 84 | net_kwargs = {'tenant_id': self.client.tenant_id} |
Federico Ressi | 0ddc93b | 2018-04-09 12:01:48 +0200 | [diff] [blame] | 85 | for net_type in ['vxlan', 'gre']: |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 86 | net_kwargs['name'] = '-'.join([net_type, 'net']) |
| 87 | net_kwargs['provider:network_type'] = net_type |
| 88 | network = self.admin_client.create_network(**net_kwargs)[ |
| 89 | 'network'] |
| 90 | self.networks.append(network) |
| 91 | self.addCleanup(self.admin_client.delete_network, network['id']) |
Federico Ressi | 0ddc93b | 2018-04-09 12:01:48 +0200 | [diff] [blame] | 92 | subnet = self.create_subnet(network) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 93 | self.create_router_interface(self.router['id'], subnet['id']) |
| 94 | self.addCleanup(self.client.remove_router_interface_with_subnet_id, |
| 95 | self.router['id'], subnet['id']) |
| 96 | # check that MTUs are different for 2 networks |
| 97 | self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu']) |
| 98 | self.networks.sort(key=lambda net: net['mtu']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 99 | server1, fip1 = self.create_pingable_vm(self.networks[0], |
| 100 | self.keypair, self.secgroup) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 101 | server_ssh_client1 = ssh.Client( |
| 102 | self.floating_ips[0]['floating_ip_address'], |
| 103 | CONF.validation.image_ssh_user, |
| 104 | pkey=self.keypair['private_key']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 105 | server2, fip2 = self.create_pingable_vm(self.networks[1], |
| 106 | self.keypair, self.secgroup) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 107 | server_ssh_client2 = ssh.Client( |
| 108 | self.floating_ips[0]['floating_ip_address'], |
| 109 | CONF.validation.image_ssh_user, |
| 110 | pkey=self.keypair['private_key']) |
| 111 | for fip in (fip1, fip2): |
| 112 | self.check_connectivity(fip['floating_ip_address'], |
| 113 | CONF.validation.image_ssh_user, |
| 114 | self.keypair['private_key']) |
| 115 | return server_ssh_client1, fip1, server_ssh_client2, fip2 |
| 116 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 117 | @decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a273d9d344') |
| 118 | def test_connectivity_min_max_mtu(self): |
| 119 | server_ssh_client, _, _, fip2 = self._create_setup() |
| 120 | # ping with min mtu of 2 networks succeeds even when |
| 121 | # fragmentation is disabled |
| 122 | self.check_remote_connectivity( |
| 123 | server_ssh_client, fip2['fixed_ip_address'], |
| 124 | mtu=self.networks[0]['mtu'], fragmentation=False) |
| 125 | |
| 126 | # ping with the size above min mtu of 2 networks |
| 127 | # fails when fragmentation is disabled |
| 128 | self.check_remote_connectivity( |
| 129 | server_ssh_client, fip2['fixed_ip_address'], should_succeed=False, |
| 130 | mtu=self.networks[0]['mtu'] + 1, fragmentation=False) |
| 131 | |
| 132 | # ping with max mtu of 2 networks succeeds when |
| 133 | # fragmentation is enabled |
| 134 | self.check_remote_connectivity( |
| 135 | server_ssh_client, fip2['fixed_ip_address'], |
| 136 | mtu=self.networks[1]['mtu']) |
| 137 | |
| 138 | # ping with max mtu of 2 networks 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[1]['mtu'], fragmentation=False) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 142 | |
| 143 | |
| 144 | class NetworkWritableMtuTest(NetworkMtuBaseTest): |
| 145 | credentials = ['primary', 'admin'] |
| 146 | servers = [] |
| 147 | networks = [] |
| 148 | |
| 149 | @classmethod |
| 150 | def skip_checks(cls): |
| 151 | super(NetworkWritableMtuTest, cls).skip_checks() |
| 152 | if ("vxlan" not in |
| 153 | config.CONF.neutron_plugin_options.available_type_drivers): |
| 154 | raise cls.skipException("VXLAN type_driver is not enabled") |
| 155 | |
| 156 | @classmethod |
| 157 | @utils.requires_ext(extension="net-mtu-writable", service="network") |
| 158 | def resource_setup(cls): |
| 159 | super(NetworkWritableMtuTest, cls).resource_setup() |
| 160 | |
| 161 | def _create_setup(self): |
| 162 | self.admin_client = self.os_admin.network_client |
| 163 | net_kwargs = {'tenant_id': self.client.tenant_id, |
| 164 | 'provider:network_type': 'vxlan'} |
Federico Ressi | 0ddc93b | 2018-04-09 12:01:48 +0200 | [diff] [blame] | 165 | for _ in range(2): |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 166 | net_kwargs['name'] = data_utils.rand_name('net') |
| 167 | network = self.admin_client.create_network(**net_kwargs)[ |
| 168 | 'network'] |
| 169 | self.networks.append(network) |
| 170 | self.addCleanup(self.admin_client.delete_network, network['id']) |
Federico Ressi | 0ddc93b | 2018-04-09 12:01:48 +0200 | [diff] [blame] | 171 | subnet = self.create_subnet(network) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 172 | self.create_router_interface(self.router['id'], subnet['id']) |
| 173 | self.addCleanup(self.client.remove_router_interface_with_subnet_id, |
| 174 | self.router['id'], subnet['id']) |
| 175 | |
| 176 | # Update network mtu. |
| 177 | net_mtu = self.admin_client.show_network( |
| 178 | self.networks[0]['id'])['network']['mtu'] |
| 179 | self.admin_client.update_network(self.networks[0]['id'], |
| 180 | mtu=(net_mtu - 1)) |
| 181 | self.networks[0]['mtu'] = ( |
| 182 | self.admin_client.show_network( |
| 183 | self.networks[0]['id'])['network']['mtu']) |
| 184 | |
| 185 | # check that MTUs are different for 2 networks |
| 186 | self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu']) |
| 187 | self.networks.sort(key=lambda net: net['mtu']) |
| 188 | server1, fip1 = self.create_pingable_vm(self.networks[0], |
| 189 | self.keypair, self.secgroup) |
| 190 | server_ssh_client1 = ssh.Client( |
| 191 | self.floating_ips[0]['floating_ip_address'], |
| 192 | CONF.validation.image_ssh_user, |
| 193 | pkey=self.keypair['private_key']) |
| 194 | server2, fip2 = self.create_pingable_vm(self.networks[1], |
| 195 | self.keypair, self.secgroup) |
| 196 | server_ssh_client2 = ssh.Client( |
| 197 | self.floating_ips[0]['floating_ip_address'], |
| 198 | CONF.validation.image_ssh_user, |
| 199 | pkey=self.keypair['private_key']) |
| 200 | for fip in (fip1, fip2): |
| 201 | self.check_connectivity(fip['floating_ip_address'], |
| 202 | CONF.validation.image_ssh_user, |
| 203 | self.keypair['private_key']) |
| 204 | return server_ssh_client1, fip1, server_ssh_client2, fip2 |
| 205 | |
| 206 | @decorators.idempotent_id('bc470200-d8f4-4f07-b294-1b4cbaaa35b9') |
| 207 | def test_connectivity_min_max_mtu(self): |
| 208 | server_ssh_client, _, _, fip2 = self._create_setup() |
| 209 | # ping with min mtu of 2 networks succeeds even when |
| 210 | # fragmentation is disabled |
| 211 | self.check_remote_connectivity( |
| 212 | server_ssh_client, fip2['fixed_ip_address'], |
| 213 | mtu=self.networks[0]['mtu'], fragmentation=False) |
| 214 | |
| 215 | # ping with the size above min mtu of 2 networks |
| 216 | # fails when fragmentation is disabled |
| 217 | self.check_remote_connectivity( |
| 218 | server_ssh_client, fip2['fixed_ip_address'], should_succeed=False, |
| 219 | mtu=self.networks[0]['mtu'] + 2, fragmentation=False) |
| 220 | |
| 221 | # ping with max mtu of 2 networks succeeds when |
| 222 | # fragmentation is enabled |
| 223 | self.check_remote_connectivity( |
| 224 | server_ssh_client, fip2['fixed_ip_address'], |
| 225 | mtu=self.networks[1]['mtu']) |
| 226 | |
| 227 | # ping with max mtu of 2 networks fails when fragmentation is disabled |
| 228 | self.check_remote_connectivity( |
| 229 | server_ssh_client, fip2['fixed_ip_address'], should_succeed=False, |
| 230 | mtu=self.networks[1]['mtu'], fragmentation=False) |