blob: de409caa8b438052fbe239aead45923927996cea [file] [log] [blame]
Slawek Kaplonskib1a32892018-08-27 07:24:00 +02001# 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 Hryhorov9bb27d42021-01-12 12:40:55 +020016import time
17
ccamposr3e1921b2020-01-29 11:10:05 +010018import netaddr
19
Slawek Kaplonski2a71a892020-02-03 11:48:34 +010020from neutron_lib import constants
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020021from tempest.common import compute
22from tempest.common import utils
23from tempest.lib.common.utils import data_utils
24from tempest.lib import decorators
25
ccamposr3e1921b2020-01-29 11:10:05 +010026from neutron_tempest_plugin.common import ip as ip_utils
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020027from neutron_tempest_plugin.common import ssh
28from neutron_tempest_plugin import config
29from neutron_tempest_plugin.scenario import base
30
31CONF = config.CONF
32
33
34class 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 Kaplonski6aae0d42019-06-26 10:17:15 +020056 vms = []
57 vms.append(
58 self.create_server(networks=[{'port': port_1['id']}], **params))
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020059
60 if (CONF.compute.min_compute_nodes > 1 and
61 compute.is_scheduler_filter_enabled("DifferentHostFilter")):
62 params['scheduler_hints'] = {
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020063 'different_host': [vms[0]['server']['id']]}
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020064
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020065 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 Kaplonskib1a32892018-08-27 07:24:00 +020070
Slawek Kaplonskie58219b2019-12-09 12:10:55 +010071 return vms
72
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020073 @decorators.idempotent_id('8944b90d-1766-4669-bd8a-672b5d106bb7')
74 def test_connectivity_through_2_routers(self):
75 ap1_net = self.create_network()
76 ap2_net = self.create_network()
77 wan_net = self.create_network()
78 ap1_subnet = self.create_subnet(
79 ap1_net, cidr="10.10.210.0/24", gateway="10.10.210.254")
80 ap2_subnet = self.create_subnet(
81 ap2_net, cidr="10.10.220.0/24", gateway="10.10.220.254")
82 self.create_subnet(
83 wan_net, cidr="10.10.200.0/24", gateway="10.10.200.254")
84
85 ap1_rt = self.create_router(
86 router_name=data_utils.rand_name("ap1_rt"),
87 admin_state_up=True,
88 external_network_id=CONF.network.public_network_id)
89 ap2_rt = self.create_router(
90 router_name=data_utils.rand_name("ap2_rt"),
91 admin_state_up=True)
92
93 ap1_internal_port = self.create_port(
94 ap1_net, security_groups=[self.secgroup['id']])
95 ap2_internal_port = self.create_port(
96 ap2_net, security_groups=[self.secgroup['id']])
97 ap1_wan_port = self.create_port(wan_net)
98 ap2_wan_port = self.create_port(wan_net)
99
Slawek Kaplonskib1a32892018-08-27 07:24:00 +0200100 self.client.add_router_interface_with_port_id(
101 ap1_rt['id'], ap1_wan_port['id'])
102 self.client.add_router_interface_with_port_id(
103 ap2_rt['id'], ap2_wan_port['id'])
104 self.create_router_interface(ap1_rt['id'], ap1_subnet['id'])
105 self.create_router_interface(ap2_rt['id'], ap2_subnet['id'])
106
Oleh Hryhorov9bb27d42021-01-12 12:40:55 +0200107 # NOTE(ohryhorov): the sleep below is added to avoid the situation
108 # when a port is not in active state yet but static route is added.
109 time.sleep(15)
110
Slawek Kaplonskib1a32892018-08-27 07:24:00 +0200111 self.client.update_router(
112 ap1_rt['id'],
113 routes=[{"destination": ap2_subnet['cidr'],
114 "nexthop": ap2_wan_port['fixed_ips'][0]['ip_address']}])
115 self.client.update_router(
116 ap2_rt['id'],
117 routes=[{"destination": ap1_subnet['cidr'],
118 "nexthop": ap1_wan_port['fixed_ips'][0]['ip_address']}])
119
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100120 servers = self._create_servers(ap1_internal_port, ap2_internal_port)
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +0200121
Slawek Kaplonskib1a32892018-08-27 07:24:00 +0200122 ap1_fip = self.create_and_associate_floatingip(
123 ap1_internal_port['id'])
124 ap1_sshclient = ssh.Client(
125 ap1_fip['floating_ip_address'], CONF.validation.image_ssh_user,
126 pkey=self.keypair['private_key'])
127
128 self.check_remote_connectivity(
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100129 ap1_sshclient, ap2_internal_port['fixed_ips'][0]['ip_address'],
130 servers=servers)
LIU Yulong68ab2452019-05-18 10:19:49 +0800131
132 @decorators.idempotent_id('b72c3b77-3396-4144-b05d-9cd3c0099893')
133 def test_connectivity_router_east_west_traffic(self):
134 """This case is intended to test router east west taffic
135
136 The case can be used in various scenarios: legacy/distributed router,
137 same/different host.
138 """
139 net_1 = self.create_network()
140 net_2 = self.create_network()
141 subnet_1 = self.create_subnet(net_1, cidr="10.10.1.0/24")
142 subnet_2 = self.create_subnet(net_2, cidr="10.10.2.0/24")
143
144 router = self.create_router(
145 router_name=data_utils.rand_name("east_west_traffic_router"),
146 admin_state_up=True,
147 external_network_id=CONF.network.public_network_id)
148
149 internal_port_1 = self.create_port(
150 net_1, security_groups=[self.secgroup['id']])
151 internal_port_2 = self.create_port(
152 net_2, security_groups=[self.secgroup['id']])
153
LIU Yulong68ab2452019-05-18 10:19:49 +0800154 self.create_router_interface(router['id'], subnet_1['id'])
155 self.create_router_interface(router['id'], subnet_2['id'])
156
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100157 servers = self._create_servers(internal_port_1, internal_port_2)
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +0200158
LIU Yulong68ab2452019-05-18 10:19:49 +0800159 fip = self.create_and_associate_floatingip(
160 internal_port_1['id'])
161 sshclient = ssh.Client(
162 fip['floating_ip_address'], CONF.validation.image_ssh_user,
163 pkey=self.keypair['private_key'])
164
165 self.check_remote_connectivity(
166 sshclient, internal_port_2['fixed_ips'][0]['ip_address'],
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100167 ping_count=10, servers=servers)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200168
169 @utils.requires_ext(extension="dvr", service="network")
170 @decorators.idempotent_id('69d3650a-5c32-40bc-ae56-5c4c849ddd37')
171 def test_connectivity_dvr_and_no_dvr_routers_in_same_subnet(self):
172 """This test case tests connectivity between vm and 2 routers.
173
174 Subnet is connected to dvr and non-dvr routers in the same time, test
175 ensures that connectivity from VM to both routers is working.
176
ccamposr3e1921b2020-01-29 11:10:05 +0100177 Test scenario: (NOTE: 10.1.0.0/24 private CIDR is used as an example)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200178 +----------------+ +------------+
179 | Non-dvr router | | DVR router |
180 | | | |
ccamposr3e1921b2020-01-29 11:10:05 +0100181 | 10.1.0.1 | | 10.1.0.x |
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200182 +-------+--------+ +-----+------+
183 | |
ccamposr3e1921b2020-01-29 11:10:05 +0100184 | 10.1.0.0/24 |
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200185 +----------------+----------------+
186 |
187 +-+-+
188 |VM |
189 +---+
190
191 where:
ccamposr3e1921b2020-01-29 11:10:05 +0100192 10.1.0.1 - is subnet's gateway IP address,
193 10.1.0.x - is any other IP address taken from subnet's range
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200194
ccamposr3e1921b2020-01-29 11:10:05 +0100195 Test ensures that both 10.1.0.1 and 10.1.0.x IP addresses are
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200196 reachable from VM.
197 """
Slawek Kaplonski2a71a892020-02-03 11:48:34 +0100198 ext_network = self.client.show_network(self.external_network_id)
199 for ext_subnetid in ext_network['network']['subnets']:
200 ext_subnet = self.os_admin.network_client.show_subnet(ext_subnetid)
201 ext_cidr = ext_subnet['subnet']['cidr']
202 if ext_subnet['subnet']['ip_version'] == constants.IP_VERSION_4:
203 break
204 else:
205 self.fail('No IPv4 subnet was found in external network %s' %
206 ext_network['network']['id'])
207
ccamposr3e1921b2020-01-29 11:10:05 +0100208 subnet_cidr = ip_utils.find_valid_cidr(used_cidr=ext_cidr)
209 gw_ip = netaddr.IPAddress(subnet_cidr.first + 1)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200210
211 network = self.create_network()
212 subnet = self.create_subnet(
ccamposr3e1921b2020-01-29 11:10:05 +0100213 network, cidr=str(subnet_cidr), gateway=str(gw_ip))
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200214
215 non_dvr_router = self.create_router_by_client(
216 tenant_id=self.client.tenant_id,
217 is_admin=True,
218 router_name=data_utils.rand_name("nondvr-2-routers-same-network"),
219 admin_state_up=True,
220 distributed=False)
221 self.create_router_interface(non_dvr_router['id'], subnet['id'])
222
223 dvr_router = self.create_router_by_client(
224 tenant_id=self.client.tenant_id,
225 is_admin=True,
226 router_name=data_utils.rand_name("dvr-2-rotuers-same-network"),
227 admin_state_up=True,
228 distributed=True)
229 dvr_router_port = self.create_port(network)
230 self.client.add_router_interface_with_port_id(
231 dvr_router['id'], dvr_router_port['id'])
232
233 vm = self.create_server(
234 flavor_ref=CONF.compute.flavor_ref,
235 image_ref=CONF.compute.image_ref,
236 key_name=self.keypair['name'],
237 networks=[{'uuid': network['id']}],
238 security_groups=[{'name': self.secgroup['name']}])
239 self.wait_for_server_active(vm['server'])
240
241 vm_port = self.client.list_ports(
242 network_id=network['id'], device_id=vm['server']['id'])['ports'][0]
243 fip = self.create_and_associate_floatingip(vm_port['id'])
244
245 sshclient = ssh.Client(
246 fip['floating_ip_address'], CONF.validation.image_ssh_user,
247 pkey=self.keypair['private_key'])
248
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100249 self.check_remote_connectivity(
250 sshclient, str(gw_ip), ping_count=10, servers=[vm])
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200251 self.check_remote_connectivity(
252 sshclient, dvr_router_port['fixed_ips'][0]['ip_address'],
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100253 ping_count=10, servers=[vm])