f7b061b7bc3f960f56064e13930dfbaeedf8dece
[integration/test.git] / csit / suites / bgpcep / bgpclustering / bgp_ha_karaf_isolation.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 killing karaf which owned connection new owner should be elected and
14 ...               this new owner should accept incomming bgp connection.
15 Suite Setup       Setup_Everything
16 Suite Teardown    Teardown_Everything
17 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
18 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
19 Library           SSHLibrary    timeout=10s
20 Library           RequestsLibrary
21 Variables         ${CURDIR}/../../../variables/Variables.py
22 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
23 Resource          ${CURDIR}/../../../libraries/ClusterManagement.robot
24 Resource          ${CURDIR}/../../../libraries/RemoteBash.robot
25 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
26 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
27
28 *** Variables ***
29 ${BGP_VAR_FOLDER}    ${CURDIR}/../../../variables/bgpclustering
30 ${BGP_PEER_FOLDER}    ${CURDIR}/../../../variables/bgpclustering/bgp_peer_openconf
31 ${DEFAUTL_EXA_CFG}    exa.cfg
32 ${EXA_CMD}        env exabgp.tcp.port=1790 exabgp
33 ${PEER_CHECK_URL}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/peer/bgp:%2F%2F
34 ${HOLDTIME}       180
35 ${RIB_INSTANCE}    example-bgp-rib
36
37 *** Test Cases ***
38 Get Example Bgp Rib Owner
39     [Documentation]    Find an odl node which is able to accept incomming connection. To this node netconf connector should be configured.
40     ${rib_owner}    ${rib_candidates}=    BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    ClusterManagement.Get_Owner_And_Successors_For_Device    example-bgp-rib
41     ...    Bgpcep    1
42     BuiltIn.Set Suite variable    ${rib_owner}
43     BuiltIn.Log    ${ODL_SYSTEM_${rib_owner}_IP}
44     BuiltIn.Set Suite variable    ${rib_candidates}
45     ${session}=    Resolve_Http_Session_For_Member    member_index=${rib_owner}
46     BuiltIn.Set_Suite_Variable    ${living_session}    ${session}
47     BuiltIn.Set_Suite_Variable    ${living_node}    ${rib_owner}
48
49 Reconfigure_ODL_To_Accept_Connection
50     [Documentation]    Configure BGP peer module with initiate-connection set to false.
51     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
52     &{mapping}    Create Dictionary    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}    PASSIVE_MODE=true    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
53     TemplatedRequests.Put_As_Xml_Templated    ${BGP_PEER_FOLDER}    mapping=${mapping}    session=${living_session}    http_timeout=5
54     [Teardown]    SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
55
56 Start_ExaBgp_Peer
57     [Documentation]    Starts exabgp
58     Start_Tool    ${DEFAUTL_EXA_CFG}
59
60 Verify ExaBgp Connected
61     [Documentation]    Verifies exabgp's presence in operational ds.
62     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_Tools_Connection    ${living_session}
63
64 Isolate_Current_Owner_Member
65     [Documentation]    Isolating cluster node which is connected with exabgp.
66     ClusterManagement.Isolate_Member_From_List_Or_All    ${rib_owner}
67     BuiltIn.Set Suite variable    ${old_rib_owner}    ${rib_owner}
68     BuiltIn.Set Suite variable    ${old_rib_candidates}    ${rib_candidates}
69     ${idx}=    Collections.Get From List    ${old_rib_candidates}    0
70     ${session}=    Resolve_Http_Session_For_Member    member_index=${idx}
71     BuiltIn.Set_Suite_Variable    ${living_session}    ${session}
72     BuiltIn.Set_Suite_Variable    ${living_node}    ${idx}
73
74 Verify_New_Rib_Owner
75     [Documentation]    Verifies if new owner of example-bgp-rib is elected.
76     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_New_Rib_Owner_Elected    ${old_rib_owner}    ${living_node}
77
78 Verify_ExaBgp_Reconnected
79     [Documentation]    Verifies exabgp's presence in operational ds.
80     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_Tools_Connection    ${living_session}
81
82 Rejoin_Isolated_Member
83     [Documentation]    Rejoin isolated node
84     ClusterManagement.Rejoin_Member_From_List_Or_All    ${old_rib_owner}
85
86 Verify_New_Candidate
87     [Documentation]    Verifies started node become candidate for example-bgp-rib
88     BuiltIn.Wait_Until_Keyword_Succeeds    10x    5s    Verify_New_Rib_Candidate_Present    ${old_rib_owner}    ${living_node}
89
90 Verify ExaBgp Still Connected
91     [Documentation]    Verifies exabgp's presence in operational ds
92     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_Tools_Connection    ${living_session}
93
94 Stop_ExaBgp_Peer
95     [Documentation]    Stops exabgp
96     Stop_Tool
97
98 Delete_Bgp_Peer_Configuration
99     [Documentation]    Revert the BGP configuration to the original state: without any configured peers
100     &{mapping}    Create Dictionary    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}    IP=${TOOLS_SYSTEM_IP}
101     TemplatedRequests.Delete_Templated    ${BGP_PEER_FOLDER}    mapping=${mapping}    session=${living_session}    http_timeout=5
102
103 *** Keywords ***
104 Setup_Everything
105     [Documentation]    Initial setup
106     SetupUtils.Setup_Utils_For_Setup_And_Teardown
107     ClusterManagement.ClusterManagement_Setup
108     ${tools_system_conn_id}=    SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
109     Builtin.Set_Suite_Variable    ${tools_system_conn_id}
110     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
111     SSHKeywords.Virtual_Env_Create
112     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
113     Upload_Config_Files
114
115 Teardown_Everything
116     [Documentation]    Suite cleanup
117     SSHKeywords.Virtual_Env_Delete
118     RequestsLibrary.Delete_All_Sessions
119     SSHLibrary.Close_All_Connections
120
121 Start_Tool
122     [Arguments]    ${cfg_file}    ${mapping}={}
123     [Documentation]    Starts the tool
124     ${start_cmd}    BuiltIn.Set_Variable    ${EXA_CMD} ${cfg_file}
125     BuiltIn.Log    ${start_cmd}
126     SSHKeywords.Virtual_Env_Activate_On_Current_Session    log_output=${True}
127     ${output}=    SSHLibrary.Write    ${start_cmd}
128     BuiltIn.Log    ${output}
129
130 Stop_Tool
131     [Documentation]    Stops the tool by sending ctrl+c
132     ${output}=    SSHLibrary.Read
133     BuiltIn.Log    ${output}
134     RemoteBash.Write_Bare_Ctrl_C
135     ${output}=    SSHLibrary.Read_Until_Prompt
136     BuiltIn.Log    ${output}
137     SSHKeywords.Virtual_Env_Deactivate_On_Current_Session    log_output=${True}
138
139 Upload_Config_Files
140     [Documentation]    Uploads exabgp config files.
141     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${DEFAUTL_EXA_CFG}    .
142     @{cfgfiles}=    SSHLibrary.List_Files_In_Directory    .    *.cfg
143     : FOR    ${cfgfile}    IN    @{cfgfiles}
144     \    SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
145     \    SSHLibrary.Execute_Command    sed -i -e 's/ODLIP1/${ODL_SYSTEM_1_IP}/g' ${cfgfile}
146     \    SSHLibrary.Execute_Command    sed -i -e 's/ODLIP2/${ODL_SYSTEM_2_IP}/g' ${cfgfile}
147     \    SSHLibrary.Execute_Command    sed -i -e 's/ODLIP3/${ODL_SYSTEM_3_IP}/g' ${cfgfile}
148     \    SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/disable/g' ${cfgfile}
149     \    SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
150     \    ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
151     \    Log    ${stdout}
152
153 Verify_New_Rib_Owner_Elected
154     [Arguments]    ${old_owner}    ${node_to_ask}
155     [Documentation]    Verifies new owner was elected
156     ${owner}    ${candidates}=    ClusterManagement.Get_Owner_And_Successors_For_device    example-bgp-rib    Bgpcep    ${node_to_ask}
157     BuiltIn.Should_Not_Be_Equal    ${old_owner}    ${owner}
158
159 Verify_New_Rib_Candidate_Present
160     [Arguments]    ${candidate}    ${node_to_ask}
161     [Documentation]    Verifies candidate's presence.
162     ${owner}    ${candidates}=    ClusterManagement.Get_Owner_And_Successors_For_device    example-bgp-rib    Bgpcep    ${node_to_ask}
163     BuiltIn.Should_Contain    ${candidates}    ${candidate}
164
165 Verify_Tools_Connection
166     [Arguments]    ${session}    ${connected}=${True}
167     [Documentation]    Checks peer presence in operational datastore
168     ${exp_status_code}=    BuiltIn.Set_Variable_If    ${connected}    ${200}    ${404}
169     ${rsp}=    RequestsLibrary.Get Request    ${session}    ${PEER_CHECK_URL}${TOOLS_SYSTEM_IP}    timeout=10
170     BuiltIn.Log    ${rsp.content}
171     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_status_code}    ${rsp.status_code}