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