Correctly space expected_status
[integration/test.git] / csit / libraries / ExaBgpLib.robot
1 *** Settings ***
2 Documentation       Robot keyword library (Resource) for handling the ExaBgp tool.
3 ...
4 ...                 Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...                 This program and the accompanying materials are made available under the
7 ...                 terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...                 and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...
11 ...                 This library assumes that a SSH connection exists (and is switched to)
12 ...                 to a Linux machine (usualy TOOLS_SYSTEM) where the ExaBgp should be run.
13 ...
14 ...                 TODO: RemoteBash.robot contains logic which could be reused here.
15
16 Library             SSHLibrary
17 Resource            ${CURDIR}/SSHKeywords.robot
18 Resource            ${CURDIR}/RemoteBash.robot
19 Resource            ${CURDIR}/BGPcliKeywords.robot
20
21
22 *** Variables ***
23 ${EXABGP_KILL_COMMAND}      ps axf | grep exabgp | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
24 ${CMD}                      env exabgp.tcp.port=1790 exabgp --debug
25
26
27 *** Keywords ***
28 Start_ExaBgp
29     [Documentation]    Dump the start command into prompt. It assumes that no exabgp is running. For verified
30     ...    start use Start_ExaBgp_And_Verify_Connected keyword.
31     [Arguments]    ${cfg_file}
32     ${start_cmd}=    BuiltIn.Set_Variable    ${CMD} ${cfg_file}
33     BuiltIn.Log    ${start_cmd}
34     SSHKeywords.Virtual_Env_Activate_On_Current_Session    log_output=${True}
35     ${output}=    SSHLibrary.Write    ${start_cmd}
36     BuiltIn.Log    ${output}
37
38 Stop_ExaBgp
39     [Documentation]    Stops the ExaBgp by sending ctrl+c
40     ${output}=    SSHLibrary.Read
41     BuiltIn.Log    ${output}
42     RemoteBash.Write_Bare_Ctrl_C
43     ${output}=    SSHLibrary.Read_Until_Prompt
44     BuiltIn.Log    ${output}
45     SSHKeywords.Virtual_Env_Deactivate_On_Current_Session    log_output=${True}
46
47 Stop_All_ExaBgps
48     [Documentation]    Sends kill command to stop all exabgps running
49     ${output}=    SSHLibrary.Read
50     BuiltIn.Log    ${output}
51     ${output}=    SSHLibrary.Write    ${EXABGP_KILL_COMMAND}
52     BuiltIn.Log    ${output}
53
54 Start_ExaBgp_And_Verify_Connected
55     [Documentation]    Starts the ExaBgp and verifies its connection. The verification is done by checking the presence
56     ...    of the peer in the bgp rib.
57     [Arguments]    ${cfg_file}    ${session}    ${exabgp_ip}    ${connection_retries}=${3}
58     FOR    ${idx}    IN RANGE    ${connection_retries}
59         Start_ExaBgp    ${cfg_file}
60         ${status}    ${value}=    BuiltIn.Run_Keyword_And_Ignore_Error
61         ...    BuiltIn.Wait_Until_Keyword_Succeeds
62         ...    3x
63         ...    3s
64         ...    Verify_ExaBgps_Connection
65         ...    ${session}
66         ...    ${exabgp_ip}
67         ...    connected=${True}
68         IF    "${status}" != "PASS"    Stop_ExaBgp
69         IF    "${status}" == "PASS"    RETURN
70     END
71     BuiltIn.Fail    Unable to connect ExaBgp to ODL
72
73 Verify_ExaBgps_Connection
74     [Documentation]    Checks peer presence in operational datastore
75     [Arguments]    ${session}    ${exabgp_ip}=${TOOLS_SYSTEM_IP}    ${connected}=${True}
76     ${peer_check_url}=    BuiltIn.Set_Variable    ${REST_API}/bgp-rib:bgp-rib/rib=example-bgp-rib/peer=bgp:%2F%2F
77     ${exp_status_code}=    BuiltIn.Set_Variable_If    ${connected}    ${200}    ${404}
78     ${rsp}=    RequestsLibrary.Get Request    ${session}    ${peer_check_url}${exabgp_ip}?content=nonconfig
79     BuiltIn.Log    ${rsp.content}
80     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_status_code}    ${rsp.status_code}
81
82 Upload_ExaBgp_Cluster_Config_Files
83     [Documentation]    Uploads exabgp config files.
84     [Arguments]    ${bgp_var_folder}    ${cfg_file}
85     SSHLibrary.Put_File    ${bgp_var_folder}/${cfg_file}    .
86     @{cfgfiles}=    SSHLibrary.List_Files_In_Directory    .    *.cfg
87     FOR    ${cfgfile}    IN    @{cfgfiles}
88         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
89         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP1/${ODL_SYSTEM_1_IP}/g' ${cfgfile}
90         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP2/${ODL_SYSTEM_2_IP}/g' ${cfgfile}
91         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP3/${ODL_SYSTEM_3_IP}/g' ${cfgfile}
92         SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/disable/g' ${cfgfile}
93         SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
94         ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
95         Log    ${stdout}
96     END