Add ping test in aclrecovery suite
[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           string
8 Resource          ClusterManagement.robot
9 Resource          CompareStream.robot
10 Resource          DataModels.robot
11 Resource          KarafKeywords.robot
12 Resource          ODLTools.robot
13 Resource          OVSDB.robot
14 Resource          ToolsSystem.robot
15 Resource          Utils.robot
16 Resource          VpnOperations.robot
17 Resource          ../variables/Variables.robot
18 Resource          ../variables/netvirt/Variables.robot
19
20 *** Variables ***
21 @{itm_created}    TZA
22 ${genius_config_dir}    ${CURDIR}/../variables/genius
23 ${Bridge}         ${INTEGRATION_BRIDGE}
24 ${DEFAULT_MONITORING_INTERVAL}    Tunnel Monitoring Interval (for VXLAN tunnels): 1000
25 @{GENIUS_DIAG_SERVICES}    OPENFLOW    IFM    ITM    DATASTORE    OVSDB
26 ${gateway_ip}     0.0.0.0
27 ${port_name}      br-int-eth1
28 ${VLAN}           100
29 ${NO_VLAN}        0
30
31 *** Keywords ***
32 Genius Suite Setup
33     [Documentation]    Create Rest Session to http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
34     Genius.Start Suite
35     RequestsLibrary.Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}    timeout=5
36
37 Genius Suite Teardown
38     [Documentation]    Delete all sessions
39     RequestsLibrary.Delete All Sessions
40     Genius.Stop Suite
41
42 Start Suite
43     [Documentation]    Initial setup for Genius test suites
44     Run_Keyword_If_At_Least_Oxygen    Wait Until Keyword Succeeds    60    2    ClusterManagement.Check Status Of Services Is OPERATIONAL    @{GENIUS_DIAG_SERVICES}
45     KarafKeywords.Setup_Karaf_Keywords
46     ToolsSystem.Get Tools System Nodes Data
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     Genius.Set Switch Configuration
50     ${check} =    BuiltIn.Wait Until Keyword Succeeds    30    10    Check Port Status Is ESTABLISHED    ${ODL_OF_PORT_6653}    @{TOOLS_SYSTEM_ALL_IPS}
51     ${check} =    BuiltIn.Wait Until Keyword Succeeds    30    10    Check Port Status Is ESTABLISHED    ${OVSDBPORT}    @{TOOLS_SYSTEM_ALL_IPS}
52     Genius.Build Dpn List
53     @{SWITCH_DATA} =    Collections.Combine Lists    ${DPN_ID_LIST}    ${TOOLS_SYSTEM_ALL_IPS}
54     BuiltIn.Set Suite Variable    @{SWITCH_DATA}
55     ${substr}    Should Match Regexp    ${TOOLS_SYSTEM_1_IP}    [0-9]\{1,3}\.[0-9]\{1,3}\.[0-9]\{1,3}\.
56     ${SUBNET} =    Catenate    ${substr}0
57     BuiltIn.Set Suite Variable    ${SUBNET}
58
59 Stop Suite
60     [Documentation]    stops all connections and deletes all the bridges available on OVS
61     : FOR    ${tool_system_index}    IN RANGE    ${NUM_TOOLS_SYSTEM}
62     \    SSHLibrary.Switch Connection    @{TOOLS_SYSTEM_ALL_CONN_IDS}[${tool_system_index}]
63     \    SSHLibrary.Execute Command    sudo ovs-vsctl del-br ${Bridge}
64     \    SSHLibrary.Execute Command    sudo ovs-vsctl del-manager
65     \    SSHLibrary.Write    exit
66     \    SSHLibrary.Close Connection
67
68 Check Port Status Is ESTABLISHED
69     [Arguments]    ${port}    @{tools_ips}
70     [Documentation]    This keyword will check whether ports are established or not on OVS
71     : FOR    ${tools_ip}    IN    @{tools_ips}
72     \    ${check_establishment} =    Utils.Run Command On Remote System And Log    ${tools_ip}    netstat -anp | grep ${port}
73     \    BuiltIn.Should Contain    ${check_establishment}    ESTABLISHED
74     [Return]    ${check_establishment}
75
76 Create Vteps
77     [Arguments]    ${vlan_id}    ${gateway_ip}
78     [Documentation]    This keyword creates VTEPs between OVS
79     ${body} =    OperatingSystem.Get File    ${genius_config_dir}/Itm_creation_no_vlan.json
80     ${body} =    Genius.Set Json    ${vlan_id}    ${gateway_ip}    ${SUBNET}    @{TOOLS_SYSTEM_ALL_IPS}
81     ${resp} =    RequestsLibrary.Put Request    session    ${CONFIG_API}/itm:transport-zones/transport-zone/TZA    data=${body}
82     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
83
84 Set Json
85     [Arguments]    ${vlan}    ${gateway_ip}    ${subnet}    @{tools_ips}
86     [Documentation]    Sets Json with the values passed for it.
87     ${body} =    OperatingSystem.Get File    ${genius_config_dir}/Itm_creation_no_vlan.json
88     ${body} =    String.Replace String    ${body}    1.1.1.1    ${subnet}
89     : FOR    ${tool_system_index}    IN RANGE    ${NUM_TOOLS_SYSTEM}
90     \    ${body}    String.Replace String    ${body}    "dpn-id": 10${tool_system_index}    "dpn-id": ${DPN_ID_LIST[${tool_system_index}]}
91     \    ${body}    String.Replace String    ${body}    "ip-address": "${tool_system_index+2}.${tool_system_index+2}.${tool_system_index+2}.${tool_system_index+2}"    "ip-address": "@{tools_ips}[${tool_system_index}]"
92     ${body} =    String.Replace String    ${body}    "vlan-id": 0    "vlan-id": ${vlan}
93     ${body} =    String.Replace String    ${body}    "gateway-ip": "0.0.0.0"    "gateway-ip": "${gateway_ip}"
94     BuiltIn.Log    ${body}
95     [Return]    ${body}    # returns complete json that has been updated
96
97 Build Dpn List
98     [Documentation]    This keyword builds the list of DPN ids after configuring OVS bridges on each of the TOOLS_SYSTEM_IPs.
99     @{DPN_ID_LIST} =    BuiltIn.Create List
100     : FOR    ${tools_ip}    IN    @{TOOLS_SYSTEM_ALL_IPS}
101     \    ${output}    Utils.Run Command On Remote System And Log    ${tools_ip}    sudo ovs-ofctl show -O Openflow13 ${Bridge} | head -1 | awk -F "dpid:" '{ print $2 }'
102     \    ${dpn_id}    Utils.Run Command On Remote System And Log    ${tools_ip}    echo \$\(\(16\#${output}\)\)
103     \    Collections.Append To List    ${DPN_ID_LIST}    ${dpn_id}
104     BuiltIn.Set Suite Variable    @{DPN_ID_LIST}
105
106 BFD Suite Teardown
107     [Documentation]    Run at end of BFD suite
108     Genius.Delete All Vteps
109     Genius.Stop Suite
110
111 Delete All Vteps
112     [Documentation]    This will delete vtep.
113     ${resp} =    RequestsLibrary.Delete Request    session    ${CONFIG_API}/itm:transport-zones/
114     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
115     BuiltIn.Wait Until Keyword Succeeds    30    5    Genius.Verify Tunnel Delete on DS    tun
116
117 Genius Test Setup
118     [Documentation]    Genius test case setup
119     BuiltIn.Run Keyword And Ignore Error    KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
120
121 Genius Test Teardown
122     [Arguments]    ${data_models}    ${test_name}=${SUITE_NAME}.${TEST_NAME}    ${fail}=${FAIL_ON_EXCEPTIONS}
123     : FOR    ${tool_system_index}    IN RANGE    ${NUM_TOOLS_SYSTEM}
124     \    OVSDB.Get DumpFlows And Ovsconfig    @{TOOLS_SYSTEM_ALL_CONN_IDS}[${tool_system_index}]    ${Bridge}
125     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${ODL_SYSTEM_IP}    ${data_models}
126     KarafKeywords.Fail If Exceptions Found During Test    ${test_name}    fail=${fail}
127     ODLTools.Get All    test_name=${test_name}
128
129 Genius Suite Debugs
130     [Arguments]    ${data_models}
131     Genius.Genius Test Teardown    ${data_models}    test_name=${SUITE_NAME}    fail=False
132
133 ITM Direct Tunnels Start Suite
134     [Documentation]    start suite for itm scalability
135     ClusterManagement.ClusterManagement_Setup
136     ClusterManagement.Stop_Members_From_List_Or_All
137     : FOR    ${controller_index}    IN RANGE    ${NUM_ODL_SYSTEM}
138     \    Utils.Run Command On Remote System And Log    ${ODL_SYSTEM_${controller_index+1}_IP}    sed -i -- 's/<itm-direct-tunnels>false/<itm-direct-tunnels>true/g' ${GENIUS_IFM_CONFIG_FLAG}
139     ClusterManagement.Start_Members_From_List_Or_All
140     Genius.Genius Suite Setup
141
142 ITM Direct Tunnels Stop Suite
143     [Documentation]    Stop suite for ITM Direct Tunnels.
144     : FOR    ${controller_index}    IN RANGE    ${NUM_ODL_SYSTEM}
145     \    Utils.Run Command On Remote System And Log    ${ODL_SYSTEM_${controller_index+1}_IP}    sed -i -- 's/<itm-direct-tunnels>true/<itm-direct-tunnels>false/g' ${GENIUS_IFM_CONFIG_FLAG}
146     Genius.Genius Suite Teardown
147
148 Ovs Interface Verification
149     [Documentation]    Checks whether the created Interface is seen on OVS or not.
150     : FOR    ${tools_ip}    IN    @{TOOLS_SYSTEM_ALL_IPS}
151     \    Genius.Ovs Verification For Each Dpn    ${tools_ip}    ${TOOLS_SYSTEM_ALL_IPS}
152
153 Get ITM
154     [Arguments]    ${itm_created[0]}    ${subnet}    ${vlan}
155     [Documentation]    It returns the created ITM Transport zone with the passed values during the creation is done.
156     @{Itm-no-vlan} =    BuiltIn.Create List    ${itm_created[0]}    ${subnet}    ${vlan}
157     @{Itm-no-vlan} =    Collections.Combine Lists    ${Itm-no-vlan}    ${SWITCH_DATA}
158     Utils.Check For Elements At URI    ${TUNNEL_TRANSPORTZONE}/transport-zone/${itm_created[0]}    ${Itm-no-vlan}
159
160 Check Tunnel Delete On OVS
161     [Arguments]    ${tunnel_list}
162     [Documentation]    Verifies the Tunnel is deleted from OVS.
163     : FOR    ${tools_ip}    IN    @{TOOLS_SYSTEM_ALL_IPS}
164     \    ${output} =    Utils.Run Command On Remote System    ${tools_ip}    sudo ovs-vsctl show
165     \    Genius.Verify Deleted Tunnels on OVS    ${tunnel_list}    ${output}
166
167 Check Table0 Entry In a Dpn
168     [Arguments]    ${tools_ip}    ${bridgename}    ${port_numbers}
169     [Documentation]    Checks the Table 0 entry in the OVS when flows are dumped.
170     ${check} =    Utils.Run Command On Remote System And Log    ${tools_ip}    sudo ovs-ofctl -OOpenFlow13 dump-flows ${bridgename}
171     ${num_ports} =    BuiltIn.Get Length    ${port_numbers}
172     : FOR    ${port_index}    IN RANGE    ${num_ports}
173     \    BuiltIn.Should Contain    ${check}    in_port=@{port_numbers}[${port_index}]
174
175 Verify Tunnel Status As Up
176     [Arguments]    ${no_of_switches}=${NUM_TOOLS_SYSTEM}
177     [Documentation]    Verify that the number of tunnels are UP
178     ${no_of_tunnels} =    KarafKeywords.Issue Command On Karaf Console    ${TEP_SHOW_STATE}
179     ${lines_of_state_up} =    String.Get Lines Containing String    ${no_of_tunnels}    ${STATE_UP}
180     ${actual_tunnel_count} =    String.Get Line Count    ${lines_of_state_up}
181     ${expected_tunnel_count} =    BuiltIn.Evaluate    ${no_of_switches}*(${no_of_switches}-1)
182     BuiltIn.Should Be Equal As Strings    ${actual_tunnel_count}    ${expected_tunnel_count}
183
184 Verify Tunnel Status
185     [Arguments]    ${tunnel_status}    ${tunnel_names}
186     [Documentation]    Verifies if all tunnels in the input, has the expected status(UP/DOWN/UNKNOWN)
187     ${tep_result} =    KarafKeywords.Issue Command On Karaf Console    ${TEP_SHOW_STATE}
188     ${number_of_tunnels} =    BuiltIn.Get Length    ${tunnel_names}
189     : FOR    ${each_tunnel}    IN RANGE    ${number_of_tunnels}
190     \    ${tunnel} =    Collections.Get From List    ${tunnel_names}    ${each_tunnel}
191     \    ${tep_output} =    String.Get Lines Containing String    ${tep_result}    ${tunnel}
192     \    BuiltIn.Should Contain    ${tep_output}    ${tunnel_status}
193
194 Get Tunnels On OVS
195     [Arguments]    ${connection_id}
196     [Documentation]    Retrieves the list of tunnel ports present on OVS
197     SSHLibrary.Switch Connection    ${connection_id}
198     ${ovs_result} =    Utils.Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
199     @{tunnel_names} =    BuiltIn.Create List
200     ${tunnels} =    String.Get Lines Matching Regexp    ${ovs_result}    Interface "tun.*"    True
201     @{tunnels_list} =    String.Split To Lines    ${tunnels}
202     : FOR    ${tun}    IN    @{tunnels_list}
203     \    ${tun_list}    Get Regexp Matches    ${tun}    tun.*\\w
204     \    Collections.Append To List    ${tunnel_names}    @{tun_list}
205     ${items_in_list} =    BuiltIn.Get Length    ${tunnel_names}
206     [Return]    @{tunnel_names}
207
208 Get Tunnel
209     [Arguments]    ${src}    ${dst}    ${type}    ${config_api_type}=${EMPTY}
210     [Documentation]    This keyword returns tunnel interface name between source DPN and destination DPN.
211     ...    Statements are executed depending on whether it is itm tunnel state(default) or dpn tep state.
212     ${resp} =    BuiltIn.Run Keyword If    '${config_api_type}' == '${EMPTY}'    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm-state:tunnel-list/internal-tunnel/${src}/${dst}/${type}/
213     ...    ELSE    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm-state:dpn-teps-state/dpns-teps/${src}/remote-dpns/${dst}/
214     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    ${RESP_CODE}
215     BuiltIn.Log    ${resp.content}
216     ${respjson} =    RequestsLibrary.To Json    ${resp.content}    pretty_print=True
217     ${json} =    Utils.Json Parse From String    ${resp.content}
218     BuiltIn.Should Contain    ${resp.content}    ${dst}
219     BuiltIn.Run Keyword If    '${config_api_type}' == '${EMPTY}'    BuiltIn.Should Contain    ${resp.content}    ${src}
220     ${tunnel_interface_name} =    BuiltIn.Run Keyword If    "tunnel-interface-names" in "${json}"    Genius.Get Tunnel Interface Name    ${json["internal-tunnel"][0]}    tunnel-interface-names
221     ${tunnel_name_output}    ${tunnel_name} =    BuiltIn.Run Keyword Unless    '${config_api_type}' == '${EMPTY}'    BuiltIn.Should Match Regexp    ${resp.content}    "tunnel-name":"(tun[\\w\\d]+)"
222     ${tunnel} =    BuiltIn.Set Variable If    '${config_api_type}' == '${EMPTY}'    ${tunnel_interface_name}    ${tunnel_name}
223     [Return]    ${tunnel}
224
225 Get Tunnel Interface Name
226     [Arguments]    ${json}    ${expected_tunnel_interface_name}
227     [Documentation]    This keyword extracts tunnel interface name from json given as input.
228     ${tunnels} =    Collections.Get From Dictionary    ${json}    ${expected_tunnel_interface_name}
229     [Return]    ${tunnels[0]}
230
231 Verify Tunnel Delete on DS
232     [Arguments]    ${tunnel}
233     [Documentation]    This keyword confirms that specified tunnel is not present by giving command from karaf console.
234     ${output} =    KarafKeywords.Issue Command On Karaf Console    ${TEP_SHOW_STATE}
235     BuiltIn.Should Not Contain    ${output}    ${tunnel}
236
237 SRM Start Suite
238     [Documentation]    Start suite for service recovery.
239     Genius Suite Setup
240     Genius.Create Vteps    ${NO_VLAN}    ${gateway_ip}
241     BuiltIn.Wait Until Keyword Succeeds    60s    5s    Genius.Verify Tunnel Status As Up
242     Genius.Genius Suite Debugs    ${data_models}
243
244 SRM Stop Suite
245     [Documentation]    Stop suite for service recovery.
246     Genius.Delete All Vteps
247     Genius.Genius Suite Debugs    ${data_models}
248     Genius.Genius Suite Teardown
249
250 Verify Tunnel Monitoring Status
251     [Arguments]    ${tunnel_monitor_status}
252     ${output}=    KarafKeywords.Issue Command On Karaf Console    ${TEP_SHOW}
253     BuiltIn.Should Contain    ${output}    ${tunnel_monitor_status}
254
255 Set Switch Configuration
256     [Documentation]    This keyword will set manager,controller,tap port,bridge on each OVS
257     : FOR    ${tool_system_index}    IN RANGE    ${NUM_TOOLS_SYSTEM}
258     \    SSHLibrary.Switch Connection    @{TOOLS_SYSTEM_ALL_CONN_IDS}[${tool_system_index}]
259     \    SSHLibrary.Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
260     \    SSHLibrary.Execute Command    sudo ovs-vsctl add-br ${Bridge}
261     \    SSHLibrary.Execute Command    sudo ovs-vsctl set bridge ${Bridge} protocols=OpenFlow13
262     \    SSHLibrary.Execute Command    sudo ovs-vsctl set-controller ${Bridge} tcp:${ODL_SYSTEM_IP}:${ODL_OF_PORT_6653}
263     \    SSHLibrary.Execute Command    sudo ifconfig ${Bridge} up
264     \    SSHLibrary.Execute Command    sudo ovs-vsctl add-port ${Bridge} tap${tool_system_index}ed70586-6c -- set Interface tap${tool_system_index}ed70586-6c type=tap
265     \    SSHLibrary.Execute Command    sudo ovs-vsctl set-manager tcp:${ODL_SYSTEM_IP}:${OVSDBPORT}
266     \    SSHLibrary.Execute Command    sudo ovs-vsctl show
267
268 Ovs Verification For Each Dpn
269     [Arguments]    ${tools_system_ip}    ${tools_ips}
270     [Documentation]    This keyword will verify whether local and remote ip are present on the tunnels available on OVS
271     ${ovs_output} =    Utils.Run Command On Remote System And Log    ${tools_system_ip}    sudo ovs-vsctl show
272     @{updated_tools_ip_list} =    BuiltIn.Create List    @{tools_ips}
273     Collections.Remove Values From List    ${updated_tools_ip_list}    ${tools_system_ip}
274     BuiltIn.Log Many    @{updated_tools_ip_list}
275     ${num_tool_ips}    BuiltIn.Get Length    ${updated_tools_ip_list}
276     : FOR    ${num}    IN RANGE    ${num_tool_ips}
277     \    ${tools_ip} =    Collections.Get From List    ${updated_tools_ip_list}    ${num}
278     \    BuiltIn.Should Contain    ${ovs_output}    ${tools_ip}
279
280 Get Tunnels List
281     [Documentation]    The keyword fetches the list of operational tunnels from ODL
282     ${no_of_tunnels}    KarafKeywords.Issue Command On Karaf Console    ${TEP_SHOW_STATE}
283     ${tunnels} =    String.Get Regexp Matches    ${no_of_tunnels}    tun[\\w\\d]+
284     BuiltIn.Log    ${tunnels}
285     [Return]    ${tunnels}
286
287 Verify Table0 Entry After fetching Port Number
288     [Documentation]    This keyword will get the port number and checks the table0 entry for each dpn
289     : FOR    ${tools_ip}    IN    @{TOOLS_SYSTEM_ALL_IPS}
290     \    ${check} =    Utils.Run Command On Remote System And Log    ${tools_ip}    sudo ovs-ofctl -O OpenFlow13 show ${Bridge}
291     \    ${port_numbers} =    String.Get Regexp Matches    ${check}    (\\d+).tun.*    1
292     \    Genius.Check Table0 Entry In a Dpn    ${tools_ip}    ${Bridge}    ${port_numbers}
293
294 Verify Deleted Tunnels On OVS
295     [Arguments]    ${tunnel_list}    ${resp_data}
296     [Documentation]    This will verify whether tunnel is deleted.
297     BuiltIn.Log    ${resp_data}
298     : FOR    ${tunnel}    IN    @{tunnel_list}
299     \    BuiltIn.Should Not Contain    ${resp_data}    ${tunnel}
300
301 Verify Response Code Of Dpn End Point Config API
302     [Documentation]    This keyword will verify response code from itm-state: dpn endpoints config api for each dpn
303     : FOR    ${dpn}    IN    @{DPN_ID_LIST}
304     \    BuiltIn.Wait Until Keyword Succeeds    40    5    Utils.Get Data From URI    session    ${CONFIG_API}/itm-state:dpn-endpoints/DPN-TEPs-info/${dpn}/
305
306 Get Tunnel Between DPNs
307     [Arguments]    ${tunnel_type}    ${config_api_type}    ${dpn_id_index}    @{DPN_ID_UPDATED_LIST}
308     [Documentation]    This keyword will Get All the Tunnels available on DPN's
309     : FOR    ${tool_system_index}    IN RANGE    ${NUM_TOOLS_SYSTEM} -1
310     \    ${tunnel}    BuiltIn.Wait Until Keyword Succeeds    30    10    Genius.Get Tunnel    ${DPN_ID_LIST[${dpn_id_index}]}
311     \    ...    ${DPN_ID_UPDATED_LIST[${tool_system_index}]}    ${tunnel_type}    ${config_api_type}
312     ${dpn_id_index} =    BuiltIn.Evaluate    ${dpn_id_index}+1
313     [Return]    ${dpn_id_index}
314
315 Update Dpn id List And Get Tunnels
316     [Arguments]    ${tunnel_type}    ${config_api_type}=${EMPTY}
317     [Documentation]    Update the exisisting dpn id list to form different combination of dpn ids such that tunnel formation between all dpns is verified.
318     ${dpn_id_index_1} =    BuiltIn.Set Variable    0
319     : FOR    ${tool_system_index}    IN RANGE    ${NUM_TOOLS_SYSTEM}
320     \    ${dpn_id_index_2} =    BuiltIn.Set Variable    ${dpn_id_index_1}
321     \    @{DPN_ID_UPDATED_LIST} =    BuiltIn.Create List    @{DPN_ID_LIST}
322     \    Collections.Remove Values From List    ${DPN_ID_UPDATED_LIST}    ${DPN_ID_LIST[${tool_system_index}]}
323     \    BuiltIn.Log Many    ${DPN_ID_UPDATED_LIST}
324     \    ${dpn_id_index_1} =    Genius.Get Tunnel Between DPNs    ${tunnel_type}    ${config_api_type}    ${dpn_id_index_2}    @{DPN_ID_UPDATED_LIST}