Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 1 | # Copyright 2018 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 | |
Oleh Hryhorov | f0283f7 | 2021-01-12 12:40:55 +0200 | [diff] [blame^] | 16 | import time |
| 17 | |
ccamposr | 3e1921b | 2020-01-29 11:10:05 +0100 | [diff] [blame] | 18 | import netaddr |
| 19 | |
Slawek Kaplonski | 2a71a89 | 2020-02-03 11:48:34 +0100 | [diff] [blame] | 20 | from neutron_lib import constants |
Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 21 | from tempest.common import compute |
| 22 | from tempest.common import utils |
| 23 | from tempest.lib.common.utils import data_utils |
| 24 | from tempest.lib import decorators |
| 25 | |
ccamposr | 3e1921b | 2020-01-29 11:10:05 +0100 | [diff] [blame] | 26 | from neutron_tempest_plugin.common import ip as ip_utils |
Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 27 | from neutron_tempest_plugin.common import ssh |
| 28 | from neutron_tempest_plugin import config |
| 29 | from neutron_tempest_plugin.scenario import base |
| 30 | |
| 31 | CONF = config.CONF |
| 32 | |
| 33 | |
| 34 | class NetworkConnectivityTest(base.BaseTempestTestCase): |
| 35 | credentials = ['primary', 'admin'] |
| 36 | |
| 37 | @classmethod |
| 38 | @utils.requires_ext(extension="router", service="network") |
| 39 | def resource_setup(cls): |
| 40 | super(NetworkConnectivityTest, cls).resource_setup() |
| 41 | # Create keypair with admin privileges |
| 42 | cls.keypair = cls.create_keypair() |
| 43 | # Create security group with admin privileges |
| 44 | cls.secgroup = cls.create_security_group( |
| 45 | name=data_utils.rand_name('secgroup')) |
| 46 | # Execute funcs to achieve ssh and ICMP capabilities |
| 47 | cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 48 | cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 49 | |
| 50 | def _create_servers(self, port_1, port_2): |
| 51 | params = { |
| 52 | 'flavor_ref': CONF.compute.flavor_ref, |
| 53 | 'image_ref': CONF.compute.image_ref, |
| 54 | 'key_name': self.keypair['name'] |
| 55 | } |
Slawek Kaplonski | 6aae0d4 | 2019-06-26 10:17:15 +0200 | [diff] [blame] | 56 | vms = [] |
| 57 | vms.append( |
| 58 | self.create_server(networks=[{'port': port_1['id']}], **params)) |
Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 59 | |
| 60 | if (CONF.compute.min_compute_nodes > 1 and |
| 61 | compute.is_scheduler_filter_enabled("DifferentHostFilter")): |
| 62 | params['scheduler_hints'] = { |
Slawek Kaplonski | 6aae0d4 | 2019-06-26 10:17:15 +0200 | [diff] [blame] | 63 | 'different_host': [vms[0]['server']['id']]} |
Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 64 | |
Slawek Kaplonski | 6aae0d4 | 2019-06-26 10:17:15 +0200 | [diff] [blame] | 65 | vms.append( |
| 66 | self.create_server(networks=[{'port': port_2['id']}], **params)) |
| 67 | |
| 68 | for vm in vms: |
| 69 | self.wait_for_server_active(vm['server']) |
Slawek Kaplonski | 2211eab | 2020-10-20 16:43:53 +0200 | [diff] [blame] | 70 | self.wait_for_guest_os_ready(vm['server']) |
Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 71 | |
Slawek Kaplonski | e58219b | 2019-12-09 12:10:55 +0100 | [diff] [blame] | 72 | return vms |
| 73 | |
Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 74 | @decorators.idempotent_id('8944b90d-1766-4669-bd8a-672b5d106bb7') |
| 75 | def test_connectivity_through_2_routers(self): |
| 76 | ap1_net = self.create_network() |
| 77 | ap2_net = self.create_network() |
| 78 | wan_net = self.create_network() |
| 79 | ap1_subnet = self.create_subnet( |
| 80 | ap1_net, cidr="10.10.210.0/24", gateway="10.10.210.254") |
| 81 | ap2_subnet = self.create_subnet( |
| 82 | ap2_net, cidr="10.10.220.0/24", gateway="10.10.220.254") |
| 83 | self.create_subnet( |
| 84 | wan_net, cidr="10.10.200.0/24", gateway="10.10.200.254") |
| 85 | |
| 86 | ap1_rt = self.create_router( |
| 87 | router_name=data_utils.rand_name("ap1_rt"), |
| 88 | admin_state_up=True, |
| 89 | external_network_id=CONF.network.public_network_id) |
| 90 | ap2_rt = self.create_router( |
| 91 | router_name=data_utils.rand_name("ap2_rt"), |
| 92 | admin_state_up=True) |
| 93 | |
| 94 | ap1_internal_port = self.create_port( |
| 95 | ap1_net, security_groups=[self.secgroup['id']]) |
| 96 | ap2_internal_port = self.create_port( |
| 97 | ap2_net, security_groups=[self.secgroup['id']]) |
| 98 | ap1_wan_port = self.create_port(wan_net) |
| 99 | ap2_wan_port = self.create_port(wan_net) |
| 100 | |
Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 101 | self.client.add_router_interface_with_port_id( |
| 102 | ap1_rt['id'], ap1_wan_port['id']) |
| 103 | self.client.add_router_interface_with_port_id( |
| 104 | ap2_rt['id'], ap2_wan_port['id']) |
| 105 | self.create_router_interface(ap1_rt['id'], ap1_subnet['id']) |
| 106 | self.create_router_interface(ap2_rt['id'], ap2_subnet['id']) |
| 107 | |
Oleh Hryhorov | f0283f7 | 2021-01-12 12:40:55 +0200 | [diff] [blame^] | 108 | # NOTE(ohryhorov): the sleep below is added to avoid the situation |
| 109 | # when a port is not in active state yet but static route is added. |
| 110 | time.sleep(15) |
| 111 | |
Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 112 | self.client.update_router( |
| 113 | ap1_rt['id'], |
| 114 | routes=[{"destination": ap2_subnet['cidr'], |
| 115 | "nexthop": ap2_wan_port['fixed_ips'][0]['ip_address']}]) |
| 116 | self.client.update_router( |
| 117 | ap2_rt['id'], |
| 118 | routes=[{"destination": ap1_subnet['cidr'], |
| 119 | "nexthop": ap1_wan_port['fixed_ips'][0]['ip_address']}]) |
| 120 | |
Slawek Kaplonski | e58219b | 2019-12-09 12:10:55 +0100 | [diff] [blame] | 121 | servers = self._create_servers(ap1_internal_port, ap2_internal_port) |
Slawek Kaplonski | 6aae0d4 | 2019-06-26 10:17:15 +0200 | [diff] [blame] | 122 | |
Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 123 | ap1_fip = self.create_and_associate_floatingip( |
| 124 | ap1_internal_port['id']) |
| 125 | ap1_sshclient = ssh.Client( |
| 126 | ap1_fip['floating_ip_address'], CONF.validation.image_ssh_user, |
| 127 | pkey=self.keypair['private_key']) |
| 128 | |
| 129 | self.check_remote_connectivity( |
Slawek Kaplonski | e58219b | 2019-12-09 12:10:55 +0100 | [diff] [blame] | 130 | ap1_sshclient, ap2_internal_port['fixed_ips'][0]['ip_address'], |
| 131 | servers=servers) |
LIU Yulong | 68ab245 | 2019-05-18 10:19:49 +0800 | [diff] [blame] | 132 | |
| 133 | @decorators.idempotent_id('b72c3b77-3396-4144-b05d-9cd3c0099893') |
| 134 | def test_connectivity_router_east_west_traffic(self): |
| 135 | """This case is intended to test router east west taffic |
| 136 | |
| 137 | The case can be used in various scenarios: legacy/distributed router, |
| 138 | same/different host. |
| 139 | """ |
| 140 | net_1 = self.create_network() |
| 141 | net_2 = self.create_network() |
| 142 | subnet_1 = self.create_subnet(net_1, cidr="10.10.1.0/24") |
| 143 | subnet_2 = self.create_subnet(net_2, cidr="10.10.2.0/24") |
| 144 | |
| 145 | router = self.create_router( |
| 146 | router_name=data_utils.rand_name("east_west_traffic_router"), |
| 147 | admin_state_up=True, |
| 148 | external_network_id=CONF.network.public_network_id) |
| 149 | |
| 150 | internal_port_1 = self.create_port( |
| 151 | net_1, security_groups=[self.secgroup['id']]) |
| 152 | internal_port_2 = self.create_port( |
| 153 | net_2, security_groups=[self.secgroup['id']]) |
| 154 | |
LIU Yulong | 68ab245 | 2019-05-18 10:19:49 +0800 | [diff] [blame] | 155 | self.create_router_interface(router['id'], subnet_1['id']) |
| 156 | self.create_router_interface(router['id'], subnet_2['id']) |
| 157 | |
Slawek Kaplonski | e58219b | 2019-12-09 12:10:55 +0100 | [diff] [blame] | 158 | servers = self._create_servers(internal_port_1, internal_port_2) |
Slawek Kaplonski | 6aae0d4 | 2019-06-26 10:17:15 +0200 | [diff] [blame] | 159 | |
LIU Yulong | 68ab245 | 2019-05-18 10:19:49 +0800 | [diff] [blame] | 160 | fip = self.create_and_associate_floatingip( |
| 161 | internal_port_1['id']) |
| 162 | sshclient = ssh.Client( |
| 163 | fip['floating_ip_address'], CONF.validation.image_ssh_user, |
| 164 | pkey=self.keypair['private_key']) |
| 165 | |
| 166 | self.check_remote_connectivity( |
| 167 | sshclient, internal_port_2['fixed_ips'][0]['ip_address'], |
Slawek Kaplonski | e58219b | 2019-12-09 12:10:55 +0100 | [diff] [blame] | 168 | ping_count=10, servers=servers) |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 169 | |
| 170 | @utils.requires_ext(extension="dvr", service="network") |
| 171 | @decorators.idempotent_id('69d3650a-5c32-40bc-ae56-5c4c849ddd37') |
| 172 | def test_connectivity_dvr_and_no_dvr_routers_in_same_subnet(self): |
| 173 | """This test case tests connectivity between vm and 2 routers. |
| 174 | |
| 175 | Subnet is connected to dvr and non-dvr routers in the same time, test |
| 176 | ensures that connectivity from VM to both routers is working. |
| 177 | |
ccamposr | 3e1921b | 2020-01-29 11:10:05 +0100 | [diff] [blame] | 178 | Test scenario: (NOTE: 10.1.0.0/24 private CIDR is used as an example) |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 179 | +----------------+ +------------+ |
| 180 | | Non-dvr router | | DVR router | |
| 181 | | | | | |
ccamposr | 3e1921b | 2020-01-29 11:10:05 +0100 | [diff] [blame] | 182 | | 10.1.0.1 | | 10.1.0.x | |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 183 | +-------+--------+ +-----+------+ |
| 184 | | | |
ccamposr | 3e1921b | 2020-01-29 11:10:05 +0100 | [diff] [blame] | 185 | | 10.1.0.0/24 | |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 186 | +----------------+----------------+ |
| 187 | | |
| 188 | +-+-+ |
| 189 | |VM | |
| 190 | +---+ |
| 191 | |
| 192 | where: |
ccamposr | 3e1921b | 2020-01-29 11:10:05 +0100 | [diff] [blame] | 193 | 10.1.0.1 - is subnet's gateway IP address, |
| 194 | 10.1.0.x - is any other IP address taken from subnet's range |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 195 | |
ccamposr | 3e1921b | 2020-01-29 11:10:05 +0100 | [diff] [blame] | 196 | Test ensures that both 10.1.0.1 and 10.1.0.x IP addresses are |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 197 | reachable from VM. |
| 198 | """ |
Slawek Kaplonski | 2a71a89 | 2020-02-03 11:48:34 +0100 | [diff] [blame] | 199 | ext_network = self.client.show_network(self.external_network_id) |
| 200 | for ext_subnetid in ext_network['network']['subnets']: |
| 201 | ext_subnet = self.os_admin.network_client.show_subnet(ext_subnetid) |
| 202 | ext_cidr = ext_subnet['subnet']['cidr'] |
| 203 | if ext_subnet['subnet']['ip_version'] == constants.IP_VERSION_4: |
| 204 | break |
| 205 | else: |
| 206 | self.fail('No IPv4 subnet was found in external network %s' % |
| 207 | ext_network['network']['id']) |
| 208 | |
ccamposr | 3e1921b | 2020-01-29 11:10:05 +0100 | [diff] [blame] | 209 | subnet_cidr = ip_utils.find_valid_cidr(used_cidr=ext_cidr) |
| 210 | gw_ip = netaddr.IPAddress(subnet_cidr.first + 1) |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 211 | |
| 212 | network = self.create_network() |
| 213 | subnet = self.create_subnet( |
ccamposr | 3e1921b | 2020-01-29 11:10:05 +0100 | [diff] [blame] | 214 | network, cidr=str(subnet_cidr), gateway=str(gw_ip)) |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 215 | |
| 216 | non_dvr_router = self.create_router_by_client( |
| 217 | tenant_id=self.client.tenant_id, |
| 218 | is_admin=True, |
| 219 | router_name=data_utils.rand_name("nondvr-2-routers-same-network"), |
| 220 | admin_state_up=True, |
| 221 | distributed=False) |
| 222 | self.create_router_interface(non_dvr_router['id'], subnet['id']) |
| 223 | |
| 224 | dvr_router = self.create_router_by_client( |
| 225 | tenant_id=self.client.tenant_id, |
| 226 | is_admin=True, |
| 227 | router_name=data_utils.rand_name("dvr-2-rotuers-same-network"), |
| 228 | admin_state_up=True, |
| 229 | distributed=True) |
| 230 | dvr_router_port = self.create_port(network) |
| 231 | self.client.add_router_interface_with_port_id( |
| 232 | dvr_router['id'], dvr_router_port['id']) |
| 233 | |
| 234 | vm = self.create_server( |
| 235 | flavor_ref=CONF.compute.flavor_ref, |
| 236 | image_ref=CONF.compute.image_ref, |
| 237 | key_name=self.keypair['name'], |
| 238 | networks=[{'uuid': network['id']}], |
| 239 | security_groups=[{'name': self.secgroup['name']}]) |
| 240 | self.wait_for_server_active(vm['server']) |
Slawek Kaplonski | 2211eab | 2020-10-20 16:43:53 +0200 | [diff] [blame] | 241 | self.wait_for_guest_os_ready(vm['server']) |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 242 | |
| 243 | vm_port = self.client.list_ports( |
| 244 | network_id=network['id'], device_id=vm['server']['id'])['ports'][0] |
| 245 | fip = self.create_and_associate_floatingip(vm_port['id']) |
| 246 | |
| 247 | sshclient = ssh.Client( |
| 248 | fip['floating_ip_address'], CONF.validation.image_ssh_user, |
| 249 | pkey=self.keypair['private_key']) |
| 250 | |
Slawek Kaplonski | e58219b | 2019-12-09 12:10:55 +0100 | [diff] [blame] | 251 | self.check_remote_connectivity( |
| 252 | sshclient, str(gw_ip), ping_count=10, servers=[vm]) |
Slawek Kaplonski | d2a6acc | 2019-06-04 12:22:24 +0200 | [diff] [blame] | 253 | self.check_remote_connectivity( |
| 254 | sshclient, dvr_router_port['fixed_ips'][0]['ip_address'], |
Slawek Kaplonski | e58219b | 2019-12-09 12:10:55 +0100 | [diff] [blame] | 255 | ping_count=10, servers=[vm]) |