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 import functest.utils.openstack_utils as os_utils
26 import sdnvpn.lib.utils as test_utils
27 from sdnvpn.lib.results import Results
28 import sdnvpn.lib.config as sdnvpn_config
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-8')
40 COMMON_CONFIG = sdnvpn_config.CommonConfig()
41 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig('testcase_8')
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 image_id = os_utils.create_glance_image(glance_client,
56 TESTCASE_CONFIG.image_name,
57 COMMON_CONFIG.image_path,
58 disk=COMMON_CONFIG.image_format,
61 network_1_id, _, router_1_id = test_utils.create_network(
63 TESTCASE_CONFIG.net_1_name,
64 TESTCASE_CONFIG.subnet_1_name,
65 TESTCASE_CONFIG.subnet_1_cidr,
66 TESTCASE_CONFIG.router_1_name)
67 network_2_id = test_utils.create_net(
69 TESTCASE_CONFIG.net_2_name)
70 test_utils.create_subnet(neutron_client,
71 TESTCASE_CONFIG.subnet_2_name,
72 TESTCASE_CONFIG.subnet_2_cidr,
75 sg_id = os_utils.create_security_group_full(neutron_client,
76 TESTCASE_CONFIG.secgroup_name,
77 TESTCASE_CONFIG.secgroup_descr)
78 test_utils.open_icmp(neutron_client, sg_id)
79 test_utils.open_http_port(neutron_client, sg_id)
81 vm_2 = test_utils.create_instance(
83 TESTCASE_CONFIG.instance_2_name,
87 secgroup_name=TESTCASE_CONFIG.secgroup_name)
88 vm_2_ip = test_utils.get_instance_ip(vm_2)
90 u1 = test_utils.generate_ping_userdata([vm_2_ip])
91 vm_1 = test_utils.create_instance(
93 TESTCASE_CONFIG.instance_1_name,
97 secgroup_name=TESTCASE_CONFIG.secgroup_name,
100 results.record_action("Create VPN with eRT==iRT")
101 vpn_name = "sdnvpn-7"
102 kwargs = {"import_targets": TESTCASE_CONFIG.targets,
103 "export_targets": TESTCASE_CONFIG.targets,
104 "route_distinguishers": TESTCASE_CONFIG.route_distinguishers,
106 bgpvpn = os_utils.create_bgpvpn(neutron_client, **kwargs)
107 bgpvpn_id = bgpvpn['bgpvpn']['id']
108 logger.debug("VPN created details: %s" % bgpvpn)
110 msg = ("Associate router '%s' and net '%s' to the VPN."
111 % (TESTCASE_CONFIG.router_1_name,
112 TESTCASE_CONFIG.net_2_name))
113 results.record_action(msg)
114 results.add_to_summary(0, "-")
116 os_utils.create_router_association(
117 neutron_client, bgpvpn_id, router_1_id)
118 os_utils.create_network_association(
119 neutron_client, bgpvpn_id, network_2_id)
121 test_utils.wait_for_bgp_router_assoc(
122 neutron_client, bgpvpn_id, router_1_id)
123 test_utils.wait_for_bgp_net_assoc(
124 neutron_client, bgpvpn_id, network_2_id)
126 instances_up = test_utils.wait_for_instances_up(vm_1, vm_2)
128 logger.error("One or more instances is down")
130 logger.info("Waiting for the VMs to connect to each other using the"
131 " updated network configuration")
132 test_utils.wait_before_subtest()
134 results.get_ping_status(vm_1, vm_2, expected="PASS", timeout=200)
135 results.add_to_summary(0, "=")
137 msg = "Assign a Floating IP to %s" % vm_1.name
138 results.record_action(msg)
140 fip = os_utils.create_floating_ip(neutron_client)
141 fip_added = os_utils.add_floating_ip(nova_client, vm_1.id, fip['fip_addr'])
143 results.add_success(msg)
145 results.add_failure(msg)
147 results.record_action("Ping %s via Floating IP" % vm_1.name)
148 results.add_to_summary(0, "-")
149 results.ping_ip_test(fip['fip_addr'])
151 return results.compile_summary()
154 if __name__ == '__main__':
155 logging.basicConfig(level=logging.INFO)