Correctly space expected_status
[integration/test.git] / csit / libraries / GoBgpLib.robot
1 *** Settings ***
2 Documentation       Robot keyword library (Resource) for handling the GoBgp tool.
3 ...
4 ...                 Copyright (c) 2020 Lumina Networks 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 GoBgp should be run.
13 ...
14
15 Library             Process
16 Library             SSHLibrary
17 Resource            ${CURDIR}/BGPcliKeywords.robot
18 Resource            ${CURDIR}/RemoteBash.robot
19 Resource            ${CURDIR}/SSHKeywords.robot
20
21
22 *** Variables ***
23 ${GOBGP_KILL_COMMAND}           ps axf | grep gobgp | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
24 ${GOBGP_EXECUTION_COMMAND}      /home/jenkins/gobgpd -l debug -f
25
26
27 *** Keywords ***
28 Start_GoBgp
29     [Documentation]    Dump the start command into prompt. It assumes that no gobgp is running. For verified
30     ...    start use Start_GoBgp_And_Verify_Connected keyword.
31     [Arguments]    ${cfg_file}
32     ${start_cmd}=    BuiltIn.Set Variable    ${GOBGP_EXECUTION_COMMAND} /home/jenkins/${cfg_file}
33     BuiltIn.Log    ${start_cmd}
34     ${output}=    SSHLibrary.Write    ${start_cmd}
35     BuiltIn.Log    ${output}
36
37 Stop_GoBgp
38     [Documentation]    Stops the GoBgp by sending ctrl+c
39     ${output}=    SSHLibrary.Read
40     BuiltIn.Log    ${output}
41     RemoteBash.Write_Bare_Ctrl_C
42     ${output}=    SSHLibrary.Read_Until_Prompt
43     BuiltIn.Log    ${output}
44
45 Stop_All_GoBgps
46     [Documentation]    Sends kill command to stop all Gobgps running
47     ${output}=    SSHLibrary.Read
48     BuiltIn.Log    ${output}
49     ${output}=    SSHLibrary.Write    ${GOBGP_KILL_COMMAND}
50     BuiltIn.Log    ${output}
51
52 Start_GoBgp_And_Verify_Connected
53     [Documentation]    Starts the GoBgp and verifies its connection. The verification is done by checking the presence
54     ...    of the peer in the bgp rib. [Gobgp at times might take more time, hence the loop]
55     [Arguments]    ${cfg_file}    ${session}    ${gobgp_ip}    ${connection_retries}=${3}
56     Start_GoBgp    ${cfg_file}
57     ${status}    ${value}=    BuiltIn.Run_Keyword_And_Ignore_Error
58     ...    BuiltIn.Wait_Until_Keyword_Succeeds
59     ...    ${connection_retries}x
60     ...    15s
61     ...    Verify_GoBgps_Connection
62     ...    ${session}
63     ...    ${gobgp_ip}
64     ...    connected=${True}
65     IF    "${status}" != "PASS"    Stop_GoBgp
66     IF    "${status}" == "PASS"    RETURN
67
68 Verify_GoBgps_Connection
69     [Documentation]    Checks peer presence in operational datastore
70     [Arguments]    ${session}    ${gobgp_ip}=${TOOLS_SYSTEM_IP}    ${connected}=${True}
71     ${peer_check_url}=    BuiltIn.Set_Variable    ${REST_API}/bgp-rib:bgp-rib/rib=example-bgp-rib/peer=bgp:%2F%2F
72     ${exp_status_code}=    BuiltIn.Set_Variable_If
73     ...    ${connected}
74     ...    ${ALLOWED_STATUS_CODES}
75     ...    ${DELETED_STATUS_CODES}
76     ${rsp}=    RequestsLibrary.Get Request    ${session}    ${peer_check_url}${gobgp_ip}?content=nonconfig
77     BuiltIn.Log    ${rsp.content}
78     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_status_code}    ${rsp.status_code}