Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / suites / bgpcep / bgpclustering / 060_pcep_ha_karaf_stop.robot
1 *** Settings ***
2 Documentation       PCEP functional HA testing with one pcep peer.
3 ...
4 ...                 Copyright (c) 2017 AT&T Intellectual Property. 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 distbmution,
8 ...                 and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...                 This suite uses PCC mock. It is configured to have 3 peers (all 3 nodes of odl).
11 ...                 PCEP implemented with singleton accepts only one incomming conection. PCC mock
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 PCC connection.
15 ...                 TODO: Add similar keywords from all bgpclustering-ha tests into same libraries
16
17 Library             SSHLibrary    timeout=10s
18 Library             Collections
19 Library             OperatingSystem
20 Resource            ../../../libraries/BGPcliKeywords.robot
21 Resource            ../../../libraries/ClusterManagement.robot
22 Resource            ../../../libraries/NexusKeywords.robot
23 Resource            ../../../libraries/PcepOperations.robot
24 Resource            ../../../libraries/SetupUtils.robot
25 Resource            ../../../libraries/TemplatedRequests.robot
26 Resource            ../../../variables/Variables.robot
27
28 Suite Setup         Setup_Everything
29 Suite Teardown      Teardown_Everything
30 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
31 Test Teardown       SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
32
33
34 *** Variables ***
35 ${HOLDTIME}                 180
36 ${DIR_WITH_TEMPLATES}       ${CURDIR}/../../../variables/bgpclustering/${ODL_STREAM}
37 ${PCC_LOG_FILE}             pccmock.stop.log
38 ${CONFIG_SESSION}           session
39 ${ERROR_ARGS}               ${EMPTY}
40
41
42 *** Test Cases ***
43 Get_Example_Pcep_Owner
44     [Documentation]    Find an odl node which is able to accept incomming connection.
45     ${pcep_owner}    ${pcep_candidates}=    Wait_Until_Keyword_Succeeds
46     ...    5x
47     ...    2s
48     ...    ClusterManagement.Get_Owner_And_Successors_For_device
49     ...    pcep-topology
50     ...    Bgpcep
51     ...    1
52     BuiltIn.Set Suite variable    ${pcep_owner}
53     BuiltIn.Log    ${pcep_owner}
54     BuiltIn.Set Suite variable    ${pcep_candidates}
55     ${session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${pcep_owner}
56     BuiltIn.Set_Suite_Variable    ${living_session}    ${session}
57     BuiltIn.Log    ${living_session}
58     BuiltIn.Set_Suite_Variable    ${living_node}    ${pcep_owner}
59
60 Verify_Data_Reported_1
61     [Documentation]    Verifies if pcep-topology reported expected data
62     ...    Expects pcep-topology not be empty/filled path-computation.
63     Pcep_Topology_Postcondition
64
65 Stop_Current_Owner_Member
66     [Documentation]    Stopping cluster node which is connected with pcc-mock.
67     ClusterManagement.Stop_Single_Member    ${pcep_owner}
68     BuiltIn.Set Suite variable    ${old_pcep_owner}    ${pcep_owner}
69     BuiltIn.Set Suite variable    ${old_pcep_candidates}    ${pcep_candidates}
70     ${idx}=    Collections.Get From List    ${old_pcep_candidates}    0
71     ${session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${idx}
72     BuiltIn.Set_Suite_Variable    ${living_session}    ${session}
73     BuiltIn.Set_Suite_Variable    ${living_node}    ${idx}
74
75 Verify_New_Pcep_Owner
76     [Documentation]    Verifies if new owner of pcep-topology is elected.
77     BuiltIn.Wait_Until_Keyword_Succeeds
78     ...    10x
79     ...    5s
80     ...    Verify_New_Pcep_Owner_Elected
81     ...    ${old_pcep_owner}
82     ...    ${living_node}
83
84 Verify_Data_Reported_2
85     [Documentation]    Verifies if pcep-topology reports expected data
86     ...    Expects pcep-topology not be empty/filled path-computation.
87     Pcep_Topology_Postcondition
88
89 Start_Stopped_Member
90     [Documentation]    Starting stopped node
91     ClusterManagement.Start_Single_Member    ${old_pcep_owner}
92
93 Verify_New_Candidate
94     [Documentation]    Verifies started node become candidate for pcep_topology
95     BuiltIn.Wait_Until_Keyword_Succeeds
96     ...    10x
97     ...    5s
98     ...    Verify_New_Pcep_Candidate_Present
99     ...    ${old_pcep_owner}
100     ...    ${living_node}
101
102 Verify_Data_Reported_3
103     [Documentation]    Verifies if pcep-topology reported expected data
104     ...    Expects pcep-topology not be empty/filled path-computation.
105     Pcep_Topology_Postcondition
106
107 Stop_Pcc_Mock
108     [Documentation]    Send ctrl+c to pcc-mock to stop it.
109     BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
110
111
112 *** Keywords ***
113 Setup_Everything
114     [Documentation]    Initial setup
115     SetupUtils.Setup_Utils_For_Setup_And_Teardown
116     ClusterManagement.ClusterManagement_Setup
117     NexusKeywords.Initialize_Artifact_Deployment_And_Usage
118     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
119     ${name}=    NexusKeywords.Deploy_Test_Tool    bgpcep    pcep-pcc-mock
120     BuiltIn.Set_Suite_Variable    ${filename}    ${name}
121     #Setting Pcc Name and its code for mapping for templates
122     BuiltIn.Set_Suite_Variable    ${pcc_name}    pcc_${TOOLS_SYSTEM_IP}_tunnel_1
123     ${code}=    Evaluate    binascii.b2a_base64('${pcc_name}')[:-1]    modules=binascii
124     BuiltIn.Set_Suite_Variable    ${pcc_name_code}    ${code}
125     PcepOperations.Pcep_Topology_Precondition    ${CONFIG_SESSION}
126     Start_Pcc_Mock
127
128 Teardown_Everything
129     [Documentation]    Suite cleanup
130     BGPcliKeywords.Store_File_To_Workspace    ${PCC_LOG_FILE}    ${PCC_LOG_FILE}
131     RequestsLibrary.Delete_All_Sessions
132     SSHLibrary.Close_All_Connections
133
134 Start_Pcc_Mock
135     [Documentation]    Starts pcc mock
136     ${command}=    BuiltIn.Set_Variable
137     ...    -jar ${filename} --reconnect 5 --local-address ${TOOLS_SYSTEM_IP} --remote-address ${ODL_SYSTEM_1_IP}:4189,${ODL_SYSTEM_2_IP}:4189,${ODL_SYSTEM_3_IP}:4189 --log-level INFO 2>&1 | tee ${PCC_LOG_FILE}
138     BGPcliKeywords.Start_Java_Tool_And_Verify_Connection    ${command}    started
139
140 Pcep_Topology_Postcondition
141     [Documentation]    Verifies if the tool reported expected data
142     &{mapping}=    BuiltIn.Create_Dictionary
143     ...    IP=${TOOLS_SYSTEM_IP}
144     ...    CODE=${pcc_name_code}
145     ...    NAME=${pcc_name}
146     ...    IP_ODL=${ODL_SYSTEM_${pcep_owner}_IP}
147     ...    ERRORS=${ERROR_ARGS}
148     BuiltIn.Wait_Until_Keyword_Succeeds
149     ...    10x
150     ...    5s
151     ...    TemplatedRequests.Get_As_Json_Templated
152     ...    ${DIR_WITH_TEMPLATES}${/}pcep_on_state
153     ...    ${mapping}
154     ...    ${living_session}
155     ...    verify=True
156
157 Verify_New_Pcep_Owner_Elected
158     [Documentation]    Verifies new owner was elected
159     [Arguments]    ${old_owner}    ${node_to_ask}
160     ${owner}    ${candidates}=    ClusterManagement.Get_Owner_And_Successors_For_device
161     ...    pcep-topology
162     ...    Bgpcep
163     ...    ${node_to_ask}
164     BuiltIn.Should_Not_Be_Equal    ${old_owner}    ${owner}
165     BuiltIn.Set_Suite_Variable    ${pcep_owner}    ${owner}
166
167 Verify_New_Pcep_Candidate_Present
168     [Documentation]    Verifies candidate's presence.
169     [Arguments]    ${candidate}    ${node_to_ask}
170     ${owner}    ${candidates}=    ClusterManagement.Get_Owner_And_Successors_For_device
171     ...    pcep-topology
172     ...    Bgpcep
173     ...    ${node_to_ask}
174     Collections.Append_To_List    ${candidates}    ${owner}
175     BuiltIn.Should_Contain    ${candidates}    ${candidate}
176     BuiltIn.Set_Suite_Variable    ${pcep_owner}    ${owner}