blob: 311c2632b2599158b6687e34f03ce506f49f94f8 [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)