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
14 from functest.utils import openstack_utils as os_utils
15 from random import randint
16 from sdnvpn.lib import config as sdnvpn_config
17 from sdnvpn.lib import utils as test_utils
18 from sdnvpn.lib.results import Results
20 logger = logging.getLogger(__name__)
22 COMMON_CONFIG = sdnvpn_config.CommonConfig()
23 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
24 'sdnvpn.test.functest.testcase_13')
28 results = Results(COMMON_CONFIG.line_length)
30 results.add_to_summary(0, "=")
31 results.add_to_summary(2, "STATUS", "SUBTEST")
32 results.add_to_summary(0, "=")
34 nova_client = os_utils.get_nova_client()
35 neutron_client = os_utils.get_neutron_client()
36 glance_client = os_utils.get_glance_client()
38 (floatingip_ids, instance_ids, router_ids, network_ids, image_ids,
39 subnet_ids, interfaces, bgpvpn_ids, flavor_ids) = ([] for i in range(9))
42 image_id = os_utils.create_glance_image(
44 COMMON_CONFIG.ubuntu_image_name,
45 COMMON_CONFIG.ubuntu_image_path,
49 image_ids.append(image_id)
51 _, flavor_id = test_utils.create_custom_flavor()
52 flavor_ids.append(flavor_id)
54 network_1_id, subnet_1_id, router_1_id = test_utils.create_network(
56 TESTCASE_CONFIG.net_1_name,
57 TESTCASE_CONFIG.subnet_1_name,
58 TESTCASE_CONFIG.subnet_1_cidr,
59 TESTCASE_CONFIG.router_1_name)
61 interfaces.append(tuple((router_1_id, subnet_1_id)))
62 network_ids.extend([network_1_id])
63 subnet_ids.extend([subnet_1_id])
64 router_ids.extend([router_1_id])
66 sg_id = os_utils.create_security_group_full(
67 neutron_client, TESTCASE_CONFIG.secgroup_name,
68 TESTCASE_CONFIG.secgroup_descr)
70 compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
72 av_zone_1 = "nova:" + compute_nodes[0]
73 av_zone_2 = "nova:" + compute_nodes[1]
75 u1 = test_utils.generate_userdata_interface_create(
76 TESTCASE_CONFIG.interface_name,
77 TESTCASE_CONFIG.interface_number,
78 TESTCASE_CONFIG.extra_route_ip,
79 TESTCASE_CONFIG.extra_route_subnet_mask)
81 vm_1 = test_utils.create_instance(
83 TESTCASE_CONFIG.instance_1_name,
87 flavor=COMMON_CONFIG.custom_flavor_name,
88 secgroup_name=TESTCASE_CONFIG.secgroup_name,
89 compute_node=av_zone_1,
91 vm_1_ip = test_utils.get_instance_ip(vm_1)
93 vm1_port = test_utils.get_port(neutron_client, vm_1.id)
94 test_utils.update_port_allowed_address_pairs(
97 [test_utils.AllowedAddressPair(
98 TESTCASE_CONFIG.extra_route_cidr,
99 vm1_port['mac_address'])])
101 vm_2 = test_utils.create_instance(
103 TESTCASE_CONFIG.instance_2_name,
107 flavor=COMMON_CONFIG.custom_flavor_name,
108 secgroup_name=TESTCASE_CONFIG.secgroup_name,
109 compute_node=av_zone_1,
111 vm_2_ip = test_utils.get_instance_ip(vm_2)
113 vm2_port = test_utils.get_port(neutron_client, vm_2.id)
114 test_utils.update_port_allowed_address_pairs(
117 [test_utils.AllowedAddressPair(
118 TESTCASE_CONFIG.extra_route_cidr,
119 vm2_port['mac_address'])])
121 test_utils.async_Wait_for_instances([vm_1, vm_2])
123 image_2_id = os_utils.create_glance_image(
124 glance_client, TESTCASE_CONFIG.image_name,
125 COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format,
126 container="bare", public='public')
127 image_ids.append(image_2_id)
128 # Moved vm_3 creation before associating its network/router with
129 # bgpvpn. If VM is created after its network is associated to bgpvpn
130 # via router, then BGPVPN in ODL uses router's vrf id for newly created
131 # VMs which causes testcase to fail.
132 u3 = test_utils.generate_ping_userdata(
133 [TESTCASE_CONFIG.extra_route_ip])
134 vm_3 = test_utils.create_instance(
136 TESTCASE_CONFIG.instance_3_name,
140 flavor=COMMON_CONFIG.custom_flavor_name,
141 secgroup_name=TESTCASE_CONFIG.secgroup_name,
142 compute_node=av_zone_2,
145 instance_ids.extend([vm_1.id, vm_2.id, vm_3.id])
147 instance_dhcp_up = test_utils.wait_for_instances_get_dhcp(vm_3)
149 if (not instance_dhcp_up):
150 logger.error("vm_3 instance is down")
152 msg = ("Create VPN with multiple RDs")
153 results.record_action(msg)
154 vpn_name = "sdnvpn-" + str(randint(100000, 999999))
156 "import_targets": TESTCASE_CONFIG.targets1,
157 "export_targets": TESTCASE_CONFIG.targets2,
158 "route_distinguishers": TESTCASE_CONFIG.route_distinguishers,
161 bgpvpn = test_utils.create_bgpvpn(neutron_client, **kwargs)
162 bgpvpn_id = bgpvpn['bgpvpn']['id']
163 logger.debug("VPN created details: %s" % bgpvpn)
164 bgpvpn_ids.append(bgpvpn_id)
166 msg = ("Associate router '%s' to the VPN." %
167 TESTCASE_CONFIG.router_1_name)
168 results.record_action(msg)
169 results.add_to_summary(0, "-")
171 test_utils.create_router_association(
172 neutron_client, bgpvpn_id, router_1_id)
174 test_utils.update_router_extra_route(
175 neutron_client, router_1_id,
176 [test_utils.ExtraRoute(TESTCASE_CONFIG.extra_route_cidr,
178 test_utils.ExtraRoute(TESTCASE_CONFIG.extra_route_cidr,
181 logger.info("Waiting for the VMs to connect to each other using the"
182 " updated network configuration")
183 test_utils.wait_before_subtest()
185 results.get_ping_status_target_ip(vm_3,
186 TESTCASE_CONFIG.extra_route_name,
187 TESTCASE_CONFIG.extra_route_ip,
191 results.add_to_summary(0, "=")
192 logger.info("\n%s" % results.summary)
194 except Exception as e:
195 logger.error("exception occurred while executing testcase_13: %s", e)
198 test_utils.update_router_no_extra_route(neutron_client, router_ids)
199 test_utils.cleanup_nova(nova_client, instance_ids)
200 test_utils.cleanup_glance(glance_client, image_ids)
201 test_utils.cleanup_neutron(neutron_client, floatingip_ids,
202 bgpvpn_ids, interfaces, subnet_ids,
203 router_ids, network_ids)
205 return results.compile_summary()
208 if __name__ == '__main__':
209 logging.basicConfig(level=logging.INFO)