3 # Copyright (c) 2018 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
15 from random import randint
16 from sdnvpn.lib import config as sdnvpn_config
17 from sdnvpn.lib import openstack_utils as os_utils
18 from sdnvpn.lib import utils as test_utils
19 from sdnvpn.lib.results import Results
21 logger = logging.getLogger(__name__)
23 COMMON_CONFIG = sdnvpn_config.CommonConfig()
24 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
25 'sdnvpn.test.functest.testcase_1bis')
29 conn = os_utils.get_os_connection()
30 results = Results(COMMON_CONFIG.line_length, conn)
32 results.add_to_summary(0, "=")
33 results.add_to_summary(2, "STATUS", "SUBTEST")
34 results.add_to_summary(0, "=")
36 heat_client = os_utils.get_heat_client()
37 # neutron client is needed as long as bgpvpn heat module
38 # is not yet installed by default in apex (APEX-618)
39 neutron_client = os_utils.get_neutron_client()
45 # image created outside HOT (OS::Glance::Image deprecated since ocata)
46 image_id = os_utils.create_glance_image(
47 conn, TESTCASE_CONFIG.image_name,
48 COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format,
49 container="bare", public='public')
50 image_ids = [image_id]
52 compute_nodes = test_utils.assert_and_get_compute_nodes(conn)
53 az_1 = "nova:" + compute_nodes[0]
54 az_2 = "nova:" + compute_nodes[1]
56 file_path = pkg_resources.resource_filename(
57 'sdnvpn', TESTCASE_CONFIG.hot_file_name)
58 templ = open(file_path, 'r').read()
59 logger.debug("Template is read: '%s'" % templ)
60 env = test_utils.get_heat_environment(TESTCASE_CONFIG, COMMON_CONFIG)
61 logger.debug("Environment is read: '%s'" % env)
64 "stack_name": TESTCASE_CONFIG.stack_name,
68 "image_n": TESTCASE_CONFIG.image_name,
73 stack_id = os_utils.create_stack(heat_client, **kwargs)
75 logger.error("Stack create start failed")
76 raise SystemError("Stack create start failed")
78 test_utils.wait_stack_for_status(heat_client,
79 stack_id, 'CREATE_COMPLETE')
81 net_1_output = os_utils.get_output(heat_client, stack_id, 'net_1_o')
82 network_1_id = net_1_output['output']['output_value']
83 net_2_output = os_utils.get_output(heat_client, stack_id, 'net_2_o')
84 network_2_id = net_2_output['output']['output_value']
86 vm_stack_output_keys = ['vm1_o', 'vm2_o', 'vm3_o', 'vm4_o', 'vm5_o']
87 vms = test_utils.get_vms_from_stack_outputs(heat_client,
92 logger.debug("Entering base test case with stack '%s'" % stack_id)
94 msg = ("Create VPN with eRT<>iRT")
95 results.record_action(msg)
96 vpn_name = "sdnvpn-" + str(randint(100000, 999999))
98 "import_targets": TESTCASE_CONFIG.targets1,
99 "export_targets": TESTCASE_CONFIG.targets2,
100 "route_distinguishers": TESTCASE_CONFIG.route_distinguishers,
103 bgpvpn = test_utils.create_bgpvpn(neutron_client, **kwargs)
104 bgpvpn_id = bgpvpn['bgpvpn']['id']
105 logger.debug("VPN created details: %s" % bgpvpn)
106 bgpvpn_ids.append(bgpvpn_id)
108 msg = ("Associate network '%s' to the VPN." %
109 TESTCASE_CONFIG.heat_parameters['net_1_name'])
110 results.record_action(msg)
111 results.add_to_summary(0, "-")
113 test_utils.create_network_association(
114 neutron_client, bgpvpn_id, network_1_id)
116 # Remember: vms[X] is former vm_X+1
118 results.get_ping_status(vms[0], vms[1], expected="PASS", timeout=200)
119 results.get_ping_status(vms[0], vms[2], expected="PASS", timeout=30)
120 results.get_ping_status(vms[0], vms[3], expected="FAIL", timeout=30)
122 msg = ("Associate network '%s' to the VPN." %
123 TESTCASE_CONFIG.heat_parameters['net_2_name'])
124 results.add_to_summary(0, "-")
125 results.record_action(msg)
126 results.add_to_summary(0, "-")
128 test_utils.create_network_association(
129 neutron_client, bgpvpn_id, network_2_id)
131 test_utils.wait_for_bgp_net_assocs(neutron_client,
136 logger.info("Waiting for the VMs to connect to each other using the"
137 " updated network configuration")
138 test_utils.wait_before_subtest()
140 results.get_ping_status(vms[3], vms[4], expected="PASS", timeout=30)
141 # TODO enable again when isolation in VPN with iRT != eRT works
142 # results.get_ping_status(vms[0], vms[3], expected="FAIL", timeout=30)
143 # results.get_ping_status(vms[0], vms[4], expected="FAIL", timeout=30)
145 msg = ("Update VPN with eRT=iRT ...")
146 results.add_to_summary(0, "-")
147 results.record_action(msg)
148 results.add_to_summary(0, "-")
150 # use bgpvpn-create instead of update till NETVIRT-1067 bug is fixed
151 # kwargs = {"import_targets": TESTCASE_CONFIG.targets1,
152 # "export_targets": TESTCASE_CONFIG.targets1,
154 # bgpvpn = test_utils.update_bgpvpn(neutron_client,
155 # bgpvpn_id, **kwargs)
157 test_utils.delete_bgpvpn(neutron_client, bgpvpn_id)
158 bgpvpn_ids.remove(bgpvpn_id)
160 "import_targets": TESTCASE_CONFIG.targets1,
161 "export_targets": TESTCASE_CONFIG.targets1,
162 "route_distinguishers": TESTCASE_CONFIG.route_distinguishers,
166 test_utils.wait_before_subtest()
168 bgpvpn = test_utils.create_bgpvpn(neutron_client, **kwargs)
169 bgpvpn_id = bgpvpn['bgpvpn']['id']
170 logger.debug("VPN re-created details: %s" % bgpvpn)
171 bgpvpn_ids.append(bgpvpn_id)
173 msg = ("Associate network '%s' to the VPN." %
174 TESTCASE_CONFIG.heat_parameters['net_1_name'])
175 results.record_action(msg)
176 results.add_to_summary(0, "-")
178 test_utils.create_network_association(
179 neutron_client, bgpvpn_id, network_1_id)
181 test_utils.create_network_association(
182 neutron_client, bgpvpn_id, network_2_id)
184 test_utils.wait_for_bgp_net_assocs(neutron_client,
188 # The above code has to be removed after re-enabling bgpvpn-update
190 logger.info("Waiting for the VMs to connect to each other using the"
191 " updated network configuration")
192 test_utils.wait_before_subtest()
194 results.get_ping_status(vms[0], vms[3], expected="PASS", timeout=30)
195 results.get_ping_status(vms[0], vms[4], expected="PASS", timeout=30)
197 except Exception as e:
198 logger.error("exception occurred while executing testcase_1bis: %s", e)
201 test_utils.cleanup_glance(conn, image_ids)
202 test_utils.cleanup_neutron(conn, neutron_client, [], bgpvpn_ids,
206 test_utils.delete_stack_and_wait(heat_client, stack_id)
207 except Exception as e:
209 "exception occurred while executing testcase_1bis: %s", e)
211 return results.compile_summary()
214 if __name__ == '__main__':