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 functest Quaggas peer
15 # - Exchange routing information with Quagga:
16 # - Create a network, instance and BGPVPN in OpenStack
17 # - Verify the route to the instance is present in the OpenDaylight FIB
18 # - Verify that the functest Quagga also learns these routes
22 from sdnvpn.lib import quagga
23 import sdnvpn.lib.utils as test_utils
24 import sdnvpn.lib.config as sdnvpn_config
26 import functest.utils.openstack_utils as os_utils
27 import functest.utils.functest_utils as ft_utils
28 import functest.utils.functest_logger as ft_logger
30 from sdnvpn.lib.results import Results
32 COMMON_CONFIG = sdnvpn_config.CommonConfig()
33 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig("testcase_3")
35 logger = ft_logger.Logger("sdnvpn-testcase-3").getLogger()
37 parser = argparse.ArgumentParser()
39 parser.add_argument("-r", "--report",
40 help="Create json result file",
43 args = parser.parse_args()
47 results = Results(COMMON_CONFIG.line_length)
48 results.add_to_summary(0, "=")
49 results.add_to_summary(2, "STATUS", "SUBTEST")
50 results.add_to_summary(0, "=")
52 openstack_nodes = test_utils.get_nodes()
54 controllers = [node for node in openstack_nodes
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 for controller in controllers:
70 logger.info("Starting bgp speaker of controller at IP %s "
72 logger.info("Checking if zrpcd is "
73 "running on the controller node")
75 cmd = "systemctl status zrpcd"
76 output = controller.run_cmd(cmd)
77 msg = ("zrpcd is running")
80 logger.info("zrpcd is not running on the controller node")
81 results.add_failure(msg)
83 logger.info("zrpcd is running on the controller node")
84 results.add_success(msg)
86 results.add_to_summary(0, "-")
88 # TODO here we need the external ip of the controller
89 start_quagga = "odl:configure-bgp -op start-bgp-server " \
90 "--as-num 100 --router-id {0}".format(controller.ip)
91 test_utils.run_odl_cmd(controller, start_quagga)
93 logger.info("Checking if bgpd is running"
94 " on the controller node")
96 # Check if there is a non-zombie bgpd process
97 output_bgpd = controller.run_cmd("ps --no-headers -C "
99 states = output_bgpd.split()
100 running = any([s != 'Z' for s in states])
102 msg = ("bgpd is running")
104 logger.info("bgpd is not running on the controller node")
105 results.add_failure(msg)
107 logger.info("bgpd is running on the controller node")
108 results.add_success(msg)
110 results.add_to_summary(0, "-")
112 stop_quagga = 'odl:configure-bgp -op stop-bgp-server'
114 test_utils.run_odl_cmd(controller, stop_quagga)
116 # disabled because of buggy upstream
117 # https://github.com/6WIND/zrpcd/issues/15
118 # logger.info("Checking if bgpd is still running"
119 # " on the controller node")
121 # output_bgpd = controller.run_cmd("ps --no-headers -C " \
123 # states = output_bgpd.split()
124 # running = any([s != 'Z' for s in states])
126 # msg = ("bgpd is stopped")
128 # logger.info("bgpd is not running on the controller node")
129 # results.add_success(msg)
131 # logger.info("bgpd is still running on the controller node")
132 # results.add_failure(msg)
134 # Taken from the sfc tests
135 if not os.path.isfile(COMMON_CONFIG.ubuntu_image_path):
136 logger.info("Downloading image")
137 ft_utils.download_url(
138 "https://cloud-images.ubuntu.com/releases/16.04/"
139 "release/ubuntu-16.04-server-cloudimg-amd64-disk1.img",
140 "/home/opnfv/functest/data/")
142 logger.info("Using old image")
144 glance_client = os_utils.get_glance_client()
145 nova_client = os_utils.get_nova_client()
146 neutron_client = os_utils.get_neutron_client()
148 sg_id = os_utils.create_security_group_full(neutron_client,
149 TESTCASE_CONFIG.secgroup_name,
150 TESTCASE_CONFIG.secgroup_descr)
151 test_utils.open_icmp_ssh(neutron_client, sg_id)
152 test_utils.open_bgp_port(neutron_client, sg_id)
153 net_id, _, _ = test_utils.create_network(neutron_client,
154 TESTCASE_CONFIG.net_1_name,
155 TESTCASE_CONFIG.subnet_1_name,
156 TESTCASE_CONFIG.subnet_1_cidr,
157 TESTCASE_CONFIG.router_1_name)
159 quagga_net_id, _, _ = test_utils.create_network(
161 TESTCASE_CONFIG.quagga_net_name,
162 TESTCASE_CONFIG.quagga_subnet_name,
163 TESTCASE_CONFIG.quagga_subnet_cidr,
164 TESTCASE_CONFIG.quagga_router_name)
166 ubuntu_image_id = os_utils.create_glance_image(
168 COMMON_CONFIG.ubuntu_image_name,
169 COMMON_CONFIG.ubuntu_image_path,
174 # NOTE(rski) The order of this seems a bit weird but
175 # there is a reason for this, namely
176 # https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-99
177 # so we create the quagga instance using cloud-init
178 # and immediately give it a floating IP.
179 # The cloud-init script should contain a small sleep for
181 # We also create the FIP first because it is used in the
183 fip = os_utils.create_floating_ip(neutron_client)
185 quagga_bootstrap_script = quagga.gen_quagga_setup_script(
186 controllers[0].ip, fip['fip_addr'])
187 quagga_vm = test_utils.create_instance(
189 TESTCASE_CONFIG.quagga_instance_name,
193 fixed_ip=TESTCASE_CONFIG.quagga_instance_ip,
194 flavor=TESTCASE_CONFIG.quagga_instance_flavor,
195 userdata=quagga_bootstrap_script)
196 fip_added = os_utils.add_floating_ip(nova_client,
200 msg = "Assign a Floating IP to %s " % TESTCASE_CONFIG.quagga_instance_name
202 results.add_success(msg)
204 results.add_failure(msg)
206 testcase = "Bootstrap quagga inside an OpenStack instance"
209 results.add_success(testcase)
211 results.add_failure(testcase)
212 results.add_to_summary(0, "=")
214 results.add_to_summary(0, '-')
215 results.add_to_summary(1, "Peer Quagga with OpenDaylight")
216 results.add_to_summary(0, '-')
218 neighbor = quagga.odl_add_neighbor(fip['fip_addr'], controller)
219 peer = quagga.check_for_peering(controller)
221 image_id = os_utils.create_glance_image(glance_client,
222 TESTCASE_CONFIG.image_name,
223 COMMON_CONFIG.image_path,
224 disk=COMMON_CONFIG.image_format,
228 instance = test_utils.create_instance(
230 TESTCASE_CONFIG.instance_1_name,
234 fixed_ip=TESTCASE_CONFIG.instance_1_ip,
235 secgroup_name=TESTCASE_CONFIG.secgroup_name)
237 kwargs = {"import_targets": TESTCASE_CONFIG.import_targets,
238 "export_targets": TESTCASE_CONFIG.export_targets,
239 "route_targets": TESTCASE_CONFIG.export_targets,
240 "name": "bgpvpn-3-1"}
242 bgpvpn = os_utils.create_bgpvpn(neutron_client, **kwargs)
243 bgpvpn_id = bgpvpn['bgpvpn']['id']
244 os_utils.create_network_association(
245 neutron_client, bgpvpn_id, net_id)
247 test_utils.wait_for_instance(instance)
249 exchange = quagga.check_for_route_exchange(fip['fip_addr'])
250 if neighbor and peer and exchange:
251 results.add_success("Peering with quagga")
253 results.add_failure("Peering with quagga")
255 return results.compile_summary()
258 if __name__ == '__main__':