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