bgp flowspec test fix
[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
19 *** Variables ***
20 ${CMD}            env exabgp.tcp.port=1790 exabgp --debug
21 ${PEER_CHECK_URL}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/peer/bgp:%2F%2F
22
23 *** Keywords ***
24 Start_ExaBgp
25     [Arguments]    ${cfg_file}
26     [Documentation]    Dump the start command into prompt. It assumes that no exabgp is running. For verified
27     ...    start use Start_ExaBgp_And_Verify_Connected keyword.
28     ${start_cmd}    BuiltIn.Set_Variable    ${CMD} ${cfg_file}
29     BuiltIn.Log    ${start_cmd}
30     SSHKeywords.Virtual_Env_Activate_On_Current_Session    log_output=${True}
31     ${output}=    SSHLibrary.Write    ${start_cmd}
32     BuiltIn.Log    ${output}
33
34 Stop_ExaBgp
35     [Documentation]    Stops the ExaBgp 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     SSHKeywords.Virtual_Env_Deactivate_On_Current_Session    log_output=${True}
42
43 Start_ExaBgp_And_Verify_Connected
44     [Arguments]    ${cfg_file}    ${session}    ${exabgp_ip}    ${connection_retries}=${3}
45     [Documentation]    Starts the ExaBgp and verifies its connection. The verification is done by checking the presence
46     ...    of the peer in the bgp rib.
47     : FOR    ${idx}    IN RANGE    ${connection_retries}
48     \    Start_ExaBgp    ${cfg_file}
49     \    ${status}    ${value}=    BuiltIn.Run_Keyword_And_Ignore_Error    BuiltIn.Wait_Until_Keyword_Succeeds    3x    3s
50     \    ...    Verify_ExaBgps_Connection    ${session}    ${exabgp_ip}    connected=${True}
51     \    BuiltIn.Run_Keyword_Unless    "${status}" == "PASS"    Stop_ExaBgp
52     \    BuiltIn.Return_From_Keyword_If    "${status}" == "PASS"
53     BuiltIn.Fail    Unable to connect ExaBgp to ODL
54
55 Verify_ExaBgps_Connection
56     [Arguments]    ${session}    ${exabgp_ip}    ${connected}=${True}
57     [Documentation]    Checks peer presence in operational datastore
58     ${exp_status_code}=    BuiltIn.Set_Variable_If    ${connected}    ${200}    ${404}
59     ${rsp}=    RequestsLibrary.Get Request    ${session}    ${PEER_CHECK_URL}${exabgp_ip}
60     BuiltIn.Log    ${rsp.content}
61     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_status_code}    ${rsp.status_code}