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