Fix sed command to set tell-based setting
[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     Add Termination Point    ${mininet_ip}:${OVSDB_PORT}    ${bridge_num}    ${vxlan_port}    ${remote_ip}
60
61 Add Termination Point
62     [Arguments]    ${node_id}    ${bridge_name}    ${tp_name}    ${remote_ip}=${TOOLS_SYSTEM_IP}
63     [Documentation]    Using the json data body file as a template, a REST config request is made to
64     ...    create a termination-point ${tp_name} on ${bridge_name} for the given ${node_id}. The ports
65     ...    remote-ip defaults to ${TOOLS_SYSTEM_IP}
66     ${body}    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/create_port.json
67     ${body}    Replace String    ${body}    192.168.0.21    ${remote_ip}
68     ${body}    Replace String    ${body}    vxlanport    ${tp_name}
69     ${uri}=    Set Variable    ${CONFIG_TOPO_API}/topology/ovsdb:1/node/ovsdb:%2F%2F${node_id}%2Fbridge%2F${bridge_name}
70     ${resp}    RequestsLibrary.Put Request    session    ${uri}/termination-point/${tp_name}/    data=${body}
71     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
72
73 Verify OVS Reports Connected
74     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}
75     [Documentation]    Uses "vsctl show" to check for string "is_connected"
76     ${output}    Verify Ovs-vsctl Output    show    is_connected
77     [Return]    ${output}
78
79 Verify Ovs-vsctl Output
80     [Arguments]    ${vsctl_args}    ${expected_output}    ${ovs_system}=${TOOLS_SYSTEM_IP}    ${should_match}=True
81     [Documentation]    A wrapper keyword to make it easier to validate ovs-vsctl output, and gives an easy
82     ...    way to check this output in a WUKS. The argument ${should_match} can control if the match should
83     ...    exist (True} or not (False) or don't care (anything but True or False). ${should_match} is True by default
84     ${output}=    Utils.Run Command On Mininet    ${ovs_system}    sudo ovs-vsctl ${vsctl_args}
85     Log    ${output}
86     Run Keyword If    "${should_match}"=="True"    Should Contain    ${output}    ${expected_output}
87     Run Keyword If    "${should_match}"=="False"    Should Not Contain    ${output}    ${expected_output}
88     [Return]    ${output}
89
90 Get OVSDB UUID
91     [Arguments]    ${ovs_system_ip}=${TOOLS_SYSTEM_IP}    ${controller_http_session}=session
92     [Documentation]    Queries the topology in the operational datastore and searches for the node that has
93     ...    the ${ovs_system_ip} argument as the "remote-ip". If found, the value returned will be the value of
94     ...    node-id stripped of "ovsdb://uuid/". If not found, ${EMPTY} will be returned.
95     ${uuid}=    Set Variable    ${EMPTY}
96     ${resp}=    RequestsLibrary.Get Request    ${controller_http_session}    ${OPERATIONAL_TOPO_API}/topology/ovsdb:1
97     Log    ${resp.content}
98     Should Be Equal As Strings    ${resp.status_code}    200
99     ${resp_json}=    To Json    ${resp.content}
100     ${topologies}=    Get From Dictionary    ${resp_json}    topology
101     ${topology}=    Get From List    ${topologies}    0
102     ${node_list}=    Get From Dictionary    ${topology}    node
103     Log    ${node_list}
104     # Since bridges are also listed as nodes, but will not have the extra "ovsdb:connection-info data,
105     # we need to use "Run Keyword And Ignore Error" below.
106     : FOR    ${node}    IN    @{node_list}
107     \    ${node_id}=    Get From Dictionary    ${node}    node-id
108     \    ${node_uuid}=    Replace String    ${node_id}    ovsdb://uuid/    ${EMPTY}
109     \    ${status}    ${connection_info}    Run Keyword And Ignore Error    Get From Dictionary    ${node}    ovsdb:connection-info
110     \    ${status}    ${remote_ip}    Run Keyword And Ignore Error    Get From Dictionary    ${connection_info}    remote-ip
111     \    ${uuid}=    Set Variable If    '${remote_ip}' == '${ovs_system_ip}'    ${node_uuid}    ${uuid}
112     [Return]    ${uuid}
113
114 Collect OVSDB Debugs
115     [Arguments]    ${switch}=br-int
116     [Documentation]    Used to log useful test debugs for OVSDB related system tests.
117     ${output}=    Utils.Run Command On Mininet    ${TOOLS_SYSTEM_IP}    sudo ovs-vsctl show
118     Log    ${output}
119     ${output}=    Utils.Run Command On Mininet    ${TOOLS_SYSTEM_IP}    sudo ovs-ofctl -O OpenFlow13 dump-flows ${switch} | cut -d',' -f3-
120     Log    ${output}
121
122 Clean OVSDB Test Environment
123     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}
124     [Documentation]    General Use Keyword attempting to sanitize test environment for OVSDB related
125     ...    tests. Not every step will always be neccessary, but should not cause any problems for
126     ...    any new ovsdb test suites.
127     Utils.Clean Mininet System    ${tools_system}
128     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl del-manager
129     Utils.Run Command On Mininet    ${tools_system}    sudo /usr/share/openvswitch/scripts/ovs-ctl stop
130     Utils.Run Command On Mininet    ${tools_system}    sudo rm -rf /etc/openvswitch/conf.db
131     Utils.Run Command On Mininet    ${tools_system}    sudo /usr/share/openvswitch/scripts/ovs-ctl start
132
133 Restart OVSDB
134     [Arguments]    ${ovs_ip}
135     [Documentation]    Restart the OVS node without cleaning the current configuration.
136     ${output} =    Utils.Run Command On Mininet    ${ovs_ip}    sudo /usr/share/openvswitch/scripts/ovs-ctl stop
137     Log    ${output}
138     ${output} =    Utils.Run Command On Mininet    ${ovs_ip}    sudo /usr/share/openvswitch/scripts/ovs-ctl start
139     Log    ${output}
140
141 Set Controller In OVS Bridge
142     [Arguments]    ${tools_system}    ${bridge}    ${controller_opt}
143     [Documentation]    Sets controller for a given OVS ${bridge} using controller options in ${controller_opt}
144     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl set-controller ${bridge} ${controller_opt}
145
146 Check OVS OpenFlow Connections
147     [Arguments]    ${tools_system}    ${of_connections}
148     [Documentation]    Check OVS instance with IP ${tools_system} has ${of_connections} OpenFlow connections.
149     ${output}=    Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl show
150     Log    ${output}
151     BuiltIn.Should Contain X Times    ${output}    is_connected    ${of_connections}
152
153 Add Multiple Managers to OVS
154     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}    ${controller_index_list}=${EMPTY}    ${ovs_mgr_port}=6640
155     [Documentation]    Connect OVS to the list of controllers in the ${controller_index_list} or all if no list is provided.
156     ${index_list} =    ClusterManagement.List Indices Or All    given_list=${controller_index_list}
157     Log    Clear any existing mininet
158     Utils.Clean Mininet System    ${tools_system}
159     ${ovs_opt}=    Set Variable
160     : FOR    ${index}    IN    @{index_list}
161     \    ${ovs_opt}=    Catenate    ${ovs_opt}    ${SPACE}tcp:${ODL_SYSTEM_${index}_IP}:${ovs_mgr_port}
162     \    Log    ${ovs_opt}
163     Log    Configure OVS Managers in the OVS
164     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl set-manager ${ovs_opt}
165     Log    Check OVS configuration
166     ${output}=    Wait Until Keyword Succeeds    5s    1s    Verify OVS Reports Connected    ${tools_system}
167     Log    ${output}
168     ${controller_index}=    Collections.Get_From_List    ${index_list}    0
169     ${session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${controller_index}
170     ${ovsdb_uuid}=    Wait Until Keyword Succeeds    30s    2s    Get OVSDB UUID    controller_http_session=${session}
171     [Return]    ${ovsdb_uuid}
172
173 Get DPID
174     [Arguments]    ${ip}
175     [Documentation]    Returns the dpnid from the system at the given ip address using ovs-ofctl assuming br-int is present.
176     ${output} =    Run Command On Remote System    ${ip}    sudo ovs-ofctl show -O Openflow13 br-int | head -1 | awk -F "dpid:" '{print $2}'
177     ${dpnid} =    Convert To Integer    ${output}    16
178     Log    ${dpnid}
179     [Return]    ${dpnid}
180
181 Get Subnet
182     [Arguments]    ${ip}
183     [Documentation]    Return the subnet from the system at the given ip address and interface
184     ${output} =    Run Command On Remote System    ${ip}    /usr/sbin/ip addr show | grep ${ip} | cut -d' ' -f6
185     ${interface} =    ipaddress.ip_interface    ${output}
186     ${network}=    Set Variable    ${interface.network.__str__()}
187     [Return]    ${network}
188
189 Get Ethernet Adapter
190     [Arguments]    ${ip}
191     [Documentation]    Returns the ethernet adapter name from the system at the given ip address using ip addr show.
192     ${adapter} =    Run Command On Remote System    ${ip}    /usr/sbin/ip addr show | grep ${ip} | cut -d " " -f 11
193     Log    ${adapter}
194     [Return]    ${adapter}
195
196 Get Default Gateway
197     [Arguments]    ${ip}
198     [Documentation]    Returns the default gateway at the given ip address using route command.
199     ${gateway} =    Run Command On Remote System    ${ip}    /usr/sbin/route -n | grep '^0.0.0.0' | cut -d " " -f 10
200     Log    ${gateway}
201     [Return]    ${gateway}