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