Add RESTAPI tests for Li Test jobs
[integration/test.git] / csit / libraries / VtnMaKeywordsLi.robot
1 *** Settings ***
2 Library           SSHLibrary
3 Library           String
4 Library           DateTime
5 Library           Collections
6 Library           json
7 Library           RequestsLibrary
8 Variables         ../variables/Variables.py
9 Resource          ./Utils.robot
10
11 *** Variables ***
12 ${vlan_topo_10}    sudo mn --controller=remote,ip=${CONTROLLER} --custom vlan_vtn_test.py --topo vlantopo
13 ${vlan_topo_13}    sudo mn --controller=remote,ip=${CONTROLLER} --custom vlan_vtn_test.py --topo vlantopo --switch ovsk,protocols=OpenFlow13
14 ${REST_CONTEXT_VTNS}    controller/nb/v2/vtn/default/vtns
15 ${REST_CONTEXT}    controller/nb/v2/vtn/default
16 ${VERSION_VTN}    controller/nb/v2/vtn/version
17 ${VTN_INVENTORY}    restconf/operational/vtn-inventory:vtn-nodes
18 ${DUMPFLOWS_OF10}    dpctl dump-flows -O OpenFlow10
19 ${DUMPFLOWS_OF13}    dpctl dump-flows -O OpenFlow13
20 ${index}          7
21 @{FLOWELMENTS}    nw_src=10.0.0.1    nw_dst=10.0.0.3    actions=drop
22 @{BRIDGE1_DATAFLOW}    "reason":"PORTMAPPED"    "path":{"tenant":"Tenant1","bridge":"vBridge1","interface":"if2"}
23 @{BRIDGE2_DATAFLOW}    "reason":"PORTMAPPED"    "path":{"tenant":"Tenant1","bridge":"vBridge2","interface":"if3"}
24 ${vlanmap_bridge1}    {"vlan": "200"}
25 ${vlanmap_bridge2}    {"vlan": "300"}
26 @{VLANMAP_BRIDGE1_DATAFLOW}    "reason":"VLANMAPPED"    "path":{"tenant":"Tenant1","bridge":"vBridge1_vlan"}
27 @{VLANMAP_BRIDGE2_DATAFLOW}    "reason":"VLANMAPPED"    "path":{"tenant":"Tenant1","bridge":"vBridge2_vlan"}
28 ${pathpolicy_topo_13}    sudo mn --controller=remote,ip=${CONTROLLER} --custom topo-3sw-2host_multipath.py --topo pathpolicytopo --switch ovsk,protocols=OpenFlow13
29 ${pathpolicy_topo_10}    sudo mn --controller=remote,ip=${CONTROLLER} --custom topo-3sw-2host_multipath.py --topo pathpolicytopo --switch ovsk,protocols=OpenFlow10
30 @{PATHMAP_ATTR}    "index":"1"    "condition":"flowcond_path"    "policy":"1"
31 ${policy_id}      1
32 @{PATHPOLICY_ATTR}    "id":"1"    "type":"OF"    "name":"s4-eth2"
33 ${custom}         ${CURDIR}/${CREATE_PATHPOLICY_TOPOLOGY_FILE_PATH}
34 ${in_port}        1
35 ${out_before_pathpolicy}    output:2
36 ${out_after_pathpolicy}    output:3
37
38 *** Keywords ***
39 Start SuiteVtnMa
40     [Documentation]    Start VTN Manager Init Test Suite
41     Create Session    session    http://${CONTROLLER}:${RESTPORT}    auth=${AUTH}    headers=${HEADERS}
42     BuiltIn.Wait_Until_Keyword_Succeeds    30    3    Fetch vtn list
43     Start Suite
44
45 Stop SuiteVtnMa
46     [Documentation]    Stop VTN Manager Test Suite
47     Delete All Sessions
48     Stop Suite
49
50 Start SuiteVtnMaTest
51     [Documentation]    Start VTN Manager Test Suite
52     Create Session    session    http://${CONTROLLER}:${RESTPORT}    auth=${AUTH}    headers=${HEADERS}
53
54 Stop SuiteVtnMaTest
55     [Documentation]    Stop VTN Manager Test Suite
56     Delete All Sessions
57
58 Fetch vtn list
59     [Documentation]    Check if VTN Manager is up.
60     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT_VTNS}
61     Should Be Equal As Strings    ${resp.status_code}    200
62
63 Fetch vtn switch inventory
64     [Arguments]    ${sw_name}
65     [Documentation]    Check if Switch is detected.
66     ${resp}=    RequestsLibrary.Get    session    ${VTN_INVENTORY}/vtn-inventory:vtn-node/${sw_name}
67     Should Be Equal As Strings    ${resp.status_code}    200
68
69 Add a vtn
70     [Arguments]    ${vtn_name}    ${vtn_data}
71     [Documentation]    Create a vtn with specified parameters.
72     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}    data=${vtn_data}
73     Should Be Equal As Strings    ${resp.status_code}    201
74
75 Delete a vtn
76     [Arguments]    ${vtn_name}
77     [Documentation]    Create a vtn with specified parameters.
78     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT_VTNS}/${vtn_name}
79     Should Be Equal As Strings    ${resp.status_code}    200
80
81 Add a vBridge
82     [Arguments]    ${vtn_name}    ${vBridge_name}    ${vBridge_data}
83     [Documentation]    Create a vBridge in a VTN
84     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}    data=${vBridge_data}
85     Should Be Equal As Strings    ${resp.status_code}    201
86
87 Add a interface
88     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${interface_data}
89     [Documentation]    Create a interface into a vBridge of a VTN
90     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}    data=${interface_data}
91     Should Be Equal As Strings    ${resp.status_code}    201
92
93 Add a portmap
94     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${portmap_data}
95     [Documentation]    Create a portmap for a interface of a vbridge
96     ${json_data}=    json.dumps    ${portmap_data}
97     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/portmap    data=${json_data}    headers=${HEADERS}
98     Should Be Equal As Strings    ${resp.status_code}    200
99
100 Verify Data Flows
101     [Arguments]    ${vtn_name}    ${vBridge_name}
102     [Documentation]    Verify the reason and physical data flows for the specified vtn and vbridge
103     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT_VTNS}/${vtn_name}/flows/detail
104     Run Keyword If    '${vBridge_name}' == 'vBridge1'    DataFlowsForBridge    ${resp}    @{BRIDGE1_DATAFLOW}
105     ...    ELSE IF    '${vBridge_name}' == 'vBridge2'    DataFlowsForBridge    ${resp}    @{BRIDGE2_DATAFLOW}
106     ...    ELSE IF    '${vBridge_name}' == 'vBridge1_vlan'    DataFlowsForBridge    ${resp}    @{VLANMAP_BRIDGE1_DATAFLOW}
107     ...    ELSE    DataFlowsForBridge    ${resp}    @{VLANMAP_BRIDGE2_DATAFLOW}
108
109 DataFlowsForBridge
110     [Arguments]    ${resp}    @{BRIDGE_DATAFLOW}
111     [Documentation]    Verify whether the required attributes exists.
112     : FOR    ${dataflowElement}    IN    @{BRIDGE_DATAFLOW}
113     \    should Contain    ${resp.content}    ${dataflowElement}
114
115 Add a pathmap
116     [Arguments]    ${pathmap_data}
117     [Documentation]    Create a pathmap for a vtn
118     ${json_data}=    json.dumps    ${pathmap_data}
119     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT}/pathmaps/${policy_id}    data=${pathmap_data}    headers=${HEADERS}
120     Should Be Equal As Strings    ${resp.status_code}    201
121
122 Get a pathmap
123     [Documentation]    Get a pathmap for a vtn.
124     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT}/pathmaps
125     : FOR    ${pathElement}    IN    @{PATHMAP_ATTR}
126     \    should Contain    ${resp.content}    ${pathElement}
127
128 Add a pathpolicy
129     [Arguments]    ${pathpolicy_data}
130     [Documentation]    Create a pathpolicy for a vtn
131     ${json_data}=    json.dumps    ${pathpolicy_data}
132     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT}/pathpolicies/${policy_id}    data=${pathpolicy_data}    headers=${HEADERS}
133     Should Be Equal As Strings    ${resp.status_code}    201
134
135 Get a pathpolicy
136     [Documentation]    Get a pathpolicy for a vtn.
137     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT}/pathpolicies/${policy_id}
138     : FOR    ${pathpolicyElement}    IN    @{PATHPOLICY_ATTR}
139     \    should Contain    ${resp.content}    ${pathpolicyElement}
140
141 Verify flowEntryPathPolicy
142     [Arguments]    ${of_version}    ${port}    ${output}
143     [Documentation]    Checking Flows on switch S1 and switch S3 after applying path policy
144     ${DUMPFLOWS}=    Set Variable If    "${of_version}"=="OF10"    ${DUMPFLOWS_OF10}    ${DUMPFLOWS_OF13}
145     write    ${DUMPFLOWS}
146     ${result}    Read Until    mininet>
147     Should Contain    ${result}    in_port=${port}    actions=${output}
148
149 Start PathSuiteVtnMaTest
150     [Documentation]    Start VTN Manager Test Suite and Mininet
151     Start SuiteVtnMaTest
152     Start Mininet    ${MININET}    ${pathpolicy_topo_13}    ${custom}
153
154 Start PathSuiteVtnMaTestOF10
155     [Documentation]    Start VTN Manager Test Suite and Mininet in Open Flow 10 Specification
156     Start SuiteVtnMaTest
157     Start Mininet    ${MININET}    ${pathpolicy_topo_10}    ${custom}
158
159 Stop PathSuiteVtnMaTest
160     [Documentation]    Cleanup/Shutdown work at the completion of all tests.
161     Delete All Sessions
162     Stop Mininet    ${mininet_conn_id}
163
164 Delete a pathmap
165     [Documentation]    Delete a pathmap for a vtn
166     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT}/pathmaps/1
167     Should Be Equal As Strings    ${resp.status_code}    200
168
169 Get a pathmap after delete
170     [Documentation]    Get a pathmap for a vtn.
171     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT}/pathmaps
172     : FOR    ${pathElement}    IN    @{PATHMAP_ATTR}
173     \    should Not Contain    ${resp.content}    ${pathElement}
174
175 Delete a pathpolicy
176     [Documentation]    Delete a pathpolicy for a vtn
177     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT}/pathpolicies/1
178     Should Be Equal As Strings    ${resp.status_code}    200
179
180 Get a pathpolicy after delete
181     [Documentation]    Get a pathpolicy for a vtn after delete.
182     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT}/pathpolicies/${policy_id}
183     : FOR    ${pathpolicyElement}    IN    @{PATHPOLICY_ATTR}
184     \    should Not Contain    ${resp.content}    ${pathpolicyElement}
185
186 Add a macmap
187     [Arguments]    ${vtn_name}    ${vBridge_name}    ${macmap_data}
188     [Documentation]    Create a macmap for a vbridge
189     ${json_data}=    json.dumps    ${macmap_data}
190     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/macmap/allow    data=${macmap_data}    headers=${HEADERS}
191     Should Be Equal As Strings    ${resp.status_code}    201
192
193 Get DynamicMacAddress
194     [Arguments]    ${h}
195     [Documentation]    Get Dynamic mac address of Host
196     write    ${h} ifconfig -a | grep HWaddr
197     ${source}    Read Until    mininet>
198     ${HWaddress}=    Split String    ${source}    ${SPACE}
199     ${sourceHWaddr}=    Get from List    ${HWaddress}    ${index}
200     ${sourceHWaddress}=    Convert To Lowercase    ${sourceHWaddr}
201     Return From Keyword    ${sourceHWaddress}    # Also [Return] would work here.
202
203 Add a vBridgeMacMapping
204     [Arguments]    ${tenant_name}    ${Bridge_name}    ${bridge_macmap_data}
205     [Documentation]    Create a vbridge macmap for a bridge
206     ${json_data}=    json.dumps    ${bridge_macmap_data}
207     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${tenant_name}/vbridges/${Bridge_name}/macmap/allow    data=${json_data}    headers=${HEADERS}
208     Should Be Equal As Strings    ${resp.status_code}    201
209
210 Mininet Ping Should Succeed
211     [Arguments]    ${host1}    ${host2}
212     Write    ${host1} ping -c 10 ${host2}
213     ${result}    Read Until    mininet>
214     Should Contain    ${result}    64 bytes
215
216 Mininet Ping Should Not Succeed
217     [Arguments]    ${host1}    ${host2}
218     Write    ${host1} ping -c 10 ${host2}
219     ${result}    Read Until    mininet>
220     Should Not Contain    ${result}    64 bytes
221
222 Delete a interface
223     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}
224     [Documentation]    Delete a interface with specified parameters.
225     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}
226     Should Be Equal As Strings    ${resp.status_code}    200
227
228 Start vlan_topo
229     [Arguments]    ${OF}
230     Clean Mininet System
231     ${mininet_conn_id1}=    Open Connection    ${MININET}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
232     Set Suite Variable    ${mininet_conn_id1}
233     Login With Public Key    ${MININET_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
234     Execute Command    sudo ovs-vsctl set-manager ptcp:6644
235     Put File    ${CURDIR}/${CREATE_VLAN_TOPOLOGY_FILE_PATH}
236     Run Keyword If    '${OF}' == 'OF13'    Write    ${vlan_topo_13}
237     ...    ELSE IF    '${OF}' == 'OF10'    Write    ${vlan_topo_10}
238     ${result}    Read Until    mininet>
239
240 Add a vlanmap
241     [Arguments]    ${vtn_name}    ${vBridge_name}    ${vlanmap_data}
242     [Documentation]    Create a vlanmap
243     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/vlanmaps/    data=${vlanmap_data}    headers=${HEADERS}
244     Should Be Equal As Strings    ${resp.status_code}    201
245
246 Get flow
247     [Arguments]    ${vtn_name}
248     [Documentation]    Get data flow.
249     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT_VTNS}/${vtn_name}/flows/detail
250     Should Be Equal As Strings    ${resp.status_code}    200
251
252 Remove a portmap
253     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${portmap_data}
254     [Documentation]    Remove a portmap for a interface of a vbridge
255     ${json_data}=    json.dumps    ${portmap_data}
256     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/portmap    data=${json_data}    headers=${HEADERS}
257     Should Be Equal As Strings    ${resp.status_code}    200
258
259 Verify FlowMacAddress
260     [Arguments]    ${host1}    ${host2}    ${OF_VERSION}
261     [Documentation]    Verify the source and destination mac address.
262     Run Keyword If    '${OF_VERSION}' == 'OF10'    Verify Flows On OpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF10}
263     ...    ELSE    VerifyFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF13}
264
265 Verify Flows On OpenFlow
266     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
267     [Documentation]    Verify the mac addresses on the specified open flow.
268     ${booleanValue}=    Run Keyword And Return Status    Verify macaddress    ${host1}    ${host2}    ${DUMPFLOWS}
269     Should Be Equal As Strings    ${booleanValue}    True
270
271 Verify RemovedFlowMacAddress
272     [Arguments]    ${host1}    ${host2}    ${OF_VERSION}
273     [Documentation]    Verify the removed source and destination mac address.
274     Run Keyword If    '${OF_VERSION}' == 'OF10'    Verify Removed Flows On OpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF10}
275     ...    ELSE    VerifyRemovedFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF13}
276
277 Verify Removed Flows On OpenFlow
278     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
279     [Documentation]    Verify the removed mac addresses on the specified open flow.
280     ${booleanValue}=    Run Keyword And Return Status    Verify macaddress    ${host1}    ${host2}    ${DUMPFLOWS}
281     Should Not Be Equal As Strings    ${booleanValue}    True
282
283 Verify macaddress
284     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
285     [Documentation]    Verify the source and destination mac address after ping in the dumpflows
286     write    ${host1} ifconfig -a | grep HWaddr
287     ${sourcemacaddr}    Read Until    mininet>
288     ${macaddress}=    Split String    ${sourcemacaddr}    ${SPACE}
289     ${sourcemacaddr}=    Get from List    ${macaddress}    ${index}
290     ${sourcemacaddress}=    Convert To Lowercase    ${sourcemacaddr}
291     write    ${host2} ifconfig -a | grep HWaddr
292     ${destmacaddr}    Read Until    mininet>
293     ${macaddress}=    Split String    ${destmacaddr}    ${SPACE}
294     ${destmacaddr}=    Get from List    ${macaddress}    ${index}
295     ${destmacaddress}=    Convert To Lowercase    ${destmacaddr}
296     write    ${DUMPFLOWS}
297     ${result}    Read Until    mininet>
298     Should Contain    ${result}    ${sourcemacaddress}
299     Should Contain    ${result}    ${destmacaddress}
300
301 Add a flowcondition
302     [Arguments]    ${cond_name}    ${flowcond_data}
303     [Documentation]    Create a flowcondition for a interface of a vbridge
304     ${json_data}=    json.dumps    ${flowcond_data}
305     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT}/flowconditions/${cond_name}    data=${json_data}    headers=${HEADERS}
306     Should Be Equal As Strings    ${resp.status_code}    201
307
308 Delete a flowcondition
309     [Arguments]    ${cond_name}
310     [Documentation]    Delete a flowcondition for a interface of a vbridge
311     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT}/flowconditions/${cond_name}
312     Should Be Equal As Strings    ${resp.status_code}    200
313
314 Add a flowfilter
315     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${flowfilter_data}    ${ff_index}
316     [Documentation]    Create a flowfilter for a vtn
317     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/flowfilters/IN/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
318     Should Be Equal As Strings    ${resp.status_code}    201
319
320 Add a flowfilter_vtn
321     [Arguments]    ${vtn_name}    ${flowfilter_data}    ${ff_index}
322     [Documentation]    Create a flowfilter for a vtn
323     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/flowfilters/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
324     Should Be Equal As Strings    ${resp.status_code}    201
325
326 Add a flowfilter_vbr
327     [Arguments]    ${vtn_name}    ${vBridge_name}    ${flowfilter_data}    ${ff_index}
328     [Documentation]    Create a flowfilter for a vbr
329     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/flowfilters/IN/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
330     Should Be Equal As Strings    ${resp.status_code}    201
331
332 Update a flowfilter
333     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${flowfilter_data}    ${ff_index}
334     [Documentation]    Create a flowfilter for a vtn
335     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/flowfilters/IN/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
336     Should Be Equal As Strings    ${resp.status_code}    200
337
338 Add a flowfilter for drop
339     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${flowfilter_data}    ${ff_index}
340     [Documentation]    Create a flowfilter for a vtn
341     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/flowfilters/IN/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
342     Should Be Equal As Strings    ${resp.status_code}    200
343
344 Verify Flow Entry for Inet Flowfilter
345     [Documentation]    Verify switch flow entry using flowfilter for a vtn
346     ${booleanValue}=    Run Keyword And Return Status    Verify Actions on Flow Entry
347     Should Not Be Equal As Strings    ${booleanValue}    True
348
349 Verify Removed Flow Entry for Inet Drop Flowfilter
350     [Documentation]    Verify removed switch flow entry using flowfilter drop for a vtn
351     ${booleanValue}=    Run Keyword And Return Status    Verify Actions on Flow Entry
352     Should Be Equal As Strings    ${booleanValue}    True
353
354 Verify Actions on Flow Entry
355     write    ${DUMPFLOWS_OF13}
356     ${result}    Read Until    mininet>
357     : FOR    ${flowElement}    IN    @{FLOWELMENTS}
358     \    should Contain    ${result}    ${flowElement}