blob: 78d8d9599c903c3e9cf36d1838ea6a54a5257a46 [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
16from tempest.common import compute
17from tempest.common import utils
18from tempest.lib.common.utils import data_utils
19from tempest.lib import decorators
20
21from neutron_tempest_plugin.common import ssh
22from neutron_tempest_plugin import config
23from neutron_tempest_plugin.scenario import base
24
25CONF = config.CONF
26
27
28class NetworkConnectivityTest(base.BaseTempestTestCase):
29 credentials = ['primary', 'admin']
30
31 @classmethod
32 @utils.requires_ext(extension="router", service="network")
33 def resource_setup(cls):
34 super(NetworkConnectivityTest, cls).resource_setup()
35 # Create keypair with admin privileges
36 cls.keypair = cls.create_keypair()
37 # Create security group with admin privileges
38 cls.secgroup = cls.create_security_group(
39 name=data_utils.rand_name('secgroup'))
40 # Execute funcs to achieve ssh and ICMP capabilities
41 cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id'])
42 cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id'])
43
44 def _create_servers(self, port_1, port_2):
45 params = {
46 'flavor_ref': CONF.compute.flavor_ref,
47 'image_ref': CONF.compute.image_ref,
48 'key_name': self.keypair['name']
49 }
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020050 vms = []
51 vms.append(
52 self.create_server(networks=[{'port': port_1['id']}], **params))
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020053
54 if (CONF.compute.min_compute_nodes > 1 and
55 compute.is_scheduler_filter_enabled("DifferentHostFilter")):
56 params['scheduler_hints'] = {
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020057 'different_host': [vms[0]['server']['id']]}
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020058
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +020059 vms.append(
60 self.create_server(networks=[{'port': port_2['id']}], **params))
61
62 for vm in vms:
63 self.wait_for_server_active(vm['server'])
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020064
65 @decorators.idempotent_id('8944b90d-1766-4669-bd8a-672b5d106bb7')
66 def test_connectivity_through_2_routers(self):
67 ap1_net = self.create_network()
68 ap2_net = self.create_network()
69 wan_net = self.create_network()
70 ap1_subnet = self.create_subnet(
71 ap1_net, cidr="10.10.210.0/24", gateway="10.10.210.254")
72 ap2_subnet = self.create_subnet(
73 ap2_net, cidr="10.10.220.0/24", gateway="10.10.220.254")
74 self.create_subnet(
75 wan_net, cidr="10.10.200.0/24", gateway="10.10.200.254")
76
77 ap1_rt = self.create_router(
78 router_name=data_utils.rand_name("ap1_rt"),
79 admin_state_up=True,
80 external_network_id=CONF.network.public_network_id)
81 ap2_rt = self.create_router(
82 router_name=data_utils.rand_name("ap2_rt"),
83 admin_state_up=True)
84
85 ap1_internal_port = self.create_port(
86 ap1_net, security_groups=[self.secgroup['id']])
87 ap2_internal_port = self.create_port(
88 ap2_net, security_groups=[self.secgroup['id']])
89 ap1_wan_port = self.create_port(wan_net)
90 ap2_wan_port = self.create_port(wan_net)
91
Slawek Kaplonskib1a32892018-08-27 07:24:00 +020092 self.client.add_router_interface_with_port_id(
93 ap1_rt['id'], ap1_wan_port['id'])
94 self.client.add_router_interface_with_port_id(
95 ap2_rt['id'], ap2_wan_port['id'])
96 self.create_router_interface(ap1_rt['id'], ap1_subnet['id'])
97 self.create_router_interface(ap2_rt['id'], ap2_subnet['id'])
98
99 self.client.update_router(
100 ap1_rt['id'],
101 routes=[{"destination": ap2_subnet['cidr'],
102 "nexthop": ap2_wan_port['fixed_ips'][0]['ip_address']}])
103 self.client.update_router(
104 ap2_rt['id'],
105 routes=[{"destination": ap1_subnet['cidr'],
106 "nexthop": ap1_wan_port['fixed_ips'][0]['ip_address']}])
107
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +0200108 self._create_servers(ap1_internal_port, ap2_internal_port)
109
Slawek Kaplonskib1a32892018-08-27 07:24:00 +0200110 ap1_fip = self.create_and_associate_floatingip(
111 ap1_internal_port['id'])
112 ap1_sshclient = ssh.Client(
113 ap1_fip['floating_ip_address'], CONF.validation.image_ssh_user,
114 pkey=self.keypair['private_key'])
115
116 self.check_remote_connectivity(
117 ap1_sshclient, ap2_internal_port['fixed_ips'][0]['ip_address'])
LIU Yulong68ab2452019-05-18 10:19:49 +0800118
119 @decorators.idempotent_id('b72c3b77-3396-4144-b05d-9cd3c0099893')
120 def test_connectivity_router_east_west_traffic(self):
121 """This case is intended to test router east west taffic
122
123 The case can be used in various scenarios: legacy/distributed router,
124 same/different host.
125 """
126 net_1 = self.create_network()
127 net_2 = self.create_network()
128 subnet_1 = self.create_subnet(net_1, cidr="10.10.1.0/24")
129 subnet_2 = self.create_subnet(net_2, cidr="10.10.2.0/24")
130
131 router = self.create_router(
132 router_name=data_utils.rand_name("east_west_traffic_router"),
133 admin_state_up=True,
134 external_network_id=CONF.network.public_network_id)
135
136 internal_port_1 = self.create_port(
137 net_1, security_groups=[self.secgroup['id']])
138 internal_port_2 = self.create_port(
139 net_2, security_groups=[self.secgroup['id']])
140
LIU Yulong68ab2452019-05-18 10:19:49 +0800141 self.create_router_interface(router['id'], subnet_1['id'])
142 self.create_router_interface(router['id'], subnet_2['id'])
143
Slawek Kaplonski6aae0d42019-06-26 10:17:15 +0200144 self._create_servers(internal_port_1, internal_port_2)
145
LIU Yulong68ab2452019-05-18 10:19:49 +0800146 fip = self.create_and_associate_floatingip(
147 internal_port_1['id'])
148 sshclient = ssh.Client(
149 fip['floating_ip_address'], CONF.validation.image_ssh_user,
150 pkey=self.keypair['private_key'])
151
152 self.check_remote_connectivity(
153 sshclient, internal_port_2['fixed_ips'][0]['ip_address'],
154 ping_count=10)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200155
156 @utils.requires_ext(extension="dvr", service="network")
157 @decorators.idempotent_id('69d3650a-5c32-40bc-ae56-5c4c849ddd37')
158 def test_connectivity_dvr_and_no_dvr_routers_in_same_subnet(self):
159 """This test case tests connectivity between vm and 2 routers.
160
161 Subnet is connected to dvr and non-dvr routers in the same time, test
162 ensures that connectivity from VM to both routers is working.
163
164 Test scenario:
165 +----------------+ +------------+
166 | Non-dvr router | | DVR router |
167 | | | |
168 | 10.0.0.1 | | 10.0.0.x |
169 +-------+--------+ +-----+------+
170 | |
171 | 10.0.0.0/24 |
172 +----------------+----------------+
173 |
174 +-+-+
175 |VM |
176 +---+
177
178 where:
179 10.0.0.1 - is subnet's gateway IP address,
180 10.0.0.x - is any other IP address taken from subnet's range
181
182 Test ensures that both 10.0.0.1 and 10.0.0.x IP addresses are
183 reachable from VM.
184 """
185
186 network = self.create_network()
187 subnet = self.create_subnet(
188 network, cidr="10.0.0.0/24", gateway="10.0.0.1")
189
190 non_dvr_router = self.create_router_by_client(
191 tenant_id=self.client.tenant_id,
192 is_admin=True,
193 router_name=data_utils.rand_name("nondvr-2-routers-same-network"),
194 admin_state_up=True,
195 distributed=False)
196 self.create_router_interface(non_dvr_router['id'], subnet['id'])
197
198 dvr_router = self.create_router_by_client(
199 tenant_id=self.client.tenant_id,
200 is_admin=True,
201 router_name=data_utils.rand_name("dvr-2-rotuers-same-network"),
202 admin_state_up=True,
203 distributed=True)
204 dvr_router_port = self.create_port(network)
205 self.client.add_router_interface_with_port_id(
206 dvr_router['id'], dvr_router_port['id'])
207
208 vm = self.create_server(
209 flavor_ref=CONF.compute.flavor_ref,
210 image_ref=CONF.compute.image_ref,
211 key_name=self.keypair['name'],
212 networks=[{'uuid': network['id']}],
213 security_groups=[{'name': self.secgroup['name']}])
214 self.wait_for_server_active(vm['server'])
215
216 vm_port = self.client.list_ports(
217 network_id=network['id'], device_id=vm['server']['id'])['ports'][0]
218 fip = self.create_and_associate_floatingip(vm_port['id'])
219
220 sshclient = ssh.Client(
221 fip['floating_ip_address'], CONF.validation.image_ssh_user,
222 pkey=self.keypair['private_key'])
223
224 self.check_remote_connectivity(
225 sshclient, '10.0.0.1', ping_count=10)
226 self.check_remote_connectivity(
227 sshclient, dvr_router_port['fixed_ips'][0]['ip_address'],
228 ping_count=10)