Upgrade RF syntax for v3.2 compatibility
[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 Library           SSHLibrary
16 Resource          ${CURDIR}/SSHKeywords.robot
17 Resource          ${CURDIR}/RemoteBash.robot
18 Resource          ${CURDIR}/BGPcliKeywords.robot
19
20 *** Variables ***
21 ${EXABGP_KILL_COMMAND}    ps axf | grep exabgp | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
22 ${CMD}            env exabgp.tcp.port=1790 exabgp --debug
23 ${PEER_CHECK_URL}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/peer/bgp:%2F%2F
24
25 *** Keywords ***
26 Start_ExaBgp
27     [Arguments]    ${cfg_file}
28     [Documentation]    Dump the start command into prompt. It assumes that no exabgp is running. For verified
29     ...    start use Start_ExaBgp_And_Verify_Connected keyword.
30     ${start_cmd}    BuiltIn.Set_Variable    ${CMD} ${cfg_file}
31     BuiltIn.Log    ${start_cmd}
32     SSHKeywords.Virtual_Env_Activate_On_Current_Session    log_output=${True}
33     ${output}=    SSHLibrary.Write    ${start_cmd}
34     BuiltIn.Log    ${output}
35
36 Stop_ExaBgp
37     [Documentation]    Stops the ExaBgp by sending ctrl+c
38     ${output}=    SSHLibrary.Read
39     BuiltIn.Log    ${output}
40     RemoteBash.Write_Bare_Ctrl_C
41     ${output}=    SSHLibrary.Read_Until_Prompt
42     BuiltIn.Log    ${output}
43     SSHKeywords.Virtual_Env_Deactivate_On_Current_Session    log_output=${True}
44
45 Stop_All_ExaBgps
46     [Documentation]    Sends kill command to stop all exabgps running
47     ${output}    SSHLibrary.Read
48     BuiltIn.Log    ${output}
49     ${output}    SSHLibrary.Write    ${EXABGP_KILL_COMMAND}
50     BuiltIn.Log    ${output}
51
52 Start_ExaBgp_And_Verify_Connected
53     [Arguments]    ${cfg_file}    ${session}    ${exabgp_ip}    ${connection_retries}=${3}
54     [Documentation]    Starts the ExaBgp and verifies its connection. The verification is done by checking the presence
55     ...    of the peer in the bgp rib.
56     FOR    ${idx}    IN RANGE    ${connection_retries}
57         Start_ExaBgp    ${cfg_file}
58         ${status}    ${value}=    BuiltIn.Run_Keyword_And_Ignore_Error    BuiltIn.Wait_Until_Keyword_Succeeds    3x    3s
59         ...    Verify_ExaBgps_Connection    ${session}    ${exabgp_ip}    connected=${True}
60         BuiltIn.Run_Keyword_Unless    "${status}" == "PASS"    Stop_ExaBgp
61         BuiltIn.Return_From_Keyword_If    "${status}" == "PASS"
62     END
63     BuiltIn.Fail    Unable to connect ExaBgp to ODL
64
65 Verify_ExaBgps_Connection
66     [Arguments]    ${session}    ${exabgp_ip}=${TOOLS_SYSTEM_IP}    ${connected}=${True}
67     [Documentation]    Checks peer presence in operational datastore
68     ${exp_status_code}=    BuiltIn.Set_Variable_If    ${connected}    ${200}    ${404}
69     ${rsp}=    RequestsLibrary.Get Request    ${session}    ${PEER_CHECK_URL}${exabgp_ip}
70     BuiltIn.Log    ${rsp.content}
71     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_status_code}    ${rsp.status_code}
72
73 Upload_ExaBgp_Cluster_Config_Files
74     [Arguments]    ${bgp_var_folder}    ${cfg_file}
75     [Documentation]    Uploads exabgp config files.
76     SSHLibrary.Put_File    ${bgp_var_folder}/${cfg_file}    .
77     @{cfgfiles}=    SSHLibrary.List_Files_In_Directory    .    *.cfg
78     FOR    ${cfgfile}    IN    @{cfgfiles}
79         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
80         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP1/${ODL_SYSTEM_1_IP}/g' ${cfgfile}
81         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP2/${ODL_SYSTEM_2_IP}/g' ${cfgfile}
82         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP3/${ODL_SYSTEM_3_IP}/g' ${cfgfile}
83         SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/disable/g' ${cfgfile}
84         SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
85         ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
86         Log    ${stdout}
87     END