d4b4fb3994cba367d9dec3b4172abe126561d055
[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}=    Run Command On Remote System    ${tools_system}    sudo ovs-vsctl show
68     Should Contain    ${output}    is_connected
69
70 Get OVSDB UUID
71     [Arguments]    ${ovs_system_ip}=${TOOLS_SYSTEM_IP}    ${controller_ip}=${ODL_SYSTEM_IP}    ${controller_http_session}=session
72     [Documentation]    Queries the topology in the operational datastore and searches for the node that has
73     ...    the ${ovs_system_ip} argument as the "remote-ip". If found, the value returned will be the value of
74     ...    node-id stripped of "ovsdb://uuid/". If not found, ${EMPTY} will be returned.
75     ${uuid}=    Set Variable    ${EMPTY}
76     ${resp}=    RequestsLibrary.Get Request    ${controller_http_session}    ${OPERATIONAL_TOPO_API}/topology/ovsdb:1
77     Log    ${resp.content}
78     Should Be Equal As Strings    ${resp.status_code}    200
79     ${resp_json}=    To Json    ${resp.content}
80     ${topologies}=    Get From Dictionary    ${resp_json}    topology
81     ${topology}=    Get From List    ${topologies}    0
82     ${node_list}=    Get From Dictionary    ${topology}    node
83     Log    ${node_list}
84     : FOR    ${node}    IN    @{node_list}
85     \    ${node_id}=    Get From Dictionary    ${node}    node-id
86     \    ${node_uuid}=    Replace String    ${node_id}    ovsdb://uuid/    ${EMPTY}
87     \    # Since bridges are also listed as nodes, but will not have the extra "ovsdb:connection-info data, we need to
88     \    # use "Run Keyword And Ignore Error" below.
89     \    ${status}    ${connection_info}    Run Keyword And Ignore Error    Get From Dictionary    ${node}    ovsdb:connection-info
90     \    ${status}    ${remote_ip}    Run Keyword And Ignore Error    Get From Dictionary    ${connection_info}    remote-ip
91     \    ${uuid}=    Set Variable If    '${remote_ip}' == '${ovs_system_ip}'    ${node_uuid}    ${uuid}
92     [Return]    ${uuid}
93
94 Collect OVSDB Debugs
95     [Arguments]    ${switch}=br-int
96     [Documentation]    Used to log useful test debugs for OVSDB related system tests.
97     ${output}=    Run Command On Mininet    ${TOOLS_SYSTEM_IP}    sudo ovs-vsctl show
98     Log    ${output}
99     ${output}=    Run Command On Mininet    ${TOOLS_SYSTEM_IP}    sudo ovs-ofctl -O OpenFlow13 dump-flows ${switch} | cut -d',' -f3-
100     Log    ${output}
101
102 Clean OVSDB Test Environment
103     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}
104     [Documentation]    General Use Keyword attempting to sanitize test environment for OVSDB related
105     ...    tests. Not every step will always be neccessary, but should not cause any problems for
106     ...    any new ovsdb test suites.
107     Clean Mininet System    ${tools_system}
108     Run Command On Mininet    ${tools_system}    sudo ovs-vsctl del-manager
109     Run Command On Mininet    ${tools_system}    sudo /usr/share/openvswitch/scripts/ovs-ctl stop
110     Run Command On Mininet    ${tools_system}    sudo rm -rf /etc/openvswitch/conf.db
111     Run Command On Mininet    ${tools_system}    sudo /usr/share/openvswitch/scripts/ovs-ctl start
112
113 Set Controller In OVS Bridge
114     [Arguments]    ${mininet}    ${bridge}    ${controller_opt}
115     [Documentation]    Sets controller for a given OVS ${bridge} using controller options in ${controller_opt}
116     Run Command On Mininet    ${mininet}    sudo ovs-vsctl del-controller ${bridge}
117     Run Command On Mininet    ${mininet}    sudo ovs-vsctl set-controller ${bridge} ${controller_opt}
118
119 Add Multiple Managers to OVS
120     [Arguments]    ${mininet}    ${controller_index_list}    ${ovs_mgr_port}=6640
121     [Documentation]    Start Mininet with custom topology and connect to all controllers in the ${controller_index_list}.
122     Log    Clear any existing mininet
123     Clean Mininet System    ${mininet}
124     ${mininet_conn_id}=    Open Connection    ${mininet}    prompt=${TOOLS_SYSTEM_PROMPT}    timeout=${DEFAULT_TIMEOUT}
125     Set Suite Variable    ${mininet_conn_id}
126     Flexible Mininet Login
127     ${ovs_opt}=    Set Variable
128     : FOR    ${index}    IN    @{controller_index_list}
129     \    ${ovs_opt}=    Catenate    ${ovs_opt}    ${SPACE}tcp:${ODL_SYSTEM_${index}_IP}:${ovs_mgr_port}
130     \    Log    ${ovs_opt}
131     Log    Configure OVS Managers in the OVS
132     Run Command On Mininet    ${mininet}    sudo ovs-vsctl set-manager ${ovs_opt}
133     Log    Check OVS configuratiom
134     ${output}=    Run Command On Mininet    ${mininet}    sudo ovs-vsctl show
135     Log    ${output}
136     [Return]    ${mininet_conn_id}
137