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