blob: 6aaf48d60a52185481026ddd1e4d34f631caba1c [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 }
50 vm1 = self.create_server(networks=[{'port': port_1['id']}], **params)
51
52 if (CONF.compute.min_compute_nodes > 1 and
53 compute.is_scheduler_filter_enabled("DifferentHostFilter")):
54 params['scheduler_hints'] = {
55 'different_host': [vm1['server']['id']]}
56
57 self.create_server(networks=[{'port': port_2['id']}], **params)
58
59 @decorators.idempotent_id('8944b90d-1766-4669-bd8a-672b5d106bb7')
60 def test_connectivity_through_2_routers(self):
61 ap1_net = self.create_network()
62 ap2_net = self.create_network()
63 wan_net = self.create_network()
64 ap1_subnet = self.create_subnet(
65 ap1_net, cidr="10.10.210.0/24", gateway="10.10.210.254")
66 ap2_subnet = self.create_subnet(
67 ap2_net, cidr="10.10.220.0/24", gateway="10.10.220.254")
68 self.create_subnet(
69 wan_net, cidr="10.10.200.0/24", gateway="10.10.200.254")
70
71 ap1_rt = self.create_router(
72 router_name=data_utils.rand_name("ap1_rt"),
73 admin_state_up=True,
74 external_network_id=CONF.network.public_network_id)
75 ap2_rt = self.create_router(
76 router_name=data_utils.rand_name("ap2_rt"),
77 admin_state_up=True)
78
79 ap1_internal_port = self.create_port(
80 ap1_net, security_groups=[self.secgroup['id']])
81 ap2_internal_port = self.create_port(
82 ap2_net, security_groups=[self.secgroup['id']])
83 ap1_wan_port = self.create_port(wan_net)
84 ap2_wan_port = self.create_port(wan_net)
85
86 self._create_servers(ap1_internal_port, ap2_internal_port)
87
88 self.client.add_router_interface_with_port_id(
89 ap1_rt['id'], ap1_wan_port['id'])
90 self.client.add_router_interface_with_port_id(
91 ap2_rt['id'], ap2_wan_port['id'])
92 self.create_router_interface(ap1_rt['id'], ap1_subnet['id'])
93 self.create_router_interface(ap2_rt['id'], ap2_subnet['id'])
94
95 self.client.update_router(
96 ap1_rt['id'],
97 routes=[{"destination": ap2_subnet['cidr'],
98 "nexthop": ap2_wan_port['fixed_ips'][0]['ip_address']}])
99 self.client.update_router(
100 ap2_rt['id'],
101 routes=[{"destination": ap1_subnet['cidr'],
102 "nexthop": ap1_wan_port['fixed_ips'][0]['ip_address']}])
103
104 ap1_fip = self.create_and_associate_floatingip(
105 ap1_internal_port['id'])
106 ap1_sshclient = ssh.Client(
107 ap1_fip['floating_ip_address'], CONF.validation.image_ssh_user,
108 pkey=self.keypair['private_key'])
109
110 self.check_remote_connectivity(
111 ap1_sshclient, ap2_internal_port['fixed_ips'][0]['ip_address'])
LIU Yulong68ab2452019-05-18 10:19:49 +0800112
113 @decorators.idempotent_id('b72c3b77-3396-4144-b05d-9cd3c0099893')
114 def test_connectivity_router_east_west_traffic(self):
115 """This case is intended to test router east west taffic
116
117 The case can be used in various scenarios: legacy/distributed router,
118 same/different host.
119 """
120 net_1 = self.create_network()
121 net_2 = self.create_network()
122 subnet_1 = self.create_subnet(net_1, cidr="10.10.1.0/24")
123 subnet_2 = self.create_subnet(net_2, cidr="10.10.2.0/24")
124
125 router = self.create_router(
126 router_name=data_utils.rand_name("east_west_traffic_router"),
127 admin_state_up=True,
128 external_network_id=CONF.network.public_network_id)
129
130 internal_port_1 = self.create_port(
131 net_1, security_groups=[self.secgroup['id']])
132 internal_port_2 = self.create_port(
133 net_2, security_groups=[self.secgroup['id']])
134
135 self._create_servers(internal_port_1, internal_port_2)
136
137 self.create_router_interface(router['id'], subnet_1['id'])
138 self.create_router_interface(router['id'], subnet_2['id'])
139
140 fip = self.create_and_associate_floatingip(
141 internal_port_1['id'])
142 sshclient = ssh.Client(
143 fip['floating_ip_address'], CONF.validation.image_ssh_user,
144 pkey=self.keypair['private_key'])
145
146 self.check_remote_connectivity(
147 sshclient, internal_port_2['fixed_ips'][0]['ip_address'],
148 ping_count=10)
Slawek Kaplonskid2a6acc2019-06-04 12:22:24 +0200149
150 @utils.requires_ext(extension="dvr", service="network")
151 @decorators.idempotent_id('69d3650a-5c32-40bc-ae56-5c4c849ddd37')
152 def test_connectivity_dvr_and_no_dvr_routers_in_same_subnet(self):
153 """This test case tests connectivity between vm and 2 routers.
154
155 Subnet is connected to dvr and non-dvr routers in the same time, test
156 ensures that connectivity from VM to both routers is working.
157
158 Test scenario:
159 +----------------+ +------------+
160 | Non-dvr router | | DVR router |
161 | | | |
162 | 10.0.0.1 | | 10.0.0.x |
163 +-------+--------+ +-----+------+
164 | |
165 | 10.0.0.0/24 |
166 +----------------+----------------+
167 |
168 +-+-+
169 |VM |
170 +---+
171
172 where:
173 10.0.0.1 - is subnet's gateway IP address,
174 10.0.0.x - is any other IP address taken from subnet's range
175
176 Test ensures that both 10.0.0.1 and 10.0.0.x IP addresses are
177 reachable from VM.
178 """
179
180 network = self.create_network()
181 subnet = self.create_subnet(
182 network, cidr="10.0.0.0/24", gateway="10.0.0.1")
183
184 non_dvr_router = self.create_router_by_client(
185 tenant_id=self.client.tenant_id,
186 is_admin=True,
187 router_name=data_utils.rand_name("nondvr-2-routers-same-network"),
188 admin_state_up=True,
189 distributed=False)
190 self.create_router_interface(non_dvr_router['id'], subnet['id'])
191
192 dvr_router = self.create_router_by_client(
193 tenant_id=self.client.tenant_id,
194 is_admin=True,
195 router_name=data_utils.rand_name("dvr-2-rotuers-same-network"),
196 admin_state_up=True,
197 distributed=True)
198 dvr_router_port = self.create_port(network)
199 self.client.add_router_interface_with_port_id(
200 dvr_router['id'], dvr_router_port['id'])
201
202 vm = self.create_server(
203 flavor_ref=CONF.compute.flavor_ref,
204 image_ref=CONF.compute.image_ref,
205 key_name=self.keypair['name'],
206 networks=[{'uuid': network['id']}],
207 security_groups=[{'name': self.secgroup['name']}])
208 self.wait_for_server_active(vm['server'])
209
210 vm_port = self.client.list_ports(
211 network_id=network['id'], device_id=vm['server']['id'])['ports'][0]
212 fip = self.create_and_associate_floatingip(vm_port['id'])
213
214 sshclient = ssh.Client(
215 fip['floating_ip_address'], CONF.validation.image_ssh_user,
216 pkey=self.keypair['private_key'])
217
218 self.check_remote_connectivity(
219 sshclient, '10.0.0.1', ping_count=10)
220 self.check_remote_connectivity(
221 sshclient, dvr_router_port['fixed_ips'][0]['ip_address'],
222 ping_count=10)