Increase timeout and retries for Genius
[integration/test.git] / csit / libraries / Genius.robot
1 *** Settings ***
2 Documentation     This suite is a common keywordis 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
13 *** Variables ***
14
15 *** Keywords ***
16 Genius Suite Setup
17     [Documentation]    Create Rest Session to http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
18     Start Suite
19     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}    timeout=5
20
21 Genius Suite Teardown
22     [Documentation]    Delete all sessions
23     Delete All Sessions
24     Stop Suite
25
26 Start Suite
27     [Documentation]    Initial setup for Genius test suites
28     Run_Keyword_If_At_Least_Oxygen    Check Service Status    ACTIVE    OPERATIONAL
29     Log    Start the tests
30     ${conn_id_1}=    Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
31     Set Global Variable    ${conn_id_1}
32     KarafKeywords.Setup_Karaf_Keywords
33     ${karaf_debug_enabled}    BuiltIn.Get_Variable_Value    ${KARAF_DEBUG}    ${False}
34     BuiltIn.run_keyword_if    ${karaf_debug_enabled}    KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set DEBUG org.opendaylight.genius
35     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
36     Log    ${conn_id_1}
37     Execute Command    sudo ovs-vsctl add-br BR1
38     Execute Command    sudo ovs-vsctl set bridge BR1 protocols=OpenFlow13
39     Execute Command    sudo ovs-vsctl set-controller BR1 tcp:${ODL_SYSTEM_IP}:6633
40     Execute Command    sudo ifconfig BR1 up
41     Execute Command    sudo ovs-vsctl add-port BR1 tap8ed70586-6c -- set Interface tap8ed70586-6c type=tap
42     Execute Command    sudo ovs-vsctl set-manager tcp:${ODL_SYSTEM_IP}:6640
43     ${output_1}    Execute Command    sudo ovs-vsctl show
44     Log    ${output_1}
45     ${check}    Wait Until Keyword Succeeds    30    10    check establishment    ${conn_id_1}    6633
46     log    ${check}
47     ${check_2}    Wait Until Keyword Succeeds    30    10    check establishment    ${conn_id_1}    6640
48     log    ${check_2}
49     Log    >>>>>Switch 2 configuration <<<<<
50     ${conn_id_2}=    Open Connection    ${TOOLS_SYSTEM_2_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
51     Set Global Variable    ${conn_id_2}
52     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
53     Log    ${conn_id_2}
54     Execute Command    sudo ovs-vsctl add-br BR2
55     Execute Command    sudo ovs-vsctl set bridge BR2 protocols=OpenFlow13
56     Execute Command    sudo ovs-vsctl set-controller BR2 tcp:${ODL_SYSTEM_IP}:6633
57     Execute Command    sudo ifconfig BR2 up
58     Execute Command    sudo ovs-vsctl set-manager tcp:${ODL_SYSTEM_IP}:6640
59     ${output_2}    Execute Command    sudo ovs-vsctl show
60     Log    ${output_2}
61
62 Stop Suite
63     Log    Stop the tests
64     Switch Connection    ${conn_id_1}
65     Log    ${conn_id_1}
66     Execute Command    sudo ovs-vsctl del-br BR1
67     Execute Command    sudo ovs-vsctl del-manager
68     Write    exit
69     close connection
70     Switch Connection    ${conn_id_2}
71     Log    ${conn_id_2}
72     Execute Command    sudo ovs-vsctl del-br BR2
73     Execute Command    sudo ovs-vsctl del-manager
74     Write    exit
75     close connection
76
77 check establishment
78     [Arguments]    ${conn_id}    ${port}
79     Switch Connection    ${conn_id}
80     ${check_establishment}    Execute Command    netstat -anp | grep ${port}
81     Should contain    ${check_establishment}    ESTABLISHED
82     [Return]    ${check_establishment}
83
84 Check Service Status
85     [Arguments]    ${system_ready_state}    ${service_state}
86     [Documentation]    Issues the karaf shell command showSvcStatus to verify the ready and service states are the same as the arguments passed
87     ${service_status_output}    Issue_Command_On_Karaf_Console    showSvcStatus    ${ODL_SYSTEM_IP}    8101
88     Should Contain    ${service_status_output}    ${system_ready_state}
89     @{split}    Split To Lines    ${service_status_output}    3    7
90     : FOR    ${var}    IN    @{split}
91     \    Should Contain    ${var}    ${service_state}
92
93 Create Vteps
94     [Arguments]    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}    ${gateway-ip}
95     [Documentation]    This keyword creates VTEPs between ${TOOLS_SYSTEM_IP} and ${TOOLS_SYSTEM_2_IP}
96     ${body}    OperatingSystem.Get File    ${genius_config_dir}/Itm_creation_no_vlan.json
97     ${substr}    Should Match Regexp    ${TOOLS_SYSTEM_IP}    [0-9]\{1,3}\.[0-9]\{1,3}\.[0-9]\{1,3}\.
98     ${subnet}    Catenate    ${substr}0
99     Log    ${subnet}
100     Set Global Variable    ${subnet}
101     ${vlan}=    Set Variable    ${vlan}
102     ${gateway-ip}=    Set Variable    ${gateway-ip}
103     ${body}    Set Json    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}    ${gateway-ip}    ${subnet}
104     ${vtep_body}    Set Variable    ${body}
105     Set Global Variable    ${vtep_body}
106     ${resp}    RequestsLibrary.Post Request    session    ${CONFIG_API}/itm:transport-zones/    data=${body}
107     Log    ${resp.status_code}
108     should be equal as strings    ${resp.status_code}    204
109
110 Set Json
111     [Arguments]    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}    ${vlan}    ${gateway-ip}    ${subnet}
112     [Documentation]    Sets Json with the values passed for it.
113     ${body}    OperatingSystem.Get File    ${genius_config_dir}/Itm_creation_no_vlan.json
114     ${body}    replace string    ${body}    1.1.1.1    ${subnet}
115     ${body}    replace string    ${body}    "dpn-id": 101    "dpn-id": ${Dpn_id_1}
116     ${body}    replace string    ${body}    "dpn-id": 102    "dpn-id": ${Dpn_id_2}
117     ${body}    replace string    ${body}    "ip-address": "2.2.2.2"    "ip-address": "${TOOLS_SYSTEM_IP}"
118     ${body}    replace string    ${body}    "ip-address": "3.3.3.3"    "ip-address": "${TOOLS_SYSTEM_2_IP}"
119     ${body}    replace string    ${body}    "vlan-id": 0    "vlan-id": ${vlan}
120     ${body}    replace string    ${body}    "gateway-ip": "0.0.0.0"    "gateway-ip": "${gateway-ip}"
121     Log    ${body}
122     [Return]    ${body}    # returns complete json that has been updated
123
124 Get Dpn Ids
125     [Arguments]    ${connection_id}
126     [Documentation]    This keyword gets the DPN id of the switch after configuring bridges on it.It returns the captured DPN id.
127     Switch connection    ${connection_id}
128     ${cmd}    set Variable    sudo ovs-vsctl show | grep Bridge | awk -F "\\"" '{print $2}'
129     ${Bridgename1}    Execute command    ${cmd}
130     log    ${Bridgename1}
131     ${output1}    Execute command    sudo ovs-ofctl show -O Openflow13 ${Bridgename1} | head -1 | awk -F "dpid:" '{ print $2 }'
132     log    ${output1}
133     # "echo \$\(\(16\#${output1}\)\) command below converts ovs dpnid (i.e., output1) from hexadecimal to decimal."
134     ${Dpn_id}    Execute command    echo \$\(\(16\#${output1}\)\)
135     log    ${Dpn_id}
136     [Return]    ${Dpn_id}
137
138 BFD Suite Stop
139     [Documentation]    Run at end of BFD suite
140     Delete All Vteps
141     Stop Suite
142
143 Delete All Vteps
144     [Documentation]    This will delete vtep.
145     ${resp}    RequestsLibrary.Delete Request    session    ${CONFIG_API}/itm:transport-zones/    data=${vtep_body}
146     Log    ${resp.status_code}
147     Should Be Equal As Strings    ${resp.status_code}    200
148     Log    "Before disconnecting CSS with controller"
149     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW}
150     Log    ${output}
151     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
152     Log    ${output}