Migrate Get Requests invocations(libraries)
[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 ...                 TODO: Add similar keywords from all bgpclustering-ha tests into same libraries
16
17 Library             SSHLibrary    timeout=10s
18 Library             RequestsLibrary
19 Resource            ../../../libraries/BGPcliKeywords.robot
20 Resource            ../../../libraries/ClusterManagement.robot
21 Resource            ../../../libraries/ExaBgpLib.robot
22 Resource            ../../../libraries/SetupUtils.robot
23 Resource            ../../../libraries/SSHKeywords.robot
24 Resource            ../../../libraries/TemplatedRequests.robot
25 Resource            ../../../variables/Variables.robot
26
27 Suite Setup         Setup_Everything
28 Suite Teardown      Teardown_Everything
29 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
30 Test Teardown       SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
31
32
33 *** Variables ***
34 ${BGP_VAR_FOLDER}       ${CURDIR}/../../../variables/bgpclustering
35 ${BGP_PEER_FOLDER}      ${CURDIR}/../../../variables/bgpclustering/bgp_peer_openconf
36 ${DEFAULT_EXA_CFG}      exa.cfg
37 ${EXA_CMD}              env exabgp.tcp.port=1790 exabgp
38 ${HOLDTIME}             180
39 ${RIB_INSTANCE}         example-bgp-rib
40
41
42 *** Test Cases ***
43 Get_Example_Bgp_Rib_Owner
44     [Documentation]    Find an odl node which is able to accept incomming connection.
45     ${rib_owner}    ${rib_candidates}=    BuiltIn.Wait_Until_Keyword_Succeeds
46     ...    5x
47     ...    5s
48     ...    ClusterManagement.Get_Owner_And_Successors_For_Device
49     ...    example-bgp-rib
50     ...    Bgpcep
51     ...    1
52     BuiltIn.Set Suite variable    ${rib_owner}
53     BuiltIn.Log    ${ODL_SYSTEM_${rib_owner}_IP}
54     BuiltIn.Set Suite variable    ${rib_candidates}
55     ${session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${rib_owner}
56     BuiltIn.Set_Suite_Variable    ${living_session}    ${session}
57     BuiltIn.Set_Suite_Variable    ${living_node}    ${rib_owner}
58
59 Reconfigure_ODL_To_Accept_Connection
60     [Documentation]    Configure BGP peer module with initiate-connection set to false.
61     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
62     &{mapping}=    Create Dictionary
63     ...    IP=${TOOLS_SYSTEM_IP}
64     ...    HOLDTIME=${HOLDTIME}
65     ...    PEER_PORT=${BGP_TOOL_PORT}
66     ...    PASSIVE_MODE=true
67     ...    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
68     TemplatedRequests.Put_As_Xml_Templated
69     ...    ${BGP_PEER_FOLDER}
70     ...    mapping=${mapping}
71     ...    session=${living_session}
72     ...    http_timeout=5
73     [Teardown]    SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
74
75 Start_ExaBgp_Peer
76     [Documentation]    Starts exabgp
77     SSHKeywords.Virtual_Env_Activate_On_Current_Session    log_output=${True}
78     BGPcliKeywords.Start_Console_Tool    ${EXA_CMD}    ${DEFAULT_EXA_CFG} > exa_ha_restart.log 2>&1
79
80 Verify ExaBgp Connected
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 Kill_Current_Owner_Member
85     [Documentation]    Killing karaf which is connected with exabgp.
86     ClusterManagement.Kill_Single_Member    ${rib_owner}
87     BuiltIn.Set Suite variable    ${old_rib_owner}    ${rib_owner}
88     BuiltIn.Set Suite variable    ${old_rib_candidates}    ${rib_candidates}
89     ${idx}=    Collections.Get From List    ${old_rib_candidates}    0
90     ${session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${idx}
91     BuiltIn.Set_Suite_Variable    ${living_session}    ${session}
92     BuiltIn.Set_Suite_Variable    ${living_node}    ${idx}
93
94 Verify_New_Rib_Owner
95     [Documentation]    Verifies if new owner of example-bgp-rib is elected.
96     BuiltIn.Wait_Until_Keyword_Succeeds
97     ...    5x
98     ...    5s
99     ...    Verify_New_Rib_Owner_Elected
100     ...    ${old_rib_owner}
101     ...    ${living_node}
102
103 Verify_ExaBgp_Reconnected
104     [Documentation]    Verifies exabgp's presence in operational ds.
105     BuiltIn.Wait_Until_Keyword_Succeeds    5x    5s    ExaBgpLib.Verify_ExaBgps_Connection    ${living_session}
106
107 Start_Stopped_Member
108     [Documentation]    Starting stopped node
109     ClusterManagement.Start_Single_Member    ${old_rib_owner}
110
111 Verify_New_Candidate
112     [Documentation]    Verifies started node become candidate for example-bgp-rib
113     BuiltIn.Wait_Until_Keyword_Succeeds
114     ...    10x
115     ...    5s
116     ...    Verify_New_Rib_Candidate_Present
117     ...    ${old_rib_owner}
118     ...    ${living_node}
119
120 Verify_ExaBgp_Still_Connected
121     [Documentation]    Verifies exabgp's presence in operational ds
122     BuiltIn.Wait_Until_Keyword_Succeeds    5x    5s    ExaBgpLib.Verify_ExaBgps_Connection    ${living_session}
123
124 Stop_ExaBgp_Peer
125     [Documentation]    Stops exabgp tool by sending ctrl+c
126     BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
127     BGPcliKeywords.Store_File_To_Workspace    exa_ha_restart.log    exa_ha_restart.log
128     SSHKeywords.Virtual_Env_Deactivate_On_Current_Session    log_output=${True}
129
130 Delete_Bgp_Peer_Configuration
131     [Documentation]    Revert the BGP configuration to the original state: without any configured peers
132     &{mapping}=    Create Dictionary    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}    IP=${TOOLS_SYSTEM_IP}
133     TemplatedRequests.Delete_Templated
134     ...    ${BGP_PEER_FOLDER}
135     ...    mapping=${mapping}
136     ...    session=${living_session}
137     ...    http_timeout=5
138
139
140 *** Keywords ***
141 Setup_Everything
142     [Documentation]    Initial setup
143     SetupUtils.Setup_Utils_For_Setup_And_Teardown
144     ClusterManagement.ClusterManagement_Setup
145     ${tools_system_conn_id}=    SSHLibrary.Open_Connection
146     ...    ${TOOLS_SYSTEM_IP}
147     ...    prompt=${DEFAULT_LINUX_PROMPT}
148     ...    timeout=6s
149     Builtin.Set_Suite_Variable    ${tools_system_conn_id}
150     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
151     SSHKeywords.Virtual_Env_Create
152     SSHKeywords.Virtual_Env_Install_Package    setuptools==44.0.0
153     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
154     ExaBgpLib.Upload_ExaBgp_Cluster_Config_Files    ${BGP_VAR_FOLDER}    ${DEFAULT_EXA_CFG}
155
156 Teardown_Everything
157     [Documentation]    Suite cleanup
158     SSHKeywords.Virtual_Env_Delete
159     RequestsLibrary.Delete_All_Sessions
160     SSHLibrary.Close_All_Connections
161
162 Verify_New_Rib_Owner_Elected
163     [Documentation]    Verifies new owner was elected
164     [Arguments]    ${old_owner}    ${node_to_ask}
165     ${owner}    ${candidates}=    ClusterManagement.Get_Owner_And_Successors_For_device
166     ...    example-bgp-rib
167     ...    Bgpcep
168     ...    ${node_to_ask}
169     BuiltIn.Should_Not_Be_Equal    ${old_owner}    ${owner}
170
171 Verify_New_Rib_Candidate_Present
172     [Documentation]    Verifies candidate's presence.
173     [Arguments]    ${candidate}    ${node_to_ask}
174     ${owner}    ${candidates}=    ClusterManagement.Get_Owner_And_Successors_For_device
175     ...    example-bgp-rib
176     ...    Bgpcep
177     ...    ${node_to_ask}
178     BuiltIn.Should_Contain    ${candidates}    ${candidate}