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