Correctly space expected_status
[integration/test.git] / csit / libraries / ClusterOpenFlow.robot
1 *** Settings ***
2 Documentation       Cluster OpenFlow library. So far this library is only to be used by OpenFlow cluster test as it is very specific for this test.
3
4 Library             Collections
5 Library             RequestsLibrary
6 Library             ${CURDIR}/ScaleClient.py
7 Resource            ClusterManagement.robot
8 Resource            CompareStream.robot
9 Resource            MininetKeywords.robot
10 Resource            Utils.robot
11 Resource            ../variables/openflowplugin/Variables.robot
12 Variables           ../variables/Variables.py
13
14
15 *** Variables ***
16 @{SHARD_OPER_LIST}          inventory    topology    default    entity-ownership
17 @{SHARD_CONF_LIST}          inventory    topology    default
18 ${config_table_0}           ${RFC8040_NODES_API}/node=openflow%3A1/flow-node-inventory:table=0
19 ${operational_table_0}
20 ...                         ${RFC8040_NODES_API}/node=openflow%3A1/flow-node-inventory:table=0?${RFC8040_OPERATIONAL_CONTENT}
21 ${operational_port_1}
22 ...                         ${RFC8040_NODES_API}/node=openflow%3A1/node-connector=openflow%3A1%3A1?${RFC8040_OPERATIONAL_CONTENT}
23
24
25 *** Keywords ***
26 Get InventoryConfig Shard Status
27     [Documentation]    Check Status for Inventory Config shard in OpenFlow application.
28     [Arguments]    ${controller_index_list}=${EMPTY}
29     ${inv_conf_leader}    ${inv_conf_followers_list}=    Wait Until Keyword Succeeds
30     ...    10s
31     ...    1s
32     ...    ClusterManagement.Get_Leader_And_Followers_For_Shard
33     ...    shard_name=inventory
34     ...    shard_type=config
35     ...    member_index_list=${controller_index_list}
36     Log    config inventory Leader is ${inv_conf_leader} and followers are ${inv_conf_followers_list}
37     RETURN    ${inv_conf_leader}    ${inv_conf_followers_list}
38
39 Check OpenFlow Shards Status
40     [Documentation]    Check Status for all shards in OpenFlow application.
41     [Arguments]    ${controller_index_list}=${EMPTY}
42     CompareStream.Run_Keyword_If_At_Least_Phosphorus
43     ...    Collections.Remove Values From List
44     ...    ${SHARD_OPER_LIST}
45     ...    entity-ownership
46     Log    ${SHARD_OPER_LIST}
47     ClusterManagement.Verify_Leader_Exists_For_Each_Shard
48     ...    shard_name_list=${SHARD_OPER_LIST}
49     ...    shard_type=operational
50     ...    member_index_list=${controller_index_list}
51     ClusterManagement.Verify_Leader_Exists_For_Each_Shard
52     ...    shard_name_list=${SHARD_CONF_LIST}
53     ...    shard_type=config
54     ...    member_index_list=${controller_index_list}
55
56 Check OpenFlow Shards Status After Cluster Event
57     [Documentation]    Check Shards Status after some cluster event.
58     [Arguments]    ${controller_index_list}=${EMPTY}
59     Wait Until Keyword Succeeds
60     ...    90s
61     ...    1s
62     ...    ClusterOpenFlow.Check OpenFlow Shards Status
63     ...    ${controller_index_list}
64
65 Get OpenFlow Entity Owner Status For One Device
66     [Documentation]    Check Entity Owner Status and identify owner and successors for the device ${device}. Request is sent to controller ${controller_index}.
67     [Arguments]    ${device}    ${controller_index}    ${controller_index_list}=${EMPTY}    ${after_stop}=False
68     ${owner}    ${successor_list}=    Wait Until Keyword Succeeds
69     ...    30s
70     ...    1s
71     ...    ClusterManagement.Verify_Owner_And_Successors_For_Device
72     ...    device_name=${device}
73     ...    device_type=openflow
74     ...    member_index=${controller_index}
75     ...    candidate_list=${controller_index_list}
76     ...    after_stop=${after_stop}
77     RETURN    ${owner}    ${successor_list}
78
79 Check OpenFlow Device Owner
80     [Documentation]    Check owner and candidates for the device ${device}. Request is sent to controller ${controller_index}.
81     [Arguments]    ${device}    ${controller_index}    ${expected_owner}    ${expected_candidate_list}=${EMPTY}
82     ${owner}    ${successor_list}=    ClusterManagement.Verify_Owner_And_Successors_For_Device
83     ...    device_name=${device}
84     ...    device_type=openflow
85     ...    member_index=${controller_index}
86     ...    candidate_list=${expected_candidate_list}
87     Should Be Equal    ${owner}    ${expected_owner}
88
89 Check OpenFlow Network Operational Information For Sample Topology
90     [Documentation]    Check devices in tree,2 are in operational inventory and topology in all instances in ${controller_index_list}.
91     ...    Inventory should show 1x node_id per device 1x node_id per connector. Topology should show 2x node_id per device + 3x node_id per connector
92     ...    + 5x node_id per link termination. TODO: A Keyword that can calculate this based on mininet topology.
93     [Arguments]    ${controller_index_list}=${EMPTY}
94     ${dictionary}=    Create Dictionary    openflow:1=4    openflow:2=5    openflow:3=5
95     Wait Until Keyword Succeeds
96     ...    5s
97     ...    1s
98     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
99     ...    uri=${RFC8040_OPERATIONAL_NODES_API}
100     ...    dictionary=${dictionary}
101     ...    member_index_list=${controller_index_list}
102     ${dictionary}=    Create Dictionary    openflow:1=21    openflow:2=19    openflow:3=19
103     Wait Until Keyword Succeeds
104     ...    5s
105     ...    1s
106     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
107     ...    uri=${RFC8040_OPERATIONAL_TOPO_API}
108     ...    dictionary=${dictionary}
109     ...    member_index_list=${controller_index_list}
110
111 Check No OpenFlow Network Operational Information
112     [Documentation]    Check device is not in operational inventory or topology in all cluster instances in ${controller_index_list}.
113     [Arguments]    ${controller_index_list}=${EMPTY}
114     ${dictionary}=    Create Dictionary    openflow=0
115     Wait Until Keyword Succeeds
116     ...    5s
117     ...    1s
118     ...    ClusterManagement.Check_No_Content_Member_List_Or_All
119     ...    uri=${RFC8040_OPERATIONAL_NODES_API}
120     ...    member_index_list=${controller_index_list}
121     ${dictionary}=    Create Dictionary    openflow=0
122     Wait Until Keyword Succeeds
123     ...    20s
124     ...    2s
125     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
126     ...    uri=${RFC8040_OPERATIONAL_TOPO_API}
127     ...    dictionary=${dictionary}
128     ...    member_index_list=${controller_index_list}
129
130 Add Sample Flow And Verify
131     [Documentation]    Add sample flow in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
132     [Arguments]    ${controller_index}    ${controller_index_list}=${EMPTY}
133     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/sample_flow_1.json
134     # There are slight differences on the way He and Li plugin display table information. He plugin has an additional Hashmap field
135     # replicating some of the matches in the flows section. Same comment applies for further keywords.
136     IF    '${ODL_OF_PLUGIN}' == 'helium'
137         Set Test Variable    &{dictionary}    10.0.1.0/24=2    "output-node-connector":"1"=1
138     END
139     IF    '${ODL_OF_PLUGIN}' == 'lithium'
140         Set Test Variable    &{dictionary}    10.0.1.0/24=1    "output-node-connector":"1"=1
141     END
142     ClusterManagement.Put_As_Json_And_Check_Member_List_Or_All
143     ...    ${config_table_0}/flow=1
144     ...    ${body}
145     ...    ${controller_index}
146     ...    ${controller_index_list}
147     Wait Until Keyword Succeeds
148     ...    15s
149     ...    1s
150     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
151     ...    uri=${operational_table_0}
152     ...    dictionary=${dictionary}
153     ...    member_index_list=${controller_index_list}
154
155 Verify Sample Flow
156     [Documentation]    Verify sample flow gets applied in all instances in ${controller_index_list}.
157     [Arguments]    ${controller_index_list}=${EMPTY}
158     # There are slight differences on the way He and Li plugin display table information. He plugin has an additional Hashmap field
159     # replicating some of the matches in the flows section. Same comment applies for further keywords.
160     IF    '${ODL_OF_PLUGIN}' == 'helium'
161         Set Test Variable    &{dictionary}    10.0.1.0/24=2    "output-node-connector":"1"=1
162     END
163     IF    '${ODL_OF_PLUGIN}' == 'lithium'
164         Set Test Variable    &{dictionary}    10.0.1.0/24=1    "output-node-connector":"1"=1
165     END
166     Wait Until Keyword Succeeds
167     ...    15s
168     ...    1s
169     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
170     ...    uri=${operational_table_0}
171     ...    dictionary=${dictionary}
172     ...    member_index_list=${controller_index_list}
173
174 Modify Sample Flow And Verify
175     [Documentation]    Modify sample flow in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
176     [Arguments]    ${controller_index}    ${controller_index_list}=${EMPTY}
177     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/sample_flow_2.json
178     IF    '${ODL_OF_PLUGIN}' == 'helium'
179         Set Test Variable    &{dictionary}    10.0.1.0/24=2    "output-node-connector":"2"=1
180     END
181     IF    '${ODL_OF_PLUGIN}' == 'lithium'
182         Set Test Variable    &{dictionary}    10.0.1.0/24=1    "output-node-connector":"2"=1
183     END
184     ClusterManagement.Put_As_Json_And_Check_Member_List_Or_All
185     ...    ${config_table_0}/flow=1
186     ...    ${body}
187     ...    ${controller_index}
188     ...    ${controller_index_list}
189     Wait Until Keyword Succeeds
190     ...    15s
191     ...    1s
192     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
193     ...    uri=${operational_table_0}
194     ...    dictionary=${dictionary}
195     ...    member_index_list=${controller_index_list}
196
197 Delete Sample Flow And Verify
198     [Documentation]    Delete sample flow in Owner and verify it gets removed from all instances.
199     [Arguments]    ${controller_index}    ${controller_index_list}=${EMPTY}
200     ${dictionary}=    Create Dictionary    10.0.1.0/24=0
201     ClusterManagement.Delete_And_Check_Member_List_Or_All
202     ...    ${config_table_0}/flow=1
203     ...    ${controller_index}
204     ...    ${controller_index_list}
205     Wait Until Keyword Succeeds
206     ...    5s
207     ...    1s
208     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
209     ...    uri=${operational_table_0}
210     ...    dictionary=${dictionary}
211     ...    member_index_list=${controller_index_list}
212
213 Send RPC Add Sample Flow And Verify
214     [Documentation]    Add sample flow in ${controller_index} and verify it gets applied from all instances in ${controller_index_list}.
215     [Arguments]    ${controller_index}    ${controller_index_list}=${EMPTY}
216     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/add_flow_rpc.json
217     IF    '${ODL_OF_PLUGIN}' == 'helium'
218         Set Test Variable    &{dictionary}    10.0.1.0/24=2
219     END
220     IF    '${ODL_OF_PLUGIN}' == 'lithium'
221         Set Test Variable    &{dictionary}    10.0.1.0/24=1
222     END
223     ClusterManagement.Post_As_Json_To_Member
224     ...    uri=/rests/operations/sal-flow:add-flow
225     ...    data=${body}
226     ...    member_index=${controller_index}
227     Wait Until Keyword Succeeds
228     ...    15s
229     ...    1s
230     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
231     ...    uri=${operational_table_0}
232     ...    dictionary=${dictionary}
233     ...    member_index_list=${controller_index_list}
234
235 Send RPC Delete Sample Flow And Verify
236     [Documentation]    Delete sample flow in ${controller_index} and verify it gets removed from all instances in ${controller_index_list}.
237     [Arguments]    ${controller_index}    ${controller_index_list}=${EMPTY}
238     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/delete_flow_rpc.json
239     ${dictionary}=    Create Dictionary    10.0.1.0/24=0
240     ClusterManagement.Post_As_Json_To_Member
241     ...    uri=/rests/operations/sal-flow:remove-flow
242     ...    data=${body}
243     ...    member_index=${controller_index}
244     Wait Until Keyword Succeeds
245     ...    5s
246     ...    1s
247     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
248     ...    uri=${operational_table_0}
249     ...    dictionary=${dictionary}
250     ...    member_index_list=${controller_index_list}
251
252 Take OpenFlow Device Link Down and Verify
253     [Documentation]    Take a link down and verify port status in all instances in ${controller_index_list}.
254     [Arguments]    ${controller_index_list}=${EMPTY}
255     ${dictionary}=    Create Dictionary    "link-down":true=1
256     ${ouput}=    MininetKeywords.Send Mininet Command    ${mininet_conn_id}    link s1 s2 down
257     Wait Until Keyword Succeeds
258     ...    5s
259     ...    1s
260     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
261     ...    uri=${operational_port_1}
262     ...    dictionary=${dictionary}
263     ...    member_index_list=${controller_index_list}
264     ${dictionary}=    Create Dictionary    openflow:1=16    openflow:2=14    openflow:3=19
265     Wait Until Keyword Succeeds
266     ...    20s
267     ...    2s
268     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
269     ...    uri=${RFC8040_OPERATIONAL_TOPO_API}
270     ...    dictionary=${dictionary}
271     ...    member_index_list=${controller_index_list}
272
273 Take OpenFlow Device Link Up and Verify
274     [Documentation]    Take the link up and verify port status in all instances in ${controller_index_list}.
275     [Arguments]    ${controller_index_list}=${EMPTY}
276     ${dictionary}=    Create Dictionary    "link-down":true=0
277     ${ouput}=    MininetKeywords.Send Mininet Command    ${mininet_conn_id}    link s1 s2 up
278     Wait Until Keyword Succeeds
279     ...    5s
280     ...    1s
281     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
282     ...    uri=${operational_port_1}
283     ...    dictionary=${dictionary}
284     ...    member_index_list=${controller_index_list}
285     ${dictionary}=    Create Dictionary    openflow:1=21    openflow:2=19    openflow:3=19
286     Wait Until Keyword Succeeds
287     ...    10s
288     ...    1s
289     ...    ClusterManagement.Check_Item_Occurrence_Member_List_Or_All
290     ...    uri=${RFC8040_OPERATIONAL_TOPO_API}
291     ...    dictionary=${dictionary}
292     ...    member_index_list=${controller_index_list}
293
294 Verify Switch Connections Running On Member
295     [Documentation]    Check if number of Switch connections on member of given index is equal to ${switch_count}.
296     [Arguments]    ${switch_count}    ${member_index}
297     ${count}=    ScaleClient.Get_Switches_Count    controller=${ODL_SYSTEM_${member_index}_IP}
298     BuiltIn.Should_Be_Equal_As_Numbers    ${switch_count}    ${count}
299
300 Check Flows Operational Datastore On Member
301     [Documentation]    Check if number of Operational Flows on member of given index is equal to ${flow_count}.
302     [Arguments]    ${flow_count}    ${member_index}
303     ${sw}    ${reported_flow}    ${found_flow}=    ScaleClient.Flow Stats Collected
304     ...    controller=${ODL_SYSTEM_${member_index}_IP}
305     BuiltIn.Should_Be_Equal_As_Numbers    ${flow_count}    ${found_flow}
306
307 Check Linear Topology On Member
308     [Documentation]    Check Linear topology.
309     [Arguments]    ${switches}    ${member_index}=1
310     ${session}=    Resolve_Http_Session_For_Member    member_index=${member_index}
311     ${resp}=    RequestsLibrary.Get Request    ${session}    ${RFC8040_OPERATIONAL_TOPO_API}
312     Log    ${resp.text}
313     Should Be Equal As Strings    ${resp.status_code}    200
314     FOR    ${switch}    IN RANGE    1    ${switches+1}
315         Should Contain    ${resp.text}    "node-id":"openflow:${switch}"
316         Should Contain    ${resp.text}    "tp-id":"openflow:${switch}:1"
317         Should Contain    ${resp.text}    "tp-id":"openflow:${switch}:2"
318         Should Contain    ${resp.text}    "source-tp":"openflow:${switch}:2"
319         Should Contain    ${resp.text}    "dest-tp":"openflow:${switch}:2"
320         ${edge}=    Evaluate    ${switch}==1 or ${switch}==${switches}
321         IF    not ${edge}
322             Should Contain    ${resp.text}    "tp-id":"openflow:${switch}:3"
323         END
324         IF    not ${edge}
325             Should Contain    ${resp.text}    "source-tp":"openflow:${switch}:3"
326         END
327         IF    not ${edge}
328             Should Contain    ${resp.text}    "dest-tp":"openflow:${switch}:3
329         END
330     END
331
332 Check No Switches On Member
333     [Documentation]    Check no switch is in topology
334     [Arguments]    ${switches}    ${member_index}=1
335     ${session}=    Resolve_Http_Session_For_Member    member_index=${member_index}
336     ${resp}=    RequestsLibrary.Get Request    ${session}    ${RFC8040_OPERATIONAL_TOPO_API}
337     Log    ${resp.text}
338     Should Be Equal As Strings    ${resp.status_code}    200
339     FOR    ${switch}    IN RANGE    1    ${switches+1}
340         Should Not Contain    ${resp.text}    openflow:${switch}
341     END
342
343 Check Number Of Flows On Member
344     [Documentation]    Check number of flows in the inventory.
345     [Arguments]    ${flows}    ${member_index}=1
346     ${session}=    Resolve_Http_Session_For_Member    member_index=${member_index}
347     ${resp}=    RequestsLibrary.Get Request    ${session}    ${RFC8040_OPERATIONAL_NODES_API}
348     Log    ${resp.text}
349     Should Be Equal As Strings    ${resp.status_code}    200
350     ${count}=    Get Count    ${resp.text}    "priority"
351     Should Be Equal As Integers    ${count}    ${flows}
352
353 Check Number Of Groups On Member
354     [Documentation]    Check number of groups in the inventory.
355     [Arguments]    ${groups}    ${member_index}=1
356     ${session}=    Resolve_Http_Session_For_Member    member_index=${member_index}
357     ${resp}=    RequestsLibrary.Get Request    ${session}    ${RFC8040_OPERATIONAL_NODES_API}
358     Log    ${resp.text}
359     Should Be Equal As Strings    ${resp.status_code}    200
360     ${group_count}=    Get Count    ${resp.text}    "group-type"
361     Should Be Equal As Integers    ${group_count}    ${groups}