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. |
| 15 | import netaddr |
| 16 | |
| 17 | from neutron_lib.api.definitions import provider_net |
| 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 |
| 22 | |
| 23 | from neutron_tempest_plugin.common import ssh |
| 24 | from neutron_tempest_plugin import config |
| 25 | from neutron_tempest_plugin.scenario import base |
| 26 | from neutron_tempest_plugin.scenario import constants |
| 27 | |
| 28 | CONF = config.CONF |
| 29 | |
| 30 | |
| 31 | class NetworkMtuBaseTest(base.BaseTempestTestCase): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 32 | |
| 33 | @classmethod |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 34 | 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 Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 47 | 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 | |
| 63 | |
| 64 | class NetworkMtuTest(NetworkMtuBaseTest): |
| 65 | credentials = ['primary', 'admin'] |
| 66 | servers = [] |
| 67 | networks = [] |
| 68 | |
| 69 | @classmethod |
| 70 | def skip_checks(cls): |
| 71 | super(NetworkMtuTest, cls).skip_checks() |
| 72 | if ("vxlan" not in |
| 73 | config.CONF.neutron_plugin_options.available_type_drivers |
| 74 | or "gre" not in |
| 75 | config.CONF.neutron_plugin_options.available_type_drivers): |
| 76 | raise cls.skipException("GRE or VXLAN type_driver is not enabled") |
| 77 | |
| 78 | @classmethod |
| 79 | @utils.requires_ext(extension=provider_net.ALIAS, service="network") |
| 80 | def resource_setup(cls): |
| 81 | super(NetworkMtuTest, cls).resource_setup() |
| 82 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 83 | def _create_setup(self): |
| 84 | self.admin_client = self.os_admin.network_client |
| 85 | net_kwargs = {'tenant_id': self.client.tenant_id} |
| 86 | for sub, net_type in ( |
| 87 | ('10.100.0.0/16', 'vxlan'), ('10.200.0.0/16', 'gre')): |
| 88 | net_kwargs['name'] = '-'.join([net_type, 'net']) |
| 89 | net_kwargs['provider:network_type'] = net_type |
| 90 | network = self.admin_client.create_network(**net_kwargs)[ |
| 91 | 'network'] |
| 92 | self.networks.append(network) |
| 93 | self.addCleanup(self.admin_client.delete_network, network['id']) |
| 94 | cidr = netaddr.IPNetwork(sub) |
| 95 | subnet = self.create_subnet(network, cidr=cidr) |
| 96 | self.create_router_interface(self.router['id'], subnet['id']) |
| 97 | self.addCleanup(self.client.remove_router_interface_with_subnet_id, |
| 98 | self.router['id'], subnet['id']) |
| 99 | # check that MTUs are different for 2 networks |
| 100 | self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu']) |
| 101 | self.networks.sort(key=lambda net: net['mtu']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 102 | server1, fip1 = self.create_pingable_vm(self.networks[0], |
| 103 | self.keypair, self.secgroup) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 104 | server_ssh_client1 = ssh.Client( |
| 105 | self.floating_ips[0]['floating_ip_address'], |
| 106 | CONF.validation.image_ssh_user, |
| 107 | pkey=self.keypair['private_key']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 108 | server2, fip2 = self.create_pingable_vm(self.networks[1], |
| 109 | self.keypair, self.secgroup) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 110 | server_ssh_client2 = ssh.Client( |
| 111 | self.floating_ips[0]['floating_ip_address'], |
| 112 | CONF.validation.image_ssh_user, |
| 113 | pkey=self.keypair['private_key']) |
| 114 | for fip in (fip1, fip2): |
| 115 | self.check_connectivity(fip['floating_ip_address'], |
| 116 | CONF.validation.image_ssh_user, |
| 117 | self.keypair['private_key']) |
| 118 | return server_ssh_client1, fip1, server_ssh_client2, fip2 |
| 119 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 120 | @decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a273d9d344') |
| 121 | def test_connectivity_min_max_mtu(self): |
| 122 | server_ssh_client, _, _, fip2 = self._create_setup() |
| 123 | # ping with min mtu of 2 networks succeeds even when |
| 124 | # fragmentation is disabled |
| 125 | self.check_remote_connectivity( |
| 126 | server_ssh_client, fip2['fixed_ip_address'], |
| 127 | mtu=self.networks[0]['mtu'], fragmentation=False) |
| 128 | |
| 129 | # ping with the size above min mtu of 2 networks |
| 130 | # fails when fragmentation is disabled |
| 131 | self.check_remote_connectivity( |
| 132 | server_ssh_client, fip2['fixed_ip_address'], should_succeed=False, |
| 133 | mtu=self.networks[0]['mtu'] + 1, fragmentation=False) |
| 134 | |
| 135 | # ping with max mtu of 2 networks succeeds when |
| 136 | # fragmentation is enabled |
| 137 | self.check_remote_connectivity( |
| 138 | server_ssh_client, fip2['fixed_ip_address'], |
| 139 | mtu=self.networks[1]['mtu']) |
| 140 | |
| 141 | # ping with max mtu of 2 networks fails when fragmentation is disabled |
| 142 | self.check_remote_connectivity( |
| 143 | server_ssh_client, fip2['fixed_ip_address'], should_succeed=False, |
| 144 | mtu=self.networks[1]['mtu'], fragmentation=False) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 145 | |
| 146 | |
| 147 | class NetworkWritableMtuTest(NetworkMtuBaseTest): |
| 148 | credentials = ['primary', 'admin'] |
| 149 | servers = [] |
| 150 | networks = [] |
| 151 | |
| 152 | @classmethod |
| 153 | def skip_checks(cls): |
| 154 | super(NetworkWritableMtuTest, cls).skip_checks() |
| 155 | if ("vxlan" not in |
| 156 | config.CONF.neutron_plugin_options.available_type_drivers): |
| 157 | raise cls.skipException("VXLAN type_driver is not enabled") |
| 158 | |
| 159 | @classmethod |
| 160 | @utils.requires_ext(extension="net-mtu-writable", service="network") |
| 161 | def resource_setup(cls): |
| 162 | super(NetworkWritableMtuTest, cls).resource_setup() |
| 163 | |
| 164 | def _create_setup(self): |
| 165 | self.admin_client = self.os_admin.network_client |
| 166 | net_kwargs = {'tenant_id': self.client.tenant_id, |
| 167 | 'provider:network_type': 'vxlan'} |
| 168 | for sub in ('10.100.0.0/16', '10.200.0.0/16'): |
| 169 | net_kwargs['name'] = data_utils.rand_name('net') |
| 170 | network = self.admin_client.create_network(**net_kwargs)[ |
| 171 | 'network'] |
| 172 | self.networks.append(network) |
| 173 | self.addCleanup(self.admin_client.delete_network, network['id']) |
| 174 | cidr = netaddr.IPNetwork(sub) |
| 175 | subnet = self.create_subnet(network, cidr=cidr) |
| 176 | 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 | |
| 180 | # Update network mtu. |
| 181 | net_mtu = self.admin_client.show_network( |
| 182 | self.networks[0]['id'])['network']['mtu'] |
| 183 | self.admin_client.update_network(self.networks[0]['id'], |
| 184 | mtu=(net_mtu - 1)) |
| 185 | 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], |
| 193 | self.keypair, self.secgroup) |
| 194 | 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], |
| 199 | self.keypair, self.secgroup) |
| 200 | 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) |