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