Step 1: Move vm scripts to the right place
[integration/test.git] / test / 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    f12.xml    f13.xml    f14.xml    f17.xml    f19.xml
19 ...               f24.xml
20
21 *** Test Cases ***
22 Test Add Flows
23     [Documentation]    Add all flows and waits for SM to collect data
24     : FOR    ${flowfile}    IN    @{xml_files}
25     \    Log    ${flowfile}
26     \    Init Flow Variables    ${flowfile}
27     \    Run Keyword And Continue On Failure    Add Flow
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 12 Added
84     [Documentation]    Checks if flow is configured and operational
85     Init Flow Variables    f12.xml
86     Check Config Flow    ${True}
87     Check Operational Table    ${True}
88
89 Test Is Flow 13 Added
90     [Documentation]    Checks if flow is configured and operational
91     Init Flow Variables    f13.xml
92     Check Config Flow    ${True}
93     Check Operational Table    ${True}
94
95 Test Is Flow 14 Added
96     [Documentation]    Checks if flow is configured and operational
97     Init Flow Variables    f14.xml
98     Check Config Flow    ${True}
99     Check Operational Table    ${True}
100
101 Test Is Flow 17 Added
102     [Documentation]    Checks if flow is configured and operational
103     Init Flow Variables    f17.xml
104     Check Config Flow    ${True}
105     Check Operational Table    ${True}
106
107 Test Is Flow 19 Added
108     [Documentation]    Checks if flow is configured and operational
109     Init Flow Variables    f19.xml
110     Check Config Flow    ${True}
111     Check Operational Table    ${True}
112
113 Test Is Flow 24 Added
114     [Documentation]    Checks if flow is configured and operational
115     Init Flow Variables    f24.xml
116     Check Config Flow    ${True}
117     Check Operational Table    ${True}
118
119 Test Delete Flows
120     [Documentation]    Delete all flows and waits for SM to collect data
121     : FOR    ${flowfile}    IN    @{xml_files}
122     \    Log    ${flowfile}
123     \    Init Flow Variables    ${flowfile}
124     \    Run Keyword And Continue On Failure    Delete Flow
125
126 Test Is Flow 1 Deleted
127     [Documentation]    Checks if flow is not configured and operational
128     Init Flow Variables    f1.xml
129     Check Config Flow    ${False}
130     Check Operational Table    ${False}
131
132 Test Is Flow 2 Deleted
133     [Documentation]    Checks if flow is not configured and operational
134     Init Flow Variables    f2.xml
135     Check Config Flow    ${False}
136     Check Operational Table    ${False}
137
138 Test Is Flow 3 Deleted
139     [Documentation]    Checks if flow is not configured and operational
140     Init Flow Variables    f3.xml
141     Check Config Flow    ${False}
142     Check Operational Table    ${False}
143
144 Test Is Flow 5 Deleted
145     [Documentation]    Checks if flow is not configured and operational
146     Init Flow Variables    f5.xml
147     Check Config Flow    ${False}
148     Check Operational Table    ${False}
149
150 Test Is Flow 7 Deleted
151     [Documentation]    Checks if flow is not configured and operational
152     Init Flow Variables    f7.xml
153     Check Config Flow    ${False}
154     Check Operational Table    ${False}
155
156 Test Is Flow 8 Deleted
157     [Documentation]    Checks if flow is not configured and operational
158     Init Flow Variables    f8.xml
159     Check Config Flow    ${False}
160     Check Operational Table    ${False}
161
162 Test Is Flow 9 Deleted
163     [Documentation]    Checks if flow is not configured and operational
164     Init Flow Variables    f9.xml
165     Check Config Flow    ${False}
166     Check Operational Table    ${False}
167
168 Test Is Flow 10 Deleted
169     [Documentation]    Checks if flow is not configured and operational
170     Init Flow Variables    f10.xml
171     Check Config Flow    ${False}
172     Check Operational Table    ${False}
173
174 Test Is Flow 11 Deleted
175     [Documentation]    Checks if flow is not configured and operational
176     Init Flow Variables    f11.xml
177     Check Config Flow    ${False}
178     Check Operational Table    ${False}
179
180 Test Is Flow 12 Deleted
181     [Documentation]    Checks if flow is not configured and operational
182     Init Flow Variables    f12.xml
183     Check Config Flow    ${False}
184     Check Operational Table    ${False}
185
186 Test Is Flow 13 Deleted
187     [Documentation]    Checks if flow is not configured and operational
188     Init Flow Variables    f13.xml
189     Check Config Flow    ${False}
190     Check Operational Table    ${False}
191
192 Test Is Flow 14 Deleted
193     [Documentation]    Checks if flow is not configured and operational
194     Init Flow Variables    f14.xml
195     Check Config Flow    ${False}
196     Check Operational Table    ${False}
197
198 Test Is Flow 17 Deleted
199     [Documentation]    Checks if flow is not configured and operational
200     Init Flow Variables    f17.xml
201     Check Config Flow    ${False}
202     Check Operational Table    ${False}
203
204 Test Is Flow 19 Deleted
205     [Documentation]    Checks if flow is not configured and operational
206     Init Flow Variables    f19.xml
207     Check Config Flow    ${False}
208     Check Operational Table    ${False}
209
210 Test Is Flow 24 Deleted
211     [Documentation]    Checks if flow is not configured and operational
212     Init Flow Variables    f24.xml
213     Check Config Flow    ${False}
214     Check Operational Table    ${False}
215
216 *** Keywords ***
217 Init Flow Variables
218     [Arguments]    ${file}
219     ${data}=    Get File    ${XmlsDir}/${file}
220     ${xmlroot}=    Parse Xml    ${XmlsDir}/${file}
221     ${table_id}=    Get Element Text    ${xmlroot}    table_id
222     ${flow_id}=    Get Element Text    ${xmlroot}    id
223     ${flow_priority}=    Get Element Text    ${xmlroot}    priority
224     Set Suite Variable    ${table_id}
225     Set Suite Variable    ${flow_id}
226     Set Suite Variable    ${flow_priority}
227     Set Suite Variable    ${data}
228     Set Suite Variable    ${xmlroot}
229
230 Check Config Flow
231     [Arguments]    ${expected}
232     Wait Until Keyword Succeeds    40s    2s    Check Config Flow Presence    ${expected}
233
234 Check Config Flow Presence
235     [Arguments]    ${expected}
236     ${presence_flow}    ${msg}=    Flow Presence Config Flow
237     ${msgf}=    Get Presence Failure Message    config    ${expected}    ${presence_flow}    ${msg}
238     Should Be Equal    ${expected}    ${presence_flow}    msg=${msgf}
239
240 Flow Presence Config Flow
241     ${headers}=    Create Dictionary    Accept    application/xml
242     ${resp}=    RequestsLibrary.Get    session    /restconf/config/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}/flow/${flow_id}    headers=${headers}
243     Log    ${resp}
244     Log    ${resp.content}
245     Return From Keyword If    ${resp.status_code}!=200    ${False}    ${EMPTY}
246     ${pres}    ${msg}=    Is Flow Configured    ${data}    ${resp.content}
247     Run Keyword If    '''${msg}'''!='${EMPTY}'    Log    ${msg}
248     Return From Keyword    ${pres}    ${msg}
249
250 Check Operational Table
251     [Arguments]    ${expected}
252     Wait Until Keyword Succeeds    120s    2s    Check Operational Table Presence    ${expected}
253
254 Check Operational Table Presence
255     [Arguments]    ${expected}
256     ${presence_table}    ${msg}=    Flow Presence Operational Table
257     ${msgf}=    Get Presence Failure Message    config    ${expected}    ${presence_table}    ${msg}
258     Should Be Equal    ${expected}    ${presence_table}    msg=${msgf}
259
260 Flow Presence Operational Table
261     ${headers}=    Create Dictionary    Accept    application/xml
262     ${resp}=    RequestsLibrary.Get    session    /restconf/operational/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}    headers=${headers}
263     Log    ${resp}
264     Log    ${resp.content}
265     Return From Keyword If    ${resp.status_code}!=200    ${False}    ${EMPTY}
266     ${pres}    ${msg}=    Is Flow Operational2    ${data}    ${resp.content}
267     Run Keyword If    '''${msg}'''!='${EMPTY}'    Log    ${msg}
268     Return From Keyword    ${pres}    ${msg}
269
270 Add Flow
271     Log    ${data}
272     ${resp}=    RequestsLibrary.Put    session    /restconf/config/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}/flow/${flow_id}    headers=${HEADERS_XML}    data=${data}
273     ${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.
274     Should Be Equal As Strings    ${resp.status_code}    200    msg=${msg}
275
276 Delete Flow
277     ${resp}=    RequestsLibrary.Delete    session    /restconf/config/opendaylight-inventory:nodes/node/openflow:${switch_idx}/table/${table_id}/flow/${flow_id}
278     ${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.
279     Should Be Equal As Strings    ${resp.status_code}    200    msg=${msg}
280
281 Delete All Flows
282     [Documentation]    Deletes all flows
283     : FOR    ${flowfile}    IN    @{xml_files}
284     \    Log    ${flowfile}
285     \    Init Flow Variables    ${flowfile}
286     \    Delete Flow
287
288 Initialization Phase
289     [Documentation]    Initiate tcp connection with controller
290     Create Session    session    http://${CONTROLLER}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
291
292 Teardown Phase
293     [Documentation]    Closes tcp connection with controller and removes flows
294     Delete All Sessions
295
296 Get Presence Failure Message
297     [Arguments]    ${ds}    ${expected}    ${presence}    ${diffmsg}
298     Return From Keyword If    '''${diffmsg}'''!='${EMPTY}'    Flow found in ${ds} data store but: ${diffmsg}
299     ${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
300     ${msgp}=    Set Variable If    ${presence}==${True}    it is present.    it is not present.
301     Return From Keyword    ${msgf} ${msgp}