summaryrefslogtreecommitdiffstats
path: root/sdnvpn/test/functest/testcase_3.py
blob: 42b672a0026aea3598ffc6d2fbe8a8063809b944 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/python
#
# Copyright (c) 2017 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
#
# http://www.apache.org/licenses/LICENSE-2.0
#

import argparse
import functest.utils.functest_logger as ft_logger
from sdnvpn.lib import config as sdnvpn_config
from sdnvpn.lib.results import Results
from opnfv.deployment.factory import Factory as DeploymentFactory

parser = argparse.ArgumentParser()

parser.add_argument("-r", "--report",
                    help="Create json result file",
                    action="store_true")

args = parser.parse_args()

logger = ft_logger.Logger("sdnvpn-testcase-3").getLogger()

COMMON_CONFIG = sdnvpn_config.CommonConfig()
TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig("testcase_3")


def main():
    results = Results(COMMON_CONFIG.line_length)
    results.add_to_summary(0, "=")
    results.add_to_summary(2, "STATUS", "SUBTEST")
    results.add_to_summary(0, "=")

    # TODO unhardcode this to work with apex
    deploymentHandler = DeploymentFactory.get_handler(
        'fuel',
        '10.20.0.2',
        'root',
        'r00tme')

    openstack_nodes = deploymentHandler.get_nodes()

    controllers = [node for node in openstack_nodes
                   if node.is_odl()]

    msg = ("Verify that OpenDaylight can start/communicate with zrpcd/Quagga")
    results.record_action(msg)
    results.add_to_summary(0, "-")

    if not controllers:
        msg = ("Controller (ODL) list is empty")
        logger.info(msg)
        results.add_failure(msg)
    else:
        msg = ("Controller (ODL) list is ready")
        logger.info(msg)
        results.add_success(msg)

    for controller in controllers:
        logger.info("Starting bgp speaker of controller at IP %s "
                    % controller.ip)
        logger.info("Checking if zrpcd is "
                    "running on the controller node")

        cmd = "systemctl status zrpcd"
        output = controller.run_cmd(cmd)
        msg = ("zrpcd is running")

        if not output:
            logger.info("zrpcd is not running on the controller node")
            results.add_failure(msg)
        else:
            logger.info("zrpcd is running on the controller node")
            results.add_success(msg)

        results.add_to_summary(0, "-")

        # TODO here we need the external ip of the controller
        cmd_start_quagga = '/opt/opendaylight/bin/client "odl:configure-bgp ' \
                           '-op start-bgp-server --as-num 100 ' \
                           '--router-id {0}"'.format(controller.ip)

        controller.run_cmd(cmd_start_quagga)

        logger.info("Checking if bgpd is running"
                    " on the controller node")

        # Check if there is a non-zombie bgpd process
        output_bgpd = controller.run_cmd("ps --no-headers -C bgpd -o state")
        states = output_bgpd.split()
        running = any([s != 'Z' for s in states])

        msg = ("bgpd is running")
        if not running:
            logger.info("bgpd is not running on the controller node")
            results.add_failure(msg)
        else:
            logger.info("bgpd is running on the controller node")
            results.add_success(msg)

        results.add_to_summary(0, "-")

        cmd_stop_quagga = '/opt/opendaylight/bin/client -v "odl:configure' \
                          '-bgp -op stop-bgp-server"'

        controller.run_cmd(cmd_stop_quagga)

        # disabled because of buggy upstream
        # https://github.com/6WIND/zrpcd/issues/15
        # logger.info("Checking if bgpd is still running"
        #             " on the controller node")

        # output_bgpd = controller.run_cmd("ps --no-headers -C bgpd -o state")
        # states = output_bgpd.split()
        # running = any([s != 'Z' for s in states])

        # msg = ("bgpd is stopped")
        # if not running:
        #     logger.info("bgpd is not running on the controller node")
        #     results.add_success(msg)
        # else:
        #     logger.info("bgpd is still running on the controller node")
        #     results.add_failure(msg)

    return results.compile_summary()


if __name__ == '__main__':
    main()