3 # Copyright (c) 2017 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
11 Testcase for router/FloatingIP & net assoc mutual exclusivity
13 A testcase for ODL Bug 6962, testing whether a subnet with a router can be
15 - Create two VMs, each in a subnet with a router
16 - Network assoc the two networks in a VPN iRT=eRT
17 - Try to ping from one VM to the other
18 - Assign a floating IP to a VM
24 import functest.utils.openstack_utils as os_utils
26 from sdnvpn.lib import utils as test_utils
27 from sdnvpn.lib import config as sdnvpn_config
28 from sdnvpn.lib.results import Results
30 parser = argparse.ArgumentParser()
32 parser.add_argument("-r", "--report",
33 help="Create json result file",
36 args = parser.parse_args()
38 logger = logging.getLogger('sdnvpn-testcase-7')
40 COMMON_CONFIG = sdnvpn_config.CommonConfig()
41 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig('testcase_7')
45 results = Results(COMMON_CONFIG.line_length)
47 results.add_to_summary(0, "=")
48 results.add_to_summary(2, "STATUS", "SUBTEST")
49 results.add_to_summary(0, "=")
51 nova_client = os_utils.get_nova_client()
52 neutron_client = os_utils.get_neutron_client()
53 glance_client = os_utils.get_glance_client()
55 (floatingip_ids, instance_ids, router_ids, network_ids, image_ids,
56 subnet_ids, interfaces, bgpvpn_ids) = ([] for i in range(8))
58 image_id = os_utils.create_glance_image(glance_client,
59 TESTCASE_CONFIG.image_name,
60 COMMON_CONFIG.image_path,
61 disk=COMMON_CONFIG.image_format,
64 image_ids.append(image_id)
66 network_1_id, subnet_1_id, router_1_id = test_utils.create_network(
68 TESTCASE_CONFIG.net_1_name,
69 TESTCASE_CONFIG.subnet_1_name,
70 TESTCASE_CONFIG.subnet_1_cidr,
71 TESTCASE_CONFIG.router_1_name)
73 network_2_id, subnet_2_id, router_2_id = test_utils.create_network(
75 TESTCASE_CONFIG.net_2_name,
76 TESTCASE_CONFIG.subnet_2_name,
77 TESTCASE_CONFIG.subnet_2_cidr,
78 TESTCASE_CONFIG.router_2_name)
80 interfaces.append(tuple((router_1_id, subnet_1_id)))
81 interfaces.append(tuple((router_2_id, subnet_2_id)))
82 network_ids.extend([network_1_id, network_2_id])
83 router_ids.extend([router_1_id, router_2_id])
84 subnet_ids.extend([subnet_1_id, subnet_2_id])
86 sg_id = os_utils.create_security_group_full(neutron_client,
87 TESTCASE_CONFIG.secgroup_name,
88 TESTCASE_CONFIG.secgroup_descr)
89 test_utils.open_icmp(neutron_client, sg_id)
90 test_utils.open_http_port(neutron_client, sg_id)
92 vm_2 = test_utils.create_instance(
94 TESTCASE_CONFIG.instance_2_name,
98 secgroup_name=TESTCASE_CONFIG.secgroup_name)
99 vm_2_ip = test_utils.get_instance_ip(vm_2)
101 u1 = test_utils.generate_ping_userdata([vm_2_ip])
102 vm_1 = test_utils.create_instance(
104 TESTCASE_CONFIG.instance_1_name,
108 secgroup_name=TESTCASE_CONFIG.secgroup_name,
111 instance_ids.extend([vm_1.id, vm_2.id])
113 msg = ("Create VPN with eRT==iRT")
114 results.record_action(msg)
115 vpn_name = "sdnvpn-7"
116 kwargs = {"import_targets": TESTCASE_CONFIG.targets,
117 "export_targets": TESTCASE_CONFIG.targets,
118 "route_distinguishers": TESTCASE_CONFIG.route_distinguishers,
120 bgpvpn = test_utils.create_bgpvpn(neutron_client, **kwargs)
121 bgpvpn_id = bgpvpn['bgpvpn']['id']
122 logger.debug("VPN created details: %s" % bgpvpn)
123 bgpvpn_ids.append(bgpvpn_id)
125 msg = ("Associate networks '%s', '%s' to the VPN."
126 % (TESTCASE_CONFIG.net_1_name,
127 TESTCASE_CONFIG.net_2_name))
128 results.record_action(msg)
129 results.add_to_summary(0, "-")
131 test_utils.create_network_association(
132 neutron_client, bgpvpn_id, network_1_id)
133 test_utils.create_network_association(
134 neutron_client, bgpvpn_id, network_2_id)
136 test_utils.wait_for_bgp_net_assoc(
137 neutron_client, bgpvpn_id, network_1_id)
138 test_utils.wait_for_bgp_net_assoc(
139 neutron_client, bgpvpn_id, network_2_id)
141 instances_up = test_utils.wait_for_instances_up(vm_1, vm_2)
143 logger.error("One or more instances is down")
145 logger.info("Waiting for the VMs to connect to each other using the"
146 " updated network configuration")
147 test_utils.wait_before_subtest()
149 results.get_ping_status(vm_1, vm_2, expected="PASS", timeout=200)
150 results.add_to_summary(0, "=")
152 msg = "Assign a Floating IP to %s and ping it" % vm_2.name
153 results.record_action(msg)
154 results.add_to_summary(0, '-')
156 fip = os_utils.create_floating_ip(neutron_client)
157 fip_added = os_utils.add_floating_ip(nova_client, vm_2.id,
160 results.add_success(msg)
162 results.add_failure(msg)
164 results.ping_ip_test(fip['fip_addr'])
166 floatingip_ids.append(fip['fip_id'])
167 test_utils.cleanup_nova(nova_client, floatingip_ids, instance_ids,
169 test_utils.cleanup_neutron(neutron_client, bgpvpn_ids, interfaces,
170 subnet_ids, router_ids, network_ids)
172 return results.compile_summary()
175 if __name__ == '__main__':
176 logging.basicConfig(level=logging.INFO)