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 computes = [node for node in openstack_nodes if node.is_compute()]
57 msg = ("Verify that OpenDaylight can start/communicate with zrpcd/Quagga")
58 results.record_action(msg)
59 results.add_to_summary(0, "-")
61 msg = ("Controller (ODL) list is empty. Skipping rest of tests.")
63 results.add_failure(msg)
64 return results.compile_summary()
66 msg = ("Controller (ODL) list is ready")
68 results.add_success(msg)
70 for controller in controllers:
71 logger.info("Starting bgp speaker of controller at IP %s "
73 logger.info("Checking if zrpcd is "
74 "running on the controller node")
76 cmd = "systemctl status zrpcd"
77 output = controller.run_cmd(cmd)
78 msg = ("zrpcd is running")
81 logger.info("zrpcd is not running on the controller node")
82 results.add_failure(msg)
84 logger.info("zrpcd is running on the controller node")
85 results.add_success(msg)
87 results.add_to_summary(0, "-")
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)
184 # fake_fip is needed to bypass NAT
185 # see below for the reason why.
186 fake_fip = os_utils.create_floating_ip(neutron_client)
187 # pin quagga to some compute
188 compute_node = nova_client.hypervisors.list()[0]
189 quagga_compute_node = "nova:" + compute_node.hypervisor_hostname
190 # Map the hypervisor used above to a compute handle
191 # returned by releng's manager
192 for comp in computes:
193 if compute_node.host_ip in comp.run_cmd("ip a"):
196 # Get the mask of ext net of the compute where quagga is running
197 # TODO check this works on apex
198 cmd = "ip a | grep br-ex | grep inet | awk '{print $2}'"
199 ext_cidr = compute.run_cmd(cmd).split("/")
200 ext_net_mask = ext_cidr[1]
201 quagga_bootstrap_script = quagga.gen_quagga_setup_script(
203 fake_fip['fip_addr'],
205 quagga_vm = test_utils.create_instance(
207 TESTCASE_CONFIG.quagga_instance_name,
211 fixed_ip=TESTCASE_CONFIG.quagga_instance_ip,
212 flavor=TESTCASE_CONFIG.quagga_instance_flavor,
213 userdata=quagga_bootstrap_script,
214 compute_node=quagga_compute_node)
216 fip_added = os_utils.add_floating_ip(nova_client,
220 msg = "Assign a Floating IP to %s " % TESTCASE_CONFIG.quagga_instance_name
222 results.add_success(msg)
224 results.add_failure(msg)
226 testcase = "Bootstrap quagga inside an OpenStack instance"
229 results.add_success(testcase)
231 results.add_failure(testcase)
232 results.add_to_summary(0, "=")
234 # This part works around NAT
235 # What we do is attach the instance directly to the OpenStack
236 # external network. This way is is directly accessible from the
237 # controller without NAT. We assign a floating IP for this
238 # to make sure no overlaps happen.
239 libvirt_instance_name = getattr(quagga_vm, "OS-EXT-SRV-ATTR:instance_name")
240 compute.run_cmd("virsh attach-interface %s"
241 " bridge br-ex" % libvirt_instance_name)
243 results.add_to_summary(0, '-')
244 results.add_to_summary(1, "Peer Quagga with OpenDaylight")
245 results.add_to_summary(0, '-')
247 neighbor = quagga.odl_add_neighbor(fip['fip_addr'], controller)
248 peer = quagga.check_for_peering(controller)
250 image_id = os_utils.create_glance_image(glance_client,
251 TESTCASE_CONFIG.image_name,
252 COMMON_CONFIG.image_path,
253 disk=COMMON_CONFIG.image_format,
257 instance = test_utils.create_instance(
259 TESTCASE_CONFIG.instance_1_name,
263 fixed_ip=TESTCASE_CONFIG.instance_1_ip,
264 secgroup_name=TESTCASE_CONFIG.secgroup_name)
266 kwargs = {"import_targets": TESTCASE_CONFIG.import_targets,
267 "export_targets": TESTCASE_CONFIG.export_targets,
268 "route_targets": TESTCASE_CONFIG.export_targets,
269 "name": "bgpvpn-3-1"}
271 bgpvpn = os_utils.create_bgpvpn(neutron_client, **kwargs)
272 bgpvpn_id = bgpvpn['bgpvpn']['id']
273 os_utils.create_network_association(
274 neutron_client, bgpvpn_id, net_id)
276 test_utils.wait_for_instance(instance)
278 exchange = quagga.check_for_route_exchange(fip['fip_addr'])
279 if neighbor and peer and exchange:
280 results.add_success("Peering with quagga")
282 results.add_failure("Peering with quagga")
284 return results.compile_summary()
287 if __name__ == '__main__':