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