blob: 7d728323316838fc18ca39e7a0a007d038f126aa [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 Kaplonskib1a32892018-08-27 07:24:00 +020018from tempest.common import compute
19from tempest.common import utils
20from tempest.lib.common.utils import data_utils
21from tempest.lib import decorators
22
ccamposr3e1921b2020-01-29 11:10:05 +010023from neutron_tempest_plugin.common import ip as ip_utils
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020024from neutron_tempest_plugin.common import ssh
25from neutron_tempest_plugin import config
26from neutron_tempest_plugin.scenario import base
27
28CONF = config.CONF
29
30
31class NetworkConnectivityTest(base.BaseTempestTestCase):
32 credentials = ['primary', 'admin']
33
34 @classmethod
35 @utils.requires_ext(extension="router", service="network")
36 def resource_setup(cls):
37 super(NetworkConnectivityTest, cls).resource_setup()
38 # Create keypair with admin privileges
39 cls.keypair = cls.create_keypair()
40 # Create security group with admin privileges
41 cls.secgroup = cls.create_security_group(
42 name=data_utils.rand_name('secgroup'))
43 # Execute funcs to achieve ssh and ICMP capabilities
44 cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id'])
45 cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id'])
46
47 def _create_servers(self, port_1, port_2):
48 params = {
49 'flavor_ref': CONF.compute.flavor_ref,
50 'image_ref': CONF.compute.image_ref,
51 'key_name': self.keypair['name']
52 }
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020053 vms = []
54 vms.append(
55 self.create_server(networks=[{'port': port_1['id']}], **params))
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020056
57 if (CONF.compute.min_compute_nodes > 1 and
58 compute.is_scheduler_filter_enabled("DifferentHostFilter")):
59 params['scheduler_hints'] = {
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020060 'different_host': [vms[0]['server']['id']]}
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020061
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020062 vms.append(
63 self.create_server(networks=[{'port': port_2['id']}], **params))
64
65 for vm in vms:
66 self.wait_for_server_active(vm['server'])
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020067
68 @decorators.idempotent_id('8944b90d-1766-4669-bd8a-672b5d106bb7')
69 def test_connectivity_through_2_routers(self):
70 ap1_net = self.create_network()
71 ap2_net = self.create_network()
72 wan_net = self.create_network()
73 ap1_subnet = self.create_subnet(
74 ap1_net, cidr="10.10.210.0/24", gateway="10.10.210.254")
75 ap2_subnet = self.create_subnet(
76 ap2_net, cidr="10.10.220.0/24", gateway="10.10.220.254")
77 self.create_subnet(
78 wan_net, cidr="10.10.200.0/24", gateway="10.10.200.254")
79
80 ap1_rt = self.create_router(
81 router_name=data_utils.rand_name("ap1_rt"),
82 admin_state_up=True,
83 external_network_id=CONF.network.public_network_id)
84 ap2_rt = self.create_router(
85 router_name=data_utils.rand_name("ap2_rt"),
86 admin_state_up=True)
87
88 ap1_internal_port = self.create_port(
89 ap1_net, security_groups=[self.secgroup['id']])
90 ap2_internal_port = self.create_port(
91 ap2_net, security_groups=[self.secgroup['id']])
92 ap1_wan_port = self.create_port(wan_net)
93 ap2_wan_port = self.create_port(wan_net)
94
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020095 self.client.add_router_interface_with_port_id(
96 ap1_rt['id'], ap1_wan_port['id'])
97 self.client.add_router_interface_with_port_id(
98 ap2_rt['id'], ap2_wan_port['id'])
99 self.create_router_interface(ap1_rt['id'], ap1_subnet['id'])
100 self.create_router_interface(ap2_rt['id'], ap2_subnet['id'])
101
102 self.client.update_router(
103 ap1_rt['id'],
104 routes=[{"destination": ap2_subnet['cidr'],
105 "nexthop": ap2_wan_port['fixed_ips'][0]['ip_address']}])
106 self.client.update_router(
107 ap2_rt['id'],
108 routes=[{"destination": ap1_subnet['cidr'],
109 "nexthop": ap1_wan_port['fixed_ips'][0]['ip_address']}])
110
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +0200111 self._create_servers(ap1_internal_port, ap2_internal_port)
112
Slawek Kaplonskib1a32892018-08-27 07:24:00 +0200113 ap1_fip = self.create_and_associate_floatingip(
114 ap1_internal_port['id'])
115 ap1_sshclient = ssh.Client(
116 ap1_fip['floating_ip_address'], CONF.validation.image_ssh_user,
117 pkey=self.keypair['private_key'])
118
119 self.check_remote_connectivity(
120 ap1_sshclient, ap2_internal_port['fixed_ips'][0]['ip_address'])
LIU Yulong68ab2452019-05-18 10:19:49 +0800121
122 @decorators.idempotent_id('b72c3b77-3396-4144-b05d-9cd3c0099893')
123 def test_connectivity_router_east_west_traffic(self):
124 """This case is intended to test router east west taffic
125
126 The case can be used in various scenarios: legacy/distributed router,
127 same/different host.
128 """
129 net_1 = self.create_network()
130 net_2 = self.create_network()
131 subnet_1 = self.create_subnet(net_1, cidr="10.10.1.0/24")
132 subnet_2 = self.create_subnet(net_2, cidr="10.10.2.0/24")
133
134 router = self.create_router(
135 router_name=data_utils.rand_name("east_west_traffic_router"),
136 admin_state_up=True,
137 external_network_id=CONF.network.public_network_id)
138
139 internal_port_1 = self.create_port(
140 net_1, security_groups=[self.secgroup['id']])
141 internal_port_2 = self.create_port(
142 net_2, security_groups=[self.secgroup['id']])
143
LIU Yulong68ab2452019-05-18 10:19:49 +0800144 self.create_router_interface(router['id'], subnet_1['id'])
145 self.create_router_interface(router['id'], subnet_2['id'])
146
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +0200147 self._create_servers(internal_port_1, internal_port_2)
148
LIU Yulong68ab2452019-05-18 10:19:49 +0800149 fip = self.create_and_associate_floatingip(
150 internal_port_1['id'])
151 sshclient = ssh.Client(
152 fip['floating_ip_address'], CONF.validation.image_ssh_user,
153 pkey=self.keypair['private_key'])
154
155 self.check_remote_connectivity(
156 sshclient, internal_port_2['fixed_ips'][0]['ip_address'],
157 ping_count=10)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200158
159 @utils.requires_ext(extension="dvr", service="network")
160 @decorators.idempotent_id('69d3650a-5c32-40bc-ae56-5c4c849ddd37')
161 def test_connectivity_dvr_and_no_dvr_routers_in_same_subnet(self):
162 """This test case tests connectivity between vm and 2 routers.
163
164 Subnet is connected to dvr and non-dvr routers in the same time, test
165 ensures that connectivity from VM to both routers is working.
166
ccamposr3e1921b2020-01-29 11:10:05 +0100167 Test scenario: (NOTE: 10.1.0.0/24 private CIDR is used as an example)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200168 +----------------+ +------------+
169 | Non-dvr router | | DVR router |
170 | | | |
ccamposr3e1921b2020-01-29 11:10:05 +0100171 | 10.1.0.1 | | 10.1.0.x |
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200172 +-------+--------+ +-----+------+
173 | |
ccamposr3e1921b2020-01-29 11:10:05 +0100174 | 10.1.0.0/24 |
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200175 +----------------+----------------+
176 |
177 +-+-+
178 |VM |
179 +---+
180
181 where:
ccamposr3e1921b2020-01-29 11:10:05 +0100182 10.1.0.1 - is subnet's gateway IP address,
183 10.1.0.x - is any other IP address taken from subnet's range
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200184
ccamposr3e1921b2020-01-29 11:10:05 +0100185 Test ensures that both 10.1.0.1 and 10.1.0.x IP addresses are
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200186 reachable from VM.
187 """
ccamposr3e1921b2020-01-29 11:10:05 +0100188 ext_network = self.safe_client.show_network(self.external_network_id)
189 ext_subnet_id = ext_network['network']['subnets'][0]['id']
190 ext_subnet = self.safe_client.show_subnet(ext_subnet_id)
191 ext_cidr = ext_subnet['subnet']['cidr']
192 subnet_cidr = ip_utils.find_valid_cidr(used_cidr=ext_cidr)
193 gw_ip = netaddr.IPAddress(subnet_cidr.first + 1)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200194
195 network = self.create_network()
196 subnet = self.create_subnet(
ccamposr3e1921b2020-01-29 11:10:05 +0100197 network, cidr=str(subnet_cidr), gateway=str(gw_ip))
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200198
199 non_dvr_router = self.create_router_by_client(
200 tenant_id=self.client.tenant_id,
201 is_admin=True,
202 router_name=data_utils.rand_name("nondvr-2-routers-same-network"),
203 admin_state_up=True,
204 distributed=False)
205 self.create_router_interface(non_dvr_router['id'], subnet['id'])
206
207 dvr_router = self.create_router_by_client(
208 tenant_id=self.client.tenant_id,
209 is_admin=True,
210 router_name=data_utils.rand_name("dvr-2-rotuers-same-network"),
211 admin_state_up=True,
212 distributed=True)
213 dvr_router_port = self.create_port(network)
214 self.client.add_router_interface_with_port_id(
215 dvr_router['id'], dvr_router_port['id'])
216
217 vm = self.create_server(
218 flavor_ref=CONF.compute.flavor_ref,
219 image_ref=CONF.compute.image_ref,
220 key_name=self.keypair['name'],
221 networks=[{'uuid': network['id']}],
222 security_groups=[{'name': self.secgroup['name']}])
223 self.wait_for_server_active(vm['server'])
224
225 vm_port = self.client.list_ports(
226 network_id=network['id'], device_id=vm['server']['id'])['ports'][0]
227 fip = self.create_and_associate_floatingip(vm_port['id'])
228
229 sshclient = ssh.Client(
230 fip['floating_ip_address'], CONF.validation.image_ssh_user,
231 pkey=self.keypair['private_key'])
232
ccamposr3e1921b2020-01-29 11:10:05 +0100233 self.check_remote_connectivity(sshclient, str(gw_ip), ping_count=10)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200234 self.check_remote_connectivity(
235 sshclient, dvr_router_port['fixed_ips'][0]['ip_address'],
236 ping_count=10)