blob: 5608daebca5084b710de60298788c6eb8088c991 [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
ccamposr3e1921b2020-01-29 11:10:05 +010016import netaddr
17
Slawek Kaplonski2a71a892020-02-03 11:48:34 +010018from neutron_lib import constants
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020019from tempest.common import compute
20from tempest.common import utils
21from tempest.lib.common.utils import data_utils
22from tempest.lib import decorators
23
ccamposr3e1921b2020-01-29 11:10:05 +010024from neutron_tempest_plugin.common import ip as ip_utils
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020025from neutron_tempest_plugin.common import ssh
26from neutron_tempest_plugin import config
27from neutron_tempest_plugin.scenario import base
28
29CONF = config.CONF
30
31
32class NetworkConnectivityTest(base.BaseTempestTestCase):
33 credentials = ['primary', 'admin']
34
35 @classmethod
36 @utils.requires_ext(extension="router", service="network")
37 def resource_setup(cls):
38 super(NetworkConnectivityTest, cls).resource_setup()
39 # Create keypair with admin privileges
40 cls.keypair = cls.create_keypair()
41 # Create security group with admin privileges
42 cls.secgroup = cls.create_security_group(
43 name=data_utils.rand_name('secgroup'))
44 # Execute funcs to achieve ssh and ICMP capabilities
45 cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id'])
46 cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id'])
47
48 def _create_servers(self, port_1, port_2):
49 params = {
50 'flavor_ref': CONF.compute.flavor_ref,
51 'image_ref': CONF.compute.image_ref,
52 'key_name': self.keypair['name']
53 }
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020054 vms = []
55 vms.append(
56 self.create_server(networks=[{'port': port_1['id']}], **params))
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020057
58 if (CONF.compute.min_compute_nodes > 1 and
59 compute.is_scheduler_filter_enabled("DifferentHostFilter")):
60 params['scheduler_hints'] = {
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020061 'different_host': [vms[0]['server']['id']]}
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020062
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020063 vms.append(
64 self.create_server(networks=[{'port': port_2['id']}], **params))
65
66 for vm in vms:
67 self.wait_for_server_active(vm['server'])
Slawek Kaplonski2211eab2020-10-20 16:43:53 +020068 self.wait_for_guest_os_ready(vm['server'])
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020069
Slawek Kaplonskie58219b2019-12-09 12:10:55 +010070 return vms
71
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020072 @decorators.idempotent_id('8944b90d-1766-4669-bd8a-672b5d106bb7')
73 def test_connectivity_through_2_routers(self):
74 ap1_net = self.create_network()
75 ap2_net = self.create_network()
76 wan_net = self.create_network()
77 ap1_subnet = self.create_subnet(
78 ap1_net, cidr="10.10.210.0/24", gateway="10.10.210.254")
79 ap2_subnet = self.create_subnet(
80 ap2_net, cidr="10.10.220.0/24", gateway="10.10.220.254")
81 self.create_subnet(
82 wan_net, cidr="10.10.200.0/24", gateway="10.10.200.254")
83
84 ap1_rt = self.create_router(
85 router_name=data_utils.rand_name("ap1_rt"),
86 admin_state_up=True,
87 external_network_id=CONF.network.public_network_id)
88 ap2_rt = self.create_router(
89 router_name=data_utils.rand_name("ap2_rt"),
90 admin_state_up=True)
Slawek Kaplonskiedf3cba2021-04-21 10:34:02 +020091 self._wait_for_router_ha_active(ap1_rt['id'])
92 self._wait_for_router_ha_active(ap2_rt['id'])
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020093
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 Kaplonskib1a32892018-08-27 07:24:00 +0200101 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
108 self.client.update_router(
109 ap1_rt['id'],
110 routes=[{"destination": ap2_subnet['cidr'],
111 "nexthop": ap2_wan_port['fixed_ips'][0]['ip_address']}])
112 self.client.update_router(
113 ap2_rt['id'],
114 routes=[{"destination": ap1_subnet['cidr'],
115 "nexthop": ap1_wan_port['fixed_ips'][0]['ip_address']}])
116
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100117 servers = self._create_servers(ap1_internal_port, ap2_internal_port)
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +0200118
Slawek Kaplonskib1a32892018-08-27 07:24:00 +0200119 ap1_fip = self.create_and_associate_floatingip(
120 ap1_internal_port['id'])
121 ap1_sshclient = ssh.Client(
122 ap1_fip['floating_ip_address'], CONF.validation.image_ssh_user,
123 pkey=self.keypair['private_key'])
124
125 self.check_remote_connectivity(
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100126 ap1_sshclient, ap2_internal_port['fixed_ips'][0]['ip_address'],
127 servers=servers)
LIU Yulong68ab2452019-05-18 10:19:49 +0800128
129 @decorators.idempotent_id('b72c3b77-3396-4144-b05d-9cd3c0099893')
130 def test_connectivity_router_east_west_traffic(self):
131 """This case is intended to test router east west taffic
132
133 The case can be used in various scenarios: legacy/distributed router,
134 same/different host.
135 """
136 net_1 = self.create_network()
137 net_2 = self.create_network()
138 subnet_1 = self.create_subnet(net_1, cidr="10.10.1.0/24")
139 subnet_2 = self.create_subnet(net_2, cidr="10.10.2.0/24")
140
141 router = self.create_router(
142 router_name=data_utils.rand_name("east_west_traffic_router"),
143 admin_state_up=True,
144 external_network_id=CONF.network.public_network_id)
Slawek Kaplonskiedf3cba2021-04-21 10:34:02 +0200145 self._wait_for_router_ha_active(router['id'])
LIU Yulong68ab2452019-05-18 10:19:49 +0800146
147 internal_port_1 = self.create_port(
148 net_1, security_groups=[self.secgroup['id']])
149 internal_port_2 = self.create_port(
150 net_2, security_groups=[self.secgroup['id']])
151
LIU Yulong68ab2452019-05-18 10:19:49 +0800152 self.create_router_interface(router['id'], subnet_1['id'])
153 self.create_router_interface(router['id'], subnet_2['id'])
154
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100155 servers = self._create_servers(internal_port_1, internal_port_2)
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +0200156
LIU Yulong68ab2452019-05-18 10:19:49 +0800157 fip = self.create_and_associate_floatingip(
158 internal_port_1['id'])
159 sshclient = ssh.Client(
160 fip['floating_ip_address'], CONF.validation.image_ssh_user,
161 pkey=self.keypair['private_key'])
162
163 self.check_remote_connectivity(
164 sshclient, internal_port_2['fixed_ips'][0]['ip_address'],
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100165 ping_count=10, servers=servers)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200166
167 @utils.requires_ext(extension="dvr", service="network")
168 @decorators.idempotent_id('69d3650a-5c32-40bc-ae56-5c4c849ddd37')
169 def test_connectivity_dvr_and_no_dvr_routers_in_same_subnet(self):
170 """This test case tests connectivity between vm and 2 routers.
171
172 Subnet is connected to dvr and non-dvr routers in the same time, test
173 ensures that connectivity from VM to both routers is working.
174
ccamposr3e1921b2020-01-29 11:10:05 +0100175 Test scenario: (NOTE: 10.1.0.0/24 private CIDR is used as an example)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200176 +----------------+ +------------+
177 | Non-dvr router | | DVR router |
178 | | | |
ccamposr3e1921b2020-01-29 11:10:05 +0100179 | 10.1.0.1 | | 10.1.0.x |
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200180 +-------+--------+ +-----+------+
181 | |
ccamposr3e1921b2020-01-29 11:10:05 +0100182 | 10.1.0.0/24 |
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200183 +----------------+----------------+
184 |
185 +-+-+
186 |VM |
187 +---+
188
189 where:
ccamposr3e1921b2020-01-29 11:10:05 +0100190 10.1.0.1 - is subnet's gateway IP address,
191 10.1.0.x - is any other IP address taken from subnet's range
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200192
ccamposr3e1921b2020-01-29 11:10:05 +0100193 Test ensures that both 10.1.0.1 and 10.1.0.x IP addresses are
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200194 reachable from VM.
195 """
Slawek Kaplonski2a71a892020-02-03 11:48:34 +0100196 ext_network = self.client.show_network(self.external_network_id)
197 for ext_subnetid in ext_network['network']['subnets']:
198 ext_subnet = self.os_admin.network_client.show_subnet(ext_subnetid)
199 ext_cidr = ext_subnet['subnet']['cidr']
200 if ext_subnet['subnet']['ip_version'] == constants.IP_VERSION_4:
201 break
202 else:
203 self.fail('No IPv4 subnet was found in external network %s' %
204 ext_network['network']['id'])
205
ccamposr3e1921b2020-01-29 11:10:05 +0100206 subnet_cidr = ip_utils.find_valid_cidr(used_cidr=ext_cidr)
207 gw_ip = netaddr.IPAddress(subnet_cidr.first + 1)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200208
209 network = self.create_network()
210 subnet = self.create_subnet(
ccamposr3e1921b2020-01-29 11:10:05 +0100211 network, cidr=str(subnet_cidr), gateway=str(gw_ip))
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200212
213 non_dvr_router = self.create_router_by_client(
Takashi Kajinamida451772023-03-22 00:19:39 +0900214 tenant_id=self.client.project_id,
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200215 is_admin=True,
216 router_name=data_utils.rand_name("nondvr-2-routers-same-network"),
217 admin_state_up=True,
218 distributed=False)
219 self.create_router_interface(non_dvr_router['id'], subnet['id'])
220
221 dvr_router = self.create_router_by_client(
Takashi Kajinamida451772023-03-22 00:19:39 +0900222 tenant_id=self.client.project_id,
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200223 is_admin=True,
224 router_name=data_utils.rand_name("dvr-2-rotuers-same-network"),
225 admin_state_up=True,
226 distributed=True)
227 dvr_router_port = self.create_port(network)
228 self.client.add_router_interface_with_port_id(
229 dvr_router['id'], dvr_router_port['id'])
230
231 vm = self.create_server(
232 flavor_ref=CONF.compute.flavor_ref,
233 image_ref=CONF.compute.image_ref,
234 key_name=self.keypair['name'],
235 networks=[{'uuid': network['id']}],
236 security_groups=[{'name': self.secgroup['name']}])
237 self.wait_for_server_active(vm['server'])
Slawek Kaplonski2211eab2020-10-20 16:43:53 +0200238 self.wait_for_guest_os_ready(vm['server'])
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200239
240 vm_port = self.client.list_ports(
241 network_id=network['id'], device_id=vm['server']['id'])['ports'][0]
242 fip = self.create_and_associate_floatingip(vm_port['id'])
243
244 sshclient = ssh.Client(
245 fip['floating_ip_address'], CONF.validation.image_ssh_user,
246 pkey=self.keypair['private_key'])
247
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100248 self.check_remote_connectivity(
249 sshclient, str(gw_ip), ping_count=10, servers=[vm])
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200250 self.check_remote_connectivity(
251 sshclient, dvr_router_port['fixed_ips'][0]['ip_address'],
Slawek Kaplonskie58219b2019-12-09 12:10:55 +0100252 ping_count=10, servers=[vm])