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