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