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]
87 vm_3 = test_utils.create_instance(
89 TESTCASE_CONFIG.instance_3_name,
93 secgroup_name=TESTCASE_CONFIG.secgroup_name,
94 compute_node=av_zone_2)
95 vm_3_ip = vm_3.networks.itervalues().next()[0]
97 vm_5 = test_utils.create_instance(
99 TESTCASE_CONFIG.instance_5_name,
103 secgroup_name=TESTCASE_CONFIG.secgroup_name,
104 compute_node=av_zone_2)
105 vm_5_ip = vm_5.networks.itervalues().next()[0]
107 # We boot vm5 first because we need vm5_ip for vm4 userdata
108 u4 = test_utils.generate_ping_userdata([vm_5_ip])
109 vm_4 = test_utils.create_instance(
111 TESTCASE_CONFIG.instance_4_name,
115 secgroup_name=TESTCASE_CONFIG.secgroup_name,
116 compute_node=av_zone_1,
118 vm_4_ip = vm_4.networks.itervalues().next()[0]
120 # We boot VM1 at the end because we need to get the IPs first to generate
122 u1 = test_utils.generate_ping_userdata([vm_2_ip,
126 vm_1 = test_utils.create_instance(
128 TESTCASE_CONFIG.instance_1_name,
132 secgroup_name=TESTCASE_CONFIG.secgroup_name,
133 compute_node=av_zone_1,
135 vm_1_ip = vm_1.networks.itervalues().next()[0]
137 msg = ("Create VPN with eRT<>iRT")
139 results.add_to_summary(1, msg)
140 vpn_name = "sdnvpn-" + str(randint(100000, 999999))
142 "import_targets": TESTCASE_CONFIG.targets1,
143 "export_targets": TESTCASE_CONFIG.targets2,
144 "route_distinguishers": TESTCASE_CONFIG.route_distinguishers,
147 bgpvpn = os_utils.create_bgpvpn(neutron_client, **kwargs)
148 bgpvpn_id = bgpvpn['bgpvpn']['id']
149 logger.debug("VPN created details: %s" % bgpvpn)
151 msg = ("Associate network '%s' to the VPN." % TESTCASE_CONFIG.net_1_name)
153 results.add_to_summary(1, msg)
154 results.add_to_summary(0, "-")
156 os_utils.create_network_association(
157 neutron_client, bgpvpn_id, network_1_id)
159 # Wait for VMs to get ips.
160 instances_up = test_utils.wait_for_instances_up(vm_1, vm_2,
165 logger.error("One or more instances is down")
166 # TODO: Handle this appropriately
168 # Ping from VM1 to VM2 should work
169 results.get_ping_status(vm_1, vm_1_ip, vm_2, vm_2_ip,
170 expected="PASS", timeout=200)
171 # Ping from VM1 to VM3 should work
172 results.get_ping_status(vm_1, vm_1_ip, vm_3, vm_3_ip,
173 expected="PASS", timeout=30)
174 # Ping from VM1 to VM4 should not work
175 results.get_ping_status(vm_1, vm_1_ip, vm_4, vm_4_ip,
176 expected="FAIL", timeout=30)
178 msg = ("Associate network '%s' to the VPN." % TESTCASE_CONFIG.net_2_name)
180 results.add_to_summary(0, "-")
181 results.add_to_summary(1, msg)
182 results.add_to_summary(0, "-")
183 os_utils.create_network_association(
184 neutron_client, bgpvpn_id, network_2_id)
186 test_utils.wait_for_bgp_net_assocs(neutron_client,
191 logger.info("Waiting for the VMs to connect to each other using the"
192 " updated network configuration")
193 test_utils.wait_before_subtest()
195 # Ping from VM4 to VM5 should work
196 results.get_ping_status(vm_4, vm_4_ip, vm_5, vm_5_ip,
197 expected="PASS", timeout=30)
198 # Ping from VM1 to VM4 should not work
199 results.get_ping_status(vm_1, vm_1_ip, vm_4, vm_4_ip,
200 expected="FAIL", timeout=30)
201 # Ping from VM1 to VM5 should not work
202 results.get_ping_status(vm_1, vm_1_ip, vm_5, vm_5_ip,
203 expected="FAIL", timeout=30)
205 msg = ("Update VPN with eRT=iRT ...")
207 results.add_to_summary(0, "-")
208 results.add_to_summary(1, msg)
209 results.add_to_summary(0, "-")
210 kwargs = {"import_targets": TESTCASE_CONFIG.targets1,
211 "export_targets": TESTCASE_CONFIG.targets1,
213 bgpvpn = os_utils.update_bgpvpn(neutron_client, bgpvpn_id, **kwargs)
215 logger.info("Waiting for the VMs to connect to each other using the"
216 " updated network configuration")
217 test_utils.wait_before_subtest()
219 # Ping from VM1 to VM4 should work
220 results.get_ping_status(vm_1, vm_1_ip, vm_4, vm_4_ip,
221 expected="PASS", timeout=30)
222 # Ping from VM1 to VM5 should work
223 results.get_ping_status(vm_1, vm_1_ip, vm_5, vm_5_ip,
224 expected="PASS", timeout=30)
226 return results.compile_summary(TESTCASE_CONFIG.success_criteria)
229 if __name__ == '__main__':