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