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 |
Roman Safronov | 561cf62 | 2019-03-04 18:56:49 +0200 | [diff] [blame] | 17 | from oslo_log import log |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 18 | from oslo_serialization import jsonutils |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 19 | from tempest.common import utils |
| 20 | from tempest.common import waiters |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 21 | from tempest.lib.common.utils import data_utils |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 22 | from tempest.lib import decorators |
Slawek Kaplonski | 1cd4fb4 | 2018-08-10 15:03:32 +0200 | [diff] [blame] | 23 | import testtools |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 24 | |
| 25 | from neutron_tempest_plugin.common import ssh |
| 26 | from neutron_tempest_plugin import config |
| 27 | from neutron_tempest_plugin.scenario import base |
| 28 | from neutron_tempest_plugin.scenario import constants |
| 29 | |
| 30 | CONF = config.CONF |
Roman Safronov | 561cf62 | 2019-03-04 18:56:49 +0200 | [diff] [blame] | 31 | LOG = log.getLogger(__name__) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 32 | |
| 33 | |
| 34 | class NetworkMtuBaseTest(base.BaseTempestTestCase): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 35 | |
| 36 | @classmethod |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 37 | 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']) |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 49 | if CONF.neutron_plugin_options.default_image_is_advanced: |
| 50 | cls.use_advanced_image = False |
| 51 | cls.username = CONF.validation.image_ssh_user |
| 52 | else: |
| 53 | cls.use_advanced_image = True |
| 54 | cls.username = CONF.neutron_plugin_options.advanced_image_ssh_user |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 55 | |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 56 | def create_pingable_vm(self, net, keypair, secgroup): |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 57 | if self.use_advanced_image: |
| 58 | flavor_ref = CONF.neutron_plugin_options.advanced_image_flavor_ref |
| 59 | image_ref = CONF.neutron_plugin_options.advanced_image_ref |
| 60 | else: |
| 61 | flavor_ref = CONF.compute.flavor_ref |
| 62 | image_ref = CONF.compute.image_ref |
| 63 | |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 64 | server = self.create_server( |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 65 | flavor_ref=flavor_ref, |
| 66 | image_ref=image_ref, |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 67 | key_name=keypair['name'], |
| 68 | networks=[{'uuid': net['id']}], |
| 69 | security_groups=[{'name': secgroup[ |
| 70 | 'security_group']['name']}]) |
| 71 | waiters.wait_for_server_status( |
| 72 | self.os_primary.servers_client, server['server']['id'], |
| 73 | constants.SERVER_STATUS_ACTIVE) |
| 74 | port = self.client.list_ports( |
| 75 | network_id=net['id'], device_id=server['server']['id'])['ports'][0] |
Federico Ressi | 3dfa94c | 2018-07-06 09:46:39 +0200 | [diff] [blame] | 76 | fip = self.create_floatingip(port=port) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 77 | return server, fip |
| 78 | |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 79 | def _get_network_params(self): |
| 80 | return jsonutils.loads(CONF.neutron_plugin_options.test_mtu_networks) |
| 81 | |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 82 | |
| 83 | class NetworkMtuTest(NetworkMtuBaseTest): |
| 84 | credentials = ['primary', 'admin'] |
| 85 | servers = [] |
| 86 | networks = [] |
| 87 | |
| 88 | @classmethod |
| 89 | def skip_checks(cls): |
| 90 | super(NetworkMtuTest, cls).skip_checks() |
| 91 | if ("vxlan" not in |
Brian Haley | 33ef460 | 2018-04-26 14:37:49 -0400 | [diff] [blame] | 92 | config.CONF.neutron_plugin_options.available_type_drivers or |
| 93 | "gre" not in |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 94 | config.CONF.neutron_plugin_options.available_type_drivers): |
| 95 | raise cls.skipException("GRE or VXLAN type_driver is not enabled") |
| 96 | |
| 97 | @classmethod |
| 98 | @utils.requires_ext(extension=provider_net.ALIAS, service="network") |
| 99 | def resource_setup(cls): |
| 100 | super(NetworkMtuTest, cls).resource_setup() |
| 101 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 102 | def _create_setup(self): |
| 103 | self.admin_client = self.os_admin.network_client |
Takashi Kajinami | da45177 | 2023-03-22 00:19:39 +0900 | [diff] [blame] | 104 | net_kwargs = {'tenant_id': self.client.project_id} |
Federico Ressi | 0ddc93b | 2018-04-09 12:01:48 +0200 | [diff] [blame] | 105 | for net_type in ['vxlan', 'gre']: |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 106 | net_kwargs['name'] = '-'.join([net_type, 'net']) |
| 107 | net_kwargs['provider:network_type'] = net_type |
| 108 | network = self.admin_client.create_network(**net_kwargs)[ |
| 109 | 'network'] |
| 110 | self.networks.append(network) |
| 111 | self.addCleanup(self.admin_client.delete_network, network['id']) |
Federico Ressi | 0ddc93b | 2018-04-09 12:01:48 +0200 | [diff] [blame] | 112 | subnet = self.create_subnet(network) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 113 | self.create_router_interface(self.router['id'], subnet['id']) |
| 114 | self.addCleanup(self.client.remove_router_interface_with_subnet_id, |
| 115 | self.router['id'], subnet['id']) |
| 116 | # check that MTUs are different for 2 networks |
| 117 | self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu']) |
| 118 | self.networks.sort(key=lambda net: net['mtu']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 119 | server1, fip1 = self.create_pingable_vm(self.networks[0], |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 120 | self.keypair, self.secgroup) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 121 | server_ssh_client1 = ssh.Client( |
| 122 | self.floating_ips[0]['floating_ip_address'], |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 123 | self.username, pkey=self.keypair['private_key']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 124 | server2, fip2 = self.create_pingable_vm(self.networks[1], |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 125 | self.keypair, self.secgroup) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 126 | server_ssh_client2 = ssh.Client( |
| 127 | self.floating_ips[0]['floating_ip_address'], |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 128 | self.username, pkey=self.keypair['private_key']) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 129 | for fip in (fip1, fip2): |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame] | 130 | self.check_connectivity( |
| 131 | fip['floating_ip_address'], |
Slawek Kaplonski | e58219b | 2019-12-09 12:10:55 +0100 | [diff] [blame] | 132 | self.username, self.keypair['private_key'], |
| 133 | servers=[server1, server2]) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 134 | return server_ssh_client1, fip1, server_ssh_client2, fip2 |
| 135 | |
Slawek Kaplonski | 1cd4fb4 | 2018-08-10 15:03:32 +0200 | [diff] [blame] | 136 | @testtools.skipUnless( |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 137 | (CONF.neutron_plugin_options.advanced_image_ref or |
| 138 | CONF.neutron_plugin_options.default_image_is_advanced), |
| 139 | "Advanced image is required to run this test.") |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 140 | @decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a273d9d344') |
| 141 | def test_connectivity_min_max_mtu(self): |
| 142 | server_ssh_client, _, _, fip2 = self._create_setup() |
| 143 | # ping with min mtu of 2 networks succeeds even when |
| 144 | # fragmentation is disabled |
| 145 | self.check_remote_connectivity( |
| 146 | server_ssh_client, fip2['fixed_ip_address'], |
| 147 | mtu=self.networks[0]['mtu'], fragmentation=False) |
| 148 | |
| 149 | # ping with the size above min mtu of 2 networks |
| 150 | # fails when fragmentation is disabled |
| 151 | self.check_remote_connectivity( |
| 152 | server_ssh_client, fip2['fixed_ip_address'], should_succeed=False, |
| 153 | mtu=self.networks[0]['mtu'] + 1, fragmentation=False) |
| 154 | |
| 155 | # ping with max mtu of 2 networks succeeds when |
| 156 | # fragmentation is enabled |
| 157 | self.check_remote_connectivity( |
| 158 | server_ssh_client, fip2['fixed_ip_address'], |
| 159 | mtu=self.networks[1]['mtu']) |
| 160 | |
| 161 | # ping with max mtu of 2 networks fails when fragmentation is disabled |
| 162 | self.check_remote_connectivity( |
| 163 | server_ssh_client, fip2['fixed_ip_address'], should_succeed=False, |
| 164 | mtu=self.networks[1]['mtu'], fragmentation=False) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 165 | |
| 166 | |
| 167 | class NetworkWritableMtuTest(NetworkMtuBaseTest): |
| 168 | credentials = ['primary', 'admin'] |
| 169 | servers = [] |
| 170 | networks = [] |
| 171 | |
| 172 | @classmethod |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 173 | @utils.requires_ext(extension="net-mtu-writable", service="network") |
| 174 | def resource_setup(cls): |
| 175 | super(NetworkWritableMtuTest, cls).resource_setup() |
Roman Safronov | 9be9375 | 2024-09-17 14:57:48 +0300 | [diff] [blame] | 176 | if cls.is_driver_ovn: |
| 177 | raise cls.skipException("East/west icmp fragmentation is not " |
| 178 | "supported with ML2/OVN") |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 179 | |
| 180 | def _create_setup(self): |
| 181 | self.admin_client = self.os_admin.network_client |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 182 | for test_net in self._get_network_params(): |
Takashi Kajinami | da45177 | 2023-03-22 00:19:39 +0900 | [diff] [blame] | 183 | test_net['tenant_id'] = self.client.project_id |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 184 | test_net['name'] = data_utils.rand_name('net') |
| 185 | cidr = None if 'cidr' not in test_net else test_net.pop('cidr') |
| 186 | network = self.admin_client.create_network(**test_net)[ |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 187 | 'network'] |
| 188 | self.networks.append(network) |
| 189 | self.addCleanup(self.admin_client.delete_network, network['id']) |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 190 | subnet = self.create_subnet(network, cidr=cidr) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 191 | self.create_router_interface(self.router['id'], subnet['id']) |
| 192 | self.addCleanup(self.client.remove_router_interface_with_subnet_id, |
| 193 | self.router['id'], subnet['id']) |
| 194 | |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 195 | # update network mtu |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 196 | net_mtu = self.admin_client.show_network( |
| 197 | self.networks[0]['id'])['network']['mtu'] |
| 198 | self.admin_client.update_network(self.networks[0]['id'], |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 199 | mtu=(net_mtu - 1)) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 200 | self.networks[0]['mtu'] = ( |
| 201 | self.admin_client.show_network( |
| 202 | self.networks[0]['id'])['network']['mtu']) |
| 203 | |
| 204 | # check that MTUs are different for 2 networks |
| 205 | self.assertNotEqual(self.networks[0]['mtu'], self.networks[1]['mtu']) |
| 206 | self.networks.sort(key=lambda net: net['mtu']) |
| 207 | server1, fip1 = self.create_pingable_vm(self.networks[0], |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 208 | self.keypair, self.secgroup) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 209 | server_ssh_client1 = ssh.Client( |
| 210 | self.floating_ips[0]['floating_ip_address'], |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 211 | self.username, pkey=self.keypair['private_key']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 212 | server2, fip2 = self.create_pingable_vm(self.networks[1], |
Yariv Rachmani | 9497088 | 2018-03-04 11:35:17 +0200 | [diff] [blame] | 213 | self.keypair, self.secgroup) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 214 | server_ssh_client2 = ssh.Client( |
| 215 | self.floating_ips[0]['floating_ip_address'], |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 216 | self.username, pkey=self.keypair['private_key']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 217 | for fip in (fip1, fip2): |
Slawek Kaplonski | da17f00 | 2018-10-11 18:35:23 +0200 | [diff] [blame] | 218 | self.check_connectivity( |
| 219 | fip['floating_ip_address'], |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 220 | self.username, self.keypair['private_key']) |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 221 | return server_ssh_client1, fip1, server_ssh_client2, fip2 |
| 222 | |
Slawek Kaplonski | 1cd4fb4 | 2018-08-10 15:03:32 +0200 | [diff] [blame] | 223 | @testtools.skipUnless( |
Yariv Rachmani | fa1081a | 2018-11-21 12:46:57 +0200 | [diff] [blame] | 224 | (CONF.neutron_plugin_options.advanced_image_ref or |
| 225 | CONF.neutron_plugin_options.default_image_is_advanced), |
| 226 | "Advanced image is required to run this test.") |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 227 | @decorators.idempotent_id('bc470200-d8f4-4f07-b294-1b4cbaaa35b9') |
| 228 | def test_connectivity_min_max_mtu(self): |
| 229 | server_ssh_client, _, _, fip2 = self._create_setup() |
Takashi Kajinami | 435ff6f | 2024-11-16 15:33:27 +0900 | [diff] [blame] | 230 | log_msg = ("Ping with %(mtu_size)s MTU of 2 networks. " |
| 231 | "Fragmentation is %(fragmentation_state)s. " |
| 232 | "Expected result: ping %(ping_status)s") |
Roman Safronov | 561cf62 | 2019-03-04 18:56:49 +0200 | [diff] [blame] | 233 | |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 234 | # ping with min mtu of 2 networks succeeds even when |
| 235 | # fragmentation is disabled |
Takashi Kajinami | 435ff6f | 2024-11-16 15:33:27 +0900 | [diff] [blame] | 236 | LOG.debug(log_msg, mtu_size='minimal', |
| 237 | fragmentation_state='disabled', ping_status='succeeded') |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 238 | self.check_remote_connectivity( |
| 239 | server_ssh_client, fip2['fixed_ip_address'], |
| 240 | mtu=self.networks[0]['mtu'], fragmentation=False) |
| 241 | |
| 242 | # ping with the size above min mtu of 2 networks |
| 243 | # fails when fragmentation is disabled |
Takashi Kajinami | 435ff6f | 2024-11-16 15:33:27 +0900 | [diff] [blame] | 244 | LOG.debug(log_msg, mtu_size='size above minimal', |
| 245 | fragmentation_state='disabled', ping_status='failed') |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 246 | self.check_remote_connectivity( |
| 247 | server_ssh_client, fip2['fixed_ip_address'], should_succeed=False, |
| 248 | mtu=self.networks[0]['mtu'] + 2, fragmentation=False) |
| 249 | |
| 250 | # ping with max mtu of 2 networks succeeds when |
| 251 | # fragmentation is enabled |
Takashi Kajinami | 435ff6f | 2024-11-16 15:33:27 +0900 | [diff] [blame] | 252 | LOG.debug(log_msg, mtu_size='maximal', |
| 253 | fragmentation_state='enabled', ping_status='succeeded') |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 254 | self.check_remote_connectivity( |
| 255 | server_ssh_client, fip2['fixed_ip_address'], |
| 256 | mtu=self.networks[1]['mtu']) |
| 257 | |
| 258 | # ping with max mtu of 2 networks fails when fragmentation is disabled |
Takashi Kajinami | 435ff6f | 2024-11-16 15:33:27 +0900 | [diff] [blame] | 259 | LOG.debug(log_msg, mtu_size='maximal', |
| 260 | fragmentation_state='disabled', ping_status='failed') |
Dongcan Ye | ee30004 | 2018-01-10 05:38:35 +0000 | [diff] [blame] | 261 | self.check_remote_connectivity( |
| 262 | server_ssh_client, fip2['fixed_ip_address'], should_succeed=False, |
| 263 | mtu=self.networks[1]['mtu'], fragmentation=False) |