3 # Copyright (c) 2015 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
12 from random import randint
14 import functest.utils.functest_logger as ft_logger
15 import functest.utils.openstack_utils as os_utils
17 import utils as test_utils
18 import config as sdnvpn_config
19 from results import Results
21 parser = argparse.ArgumentParser()
23 parser.add_argument("-r", "--report",
24 help="Create json result file",
27 args = parser.parse_args()
29 logger = ft_logger.Logger("sdnvpn-testcase-1").getLogger()
31 COMMON_CONFIG = sdnvpn_config.CommonConfig()
32 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig('testcase_1')
36 results = Results(COMMON_CONFIG.line_length)
38 results.add_to_summary(0, "=")
39 results.add_to_summary(2, "STATUS", "SUBTEST")
40 results.add_to_summary(0, "=")
42 nova_client = os_utils.get_nova_client()
43 neutron_client = os_utils.get_neutron_client()
44 glance_client = os_utils.get_glance_client()
46 image_id = os_utils.create_glance_image(glance_client,
47 TESTCASE_CONFIG.image_name,
48 COMMON_CONFIG.image_path,
49 disk=COMMON_CONFIG.image_format,
52 network_1_id = test_utils.create_net(neutron_client,
53 TESTCASE_CONFIG.net_1_name)
54 test_utils.create_subnet(neutron_client,
55 TESTCASE_CONFIG.subnet_1_name,
56 TESTCASE_CONFIG.subnet_1_cidr,
59 network_2_id = test_utils.create_net(neutron_client,
60 TESTCASE_CONFIG.net_2_name)
62 test_utils.create_subnet(neutron_client,
63 TESTCASE_CONFIG.subnet_2_name,
64 TESTCASE_CONFIG.subnet_2_cidr,
67 sg_id = os_utils.create_security_group_full(neutron_client,
68 TESTCASE_CONFIG.secgroup_name,
69 TESTCASE_CONFIG.secgroup_descr)
71 compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
73 av_zone_1 = "nova:" + compute_nodes[0]
74 av_zone_2 = "nova:" + compute_nodes[1]
77 vm_2 = test_utils.create_instance(
79 TESTCASE_CONFIG.instance_2_name,
83 secgroup_name=TESTCASE_CONFIG.secgroup_name,
84 compute_node=av_zone_1)
85 vm_2_ip = vm_2.networks.itervalues().next()[0]
86 logger.debug("Instance '%s' booted successfully. IP='%s'." %
87 (TESTCASE_CONFIG.instance_2_name, vm_2_ip))
89 vm_3 = test_utils.create_instance(
91 TESTCASE_CONFIG.instance_3_name,
95 secgroup_name=TESTCASE_CONFIG.secgroup_name,
96 compute_node=av_zone_2)
97 vm_3_ip = vm_3.networks.itervalues().next()[0]
98 logger.debug("Instance '%s' booted successfully. IP='%s'." %
99 (TESTCASE_CONFIG.instance_3_name, vm_3_ip))
101 vm_5 = test_utils.create_instance(
103 TESTCASE_CONFIG.instance_5_name,
107 secgroup_name=TESTCASE_CONFIG.secgroup_name,
108 compute_node=av_zone_2)
109 vm_5_ip = vm_5.networks.itervalues().next()[0]
110 logger.debug("Instance '%s' booted successfully. IP='%s'." %
111 (TESTCASE_CONFIG.instance_5_name, vm_5_ip))
113 # We boot vm5 first because we need vm5_ip for vm4 userdata
114 u4 = test_utils.generate_ping_userdata([vm_5_ip])
115 vm_4 = test_utils.create_instance(
117 TESTCASE_CONFIG.instance_4_name,
121 secgroup_name=TESTCASE_CONFIG.secgroup_name,
122 compute_node=av_zone_1,
124 vm_4_ip = vm_4.networks.itervalues().next()[0]
125 logger.debug("Instance '%s' booted successfully. IP='%s'." %
126 (TESTCASE_CONFIG.instance_4_name, vm_4_ip))
128 # We boot VM1 at the end because we need to get the IPs first to generate
130 u1 = test_utils.generate_ping_userdata([vm_2_ip,
134 vm_1 = test_utils.create_instance(
136 TESTCASE_CONFIG.instance_1_name,
140 secgroup_name=TESTCASE_CONFIG.secgroup_name,
141 compute_node=av_zone_1,
143 vm_1_ip = vm_1.networks.itervalues().next()[0]
144 logger.debug("Instance '%s' booted successfully. IP='%s'." %
145 (TESTCASE_CONFIG.instance_1_name, vm_1_ip))
147 msg = ("Create VPN with eRT<>iRT")
149 results.add_to_summary(1, msg)
150 vpn_name = "sdnvpn-" + str(randint(100000, 999999))
152 "import_targets": TESTCASE_CONFIG.targets1,
153 "export_targets": TESTCASE_CONFIG.targets2,
154 "route_distinguishers": TESTCASE_CONFIG.route_distinguishers,
157 bgpvpn = os_utils.create_bgpvpn(neutron_client, **kwargs)
158 bgpvpn_id = bgpvpn['bgpvpn']['id']
159 logger.debug("VPN created details: %s" % bgpvpn)
161 msg = ("Associate network '%s' to the VPN." % TESTCASE_CONFIG.net_1_name)
163 results.add_to_summary(1, msg)
164 results.add_to_summary(0, "-")
166 os_utils.create_network_association(
167 neutron_client, bgpvpn_id, network_1_id)
169 # Wait for VMs to get ips.
170 instances_up = test_utils.wait_for_instances_up(vm_1, vm_2,
175 logger.error("One or more instances is down")
176 # TODO: Handle this appropriately
178 # Ping from VM1 to VM2 should work
179 results.get_ping_status(vm_1, vm_1_ip, vm_2, vm_2_ip,
180 expected="PASS", timeout=200)
181 # Ping from VM1 to VM3 should work
182 results.get_ping_status(vm_1, vm_1_ip, vm_3, vm_3_ip,
183 expected="PASS", timeout=30)
184 # Ping from VM1 to VM4 should not work
185 results.get_ping_status(vm_1, vm_1_ip, vm_4, vm_4_ip,
186 expected="FAIL", timeout=30)
188 msg = ("Associate network '%s' to the VPN." % TESTCASE_CONFIG.net_2_name)
190 results.add_to_summary(0, "-")
191 results.add_to_summary(1, msg)
192 results.add_to_summary(0, "-")
193 os_utils.create_network_association(
194 neutron_client, bgpvpn_id, network_2_id)
196 test_utils.wait_for_bgp_net_assocs(neutron_client,
201 logger.info("Waiting for the VMs to connect to each other using the"
202 " updated network configuration")
203 test_utils.wait_before_subtest()
205 # Ping from VM4 to VM5 should work
206 results.get_ping_status(vm_4, vm_4_ip, vm_5, vm_5_ip,
207 expected="PASS", timeout=30)
208 # Ping from VM1 to VM4 should not work
209 results.get_ping_status(vm_1, vm_1_ip, vm_4, vm_4_ip,
210 expected="FAIL", timeout=30)
211 # Ping from VM1 to VM5 should not work
212 results.get_ping_status(vm_1, vm_1_ip, vm_5, vm_5_ip,
213 expected="FAIL", timeout=30)
215 msg = ("Update VPN with eRT=iRT ...")
217 results.add_to_summary(0, "-")
218 results.add_to_summary(1, msg)
219 results.add_to_summary(0, "-")
220 kwargs = {"import_targets": TESTCASE_CONFIG.targets1,
221 "export_targets": TESTCASE_CONFIG.targets1,
223 bgpvpn = os_utils.update_bgpvpn(neutron_client, bgpvpn_id, **kwargs)
225 logger.info("Waiting for the VMs to connect to each other using the"
226 " updated network configuration")
227 test_utils.wait_before_subtest()
229 # Ping from VM1 to VM4 should work
230 results.get_ping_status(vm_1, vm_1_ip, vm_4, vm_4_ip,
231 expected="PASS", timeout=30)
232 # Ping from VM1 to VM5 should work
233 results.get_ping_status(vm_1, vm_1_ip, vm_5, vm_5_ip,
234 expected="PASS", timeout=30)
236 return results.compile_summary(TESTCASE_CONFIG.success_criteria)
239 if __name__ == '__main__':