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