entity ownership tests using ofp
[integration/test.git] / csit / libraries / OvsManager.robot
1 *** Settings ***
2 Documentation     Library to provide ovsdb access to mininet topologies
3 Library           SSHLibrary
4 Library           ${CURDIR}/VsctlListParser.py
5 Library           Collections
6
7 *** Variables ***
8 ${SH_BR_CMD}      ovs-vsctl list Bridge
9 ${SH_CNTL_CMD}    ovs-vsctl list Controller
10 ${ovs_switch_data}    ${None}
11 ${lprompt}        mininet>
12 ${lcmd_prefix}    sh
13
14 *** Keywords ***
15 Initialize If Shell Used
16     [Arguments]    ${prompt}    ${cmd_prefix}
17     BuiltIn.Set Suite variable    ${lprompt}    ${prompt}
18     BuiltIn.Set Suite variable    ${lcmd_prefix}    ${cmd_prefix}
19
20 Get Ovsdb Data
21     [Arguments]    ${prompt}=mininet>
22     [Documentation]    Gets ovs data and parse them.
23     SSHLibrary.Write    ${lcmd_prefix} ${SH_BR_CMD}
24     ${brstdout}=    SSHLibrary.Read_Until    ${lprompt}
25     Log    ${brstdout}
26     SSHLibrary.Write    ${lcmd_prefix} ${SH_CNTL_CMD}
27     ${cntlstdout}=    SSHLibrary.Read_Until    ${lprompt}
28     Log    ${cntlstdout}
29     ${data}    ${bridegs}    ${controllers}=    VsctlListParser.Parse    ${brstdout}    ${cntlstdout}
30     BuiltIn.Log    ${data}
31     BuiltIn.Set Suite Variable    ${ovs_switch_data}    ${data}
32     BuiltIn.Return From Keyword    ${data}
33
34 Get Controllers Uuid
35     [Arguments]    ${switch}    ${controller}    ${update_data}=${False}
36     [Documentation]    Returns controllers uuid
37     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
38     ${bridge}=    Collections.Get From Dictionary    ${ovs_switch_data}    ${switch}
39     ${cntls}=    Collections.Get From Dictionary    ${bridge}    controller
40     ${cntl}=    Collections.Get From Dictionary    ${cntls}    ${controller}
41     ${uuid}=    Collections.Get From Dictionary    ${cntl}    _uuid
42     BuiltIn.Return From Keyword    ${uuid}
43
44 Execute OvsVsctl Show Command
45     [Documentation]    Executes ovs-vsctl show command and returns stdout, no check nor change is performed
46     SSHLibrary.Write    ${lcmd_prefix} ovs-vsctl show
47     ${output}=    SSHLibrary.Read_Until    ${lprompt}
48     Log    ${output}
49
50 Set Bridge Controllers
51     [Arguments]    ${bridge}    ${controllers}    ${disconnected}=${False}
52     [Documentation]    Adds controller to the bridge
53     ${cmd}=    BuiltIn.Set Variable    ${lcmd_prefix} ovs-vsctl set-controller ${bridge}
54     : FOR    ${cntl}    IN    @{controllers}
55     \    ${cmd}=    BuiltIn.Set Variable If    ${disconnected}==${False}    ${cmd} tcp:${cntl}:6653    ${cmd} tcp:${cntl}:6654
56     BuiltIn.Log    ${cmd}
57     SSHLibrary.Write    ${cmd}
58     ${output}=    SSHLibrary.Read_Until    ${lprompt}
59     Log    ${output}
60
61 Disconnect Switch From Controller And Verify Disconnected
62     [Arguments]    ${switch}    ${controller}    ${update_data}=${False}    ${verify_disconnected}=${True}
63     [Documentation]    Disconnects the switch from the controller by setting the incorrect port
64     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
65     ${uuid}=    Get Controllers Uuid    ${switch}    ${controller}
66     ${cmd}=    BuiltIn.Set Variable    ${lcmd_prefix} ovs-vsctl set Controller ${uuid} target="tcp\\:${controller}\\:6654"
67     SSHLibrary.Write    ${cmd}
68     ${output}=    SSHLibrary.Read_Until    ${lprompt}
69     Log    ${output}
70     Return From Keyword If    ${verify_disconnected}==${False}
71     BuiltIn.Wait Until Keyword Succeeds    5x    2s    Should Be Disconnected    ${switch}    ${controller}    update_data=${True}
72     [Teardown]    Execute OvsVsctl Show Command
73
74 Reconnect Switch To Controller And Verify Connected
75     [Arguments]    ${switch}    ${controller}    ${update_data}=${False}    ${verify_connected}=${True}
76     [Documentation]    Reconnects the switch back to the controller by setting the correct port
77     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
78     ${uuid}=    Get Controllers Uuid    ${switch}    ${controller}
79     ${cmd}=    BuiltIn.Set Variable    ${lcmd_prefix} ovs-vsctl set Controller ${uuid} target="tcp\\:${controller}\\:6653"
80     SSHLibrary.Write    ${cmd}
81     ${output}=    SSHLibrary.Read_Until    ${lprompt}
82     Log    ${output}
83     Return From Keyword If    ${verify_connected}==${False}
84     BuiltIn.Wait Until Keyword Succeeds    5x    2s    Should Be Connected    ${switch}    ${controller}    update_data=${True}
85     [Teardown]    Execute OvsVsctl Show Command
86
87 Should Be Connected
88     [Arguments]    ${switch}    ${controller}    ${update_data}=${False}
89     [Documentation]    Check if the switch is connected
90     ${connected}=    OvsManager__Is_Connected    ${switch}    ${controller}    update_data=${update_data}
91     BuiltIn.Should Be True    ${connected}
92
93 Should Be Disconnected
94     [Arguments]    ${switch}    ${controller}    ${update_data}=${False}
95     [Documentation]    Check if the switch is disconnected
96     ${connected}=    OvsManager__Is_Connected    ${switch}    ${controller}    update_data=${update_data}
97     BuiltIn.Should Be Equal    ${connected}    ${False}
98
99 OvsManager__Is_Connected
100     [Arguments]    ${switch}    ${controller}    ${update_data}=${False}
101     [Documentation]    Return is_connected boolean value
102     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
103     ${bridge}=    Collections.Get From Dictionary    ${ovs_switch_data}    ${switch}
104     ${cntls}=    Collections.Get From Dictionary    ${bridge}    controller
105     ${cntl}=    Collections.Get From Dictionary    ${cntls}    ${controller}
106     ${connected}=    Collections.Get From Dictionary    ${cntl}    is_connected
107     [Teardown]    Execute OvsVsctl Show Command
108     [Return]    ${connected}
109
110 Should Be Master
111     [Arguments]    ${switch}    ${controller}    ${update_data}=${False}
112     [Documentation]    Verifies the master role
113     ${role}    Get Node Role    ${switch}    ${controller}    update_data=${update_data}
114     BuiltIn.Should Be Equal    ${role}    master
115
116 Should Be Slave
117     [Arguments]    ${switch}    ${controller}    ${update_data}=${False}
118     [Documentation]    Verifies the slave role
119     ${role}    Get Node Role    ${switch}    ${controller}    update_data=${update_data}
120     BuiltIn.Should Be Equal    ${role}    slave
121
122 Get Node Role
123     [Arguments]    ${switch}    ${controller}    ${update_data}=${False}
124     [Documentation]    Returns the controllers role
125     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
126     ${bridge}=    Collections.Get From Dictionary    ${ovs_switch_data}    ${switch}
127     ${cntls}=    Collections.Get From Dictionary    ${bridge}    controller
128     ${cntl}=    Collections.Get From Dictionary    ${cntls}    ${controller}
129     ${role}=    Collections.Get From Dictionary    ${cntl}    role
130     Return From Keyword    ${role}
131
132 Get Master Node
133     [Arguments]    ${switch}    ${update_data}=${False}
134     [Documentation]    Gets controller which is a master
135     ${master}=    BuiltIn.Set Variable    ${None}
136     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
137     ${bridge}=    Collections.Get From Dictionary    ${ovs_switch_data}    ${switch}
138     ${cntls_dict}=    Collections.Get From Dictionary    ${bridge}    controller
139     ${cntls_items}=    Collections.Get Dictionary Items    ${cntls_dict}
140     : FOR    ${key}    ${value}    IN    @{cntls_items}
141     \    Log    ${key} : ${value}
142     \    ${role}=    Collections.Get From Dictionary    ${value}    role
143     \    Run Keyword If    "${role}"=="master"    BuiltIn.Should Be Equal    ${master}    ${None}
144     \    ${master}=    BuiltIn.Set Variable If    "${role}"=="master"    ${key}    ${master}
145     BuiltIn.Should Not Be Equal    ${master}    ${None}
146     Return From Keyword    ${master}
147
148 Get Slave Nodes
149     [Arguments]    ${switch}    ${update_data}=${False}
150     [Documentation]    Returns a list of ips of slave nodes for particular switch
151     ${slaves}=    BuiltIn.Create List
152     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
153     ${bridge}=    Collections.Get From Dictionary    ${ovs_switch_data}    ${switch}
154     ${cntls_dict}=    Collections.Get From Dictionary    ${bridge}    controller
155     ${cntls_items}=    Collections.Get Dictionary Items    ${cntls_dict}
156     : FOR    ${key}    ${value}    IN    @{cntls_items}
157     \    Log    ${key} : ${value}
158     \    ${role}=    Collections.Get From Dictionary    ${value}    role
159     \    Run Keyword If    "${role}"=="slave"    Collections.Append To List    ${slaves}    ${key}
160     Return From Keyword    ${slaves}
161
162 Setup Clustered Controller For Switches
163     [Arguments]    ${switches}    ${controller_ips}    ${verify_connected}=${False}
164     [Documentation]    The idea of this keyword is to setup clustered controller and to be more or less sure that the role is filled correctly. The problem is when
165     ...    more controllers are being set up at once, the role shown in Controller ovsdb table is not the same as we can see from wireshark traces.
166     ...    Now we set disconnected controllers and we will connect them expecting that the first connected controller will be master.
167     : FOR    ${switch_name}    IN    @{switches}
168     \    Set Bridge Controllers    ${switch_name}    ${controller_ips}    disconnected=${True}
169     # now we need to enable one node which will be master
170     OvsManager.Get Ovsdb Data
171     : FOR    ${switch_name}    IN    @{switches}
172     \    ${own}=    Collections.Get From List    ${controller_ips}    0
173     \    Reconnect Switch To Controller And Verify Connected    ${switch_name}    ${own}    verify_connected=${False}
174     # now we need to wait till master controllers are connected
175     BuiltIn.Wait Until Keyword Succeeds    5x    2s    OvsManager__Verify_Masters_Connected    ${switches}    update_data=${True}
176     # now we can enable slaves
177     OvsManager__Enable_Slaves    ${switches}    verify_connected=${verify_connected}
178
179 OvsManager__Verify_Masters_Connected
180     [Arguments]    ${switches}    ${update_data}=${False}
181     [Documentation]    Private keyword, the existence of master means it is verified
182     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
183     : FOR    ${switch_name}    IN    @{switches}
184     \    Get Master Node    ${switch_name}
185
186 OvsManager__Enable_Slaves
187     [Arguments]    ${switches}    ${update_data}=${False}    ${verify_connected}=${False}
188     [Documentation]    This is a private keyword to enable diconnected controllers
189     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
190     : FOR    ${switch_name}    IN    @{switches}
191     \    OvsManager__Enable_Slaves_For_Switch    ${switch_name}    verify_connected=${verify_connected}
192
193 OvsManager__Enable_Slaves_For_Switch
194     [Arguments]    ${switch}    ${update_data}=${False}    ${verify_connected}=${False}
195     [Documentation]    This is a private keyword, verification is not reliable yet, enables disconnected controllers
196     Run Keyword If    ${update_data}==${True}    Get Ovsdb Data
197     ${bridge}=    Collections.Get From Dictionary    ${ovs_switch_data}    ${switch}
198     ${cntls_dict}=    Collections.Get From Dictionary    ${bridge}    controller
199     ${cntls_items}=    Collections.Get Dictionary Items    ${cntls_dict}
200     : FOR    ${cntl_id}    ${cntl_value}    IN    @{cntls_items}
201     \    Log    ${cntl_id} : ${cntl_value}
202     \    ${role}=    Collections.Get From Dictionary    ${cntl_value}    role
203     \    ${connected}=    Collections.Get From Dictionary    ${cntl_value}    is_connected
204     \    Run Keyword If    ${connected}==${False}    Reconnect Switch To Controller And Verify Connected    ${switch}    ${cntl_id}    verify_connected=${verify_connected}