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