Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / bgpcep / bgpclustering / 040_bgp_ha_karaf_stop.robot
1 *** Settings ***
2 Documentation     BGP functional HA testing with one exabgp peer.
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 ...               This suite uses exabgp. It is configured to have 3 peers (all 3 nodes of odl).
11 ...               Bgp implemented with singleton accepts only one incomming conection. Exabgp
12 ...               logs will show that one peer will be connected and two will fail.
13 ...               After stopping karaf which owned connection new owner should be elected and
14 ...               this new owner should accept incomming bgp connection.
15 ...               TODO: Add similar keywords from all bgpclustering-ha tests into same libraries
16 Suite Setup       Setup_Everything
17 Suite Teardown    Teardown_Everything
18 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
19 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
20 Library           SSHLibrary    timeout=10s
21 Library           RequestsLibrary
22 Resource          ../../../libraries/BGPcliKeywords.robot
23 Resource          ../../../libraries/ClusterManagement.robot
24 Resource          ../../../libraries/ExaBgpLib.robot
25 Resource          ../../../libraries/SetupUtils.robot
26 Resource          ../../../libraries/SSHKeywords.robot
27 Resource          ../../../libraries/TemplatedRequests.robot
28 Resource          ../../../variables/Variables.robot
29
30 *** Variables ***
31 ${BGP_VAR_FOLDER}    ${CURDIR}/../../../variables/bgpclustering
32 ${BGP_PEER_FOLDER}    ${CURDIR}/../../../variables/bgpclustering/bgp_peer_openconf
33 ${DEFAULT_EXA_CFG}    exa.cfg
34 ${EXA_CMD}        env exabgp.tcp.port=1790 exabgp
35 ${HOLDTIME}       180
36 ${RIB_INSTANCE}    example-bgp-rib
37
38 *** Test Cases ***
39 Get_Example_Bgp_Rib_Owner
40     [Documentation]    Find an odl node which is able to accept incomming connection.
41     ${rib_owner}    ${rib_candidates}=    BuiltIn.Wait_Until_Keyword_Succeeds    5x    5s    ClusterManagement.Get_Owner_And_Successors_For_Device    example-bgp-rib
42     ...    Bgpcep    1
43     BuiltIn.Set Suite variable    ${rib_owner}
44     BuiltIn.Log    ${ODL_SYSTEM_${rib_owner}_IP}
45     BuiltIn.Set Suite variable    ${rib_candidates}
46     ${session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${rib_owner}
47     BuiltIn.Set_Suite_Variable    ${living_session}    ${session}
48     BuiltIn.Set_Suite_Variable    ${living_node}    ${rib_owner}
49
50 Reconfigure_ODL_To_Accept_Connection
51     [Documentation]    Configure BGP peer module with initiate-connection set to false.
52     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
53     &{mapping}    Create Dictionary    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}    PASSIVE_MODE=true    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
54     TemplatedRequests.Put_As_Xml_Templated    ${BGP_PEER_FOLDER}    mapping=${mapping}    session=${living_session}    http_timeout=5
55     [Teardown]    SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
56
57 Start_ExaBgp_Peer
58     [Documentation]    Starts exabgp
59     SSHKeywords.Virtual_Env_Activate_On_Current_Session    log_output=${True}
60     BGPcliKeywords.Start_Console_Tool    ${EXA_CMD}    ${DEFAULT_EXA_CFG} > exa_ha_stop.log 2>&1
61
62 Verify_ExaBgp_Connected
63     [Documentation]    Verifies exabgp's presence in operational ds.
64     BuiltIn.Wait_Until_Keyword_Succeeds    5x    5s    ExaBgpLib.Verify_ExaBgps_Connection    ${living_session}
65
66 Stop_Current_Owner_Member
67     [Documentation]    Stopping karaf which is connected with exabgp.
68     ClusterManagement.Kill_Single_Member    ${rib_owner}
69     BuiltIn.Set Suite variable    ${old_rib_owner}    ${rib_owner}
70     BuiltIn.Set Suite variable    ${old_rib_candidates}    ${rib_candidates}
71     ${idx}=    Collections.Get From List    ${old_rib_candidates}    0
72     ${session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${idx}
73     BuiltIn.Set_Suite_Variable    ${living_session}    ${session}
74     BuiltIn.Set_Suite_Variable    ${living_node}    ${idx}
75
76 Verify_New_Rib_Owner
77     [Documentation]    Verifies if new owner of example-bgp-rib is elected.
78     BuiltIn.Wait_Until_Keyword_Succeeds    5x    5s    Verify_New_Rib_Owner_Elected    ${old_rib_owner}    ${living_node}
79
80 Verify_ExaBgp_Reconnected
81     [Documentation]    Verifies exabgp's presence in operational ds.
82     BuiltIn.Wait_Until_Keyword_Succeeds    5x    5s    ExaBgpLib.Verify_ExaBgps_Connection    ${living_session}
83
84 Start_Stopped_Member
85     [Documentation]    Starting stopped node
86     ClusterManagement.Start_Single_Member    ${old_rib_owner}
87
88 Verify_New_Candidate
89     [Documentation]    Verifies started node become candidate for example-bgp-rib
90     BuiltIn.Wait_Until_Keyword_Succeeds    10x    5s    Verify_New_Rib_Candidate_Present    ${old_rib_owner}    ${living_node}
91
92 Verify_ExaBgp_Still_Connected
93     [Documentation]    Verifies exabgp's presence in operational ds
94     BuiltIn.Wait_Until_Keyword_Succeeds    5x    5s    ExaBgpLib.Verify_ExaBgps_Connection    ${living_session}
95
96 Stop_ExaBgp_Peer
97     [Documentation]    Stops exabgp tool by sending ctrl+c
98     BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
99     BGPcliKeywords.Store_File_To_Workspace    exa_ha_stop.log    exa_ha_stop.log
100     SSHKeywords.Virtual_Env_Deactivate_On_Current_Session    log_output=${True}
101
102 Delete_Bgp_Peer_Configuration
103     [Documentation]    Revert the BGP configuration to the original state: without any configured peers
104     &{mapping}    Create Dictionary    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}    IP=${TOOLS_SYSTEM_IP}
105     TemplatedRequests.Delete_Templated    ${BGP_PEER_FOLDER}    mapping=${mapping}    session=${living_session}    http_timeout=5
106
107 *** Keywords ***
108 Setup_Everything
109     [Documentation]    Initial setup
110     SetupUtils.Setup_Utils_For_Setup_And_Teardown
111     ClusterManagement.ClusterManagement_Setup
112     ${tools_system_conn_id}=    SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
113     Builtin.Set_Suite_Variable    ${tools_system_conn_id}
114     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
115     SSHKeywords.Virtual_Env_Create
116     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
117     ExaBgpLib.Upload_ExaBgp_Cluster_Config_Files    ${BGP_VAR_FOLDER}    ${DEFAULT_EXA_CFG}
118
119 Teardown_Everything
120     [Documentation]    Suite cleanup
121     SSHKeywords.Virtual_Env_Delete
122     RequestsLibrary.Delete_All_Sessions
123     SSHLibrary.Close_All_Connections
124
125 Verify_New_Rib_Owner_Elected
126     [Arguments]    ${old_owner}    ${node_to_ask}
127     [Documentation]    Verifies new owner was elected
128     ${owner}    ${candidates}=    ClusterManagement.Get_Owner_And_Successors_For_device    example-bgp-rib    Bgpcep    ${node_to_ask}
129     BuiltIn.Should_Not_Be_Equal    ${old_owner}    ${owner}
130
131 Verify_New_Rib_Candidate_Present
132     [Arguments]    ${candidate}    ${node_to_ask}
133     [Documentation]    Verifies candidate's presence.
134     ${owner}    ${candidates}=    ClusterManagement.Get_Owner_And_Successors_For_device    example-bgp-rib    Bgpcep    ${node_to_ask}
135     BuiltIn.Should_Contain    ${candidates}    ${candidate}