42b672a0026aea3598ffc6d2fbe8a8063809b944
[sdnvpn.git] / sdnvpn / test / functest / testcase_3.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2017 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
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10
11 import argparse
12 import functest.utils.functest_logger as ft_logger
13 from sdnvpn.lib import config as sdnvpn_config
14 from sdnvpn.lib.results import Results
15 from opnfv.deployment.factory import Factory as DeploymentFactory
16
17 parser = argparse.ArgumentParser()
18
19 parser.add_argument("-r", "--report",
20                     help="Create json result file",
21                     action="store_true")
22
23 args = parser.parse_args()
24
25 logger = ft_logger.Logger("sdnvpn-testcase-3").getLogger()
26
27 COMMON_CONFIG = sdnvpn_config.CommonConfig()
28 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig("testcase_3")
29
30
31 def main():
32     results = Results(COMMON_CONFIG.line_length)
33     results.add_to_summary(0, "=")
34     results.add_to_summary(2, "STATUS", "SUBTEST")
35     results.add_to_summary(0, "=")
36
37     # TODO unhardcode this to work with apex
38     deploymentHandler = DeploymentFactory.get_handler(
39         'fuel',
40         '10.20.0.2',
41         'root',
42         'r00tme')
43
44     openstack_nodes = deploymentHandler.get_nodes()
45
46     controllers = [node for node in openstack_nodes
47                    if node.is_odl()]
48
49     msg = ("Verify that OpenDaylight can start/communicate with zrpcd/Quagga")
50     results.record_action(msg)
51     results.add_to_summary(0, "-")
52
53     if not controllers:
54         msg = ("Controller (ODL) list is empty")
55         logger.info(msg)
56         results.add_failure(msg)
57     else:
58         msg = ("Controller (ODL) list is ready")
59         logger.info(msg)
60         results.add_success(msg)
61
62     for controller in controllers:
63         logger.info("Starting bgp speaker of controller at IP %s "
64                     % controller.ip)
65         logger.info("Checking if zrpcd is "
66                     "running on the controller node")
67
68         cmd = "systemctl status zrpcd"
69         output = controller.run_cmd(cmd)
70         msg = ("zrpcd is running")
71
72         if not output:
73             logger.info("zrpcd is not running on the controller node")
74             results.add_failure(msg)
75         else:
76             logger.info("zrpcd is running on the controller node")
77             results.add_success(msg)
78
79         results.add_to_summary(0, "-")
80
81         # TODO here we need the external ip of the controller
82         cmd_start_quagga = '/opt/opendaylight/bin/client "odl:configure-bgp ' \
83                            '-op start-bgp-server --as-num 100 ' \
84                            '--router-id {0}"'.format(controller.ip)
85
86         controller.run_cmd(cmd_start_quagga)
87
88         logger.info("Checking if bgpd is running"
89                     " on the controller node")
90
91         # Check if there is a non-zombie bgpd process
92         output_bgpd = controller.run_cmd("ps --no-headers -C bgpd -o state")
93         states = output_bgpd.split()
94         running = any([s != 'Z' for s in states])
95
96         msg = ("bgpd is running")
97         if not running:
98             logger.info("bgpd is not running on the controller node")
99             results.add_failure(msg)
100         else:
101             logger.info("bgpd is running on the controller node")
102             results.add_success(msg)
103
104         results.add_to_summary(0, "-")
105
106         cmd_stop_quagga = '/opt/opendaylight/bin/client -v "odl:configure' \
107                           '-bgp -op stop-bgp-server"'
108
109         controller.run_cmd(cmd_stop_quagga)
110
111         # disabled because of buggy upstream
112         # https://github.com/6WIND/zrpcd/issues/15
113         # logger.info("Checking if bgpd is still running"
114         #             " on the controller node")
115
116         # output_bgpd = controller.run_cmd("ps --no-headers -C bgpd -o state")
117         # states = output_bgpd.split()
118         # running = any([s != 'Z' for s in states])
119
120         # msg = ("bgpd is stopped")
121         # if not running:
122         #     logger.info("bgpd is not running on the controller node")
123         #     results.add_success(msg)
124         # else:
125         #     logger.info("bgpd is still running on the controller node")
126         #     results.add_failure(msg)
127
128     return results.compile_summary()
129
130
131 if __name__ == '__main__':
132     main()