Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / openflowplugin / Flows_Stats_OF13 / 010__SM_add_upd_del_flows.robot
1 *** Settings ***
2 Documentation     Test suite for Stats Manager flows collection
3 Suite Setup       Initialization Phase
4 Suite Teardown    Teardown Phase
5 Library           OperatingSystem
6 Library           Collections
7 Library           XML
8 Library           ../../../libraries/XmlComparator.py
9 Variables         ../../../variables/Variables.py
10 Library           RequestsLibrary
11 Library           ../../../libraries/Common.py
12
13 *** Variables ***
14 ${XmlsDir}        ${CURDIR}/../../../variables/xmls
15 ${switch_idx}     1
16 ${switch_name}    s${switch_idx}
17 @{xml_files}      f1.xml    f2.xml    f3.xml    f5.xml    f7.xml    f8.xml    f9.xml
18 ...               f10.xml    f11.xml    f14.xml    f17.xml    f19.xml    f24.xml
19
20 *** Test Cases ***
21 Test Add Flows
22     [Documentation]    Add all flows and waits for SM to collect data
23     FOR    ${flowfile}    IN    @{xml_files}
24         Log    ${flowfile}
25         Init Flow Variables    ${flowfile}
26         Run Keyword And Continue On Failure    Add Flow
27     END
28
29 Test Is Flow 1 Added
30     [Documentation]    Checks if flow is configured and operational
31     Init Flow Variables    f1.xml
32     Check Config Flow    ${True}
33     Check Operational Table    ${True}
34
35 Test Is Flow 2 Added
36     [Documentation]    Checks if flow is configured and operational
37     Init Flow Variables    f2.xml
38     Check Config Flow    ${True}
39     Check Operational Table    ${True}
40
41 Test Is Flow 3 Added
42     [Documentation]    Checks if flow is configured and operational
43     Init Flow Variables    f3.xml
44     Check Config Flow    ${True}
45     Check Operational Table    ${True}
46
47 Test Is Flow 5 Added
48     [Documentation]    Checks if flow is configured and operational
49     Init Flow Variables    f5.xml
50     Check Config Flow    ${True}
51     Check Operational Table    ${True}
52
53 Test Is Flow 7 Added
54     [Documentation]    Checks if flow is configured and operational
55     Init Flow Variables    f7.xml
56     Check Config Flow    ${True}
57     Check Operational Table    ${True}
58
59 Test Is Flow 8 Added
60     [Documentation]    Checks if flow is configured and operational
61     Init Flow Variables    f8.xml
62     Check Config Flow    ${True}
63     Check Operational Table    ${True}
64
65 Test Is Flow 9 Added
66     [Documentation]    Checks if flow is configured and operational
67     Init Flow Variables    f9.xml
68     Check Config Flow    ${True}
69     Check Operational Table    ${True}
70
71 Test Is Flow 10 Added
72     [Documentation]    Checks if flow is configured and operational
73     Init Flow Variables    f10.xml
74     Check Config Flow    ${True}
75     Check Operational Table    ${True}
76
77 Test Is Flow 11 Added
78     [Documentation]    Checks if flow is configured and operational
79     Init Flow Variables    f11.xml
80     Check Config Flow    ${True}
81     Check Operational Table    ${True}
82
83 Test Is Flow 14 Added
84     [Documentation]    Checks if flow is configured and operational
85     Init Flow Variables    f14.xml
86     Check Config Flow    ${True}
87     Check Operational Table    ${True}
88
89 Test Is Flow 17 Added
90     [Documentation]    Checks if flow is configured and operational
91     Init Flow Variables    f17.xml
92     Check Config Flow    ${True}
93     Check Operational Table    ${True}
94
95 Test Is Flow 19 Added
96     [Documentation]    Checks if flow is configured and operational
97     Init Flow Variables    f19.xml
98     Check Config Flow    ${True}
99     Check Operational Table    ${True}
100
101 Test Is Flow 24 Added
102     [Documentation]    Checks if flow is configured and operational
103     Init Flow Variables    f24.xml
104     Check Config Flow    ${True}
105     Check Operational Table    ${True}
106
107 Test Delete Flows
108     [Documentation]    Delete all flows and waits for SM to collect data
109     FOR    ${flowfile}    IN    @{xml_files}
110         Log    ${flowfile}
111         Init Flow Variables    ${flowfile}
112         Run Keyword And Continue On Failure    Delete Flow
113     END
114
115 Test Is Flow 1 Deleted
116     [Documentation]    Checks if flow is not configured and operational
117     Init Flow Variables    f1.xml
118     Check Config Flow    ${False}
119     Check Operational Table    ${False}
120
121 Test Is Flow 2 Deleted
122     [Documentation]    Checks if flow is not configured and operational
123     Init Flow Variables    f2.xml
124     Check Config Flow    ${False}
125     Check Operational Table    ${False}
126
127 Test Is Flow 3 Deleted
128     [Documentation]    Checks if flow is not configured and operational
129     Init Flow Variables    f3.xml
130     Check Config Flow    ${False}
131     Check Operational Table    ${False}
132
133 Test Is Flow 5 Deleted
134     [Documentation]    Checks if flow is not configured and operational
135     Init Flow Variables    f5.xml
136     Check Config Flow    ${False}
137     Check Operational Table    ${False}
138
139 Test Is Flow 7 Deleted
140     [Documentation]    Checks if flow is not configured and operational
141     Init Flow Variables    f7.xml
142     Check Config Flow    ${False}
143     Check Operational Table    ${False}
144
145 Test Is Flow 8 Deleted
146     [Documentation]    Checks if flow is not configured and operational
147     Init Flow Variables    f8.xml
148     Check Config Flow    ${False}
149     Check Operational Table    ${False}
150
151 Test Is Flow 9 Deleted
152     [Documentation]    Checks if flow is not configured and operational
153     Init Flow Variables    f9.xml
154     Check Config Flow    ${False}
155     Check Operational Table    ${False}
156
157 Test Is Flow 10 Deleted
158     [Documentation]    Checks if flow is not configured and operational
159     Init Flow Variables    f10.xml
160     Check Config Flow    ${False}
161     Check Operational Table    ${False}
162
163 Test Is Flow 11 Deleted
164     [Documentation]    Checks if flow is not configured and operational
165     Init Flow Variables    f11.xml
166     Check Config Flow    ${False}
167     Check Operational Table    ${False}
168
169 Test Is Flow 14 Deleted
170     [Documentation]    Checks if flow is not configured and operational
171     Init Flow Variables    f14.xml
172     Check Config Flow    ${False}
173     Check Operational Table    ${False}
174
175 Test Is Flow 17 Deleted
176     [Documentation]    Checks if flow is not configured and operational
177     Init Flow Variables    f17.xml
178     Check Config Flow    ${False}
179     Check Operational Table    ${False}
180
181 Test Is Flow 19 Deleted
182     [Documentation]    Checks if flow is not configured and operational
183     Init Flow Variables    f19.xml
184     Check Config Flow    ${False}
185     Check Operational Table    ${False}
186
187 Test Is Flow 24 Deleted
188     [Documentation]    Checks if flow is not configured and operational
189     Init Flow Variables    f24.xml
190     Check Config Flow    ${False}
191     Check Operational Table    ${False}
192
193 *** Keywords ***
194 Init Flow Variables
195     [Arguments]    ${file}
196     ${data}=    Get File    ${XmlsDir}/${file}
197     ${xmlroot}=    Parse Xml    ${XmlsDir}/${file}
198     ${table_id}=    Get Element Text    ${xmlroot}    table_id
199     ${flow_id}=    Get Element Text    ${xmlroot}    id
200     ${flow_priority}=    Get Element Text    ${xmlroot}    priority
201     Set Suite Variable    ${table_id}
202     Set Suite Variable    ${flow_id}
203     Set Suite Variable    ${flow_priority}
204     Set Suite Variable    ${data}
205     Set Suite Variable    ${xmlroot}
206
207 Check Config Flow
208     [Arguments]    ${expected}
209     Wait Until Keyword Succeeds    40s    2s    Check Config Flow Presence    ${expected}
210
211 Check Config Flow Presence
212     [Arguments]    ${expected}
213     ${presence_flow}    ${msg}=    Flow Presence Config Flow
214     ${msgf}=    Get Presence Failure Message    config    ${expected}    ${presence_flow}    ${msg}
215     Should Be Equal    ${expected}    ${presence_flow}    msg=${msgf}
216
217 Flow Presence Config Flow
218     ${headers}=    Create Dictionary    Accept=application/xml
219     ${resp}=    RequestsLibrary.Get Request    session    /restconf/config/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}/flow/${flow_id}    headers=${headers}
220     Log    ${resp}
221     Log    ${resp.content}
222     Return From Keyword If    ${resp.status_code}!=200    ${False}    ${EMPTY}
223     ${pres}    ${msg}=    Is Flow Configured    ${data}    ${resp.content}
224     Run Keyword If    '''${msg}'''!='${EMPTY}'    Log    ${msg}
225     Return From Keyword    ${pres}    ${msg}
226
227 Check Operational Table
228     [Arguments]    ${expected}
229     Wait Until Keyword Succeeds    120s    2s    Check Operational Table Presence    ${expected}
230
231 Check Operational Table Presence
232     [Arguments]    ${expected}
233     ${presence_table}    ${msg}=    Flow Presence Operational Table
234     ${msgf}=    Get Presence Failure Message    config    ${expected}    ${presence_table}    ${msg}
235     Should Be Equal    ${expected}    ${presence_table}    msg=${msgf}
236
237 Flow Presence Operational Table
238     ${headers}=    Create Dictionary    Accept=application/xml
239     ${resp}=    RequestsLibrary.Get Request    session    /restconf/operational/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}    headers=${headers}
240     Log    ${resp}
241     Log    ${resp.content}
242     Return From Keyword If    ${resp.status_code}!=200    ${False}    ${EMPTY}
243     ${pres}    ${msg}=    Is Flow Operational2    ${data}    ${resp.content}
244     Run Keyword If    '''${msg}'''!='${EMPTY}'    Log    ${msg}
245     Return From Keyword    ${pres}    ${msg}
246
247 Add Flow
248     Log    ${data}
249     ${resp}=    RequestsLibrary.Put Request    session    /restconf/config/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}/flow/${flow_id}    headers=${HEADERS_XML}    data=${data}
250     ${msg}=    Set Variable    Adding flow for /restconf/config/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}/flow/${flow_id} failed, http response ${resp.status_code} received.
251     Should Be Equal As Strings    ${resp.status_code}    200    msg=${msg}
252
253 Delete Flow
254     ${resp}=    RequestsLibrary.Delete Request    session    /restconf/config/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}/flow/${flow_id}
255     ${msg}=    Set Variable    Delete flow for /restconf/config/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}/flow/${flow_id} failed, http response ${resp.status_code} received.
256     Should Be Equal As Strings    ${resp.status_code}    200    msg=${msg}
257
258 Delete All Flows
259     [Documentation]    Deletes all flows
260     FOR    ${flowfile}    IN    @{xml_files}
261         Log    ${flowfile}
262         Init Flow Variables    ${flowfile}
263         Delete Flow
264     END
265
266 Initialization Phase
267     [Documentation]    Initiate tcp connection with controller
268     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
269
270 Teardown Phase
271     [Documentation]    Closes tcp connection with controller and removes flows
272     Delete All Sessions
273
274 Get Presence Failure Message
275     [Arguments]    ${ds}    ${expected}    ${presence}    ${diffmsg}
276     Return From Keyword If    '''${diffmsg}'''!='${EMPTY}'    Flow found in ${ds} data store but: ${diffmsg}
277     ${msgf}=    Set Variable If    ${expected}==${True}    The flow is expected in operational data store, but    The flow is not expected in operational data store, but
278     ${msgp}=    Set Variable If    ${presence}==${True}    it is present.    it is not present.
279     Return From Keyword    ${msgf} ${msgp}