2 # Copyright (c) 2017 All rights reserved
3 # This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
10 # - Peering OpenDaylight with Quagga:
11 # - Set up a Quagga instance in the functest container
12 # - Start a BGP router with OpenDaylight
13 # - Add the functest Quagga as a neighbor
14 # - Verify that the OpenDaylight and gateway Quagga peer
18 from sdnvpn.lib import quagga
19 import sdnvpn.lib.utils as test_utils
20 import sdnvpn.lib.config as sdnvpn_config
22 import functest.utils.openstack_utils as os_utils
23 import functest.utils.functest_utils as ft_utils
24 import functest.utils.functest_logger as ft_logger
26 from sdnvpn.lib.results import Results
28 COMMON_CONFIG = sdnvpn_config.CommonConfig()
29 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig("testcase_3")
31 logger = ft_logger.Logger("sdnvpn-testcase-3").getLogger()
33 parser = argparse.ArgumentParser()
35 parser.add_argument("-r", "--report",
36 help="Create json result file",
39 args = parser.parse_args()
43 results = Results(COMMON_CONFIG.line_length)
44 results.add_to_summary(0, "=")
45 results.add_to_summary(2, "STATUS", "SUBTEST")
46 results.add_to_summary(0, "=")
48 openstack_nodes = test_utils.get_nodes()
50 # node.is_odl() doesn't work in Apex
51 # https://jira.opnfv.org/browse/RELENG-192
52 controllers = [node for node in openstack_nodes
54 node.run_cmd("sudo systemctl status opendaylight")]
55 computes = [node for node in openstack_nodes if node.is_compute()]
56 msg = ("Verify that OpenDaylight can start/communicate with zrpcd/Quagga")
57 results.record_action(msg)
58 results.add_to_summary(0, "-")
60 msg = ("Controller (ODL) list is empty. Skipping rest of tests.")
62 results.add_failure(msg)
63 return results.compile_summary()
65 msg = ("Controller (ODL) list is ready")
67 results.add_success(msg)
69 controller = controllers[0] # We don't handle HA well
70 get_ext_ip_cmd = "sudo ip a | grep br-ex | grep inet | awk '{print $2}'"
71 ext_net_cidr = controller.run_cmd(get_ext_ip_cmd).split("/")
72 ext_net_mask = ext_net_cidr[1].split('\n')[0]
73 controller_ext_ip = ext_net_cidr[0]
75 logger.info("Starting bgp speaker of controller at IP %s "
77 logger.info("Checking if zrpcd is "
78 "running on the controller node")
80 cmd = "systemctl status zrpcd"
81 output = controller.run_cmd(cmd)
82 msg = ("zrpcd is running")
85 logger.info("zrpcd is not running on the controller node")
86 results.add_failure(msg)
88 logger.info("zrpcd is running on the controller node")
89 results.add_success(msg)
91 results.add_to_summary(0, "-")
93 start_quagga = "odl:configure-bgp -op start-bgp-server " \
94 "--as-num 100 --router-id {0}".format(controller_ext_ip)
95 test_utils.run_odl_cmd(controller, start_quagga)
97 logger.info("Checking if bgpd is running"
98 " on the controller node")
100 # Check if there is a non-zombie bgpd process
101 output_bgpd = controller.run_cmd("ps --no-headers -C "
103 states = output_bgpd.split()
104 running = any([s != 'Z' for s in states])
106 msg = ("bgpd is running")
108 logger.info("bgpd is not running on the controller node")
109 results.add_failure(msg)
111 logger.info("bgpd is running on the controller node")
112 results.add_success(msg)
114 results.add_to_summary(0, "-")
116 # We should be able to restart the speaker
117 # but the test is disabled because of buggy upstream
118 # https://github.com/6WIND/zrpcd/issues/15
119 # stop_quagga = 'odl:configure-bgp -op stop-bgp-server'
120 # test_utils.run_odl_cmd(controller, stop_quagga)
122 # logger.info("Checking if bgpd is still running"
123 # " on the controller node")
125 # output_bgpd = controller.run_cmd("ps --no-headers -C " \
127 # states = output_bgpd.split()
128 # running = any([s != 'Z' for s in states])
130 # msg = ("bgpd is stopped")
132 # logger.info("bgpd is not running on the controller node")
133 # results.add_success(msg)
135 # logger.info("bgpd is still running on the controller node")
136 # results.add_failure(msg)
138 # Taken from the sfc tests
139 if not os.path.isfile(COMMON_CONFIG.ubuntu_image_path):
140 logger.info("Downloading image")
141 ft_utils.download_url(
142 "https://cloud-images.ubuntu.com/releases/16.04/"
143 "release/ubuntu-16.04-server-cloudimg-amd64-disk1.img",
144 "/home/opnfv/functest/data/")
146 logger.info("Using old image")
148 glance_client = os_utils.get_glance_client()
149 nova_client = os_utils.get_nova_client()
150 neutron_client = os_utils.get_neutron_client()
152 sg_id = os_utils.create_security_group_full(neutron_client,
153 TESTCASE_CONFIG.secgroup_name,
154 TESTCASE_CONFIG.secgroup_descr)
155 test_utils.open_icmp_ssh(neutron_client, sg_id)
156 test_utils.open_bgp_port(neutron_client, sg_id)
157 net_id, _, _ = test_utils.create_network(neutron_client,
158 TESTCASE_CONFIG.net_1_name,
159 TESTCASE_CONFIG.subnet_1_name,
160 TESTCASE_CONFIG.subnet_1_cidr,
161 TESTCASE_CONFIG.router_1_name)
163 quagga_net_id, _, _ = test_utils.create_network(
165 TESTCASE_CONFIG.quagga_net_name,
166 TESTCASE_CONFIG.quagga_subnet_name,
167 TESTCASE_CONFIG.quagga_subnet_cidr,
168 TESTCASE_CONFIG.quagga_router_name)
170 installer_type = str(os.environ['INSTALLER_TYPE'].lower())
171 if installer_type == "fuel":
173 elif installer_type == "apex":
176 logger.error("Incompatible installer type")
178 ubuntu_image_id = os_utils.create_glance_image(
180 COMMON_CONFIG.ubuntu_image_name,
181 COMMON_CONFIG.ubuntu_image_path,
186 # NOTE(rski) The order of this seems a bit weird but
187 # there is a reason for this, namely
188 # https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-99
189 # so we create the quagga instance using cloud-init
190 # and immediately give it a floating IP.
191 # The cloud-init script should contain a small sleep for
193 # We also create the FIP first because it is used in the
195 fip = os_utils.create_floating_ip(neutron_client)
196 # fake_fip is needed to bypass NAT
197 # see below for the reason why.
198 fake_fip = os_utils.create_floating_ip(neutron_client)
199 # pin quagga to some compute
200 compute_node = nova_client.hypervisors.list()[0]
201 quagga_compute_node = "nova:" + compute_node.hypervisor_hostname
202 # Map the hypervisor used above to a compute handle
203 # returned by releng's manager
204 for comp in computes:
205 if compute_node.host_ip in comp.run_cmd("sudo ip a"):
208 quagga_bootstrap_script = quagga.gen_quagga_setup_script(
210 fake_fip['fip_addr'],
213 test_utils.create_custom_flavor()
215 quagga_vm = test_utils.create_instance(
217 TESTCASE_CONFIG.quagga_instance_name,
221 fixed_ip=TESTCASE_CONFIG.quagga_instance_ip,
222 flavor=COMMON_CONFIG.custom_flavor_name,
223 userdata=quagga_bootstrap_script,
224 compute_node=quagga_compute_node)
226 fip_added = os_utils.add_floating_ip(nova_client,
230 msg = "Assign a Floating IP to %s " % TESTCASE_CONFIG.quagga_instance_name
232 results.add_success(msg)
234 results.add_failure(msg)
236 test_utils.attach_instance_to_ext_br(quagga_vm, compute)
238 testcase = "Bootstrap quagga inside an OpenStack instance"
239 cloud_init_success = test_utils.wait_for_cloud_init(quagga_vm)
240 if cloud_init_success:
241 results.add_success(testcase)
243 results.add_failure(testcase)
244 results.add_to_summary(0, "=")
246 results.add_to_summary(0, '-')
247 results.add_to_summary(1, "Peer Quagga with OpenDaylight")
248 results.add_to_summary(0, '-')
250 neighbor = quagga.odl_add_neighbor(fake_fip['fip_addr'],
253 peer = quagga.check_for_peering(controller)
255 if neighbor and peer:
256 results.add_success("Peering with quagga")
258 results.add_failure("Peering with quagga")
260 return results.compile_summary()
263 if __name__ == '__main__':