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