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 from opnfv.deployment.factory import Factory as DeploymentFactory
35 COMMON_CONFIG = sdnvpn_config.CommonConfig()
36 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig("testcase_3")
38 logger = ft_logger.Logger("sdnvpn-testcase-3").getLogger()
40 parser = argparse.ArgumentParser()
42 parser.add_argument("-r", "--report",
43 help="Create json result file",
46 args = parser.parse_args()
48 logger = ft_logger.Logger("sdnvpn-testcase-3").getLogger()
50 COMMON_CONFIG = sdnvpn_config.CommonConfig()
51 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig("testcase_3")
55 results = Results(COMMON_CONFIG.line_length)
56 results.add_to_summary(0, "=")
57 results.add_to_summary(2, "STATUS", "SUBTEST")
58 results.add_to_summary(0, "=")
60 # TODO unhardcode this to work with apex
61 deploymentHandler = DeploymentFactory.get_handler(
67 openstack_nodes = deploymentHandler.get_nodes()
69 controllers = [node for node in openstack_nodes
71 msg = ("Verify that OpenDaylight can start/communicate with zrpcd/Quagga")
72 results.record_action(msg)
73 results.add_to_summary(0, "-")
76 msg = ("Controller (ODL) list is empty. Skipping rest of tests.")
78 results.add_failure(msg)
79 return results.compile_summary()
81 msg = ("Controller (ODL) list is ready")
83 results.add_success(msg)
85 for controller in controllers:
86 logger.info("Starting bgp speaker of controller at IP %s "
88 logger.info("Checking if zrpcd is "
89 "running on the controller node")
91 cmd = "systemctl status zrpcd"
92 output = controller.run_cmd(cmd)
93 msg = ("zrpcd is running")
96 logger.info("zrpcd is not running on the controller node")
97 results.add_failure(msg)
99 logger.info("zrpcd is running on the controller node")
100 results.add_success(msg)
102 results.add_to_summary(0, "-")
104 # TODO here we need the external ip of the controller
105 start_quagga = "odl:configure-bgp -op start-bgp-server " \
106 "--as-num 100 --router-id {0}".format(controller.ip)
108 test_utils.run_odl_cmd(controller, start_quagga)
110 logger.info("Checking if bgpd is running"
111 " on the controller node")
113 # Check if there is a non-zombie bgpd process
114 output_bgpd = controller.run_cmd("ps --no-headers -C bgpd -o state")
115 states = output_bgpd.split()
116 running = any([s != 'Z' for s in states])
118 msg = ("bgpd is running")
120 logger.info("bgpd is not running on the controller node")
121 results.add_failure(msg)
123 logger.info("bgpd is running on the controller node")
124 results.add_success(msg)
126 results.add_to_summary(0, "-")
128 stop_quagga = 'odl:configure-bgp -op stop-bgp-server'
130 test_utils.run_odl_cmd(controller, stop_quagga)
132 # disabled because of buggy upstream
133 # https://github.com/6WIND/zrpcd/issues/15
134 # logger.info("Checking if bgpd is still running"
135 # " on the controller node")
137 # output_bgpd = controller.run_cmd("ps --no-headers -C bgpd -o state")
138 # states = output_bgpd.split()
139 # running = any([s != 'Z' for s in states])
141 # msg = ("bgpd is stopped")
143 # logger.info("bgpd is not running on the controller node")
144 # results.add_success(msg)
146 # logger.info("bgpd is still running on the controller node")
147 # results.add_failure(msg)
149 # Taken from the sfc tests
150 if not os.path.isfile(COMMON_CONFIG.ubuntu_image_path):
151 logger.info("Downloading image")
152 ft_utils.download_url(
153 "https://cloud-images.ubuntu.com/releases/16.04/"
154 "release/ubuntu-16.04-server-cloudimg-amd64-disk1.img",
155 "/home/opnfv/functest/data/")
157 logger.info("Using old image")
159 glance_client = os_utils.get_glance_client()
160 nova_client = os_utils.get_nova_client()
161 neutron_client = os_utils.get_neutron_client()
163 sg_id = os_utils.create_security_group_full(neutron_client,
164 TESTCASE_CONFIG.secgroup_name,
165 TESTCASE_CONFIG.secgroup_descr)
166 test_utils.open_icmp_ssh(neutron_client, sg_id)
167 test_utils.open_bgp_port(neutron_client, sg_id)
168 net_id, _, _ = test_utils.create_network(neutron_client,
169 TESTCASE_CONFIG.net_1_name,
170 TESTCASE_CONFIG.subnet_1_name,
171 TESTCASE_CONFIG.subnet_1_cidr,
172 TESTCASE_CONFIG.router_1_name)
174 quagga_net_id, _, _ = test_utils.create_network(
176 TESTCASE_CONFIG.quagga_net_name,
177 TESTCASE_CONFIG.quagga_subnet_name,
178 TESTCASE_CONFIG.quagga_subnet_cidr,
179 TESTCASE_CONFIG.quagga_router_name)
181 ubuntu_image_id = os_utils.create_glance_image(
183 COMMON_CONFIG.ubuntu_image_name,
184 COMMON_CONFIG.ubuntu_image_path,
189 # NOTE(rski) The order of this seems a bit weird but
190 # there is a reason for this, namely
191 # https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-99
192 # so we create the quagga instance using cloud-init
193 # and immediately give it a floating IP.
194 # The cloud-init script should contain a small sleep for
196 # We also create the FIP first because it is used in the
198 fip = os_utils.create_floating_ip(neutron_client)
200 quagga_bootstrap_script = quagga.gen_quagga_setup_script(
201 controllers[0].ip, fip['fip_addr'])
202 quagga_vm = test_utils.create_instance(
204 TESTCASE_CONFIG.quagga_instance_name,
208 fixed_ip=TESTCASE_CONFIG.quagga_instance_ip,
209 flavor=TESTCASE_CONFIG.quagga_instance_flavor,
210 userdata=quagga_bootstrap_script)
211 fip_added = os_utils.add_floating_ip(nova_client,
215 msg = "Assign a Floating IP to %s " % TESTCASE_CONFIG.quagga_instance_name
217 results.add_success(msg)
219 results.add_failure(msg)
221 testcase = "Bootstrap quagga inside an OpenStack instance"
224 results.add_success(testcase)
226 results.add_failure(testcase)
227 results.add_to_summary(0, "=")
229 results.add_to_summary(0, '-')
230 results.add_to_summary(1, "Peer Quagga with OpenDaylight")
231 results.add_to_summary(0, '-')
233 neighbor = quagga.odl_add_neighbor(fip['fip_addr'], controller)
234 peer = quagga.check_for_peering(controller)
236 image_id = os_utils.create_glance_image(glance_client,
237 TESTCASE_CONFIG.image_name,
238 COMMON_CONFIG.image_path,
239 disk=COMMON_CONFIG.image_format,
243 instance = test_utils.create_instance(
245 TESTCASE_CONFIG.instance_1_name,
249 fixed_ip=TESTCASE_CONFIG.instance_1_ip,
250 secgroup_name=TESTCASE_CONFIG.secgroup_name)
252 kwargs = {"import_targets": TESTCASE_CONFIG.import_targets,
253 "export_targets": TESTCASE_CONFIG.export_targets,
254 "route_targets": TESTCASE_CONFIG.export_targets,
255 "name": "bgpvpn-3-1"}
257 bgpvpn = os_utils.create_bgpvpn(neutron_client, **kwargs)
258 bgpvpn_id = bgpvpn['bgpvpn']['id']
259 os_utils.create_network_association(
260 neutron_client, bgpvpn_id, net_id)
262 test_utils.wait_for_instance(instance)
264 exchange = quagga.check_for_route_exchange(fip['fip_addr'])
265 if neighbor and peer and exchange:
266 results.add_success("Peering with quagga")
268 results.add_failure("Peering with quagga")
270 return results.compile_summary()
273 if __name__ == '__main__':