ITM Testcases to Create, Delete and Get Tunnels
[integration/test.git] / csit / libraries / OVSDB.robot
1 *** Settings ***
2 Library           SSHLibrary
3 Library           String
4 Library           Collections
5 Library           RequestsLibrary
6 Resource          Utils.robot
7 Resource          ClusterManagement.robot
8 Resource          ${CURDIR}/TemplatedRequests.robot
9 Variables         ../variables/Variables.py
10
11 *** Variables ***
12 ${OVSDB_CONFIG_DIR}    ../variables/ovsdb
13 ${SOUTHBOUND_CONFIG_API}    ${CONFIG_TOPO_API}/topology/ovsdb:1/node/ovsdb:%2F%2F
14
15 *** Keywords ***
16 Connect To Ovsdb Node
17     [Arguments]    ${mininet_ip}
18     [Documentation]    This will Initiate the connection to OVSDB node from controller
19     ${sample}    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/connect.json
20     ${sample1}    Replace String    ${sample}    127.0.0.1    ${mininet_ip}
21     ${body}    Replace String    ${sample1}    61644    ${OVSDB_PORT}
22     Log    URL is ${SOUTHBOUND_CONFIG_API}${mininet_ip}:${OVSDB_PORT}
23     Log    data: ${body}
24     ${resp}    RequestsLibrary.Put Request    session    ${SOUTHBOUND_CONFIG_API}${mininet_ip}:${OVSDB_PORT}    data=${body}
25     Log    ${resp.content}
26     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
27
28 Disconnect From Ovsdb Node
29     [Arguments]    ${mininet_ip}
30     [Documentation]    This request will disconnect the OVSDB node from the controller
31     ${resp}    RequestsLibrary.Delete Request    session    ${SOUTHBOUND_CONFIG_API}${mininet_ip}:${OVSDB_PORT}
32     Should Be Equal As Strings    ${resp.status_code}    200
33
34 Add Bridge To Ovsdb Node
35     [Arguments]    ${mininet_ip}    ${bridge_num}    ${datapath_id}
36     [Documentation]    This will create a bridge and add it to the OVSDB node.
37     ${sample}    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/create_bridge.json
38     ${sample1}    Replace String    ${sample}    tcp:127.0.0.1:6633    tcp:${ODL_SYSTEM_IP}:6633
39     ${sample2}    Replace String    ${sample1}    127.0.0.1    ${mininet_ip}
40     ${sample3}    Replace String    ${sample2}    br01    ${bridge_num}
41     ${sample4}    Replace String    ${sample3}    61644    ${OVSDB_PORT}
42     ${body}    Replace String    ${sample4}    0000000000000001    ${datapath_id}
43     Log    URL is ${SOUTHBOUND_CONFIG_API}${mininet_ip}:${OVSDB_PORT}%2Fbridge%2F${bridge_num}
44     Log    data: ${body}
45     ${resp}    RequestsLibrary.Put Request    session    ${SOUTHBOUND_CONFIG_API}${mininet_ip}:${OVSDB_PORT}%2Fbridge%2F${bridge_num}    data=${body}
46     Log    ${resp.content}
47     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
48
49 Delete Bridge From Ovsdb Node
50     [Arguments]    ${mininet_ip}    ${bridge_num}
51     [Documentation]    This request will delete the bridge node from the OVSDB
52     ${resp}    RequestsLibrary.Delete Request    session    ${SOUTHBOUND_CONFIG_API}${mininet_ip}:${OVSDB_PORT}%2Fbridge%2F${bridge_num}
53     Should Be Equal As Strings    ${resp.status_code}    200
54
55 Add Vxlan To Bridge
56     [Arguments]    ${mininet_ip}    ${bridge_num}    ${vxlan_port}    ${remote_ip}    ${custom_port}=create_port.json
57     [Documentation]    This request will create vxlan port for vxlan tunnel and attach it to the specific bridge
58     ${sample}    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/${custom_port}
59     ${body}    Replace String    ${sample}    192.168.0.21    ${remote_ip}
60     Log    URL is ${SOUTHBOUND_CONFIG_API}${mininet_ip}:${OVSDB_PORT}%2Fbridge%2F${bridge_num}/termination-point/${vxlan_port}/
61     Log    data: ${body}
62     ${resp}    RequestsLibrary.Put Request    session    ${SOUTHBOUND_CONFIG_API}${mininet_ip}:${OVSDB_PORT}%2Fbridge%2F${bridge_num}/termination-point/${vxlan_port}/    data=${body}
63     Log    ${resp.content}
64     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
65
66 Verify OVS Reports Connected
67     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}
68     [Documentation]    Uses "vsctl show" to check for string "is_connected"
69     ${output}=    Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl show
70     Should Contain    ${output}    is_connected
71     [Return]    ${output}
72
73 Get OVSDB UUID
74     [Arguments]    ${ovs_system_ip}=${TOOLS_SYSTEM_IP}    ${controller_http_session}=session
75     [Documentation]    Queries the topology in the operational datastore and searches for the node that has
76     ...    the ${ovs_system_ip} argument as the "remote-ip". If found, the value returned will be the value of
77     ...    node-id stripped of "ovsdb://uuid/". If not found, ${EMPTY} will be returned.
78     ${uuid}=    Set Variable    ${EMPTY}
79     ${resp}=    RequestsLibrary.Get Request    ${controller_http_session}    ${OPERATIONAL_TOPO_API}/topology/ovsdb:1
80     Log    ${resp.content}
81     Should Be Equal As Strings    ${resp.status_code}    200
82     ${resp_json}=    To Json    ${resp.content}
83     ${topologies}=    Get From Dictionary    ${resp_json}    topology
84     ${topology}=    Get From List    ${topologies}    0
85     ${node_list}=    Get From Dictionary    ${topology}    node
86     Log    ${node_list}
87     # Since bridges are also listed as nodes, but will not have the extra "ovsdb:connection-info data,
88     # we need to use "Run Keyword And Ignore Error" below.
89     : FOR    ${node}    IN    @{node_list}
90     \    ${node_id}=    Get From Dictionary    ${node}    node-id
91     \    ${node_uuid}=    Replace String    ${node_id}    ovsdb://uuid/    ${EMPTY}
92     \    ${status}    ${connection_info}    Run Keyword And Ignore Error    Get From Dictionary    ${node}    ovsdb:connection-info
93     \    ${status}    ${remote_ip}    Run Keyword And Ignore Error    Get From Dictionary    ${connection_info}    remote-ip
94     \    ${uuid}=    Set Variable If    '${remote_ip}' == '${ovs_system_ip}'    ${node_uuid}    ${uuid}
95     [Return]    ${uuid}
96
97 Collect OVSDB Debugs
98     [Arguments]    ${switch}=br-int
99     [Documentation]    Used to log useful test debugs for OVSDB related system tests.
100     ${output}=    Utils.Run Command On Mininet    ${TOOLS_SYSTEM_IP}    sudo ovs-vsctl show
101     Log    ${output}
102     ${output}=    Utils.Run Command On Mininet    ${TOOLS_SYSTEM_IP}    sudo ovs-ofctl -O OpenFlow13 dump-flows ${switch} | cut -d',' -f3-
103     Log    ${output}
104
105 Clean OVSDB Test Environment
106     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}
107     [Documentation]    General Use Keyword attempting to sanitize test environment for OVSDB related
108     ...    tests. Not every step will always be neccessary, but should not cause any problems for
109     ...    any new ovsdb test suites.
110     Utils.Clean Mininet System    ${tools_system}
111     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl del-manager
112     Utils.Run Command On Mininet    ${tools_system}    sudo /usr/share/openvswitch/scripts/ovs-ctl stop
113     Utils.Run Command On Mininet    ${tools_system}    sudo rm -rf /etc/openvswitch/conf.db
114     Utils.Run Command On Mininet    ${tools_system}    sudo /usr/share/openvswitch/scripts/ovs-ctl start
115
116 Set Controller In OVS Bridge
117     [Arguments]    ${tools_system}    ${bridge}    ${controller_opt}
118     [Documentation]    Sets controller for a given OVS ${bridge} using controller options in ${controller_opt}
119     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl set-controller ${bridge} ${controller_opt}
120
121 Check OVS OpenFlow Connections
122     [Arguments]    ${tools_system}    ${of_connections}
123     [Documentation]    Check OVS instance with IP ${tools_system} has ${of_connections} OpenFlow connections.
124     ${output}=    Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl show
125     Log    ${output}
126     BuiltIn.Should Contain X Times    ${output}    is_connected    ${of_connections}
127
128 Add Multiple Managers to OVS
129     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}    ${controller_index_list}=${EMPTY}    ${ovs_mgr_port}=6640
130     [Documentation]    Connect OVS to the list of controllers in the ${controller_index_list} or all if no list is provided.
131     ${index_list} =    ClusterManagement__Given_Or_Internal_Index_List    given_list=${controller_index_list}
132     Log    Clear any existing mininet
133     Utils.Clean Mininet System    ${tools_system}
134     ${ovs_opt}=    Set Variable
135     : FOR    ${index}    IN    @{index_list}
136     \    ${ovs_opt}=    Catenate    ${ovs_opt}    ${SPACE}tcp:${ODL_SYSTEM_${index}_IP}:${ovs_mgr_port}
137     \    Log    ${ovs_opt}
138     Log    Configure OVS Managers in the OVS
139     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl set-manager ${ovs_opt}
140     Log    Check OVS configuration
141     ${output}=    Wait Until Keyword Succeeds    5s    1s    Verify OVS Reports Connected    ${tools_system}
142     Log    ${output}
143     ${controller_index}=    Collections.Get_From_List    ${index_list}    0
144     ${session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${controller_index}
145     ${ovsdb_uuid}=    Wait Until Keyword Succeeds    30s    2s    Get OVSDB UUID    controller_http_session=${session}
146     [Return]    ${ovsdb_uuid}
147
148 Get DPID
149     [Arguments]    ${ip}
150     [Documentation]    Returns the dpnid from the system at the given ip address using ovs-ofctl assuming br-int is present.
151     ${output} =    Run Command On Remote System    ${ip}    sudo ovs-ofctl show -O Openflow13 br-int | head -1 | awk -F "dpid:" '{print $2}'
152     ${dpnid} =    Convert To Integer    ${output}    16
153     Log    ${dpnid}
154     [Return]    ${dpnid}
155
156 Get Ethernet Adapter
157     [Arguments]    ${ip}
158     [Documentation]    Returns the ethernet adapter name from the system at the given ip address using ip addr show.
159     ${adapter} =    Run Command On Remote System    ${ip}    /usr/sbin/ip addr show | grep ${ip} | cut -d " " -f 11
160     Log    ${adapter}
161     [Return]    ${adapter}
162
163 Get Default Gateway
164     [Arguments]    ${ip}
165     [Documentation]    Returns the default gateway at the given ip address using route command.
166     ${gateway} =    Run Command On Remote System    ${ip}    /usr/sbin/route -n | grep '^0.0.0.0' | cut -d " " -f 10
167     Log    ${gateway}
168     [Return]    ${gateway}