8b3a54b1d0a9ff2d31e35dcb3eeb0df9067af8c8
[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
16 *** Variables ***
17 @{itm_created}    TZA
18 ${genius_config_dir}    ${CURDIR}/../variables/genius
19 ${Bridge-1}       BR1
20 ${Bridge-2}       BR2
21 ${DEFAULT_MONITORING_INTERVAL}    Tunnel Monitoring Interval (for VXLAN tunnels): 1000
22 @{DIAG_SERVICES}    OPENFLOW    IFM    ITM    DATASTORE
23
24 *** Keywords ***
25 Genius Suite Setup
26     [Documentation]    Create Rest Session to http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
27     Start Suite
28     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}    timeout=5
29
30 Genius Suite Teardown
31     [Documentation]    Delete all sessions
32     Delete All Sessions
33     Stop Suite
34
35 Start Suite
36     [Documentation]    Initial setup for Genius test suites
37     Run_Keyword_If_At_Least_Oxygen    Wait Until Keyword Succeeds    60    2    Check System Status
38     Log    Start the tests
39     ${conn_id_1}=    Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
40     Set Global Variable    ${conn_id_1}
41     KarafKeywords.Setup_Karaf_Keywords
42     ${karaf_debug_enabled}    BuiltIn.Get_Variable_Value    ${KARAF_DEBUG}    ${False}
43     BuiltIn.run_keyword_if    ${karaf_debug_enabled}    KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set DEBUG org.opendaylight.genius
44     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
45     Log    ${conn_id_1}
46     Execute Command    sudo ovs-vsctl add-br BR1
47     Execute Command    sudo ovs-vsctl set bridge BR1 protocols=OpenFlow13
48     Execute Command    sudo ovs-vsctl set-controller BR1 tcp:${ODL_SYSTEM_IP}:6633
49     Execute Command    sudo ifconfig BR1 up
50     Execute Command    sudo ovs-vsctl add-port BR1 tap8ed70586-6c -- set Interface tap8ed70586-6c type=tap
51     Execute Command    sudo ovs-vsctl set-manager tcp:${ODL_SYSTEM_IP}:6640
52     ${output_1}    Execute Command    sudo ovs-vsctl show
53     Log    ${output_1}
54     ${check}    Wait Until Keyword Succeeds    30    10    check establishment    ${conn_id_1}    6633
55     log    ${check}
56     ${check_2}    Wait Until Keyword Succeeds    30    10    check establishment    ${conn_id_1}    6640
57     log    ${check_2}
58     Log    >>>>>Switch 2 configuration <<<<<
59     ${conn_id_2}=    Open Connection    ${TOOLS_SYSTEM_2_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
60     Set Global Variable    ${conn_id_2}
61     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
62     Log    ${conn_id_2}
63     Execute Command    sudo ovs-vsctl add-br BR2
64     Execute Command    sudo ovs-vsctl set bridge BR2 protocols=OpenFlow13
65     Execute Command    sudo ovs-vsctl set-controller BR2 tcp:${ODL_SYSTEM_IP}:6633
66     Execute Command    sudo ifconfig BR2 up
67     Execute Command    sudo ovs-vsctl set-manager tcp:${ODL_SYSTEM_IP}:6640
68     ${output_2}    Execute Command    sudo ovs-vsctl show
69     Log    ${output_2}
70
71 Stop Suite
72     Log    Stop the tests
73     Switch Connection    ${conn_id_1}
74     Log    ${conn_id_1}
75     Execute Command    sudo ovs-vsctl del-br BR1
76     Execute Command    sudo ovs-vsctl del-manager
77     Write    exit
78     close connection
79     Switch Connection    ${conn_id_2}
80     Log    ${conn_id_2}
81     Execute Command    sudo ovs-vsctl del-br BR2
82     Execute Command    sudo ovs-vsctl del-manager
83     Write    exit
84     close connection
85
86 check establishment
87     [Arguments]    ${conn_id}    ${port}
88     Switch Connection    ${conn_id}
89     ${check_establishment}    Execute Command    netstat -anp | grep ${port}
90     Should contain    ${check_establishment}    ESTABLISHED
91     [Return]    ${check_establishment}
92
93 Check Service Status
94     [Arguments]    ${odl_ip}    ${system_ready_state}    ${service_state}
95     [Documentation]    Issues the karaf shell command showSvcStatus to verify the ready and service states are the same as the arguments passed
96     ${service_status_output}    Issue_Command_On_Karaf_Console    showSvcStatus    ${odl_ip}    8101
97     Should Contain    ${service_status_output}    ${system_ready_state}
98     : FOR    ${service}    IN    @{DIAG_SERVICES}
99     \    Should Match Regexp    ${service_status_output}    ${service} +: ${service_state}
100
101 Create Vteps
102     [Arguments]    ${Dpn_id_1}    ${Dpn_id_2}    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}    ${gateway-ip}
103     [Documentation]    This keyword creates VTEPs between ${TOOLS_SYSTEM_IP} and ${TOOLS_SYSTEM_2_IP}
104     ${body}    OperatingSystem.Get File    ${genius_config_dir}/Itm_creation_no_vlan.json
105     ${substr}    Should Match Regexp    ${TOOLS_SYSTEM_IP}    [0-9]\{1,3}\.[0-9]\{1,3}\.[0-9]\{1,3}\.
106     ${subnet}    Catenate    ${substr}0
107     Log    ${subnet}
108     Set Global Variable    ${subnet}
109     ${vlan}=    Set Variable    ${vlan}
110     ${gateway-ip}=    Set Variable    ${gateway-ip}
111     ${body}    Genius.Set Json    ${Dpn_id_1}    ${Dpn_id_2}    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}
112     ...    ${gateway-ip}    ${subnet}
113     ${vtep_body}    Set Variable    ${body}
114     Set Global Variable    ${vtep_body}
115     ${resp}    RequestsLibrary.Post Request    session    ${CONFIG_API}/itm:transport-zones/    data=${body}
116     Log    ${resp.status_code}
117     should be equal as strings    ${resp.status_code}    204
118
119 Set Json
120     [Arguments]    ${Dpn_id_1}    ${Dpn_id_2}    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}    ${gateway-ip}
121     ...    ${subnet}
122     [Documentation]    Sets Json with the values passed for it.
123     ${body}    OperatingSystem.Get File    ${genius_config_dir}/Itm_creation_no_vlan.json
124     ${body}    replace string    ${body}    1.1.1.1    ${subnet}
125     ${body}    replace string    ${body}    "dpn-id": 101    "dpn-id": ${Dpn_id_1}
126     ${body}    replace string    ${body}    "dpn-id": 102    "dpn-id": ${Dpn_id_2}
127     ${body}    replace string    ${body}    "ip-address": "2.2.2.2"    "ip-address": "${TOOLS_SYSTEM_IP}"
128     ${body}    replace string    ${body}    "ip-address": "3.3.3.3"    "ip-address": "${TOOLS_SYSTEM_2_IP}"
129     ${body}    replace string    ${body}    "vlan-id": 0    "vlan-id": ${vlan}
130     ${body}    replace string    ${body}    "gateway-ip": "0.0.0.0"    "gateway-ip": "${gateway-ip}"
131     Log    ${body}
132     [Return]    ${body}    # returns complete json that has been updated
133
134 Get Dpn Ids
135     [Arguments]    ${connection_id}
136     [Documentation]    This keyword gets the DPN id of the switch after configuring bridges on it.It returns the captured DPN id.
137     Switch connection    ${connection_id}
138     ${cmd}    set Variable    sudo ovs-vsctl show | grep Bridge | awk -F "\\"" '{print $2}'
139     ${Bridgename1}    Execute command    ${cmd}
140     log    ${Bridgename1}
141     ${output1}    Execute command    sudo ovs-ofctl show -O Openflow13 ${Bridgename1} | head -1 | awk -F "dpid:" '{ print $2 }'
142     log    ${output1}
143     # "echo \$\(\(16\#${output1}\)\) command below converts ovs dpnid (i.e., output1) from hexadecimal to decimal."
144     ${Dpn_id}    Execute command    echo \$\(\(16\#${output1}\)\)
145     log    ${Dpn_id}
146     [Return]    ${Dpn_id}
147
148 BFD Suite Stop
149     [Documentation]    Run at end of BFD suite
150     Delete All Vteps
151     Stop Suite
152
153 Delete All Vteps
154     [Documentation]    This will delete vtep.
155     ${resp}    RequestsLibrary.Delete Request    session    ${CONFIG_API}/itm:transport-zones/    data=${vtep_body}
156     Log    ${resp.status_code}
157     Should Be Equal As Strings    ${resp.status_code}    200
158     Log    "Before disconnecting CSS with controller"
159     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW}
160     Log    ${output}
161     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
162     Log    ${output}
163
164 Genius Test Teardown
165     [Arguments]    ${data_models}
166     OVSDB.Get DumpFlows And Ovsconfig    ${conn_id_1}    BR1
167     OVSDB.Get DumpFlows And Ovsconfig    ${conn_id_2}    BR2
168     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${ODL_SYSTEM_IP}    ${data_models}
169
170 ITM Direct Tunnels Start Suite
171     [Documentation]    start suite for itm scalability
172     ClusterManagement.ClusterManagement_Setup
173     ClusterManagement.Stop_Members_From_List_Or_All
174     ClusterManagement.Clean_Journals_Data_And_Snapshots_On_List_Or_All
175     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}
176     ClusterManagement.Start_Members_From_List_Or_All
177     Genius Suite Setup
178
179 ITM Direct Tunnels Stop Suite
180     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}
181     Genius Suite Teardown
182
183 Verify Tunnel Monitoring is on
184     [Documentation]    This keyword will get tep:show output and verify tunnel monitoring status
185     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW}
186     Should Contain    ${output}    ${TUNNEL_MONITOR_ON}
187
188 Ovs Verification For 2 Dpn
189     [Arguments]    ${connection_id}    ${local}    ${remote-1}    ${tunnel}    ${tunnel-type}
190     [Documentation]    Checks whether the created Interface is seen on OVS or not.
191     Switch Connection    ${connection_id}
192     ${check}    Execute Command    sudo ovs-vsctl show
193     Log    ${check}
194     Should Contain    ${check}    local_ip="${local}"    remote_ip="${remote-1}"    ${tunnel}    ${tunnel-type}
195     [Return]    ${check}
196
197 Get ITM
198     [Arguments]    ${itm_created[0]}    ${subnet}    ${vlan}    ${Dpn_id_1}    ${TOOLS_SYSTEM_IP}    ${Dpn_id_2}
199     ...    ${TOOLS_SYSTEM_2_IP}
200     [Documentation]    It returns the created ITM Transport zone with the passed values during the creation is done.
201     Log    ${itm_created[0]},${subnet}, ${vlan}, ${Dpn_id_1},${TOOLS_SYSTEM_IP}, ${Dpn_id_2}, ${TOOLS_SYSTEM_2_IP}
202     @{Itm-no-vlan}    Create List    ${itm_created[0]}    ${subnet}    ${vlan}    ${Dpn_id_1}    ${Bridge-1}-eth1
203     ...    ${TOOLS_SYSTEM_IP}    ${Dpn_id_2}    ${Bridge-2}-eth1    ${TOOLS_SYSTEM_2_IP}
204     Check For Elements At URI    ${TUNNEL_TRANSPORTZONE}/transport-zone/${itm_created[0]}    ${Itm-no-vlan}
205
206 Check Tunnel Delete On OVS
207     [Arguments]    ${connection-id}    ${tunnel}
208     [Documentation]    Verifies the Tunnel is deleted from OVS
209     Switch Connection    ${connection-id}
210     ${return}    Execute Command    sudo ovs-vsctl show
211     Log    ${return}
212     Should Not Contain    ${return}    ${tunnel}
213     [Return]    ${return}
214
215 Check Table0 Entry For 2 Dpn
216     [Arguments]    ${connection_id}    ${Bridgename}    ${port-num1}
217     [Documentation]    Checks the Table 0 entry in the OVS when flows are dumped.
218     Switch Connection    ${connection_id}
219     Log    ${connection_id}
220     ${check}    Execute Command    sudo ovs-ofctl -O OpenFlow13 dump-flows ${Bridgename}
221     Log    ${check}
222     Should Contain    ${check}    in_port=${port-num1}
223     [Return]    ${check}
224
225 Check ITM Tunnel State
226     [Arguments]    ${tunnel1}    ${tunnel2}
227     [Documentation]    Verifies the Tunnel is deleted from datastore
228     ${resp}    RequestsLibrary.Get Request    session    ${OPERATIONAL_API}/itm-state:tunnels_state/
229     Should Not Contain    ${resp.content}    ${tunnel1}    ${tunnel2}
230
231 Verify Tunnel Status as UP
232     [Documentation]    Verify that the number of tunnels are UP
233     ${No_of_Teps}    Issue_Command_On_Karaf_Console    ${TEP_SHOW}
234     ${Lines_of_TZA}    Get Lines Containing String    ${No_of_Teps}    TZA
235     ${Expected_Node_Count}    Get Line Count    ${Lines_of_TZA}
236     ${no_of_tunnels}    Issue_Command_On_Karaf_Console    ${TEP_SHOW_STATE}
237     ${lines_of_VXLAN}    Get Lines Containing String    ${no_of_tunnels}    VXLAN
238     Should Contain    ${no_of_tunnels}    ${STATE_UP}
239     Should Not Contain    ${no_of_tunnels}    ${STATE_DOWN}
240     Should Not Contain    ${no_of_tunnels}    ${STATE_UNKNOWN}
241     ${Actual_Tunnel_Count}    Get Line Count    ${lines_of_VXLAN}
242     ${Expected_Tunnel_Count}    Set Variable    ${Expected_Node_Count*${Expected_Node_Count - 1}}
243     Should Be Equal As Strings    ${Actual_Tunnel_Count}    ${Expected_Tunnel_Count}
244
245 Check System Status
246     [Documentation]    This keyword will verify whether all the services are in operational and all nodes are active based on the number of odl systems
247     : FOR    ${i}    IN RANGE    ${NUM_ODL_SYSTEM}
248     \    Check Service Status    ${ODL_SYSTEM_${i+1}_IP}    ACTIVE    OPERATIONAL