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 Test whether router assoc can coexist with floating IP
12 - Create VM1 in net1 with a subnet which is connected to a router
13 which is connected with the gateway
14 - Create VM2 in net2 with a subnet without a router attached.
15 - Create bgpvpn with iRT=eRT
16 - Assoc the router of net1 with bgpvpn and assoc net 2 with the bgpvpn
17 - Try to ping from one VM to the other
18 - Assign a floating IP to the VM in the router assoc network
19 - Ping it the floating ip
24 from sdnvpn.lib import config as sdnvpn_config
25 from sdnvpn.lib import openstack_utils as os_utils
26 from sdnvpn.lib import utils as test_utils
27 from sdnvpn.lib.results import Results
30 logger = logging.getLogger(__name__)
32 COMMON_CONFIG = sdnvpn_config.CommonConfig()
33 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
34 'sdnvpn.test.functest.testcase_8')
38 results = Results(COMMON_CONFIG.line_length)
40 results.add_to_summary(0, "=")
41 results.add_to_summary(2, "STATUS", "SUBTEST")
42 results.add_to_summary(0, "=")
44 nova_client = os_utils.get_nova_client()
45 neutron_client = os_utils.get_neutron_client()
46 glance_client = os_utils.get_glance_client()
48 (floatingip_ids, instance_ids, router_ids, network_ids, image_ids,
49 subnet_ids, interfaces, bgpvpn_ids) = ([] for i in range(8))
52 image_id = os_utils.create_glance_image(
53 glance_client, TESTCASE_CONFIG.image_name,
54 COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format,
55 container="bare", public='public')
56 image_ids.append(image_id)
58 network_1_id, subnet_1_id, router_1_id = test_utils.create_network(
60 TESTCASE_CONFIG.net_1_name,
61 TESTCASE_CONFIG.subnet_1_name,
62 TESTCASE_CONFIG.subnet_1_cidr,
63 TESTCASE_CONFIG.router_1_name)
64 network_2_id = test_utils.create_net(
66 TESTCASE_CONFIG.net_2_name)
68 subnet_2_id = test_utils.create_subnet(
70 TESTCASE_CONFIG.subnet_2_name,
71 TESTCASE_CONFIG.subnet_2_cidr,
74 interfaces.append(tuple((router_1_id, subnet_1_id)))
75 network_ids.extend([network_1_id, network_2_id])
76 router_ids.append(router_1_id)
77 subnet_ids.extend([subnet_1_id, subnet_2_id])
79 sg_id = os_utils.create_security_group_full(
80 neutron_client, TESTCASE_CONFIG.secgroup_name,
81 TESTCASE_CONFIG.secgroup_descr)
82 test_utils.open_icmp(neutron_client, sg_id)
83 test_utils.open_http_port(neutron_client, sg_id)
85 vm_2 = test_utils.create_instance(
87 TESTCASE_CONFIG.instance_2_name,
91 secgroup_name=TESTCASE_CONFIG.secgroup_name)
92 vm_2_ip = test_utils.get_instance_ip(vm_2)
94 u1 = test_utils.generate_ping_userdata([vm_2_ip])
95 vm_1 = test_utils.create_instance(
97 TESTCASE_CONFIG.instance_1_name,
101 secgroup_name=TESTCASE_CONFIG.secgroup_name,
103 instance_ids.extend([vm_1.id, vm_2.id])
105 results.record_action("Create VPN with eRT==iRT")
106 vpn_name = "sdnvpn-8"
108 "import_targets": TESTCASE_CONFIG.targets,
109 "export_targets": TESTCASE_CONFIG.targets,
110 "route_distinguishers": TESTCASE_CONFIG.route_distinguishers,
113 bgpvpn = test_utils.create_bgpvpn(neutron_client, **kwargs)
114 bgpvpn_id = bgpvpn['bgpvpn']['id']
115 logger.debug("VPN created details: %s" % bgpvpn)
116 bgpvpn_ids.append(bgpvpn_id)
118 msg = ("Associate router '%s' and net '%s' to the VPN."
119 % (TESTCASE_CONFIG.router_1_name,
120 TESTCASE_CONFIG.net_2_name))
121 results.record_action(msg)
122 results.add_to_summary(0, "-")
124 test_utils.create_router_association(
125 neutron_client, bgpvpn_id, router_1_id)
126 test_utils.create_network_association(
127 neutron_client, bgpvpn_id, network_2_id)
129 test_utils.wait_for_bgp_router_assoc(
130 neutron_client, bgpvpn_id, router_1_id)
131 test_utils.wait_for_bgp_net_assoc(
132 neutron_client, bgpvpn_id, network_2_id)
134 # Wait for VMs to get ips.
135 instances_up = test_utils.wait_for_instances_up(vm_2)
136 instances_dhcp_up = test_utils.wait_for_instances_get_dhcp(vm_1)
138 if (not instances_up or not instances_dhcp_up):
139 logger.error("One or more instances are down")
140 # TODO: Handle this appropriately
142 logger.info("Waiting for the VMs to connect to each other using the"
143 " updated network configuration")
144 test_utils.wait_before_subtest()
146 results.get_ping_status(vm_1, vm_2, expected="PASS", timeout=200)
147 results.add_to_summary(0, "=")
149 msg = "Assign a Floating IP to %s" % vm_1.name
150 results.record_action(msg)
152 fip = os_utils.create_floating_ip(neutron_client)
154 fip_added = os_utils.add_floating_ip(nova_client,
155 vm_1.id, fip['fip_addr'])
157 results.add_success(msg)
159 results.add_failure(msg)
161 results.add_to_summary(0, "=")
162 results.record_action("Ping %s via Floating IP" % vm_1.name)
163 results.add_to_summary(0, "-")
164 results.ping_ip_test(fip['fip_addr'])
166 floatingip_ids.append(fip['fip_id'])
168 except Exception as e:
169 logger.error("exception occurred while executing testcase_8: %s", e)
172 test_utils.cleanup_nova(nova_client, instance_ids)
173 test_utils.cleanup_glance(glance_client, image_ids)
174 test_utils.cleanup_neutron(neutron_client, floatingip_ids,
175 bgpvpn_ids, interfaces, subnet_ids,
176 router_ids, network_ids)
178 return results.compile_summary()
181 if __name__ == '__main__':
182 logging.basicConfig(level=logging.INFO)