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