Add suite exception debugs
[integration/test.git] / csit / libraries / Genius.robot
1 *** Settings ***
2 Documentation     This suite is a common keywords file for genius project.
3 Library           Collections
4 Library           OperatingSystem
5 Library           re
6 Library           RequestsLibrary
7 Library           SSHLibrary
8 Library           string
9 Resource          ClusterManagement.robot
10 Resource          DataModels.robot
11 Resource          KarafKeywords.robot
12 Resource          OVSDB.robot
13 Resource          Utils.robot
14 Resource          VpnOperations.robot
15 Resource          ../variables/Variables.robot
16 Resource          ../variables/netvirt/Variables.robot
17
18 *** Variables ***
19 @{itm_created}    TZA
20 ${genius_config_dir}    ${CURDIR}/../variables/genius
21 ${Bridge-1}       BR1
22 ${Bridge-2}       BR2
23 ${DEFAULT_MONITORING_INTERVAL}    Tunnel Monitoring Interval (for VXLAN tunnels): 1000
24 @{GENIUS_DIAG_SERVICES}    OPENFLOW    IFM    ITM    DATASTORE    OVSDB
25 ${vlan}           0
26 ${gateway-ip}     0.0.0.0
27
28 *** Keywords ***
29 Genius Suite Setup
30     [Documentation]    Create Rest Session to http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
31     Start Suite
32     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}    timeout=5
33
34 Genius Suite Teardown
35     [Documentation]    Delete all sessions
36     Delete All Sessions
37     Stop Suite
38
39 Start Suite
40     [Documentation]    Initial setup for Genius test suites
41     Run_Keyword_If_At_Least_Oxygen    Wait Until Keyword Succeeds    60    2    ClusterManagement.Check Status Of Services Is OPERATIONAL    @{GENIUS_DIAG_SERVICES}
42     Log    Start the tests
43     ${conn_id_1}=    Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
44     Set Global Variable    ${conn_id_1}
45     KarafKeywords.Setup_Karaf_Keywords
46     ${karaf_debug_enabled}    BuiltIn.Get_Variable_Value    ${KARAF_DEBUG}    ${False}
47     BuiltIn.run_keyword_if    ${karaf_debug_enabled}    KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set DEBUG org.opendaylight.genius
48     BuiltIn.Run Keyword And Ignore Error    KarafKeywords.Log_Test_Suite_Start_To_Controller_Karaf
49     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
50     Log    ${conn_id_1}
51     Execute Command    sudo ovs-vsctl add-br BR1
52     Execute Command    sudo ovs-vsctl set bridge BR1 protocols=OpenFlow13
53     Execute Command    sudo ovs-vsctl set-controller BR1 tcp:${ODL_SYSTEM_IP}:6633
54     Execute Command    sudo ifconfig BR1 up
55     Execute Command    sudo ovs-vsctl add-port BR1 tap8ed70586-6c -- set Interface tap8ed70586-6c type=tap
56     Execute Command    sudo ovs-vsctl set-manager tcp:${ODL_SYSTEM_IP}:6640
57     ${output_1}    Execute Command    sudo ovs-vsctl show
58     Log    ${output_1}
59     ${check}    Wait Until Keyword Succeeds    30    10    check establishment    ${conn_id_1}    6633
60     log    ${check}
61     ${check_2}    Wait Until Keyword Succeeds    30    10    check establishment    ${conn_id_1}    6640
62     log    ${check_2}
63     Log    >>>>>Switch 2 configuration <<<<<
64     ${conn_id_2}=    Open Connection    ${TOOLS_SYSTEM_2_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
65     Set Global Variable    ${conn_id_2}
66     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
67     Log    ${conn_id_2}
68     Execute Command    sudo ovs-vsctl add-br BR2
69     Execute Command    sudo ovs-vsctl set bridge BR2 protocols=OpenFlow13
70     Execute Command    sudo ovs-vsctl set-controller BR2 tcp:${ODL_SYSTEM_IP}:6633
71     Execute Command    sudo ifconfig BR2 up
72     Execute Command    sudo ovs-vsctl set-manager tcp:${ODL_SYSTEM_IP}:6640
73     ${output_2}    Execute Command    sudo ovs-vsctl show
74     Log    ${output_2}
75
76 Stop Suite
77     Log    Stop the tests
78     Switch Connection    ${conn_id_1}
79     Log    ${conn_id_1}
80     Execute Command    sudo ovs-vsctl del-br BR1
81     Execute Command    sudo ovs-vsctl del-manager
82     Write    exit
83     close connection
84     Switch Connection    ${conn_id_2}
85     Log    ${conn_id_2}
86     Execute Command    sudo ovs-vsctl del-br BR2
87     Execute Command    sudo ovs-vsctl del-manager
88     Write    exit
89     close connection
90
91 check establishment
92     [Arguments]    ${conn_id}    ${port}
93     Switch Connection    ${conn_id}
94     ${check_establishment}    Execute Command    netstat -anp | grep ${port}
95     Should contain    ${check_establishment}    ESTABLISHED
96     [Return]    ${check_establishment}
97
98 Create Vteps
99     [Arguments]    ${Dpn_id_1}    ${Dpn_id_2}    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}    ${gateway-ip}
100     [Documentation]    This keyword creates VTEPs between ${TOOLS_SYSTEM_IP} and ${TOOLS_SYSTEM_2_IP}
101     ${body}    OperatingSystem.Get File    ${genius_config_dir}/Itm_creation_no_vlan.json
102     ${substr}    Should Match Regexp    ${TOOLS_SYSTEM_IP}    [0-9]\{1,3}\.[0-9]\{1,3}\.[0-9]\{1,3}\.
103     ${subnet}    Catenate    ${substr}0
104     Log    ${subnet}
105     Set Global Variable    ${subnet}
106     ${vlan}=    Set Variable    ${vlan}
107     ${gateway-ip}=    Set Variable    ${gateway-ip}
108     ${body}    Genius.Set Json    ${Dpn_id_1}    ${Dpn_id_2}    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}
109     ...    ${gateway-ip}    ${subnet}
110     ${vtep_body}    Set Variable    ${body}
111     Set Global Variable    ${vtep_body}
112     ${resp}    RequestsLibrary.Post Request    session    ${CONFIG_API}/itm:transport-zones/    data=${body}
113     Log    ${resp.status_code}
114     should be equal as strings    ${resp.status_code}    204
115
116 Set Json
117     [Arguments]    ${Dpn_id_1}    ${Dpn_id_2}    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}    ${gateway-ip}
118     ...    ${subnet}
119     [Documentation]    Sets Json with the values passed for it.
120     ${body}    OperatingSystem.Get File    ${genius_config_dir}/Itm_creation_no_vlan.json
121     ${body}    replace string    ${body}    1.1.1.1    ${subnet}
122     ${body}    replace string    ${body}    "dpn-id": 101    "dpn-id": ${Dpn_id_1}
123     ${body}    replace string    ${body}    "dpn-id": 102    "dpn-id": ${Dpn_id_2}
124     ${body}    replace string    ${body}    "ip-address": "2.2.2.2"    "ip-address": "${TOOLS_SYSTEM_IP}"
125     ${body}    replace string    ${body}    "ip-address": "3.3.3.3"    "ip-address": "${TOOLS_SYSTEM_2_IP}"
126     ${body}    replace string    ${body}    "vlan-id": 0    "vlan-id": ${vlan}
127     ${body}    replace string    ${body}    "gateway-ip": "0.0.0.0"    "gateway-ip": "${gateway-ip}"
128     Log    ${body}
129     [Return]    ${body}    # returns complete json that has been updated
130
131 Get Dpn Ids
132     [Arguments]    ${connection_id}
133     [Documentation]    This keyword gets the DPN id of the switch after configuring bridges on it.It returns the captured DPN id.
134     Switch connection    ${connection_id}
135     ${cmd}    set Variable    sudo ovs-vsctl show | grep Bridge | awk -F "\\"" '{print $2}'
136     ${Bridgename1}    Execute command    ${cmd}
137     log    ${Bridgename1}
138     ${output1}    Execute command    sudo ovs-ofctl show -O Openflow13 ${Bridgename1} | head -1 | awk -F "dpid:" '{ print $2 }'
139     log    ${output1}
140     # "echo \$\(\(16\#${output1}\)\) command below converts ovs dpnid (i.e., output1) from hexadecimal to decimal."
141     ${Dpn_id}    Execute command    echo \$\(\(16\#${output1}\)\)
142     log    ${Dpn_id}
143     [Return]    ${Dpn_id}
144
145 BFD Suite Stop
146     [Documentation]    Run at end of BFD suite
147     Delete All Vteps
148     Stop Suite
149
150 Delete All Vteps
151     [Documentation]    This will delete vtep.
152     ${resp}    RequestsLibrary.Delete Request    session    ${CONFIG_API}/itm:transport-zones/    data=${vtep_body}
153     Should Be Equal As Strings    ${resp.status_code}    200
154     Log    "Before disconnecting CSS with controller"
155     ${output} =    Issue Command On Karaf Console    ${TEP_SHOW}
156     BuiltIn.Wait Until Keyword Succeeds    30    5    Verify All Tunnel Delete on DS
157
158 Genius Test Setup
159     [Documentation]    Genius test case setup
160     BuiltIn.Run Keyword And Ignore Error    KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
161
162 Genius Test Teardown
163     [Arguments]    ${data_models}    ${test_name}=${SUITE_NAME}.${TEST_NAME}    ${fail}=${FAIL_ON_EXCEPTIONS}
164     OVSDB.Get DumpFlows And Ovsconfig    ${conn_id_1}    BR1
165     OVSDB.Get DumpFlows And Ovsconfig    ${conn_id_2}    BR2
166     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${ODL_SYSTEM_IP}    ${data_models}
167     KarafKeywords.Fail If Exceptions Found During Test    ${test_name}    fail=${fail}
168
169 Genius Suite Debugs
170     [Arguments]    ${data_models}
171     Genius Test Teardown    ${data_models}    test_name=${SUITE_NAME}    fail=False
172
173 ITM Direct Tunnels Start Suite
174     [Documentation]    start suite for itm scalability
175     ClusterManagement.ClusterManagement_Setup
176     ClusterManagement.Stop_Members_From_List_Or_All
177     : FOR    ${i}    IN RANGE    ${NUM_ODL_SYSTEM}
178     \    Run Command On Remote System And Log    ${ODL_SYSTEM_${i+1}_IP}    sed -i -- 's/<itm-direct-tunnels>false/<itm-direct-tunnels>true/g' ${GENIUS_IFM_CONFIG_FLAG}
179     ClusterManagement.Start_Members_From_List_Or_All
180     Genius Suite Setup
181
182 ITM Direct Tunnels Stop Suite
183     : FOR    ${i}    IN RANGE    ${NUM_ODL_SYSTEM}
184     \    Run Command On Remote System And Log    ${ODL_SYSTEM_${i+1}_IP}    sed -i -- 's/<itm-direct-tunnels>true/<itm-direct-tunnels>false/g' ${GENIUS_IFM_CONFIG_FLAG}
185     Genius Suite Teardown
186
187 Verify Tunnel Monitoring is on
188     [Documentation]    This keyword will get tep:show output and verify tunnel monitoring status
189     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW}
190     Should Contain    ${output}    ${TUNNEL_MONITOR_ON}
191
192 Ovs Verification For 2 Dpn
193     [Arguments]    ${connection_id}    ${local}    ${remote-1}    ${tunnel}    ${tunnel-type}
194     [Documentation]    Checks whether the created Interface is seen on OVS or not.
195     Switch Connection    ${connection_id}
196     ${check}    Execute Command    sudo ovs-vsctl show
197     Log    ${check}
198     Should Contain    ${check}    local_ip="${local}"    remote_ip="${remote-1}"    ${tunnel}    ${tunnel-type}
199     [Return]    ${check}
200
201 Get ITM
202     [Arguments]    ${itm_created[0]}    ${subnet}    ${vlan}    ${Dpn_id_1}    ${TOOLS_SYSTEM_IP}    ${Dpn_id_2}
203     ...    ${TOOLS_SYSTEM_2_IP}
204     [Documentation]    It returns the created ITM Transport zone with the passed values during the creation is done.
205     Log    ${itm_created[0]},${subnet}, ${vlan}, ${Dpn_id_1},${TOOLS_SYSTEM_IP}, ${Dpn_id_2}, ${TOOLS_SYSTEM_2_IP}
206     @{Itm-no-vlan}    Create List    ${itm_created[0]}    ${subnet}    ${vlan}    ${Dpn_id_1}    ${Bridge-1}-eth1
207     ...    ${TOOLS_SYSTEM_IP}    ${Dpn_id_2}    ${Bridge-2}-eth1    ${TOOLS_SYSTEM_2_IP}
208     Check For Elements At URI    ${TUNNEL_TRANSPORTZONE}/transport-zone/${itm_created[0]}    ${Itm-no-vlan}
209
210 Check Tunnel Delete On OVS
211     [Arguments]    ${connection-id}    ${tunnel}
212     [Documentation]    Verifies the Tunnel is deleted from OVS.
213     Switch Connection    ${connection-id}
214     ${return} =    Execute Command    sudo ovs-vsctl show
215     log    ${return}
216     Should Not Contain    ${return}    ${tunnel}
217     [Return]    ${return}
218
219 Check Table0 Entry For 2 Dpn
220     [Arguments]    ${connection_id}    ${Bridgename}    ${port-num1}
221     [Documentation]    Checks the Table 0 entry in the OVS when flows are dumped.
222     Switch Connection    ${connection_id}
223     Log    ${connection_id}
224     ${check}    Execute Command    sudo ovs-ofctl -O OpenFlow13 dump-flows ${Bridgename}
225     Log    ${check}
226     Should Contain    ${check}    in_port=${port-num1}
227     [Return]    ${check}
228
229 Check ITM Tunnel State
230     [Arguments]    ${tunnel1}    ${tunnel2}
231     [Documentation]    Verifies the Tunnel is deleted from datastore
232     ${resp}    RequestsLibrary.Get Request    session    ${OPERATIONAL_API}/itm-state:tunnels_state/
233     Should Not Contain    ${resp.content}    ${tunnel1}    ${tunnel2}
234
235 Verify Tunnel Status as UP
236     [Arguments]    ${Transport_zone}
237     [Documentation]    Verify that the number of tunnels are UP
238     ${No_of_Teps}    Issue_Command_On_Karaf_Console    ${TEP_SHOW}
239     ${Lines_of_TZA}    Get Lines Containing String    ${No_of_Teps}    ${Transport_zone}
240     ${Expected_Node_Count}    Get Line Count    ${Lines_of_TZA}
241     ${no_of_tunnels}    Issue_Command_On_Karaf_Console    ${TEP_SHOW_STATE}
242     ${lines_of_VXLAN}    Get Lines Containing String    ${no_of_tunnels}    VXLAN
243     Should Contain    ${no_of_tunnels}    ${STATE_UP}
244     Should Not Contain    ${no_of_tunnels}    ${STATE_DOWN}
245     Should Not Contain    ${no_of_tunnels}    ${STATE_UNKNOWN}
246     ${Actual_Tunnel_Count}    Get Line Count    ${lines_of_VXLAN}
247     ${Expected_Tunnel_Count}    Set Variable    ${Expected_Node_Count*${Expected_Node_Count - 1}}
248     Should Be Equal As Strings    ${Actual_Tunnel_Count}    ${Expected_Tunnel_Count}
249
250 Verify Tunnel Status
251     [Arguments]    ${tunnel_names}    ${tunnel_status}
252     [Documentation]    Verifies if all tunnels in the input, has the expected status(UP/DOWN/UNKNOWN)
253     ${tep_result} =    KarafKeywords.Issue_Command_On_Karaf_Console    ${TEP_SHOW_STATE}
254     : FOR    ${tunnel}    IN    @{tunnel_names}
255     \    ${tep_output} =    String.Get Lines Containing String    ${tep_result}    ${tunnel}
256     \    BuiltIn.Should Contain    ${tep_output}    ${tunnel_status}
257
258 Get Tunnels On OVS
259     [Arguments]    ${connection_id}
260     [Documentation]    Retrieves the list of tunnel ports present on OVS
261     SSHLibrary.Switch Connection    ${connection_id}
262     ${ovs_result} =    Utils.Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
263     ${tunnel_names}    BuiltIn.Create List
264     ${tunnels} =    String.Get Lines Matching Regexp    ${ovs_result}    Interface "tun.*"    True
265     @{tunnels_list} =    String.Split To Lines    ${tunnels}
266     : FOR    ${tun}    IN    @{tunnels_list}
267     \    ${tun_list}    BuiltIn.Should Match Regexp    @{tunnels_list}    tun.*\\w
268     \    Collections.Append To List    ${tunnel_names}    ${tun_list}
269     ${items_in_list} =    BuiltIn.Get Length    ${tunnel_names}
270     [Return]    ${Tunnel_Names}
271
272 Get Tunnel
273     [Arguments]    ${src}    ${dst}    ${type}
274     [Documentation]    This keyword returns tunnel interface name between source DPN and destination DPN.
275     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm-state:tunnel-list/internal-tunnel/${src}/${dst}/${type}/
276     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    ${RESP_CODE}
277     BuiltIn.Should Contain    ${resp.content}    ${src}
278     BuiltIn.Should Contain    ${resp.content}    ${dst}
279     ${json} =    Utils.Json Parse From String    ${resp.content}
280     ${tunnel} =    BuiltIn.Run Keyword If    "tunnel-interface-names" in "${json}"    Get Tunnel Interface Name    ${json["internal-tunnel"][0]}    tunnel-interface-names
281     [Return]    ${tunnel}
282
283 Get Tunnel Interface Name
284     [Arguments]    ${json}    ${expected_tunnel_interface_name}
285     [Documentation]    This keyword extracts tunnel interface name from json given as input.
286     ${tunnels} =    Collections.Get From Dictionary    ${json}    ${expected_tunnel_interface_name}
287     [Return]    ${tunnels[0]}
288
289 Verify All Tunnel Delete on DS
290     [Documentation]    This keyword confirms that tunnels are not present by giving command from karaf console.
291     Verify Tunnel Delete on DS    tun
292
293 Verify Tunnel Delete on DS
294     [Arguments]    ${tunnel}
295     [Documentation]    This keyword confirms that specified tunnel is not present by giving command from karaf console.
296     ${output} =    KarafKeywords.Issue Command On Karaf Console    ${TEP_SHOW_STATE}
297     BuiltIn.Should Not Contain    ${output}    ${tunnel}
298
299 SRM Start Suite
300     [Documentation]    Start suite for service recovery.
301     Genius Suite Setup
302     ${dpn_Id_1} =    Genius.Get Dpn Ids    ${conn_id_1}
303     ${dpn_Id_2} =    Genius.Get Dpn Ids    ${conn_id_2}
304     Genius.Create Vteps    ${dpn_Id_1}    ${dpn_Id_2}    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}    ${gateway-ip}
305     ${tunnel} =    BuiltIn.Wait Until Keyword Succeeds    40    20    Genius.Get Tunnel    ${dpn_Id_1}    ${dpn_Id_2}
306     ...    odl-interface:tunnel-type-vxlan
307     BuiltIn.Wait Until Keyword Succeeds    60s    5s    Genius.Verify Tunnel Status as UP    TZA
308     Genius Suite Debugs    ${data_models}
309
310 SRM Stop Suite
311     [Documentation]    Stop suite for service recovery.
312     Delete All Vteps
313     Genius Suite Debugs    ${data_models}
314     Genius Suite Teardown