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