Fix for VTN Manager CSIT test failures for Beryllium.
[integration/test.git] / csit / libraries / VtnMaKeywords.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=${ODL_SYSTEM_IP} --custom vlan_vtn_test.py --topo vlantopo
13 ${vlan_topo_13}    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --custom vlan_vtn_test.py --topo vlantopo --switch ovsk,protocols=OpenFlow13
14 ${VERSION_VTN}    controller/nb/v2/vtn/version
15 ${VTN_INVENTORY}    restconf/operational/vtn-inventory:vtn-nodes
16 ${DUMPFLOWS_OF10}    dpctl dump-flows -O OpenFlow10
17 ${DUMPFLOWS_OF13}    dpctl dump-flows -O OpenFlow13
18 ${index}          7
19 @{inet_actions}    nw_src=10.0.0.1    nw_dst=10.0.0.3
20 @{BRIDGE1_DATAFLOW}    "reason":"PORTMAPPED"    "tenant-name":"Tenant1"    "bridge-name":"vBridge1"    "interface-name":"if2"
21 @{BRIDGE2_DATAFLOW}    "reason":"PORTMAPPED"    "tenant-name":"Tenant1"    "bridge-name":"vBridge2"    "interface-name":"if3"
22 ${vlanmap_bridge1}    200
23 ${vlanmap_bridge2}    300
24 @{VLANMAP_BRIDGE1_DATAFLOW}    "reason":"VLANMAPPED"    "tenant-name":"Tenant1"    "bridge-name":"vBridge1_vlan"
25 @{VLANMAP_BRIDGE2_DATAFLOW}    "reason":"VLANMAPPED"    "tenant-name":"Tenant1"    "bridge-name":"vBridge2_vlan"
26 ${out_before_pathpolicy}    output:2
27 ${out_after_pathpolicy}    output:3
28 ${pathpolicy_topo_13}    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --custom topo-3sw-2host_multipath.py --topo pathpolicytopo --switch ovsk,protocols=OpenFlow13
29 ${pathpolicy_topo_10}    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --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 ${in_port}        1
33 ${dscp_action}    set_field:32->nw_tos_shifted
34 ${dscp_flow}      mod_nw_tos:128
35 @{icmp_action}    nw_src=10.0.0.1    nw_dst=10.0.0.3
36 @{PATHPOLICY_ATTR}    "id":1    "port-desc":"openflow:4,2,s4-eth2"
37 ${custom}         ${CURDIR}/${CREATE_PATHPOLICY_TOPOLOGY_FILE_PATH}
38
39 *** Keywords ***
40 Start SuiteVtnMa
41     [Documentation]    Start VTN Manager Rest Config Api Test Suite
42     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
43     BuiltIn.Wait_Until_Keyword_Succeeds    30    3    Fetch vtn list
44     Start Suite
45
46 Start SuiteVtnMaTest
47     [Documentation]    Start VTN Manager Test Suite
48     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
49
50 Stop SuiteVtnMa
51     [Documentation]    Stop VTN Manager Test Suite
52     Delete All Sessions
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 Request    session    restconf/operational/vtn: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 Request    session    restconf/operational/vtn-inventory:vtn-nodes/vtn-node/${sw_name}
67     Should Be Equal As Strings    ${resp.status_code}    200
68
69 Add a Vtn
70     [Arguments]    ${vtn_name}
71     [Documentation]    Create a vtn with specified parameters.
72     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn:update-vtn    data={"input": {"tenant-name":${vtn_name}, "update-mode": "CREATE","operation": "SET", "description": "creating vtn", "idle-timeout":300, "hard-timeout":0}}
73     Should Be Equal As Strings    ${resp.status_code}    200
74
75 Add a vBridge
76     [Arguments]    ${vtn_name}    ${vbr_name}
77     [Documentation]    Create a vBridge in a VTN
78     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-vbridge:update-vbridge    data={"input": {"update-mode": "CREATE","operation":"SET", "tenant-name":${vtn_name}, "bridge-name":${vbr_name}, "description": "vbrdige created"}}
79     Should Be Equal As Strings    ${resp.status_code}    200
80
81 Add a interface
82     [Arguments]    ${vtn_name}    ${vbr_name}    ${interface_name}
83     [Documentation]    Create a interface into a vBridge of a VTN
84     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-vinterface:update-vinterface    data={"input": {"update-mode":"CREATE","operation":"SET", "tenant-name":${vtn_name}, "bridge-name":${vbr_name}, "description": "vbrdige interfacecreated", "enabled":"true", "interface-name": ${interface_name}}}
85     Should Be Equal As Strings    ${resp.status_code}    200
86
87 Add a portmap
88     [Arguments]    ${vtn_name}    ${vbr_name}    ${interface_name}    ${node_id}    ${port_id}
89     [Documentation]    Create a portmap for a interface of a vbridge
90     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-port-map:set-port-map    data={"input": { "tenant-name":${vtn_name}, "bridge-name":${vbr_name}, "interface-name": ${interface_name}, "node":"${node_id}", "port-name":"${port_id}"}}
91     Should Be Equal As Strings    ${resp.status_code}    200
92
93 Delete a Vtn
94     [Arguments]    ${vtn_name}
95     [Documentation]    Delete a vtn with specified parameters.
96     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn:remove-vtn    data={"input": {"tenant-name":${vtn_name}}}
97     Should Be Equal As Strings    ${resp.status_code}    200
98
99 Add a vlanmap
100     [Arguments]    ${vtn_name}    ${vbr_name}    ${vlan_id}
101     [Documentation]    Create a vlanmap
102     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-vlan-map:add-vlan-map    data={"input": {"tenant-name":${vtn_name},"bridge-name":${vbr_name},"vlan-id":${vlan_id}}}
103     Should Be Equal As Strings    ${resp.status_code}    200
104
105 Verify Data Flows
106     [Arguments]    ${vtn_name}    ${vBridge_name}
107     [Documentation]    Verify the reason and physical data flows for the specified vtn and vbridge
108     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow:get-data-flow    data={"input":{"tenant-name":"${vtn_name}","mode":"UPDATESTATS"}}
109     Run Keyword If    '${vBridge_name}' == 'vBridge1'    DataFlowsForBridge    ${resp}    @{BRIDGE1_DATAFLOW}
110     ...    ELSE IF    '${vBridge_name}' == 'vBridge2'    DataFlowsForBridge    ${resp}    @{BRIDGE2_DATAFLOW}
111     ...    ELSE IF    '${vBridge_name}' == 'vBridge1_vlan'    DataFlowsForBridge    ${resp}    @{VLANMAP_BRIDGE1_DATAFLOW}
112     ...    ELSE    DataFlowsForBridge    ${resp}    @{VLANMAP_BRIDGE2_DATAFLOW}
113
114 Start PathSuiteVtnMaTest
115     [Documentation]    Start VTN Manager Test Suite and Mininet
116     Start SuiteVtnMaTest
117     Start Mininet    ${TOOLS_SYSTEM_IP}    ${pathpolicy_topo_13}    ${custom}
118
119 Start PathSuiteVtnMaTestOF10
120     [Documentation]    Start VTN Manager Test Suite and Mininet in Open Flow 10 Specification
121     Start SuiteVtnMaTest
122     Start Mininet    ${TOOLS_SYSTEM_IP}    ${pathpolicy_topo_10}    ${custom}
123
124 Stop PathSuiteVtnMaTest
125     [Documentation]    Cleanup/Shutdown work at the completion of all tests.
126     Delete All Sessions
127     Stop Mininet    ${mininet_conn_id}
128
129 DataFlowsForBridge
130     [Arguments]    ${resp}    @{BRIDGE_DATAFLOW}
131     [Documentation]    Verify whether the required attributes exists.
132     : FOR    ${dataflowElement}    IN    @{BRIDGE_DATAFLOW}
133     \    should Contain    ${resp.content}    ${dataflowElement}
134
135 Add a pathmap
136     [Arguments]    ${pathmap_data}
137     [Documentation]    Create a pathmap for a vtn
138     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-path-map:set-path-map    data=${pathmap_data}
139     Should Be Equal As Strings    ${resp.status_code}    200
140
141 Get a pathmap
142     [Documentation]    Get a pathmap for a vtn.
143     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-path-map:global-path-maps
144     : FOR    ${pathElement}    IN    @{PATHMAP_ATTR}
145     \    should Contain    ${resp.content}    ${pathElement}
146
147 Add a pathpolicy
148     [Arguments]    ${pathpolicy_data}
149     [Documentation]    Create a pathpolicy for a vtn
150     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-path-policy:set-path-policy    data=${pathpolicy_data}
151     Should Be Equal As Strings    ${resp.status_code}    200
152
153 Get a pathpolicy
154     [Arguments]    ${pathpolicy_id}
155     [Documentation]    Get a pathpolicy for a vtn.
156     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-path-policy:vtn-path-policies/vtn-path-policy/${pathpolicy_id}
157     : FOR    ${pathpolicyElement}    IN    @{PATHPOLICY_ATTR}
158     \    should Contain    ${resp.content}    ${pathpolicyElement}
159
160 Delete a pathmap
161     [Arguments]    ${tenant_path}
162     [Documentation]    Remove a pathmap for a vtn
163     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-path-map:remove-path-map    data={"input":{"tenant-name":"${tenant_path}","map-index":["${policy_id}"]}}
164     Should Be Equal As Strings    ${resp.status_code}    200
165
166 Delete a pathpolicy
167     [Arguments]    ${policy_id}
168     [Documentation]    Delete a pathpolicy for a vtn
169     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-path-policy:remove-path-policy    data={"input":{"id":"${policy_id}"}}
170     Should Be Equal As Strings    ${resp.status_code}    200
171
172 Verify flowEntryPathPolicy
173     [Arguments]    ${of_version}    ${port}    ${output}
174     [Documentation]    Checking Flows on switch S1 and switch S3 after applying path policy
175     ${DUMPFLOWS}=    Set Variable If    "${of_version}"=="OF10"    ${DUMPFLOWS_OF10}    ${DUMPFLOWS_OF13}
176     write    ${DUMPFLOWS}
177     ${result}    Read Until    mininet>
178     Should Contain    ${result}    in_port=${port}    actions=${output}
179
180 Add a macmap
181     [Arguments]    ${vtn_name}    ${vBridge_name}    ${src_add}    ${dst_add}
182     [Documentation]    Create a macmap for a vbridge
183     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-mac-map:set-mac-map    data={"input":{"operation":"SET","allowed-hosts":["${dst_add}@0","${src_add}@0"],"tenant-name":"${vtn_name}","bridge-name":"${vBridge_name}"}}
184     Should Be Equal As Strings    ${resp.status_code}    200
185
186 Get DynamicMacAddress
187     [Arguments]    ${h}
188     [Documentation]    Get Dynamic mac address of Host
189     write    ${h} ifconfig -a | grep HWaddr
190     ${source}    Read Until    mininet>
191     ${HWaddress}=    Split String    ${source}    ${SPACE}
192     ${sourceHWaddr}=    Get from List    ${HWaddress}    ${index}
193     ${sourceHWaddress}=    Convert To Lowercase    ${sourceHWaddr}
194     Return From Keyword    ${sourceHWaddress}    # Also [Return] would work here.
195
196 Mininet Ping Should Succeed
197     [Arguments]    ${host1}    ${host2}
198     [Documentation]    Ping hosts to check connectivity
199     Write    ${host1} ping -c 1 ${host2}
200     ${result}    Read Until    mininet>
201     Should Contain    ${result}    64 bytes
202
203 Mininet Ping Should Not Succeed
204     [Arguments]    ${host1}    ${host2}
205     [Documentation]    Ping hosts when there is no connectivity and check hosts is unreachable
206     Write    ${host1} ping -c 3 ${host2}
207     ${result}    Read Until    mininet>
208     Should Not Contain    ${result}    64 bytes
209
210 Start vlan_topo
211     [Arguments]    ${OF}
212     [Documentation]    Create custom topology for vlan functionality
213     Clean Mininet System
214     ${mininet_conn_id1}=    Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
215     Set Suite Variable    ${mininet_conn_id1}
216     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
217     Execute Command    sudo ovs-vsctl set-manager ptcp:6644
218     Put File    ${CURDIR}/${CREATE_VLAN_TOPOLOGY_FILE_PATH}
219     Run Keyword If    '${OF}' == 'OF13'    Write    ${vlan_topo_13}
220     ...    ELSE IF    '${OF}' == 'OF10'    Write    ${vlan_topo_10}
221     ${result}    Read Until    mininet>
222
223 Get flow
224     [Arguments]    ${vtn_name}
225     [Documentation]    Get data flow.
226     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-flow-impl:vtn-flows/vtn-flow-table/${vtn_name}
227     Should Be Equal As Strings    ${resp.status_code}    200
228
229 Remove a portmap
230     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}
231     [Documentation]    Remove a portmap for a interface of a vbridge
232     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-port-map:remove-port-map    data={"input": {"tenant-name":${vtn_name},"bridge-name":${vBridge_name},"interface-name":${interface_name}}}
233     Should Be Equal As Strings    ${resp.status_code}    200
234
235 Verify FlowMacAddress
236     [Arguments]    ${host1}    ${host2}    ${OF_VERSION}
237     [Documentation]    Verify the source and destination mac address.
238     Run Keyword If    '${OF_VERSION}' == 'OF10'    Verify Flows On OpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF10}
239     ...    ELSE    VerifyFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF13}
240
241 Verify Flows On OpenFlow
242     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
243     [Documentation]    Verify the mac addresses on the specified open flow.
244     ${booleanValue}=    Run Keyword And Return Status    Verify macaddress    ${host1}    ${host2}    ${DUMPFLOWS}
245     Should Be Equal As Strings    ${booleanValue}    True
246
247 Verify RemovedFlowMacAddress
248     [Arguments]    ${host1}    ${host2}    ${OF_VERSION}
249     [Documentation]    Verify the removed source and destination mac address.
250     Run Keyword If    '${OF_VERSION}' == 'OF10'    Verify Removed Flows On OpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF10}
251     ...    ELSE    VerifyRemovedFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF13}
252
253 Verify Removed Flows On OpenFlow
254     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
255     [Documentation]    Verify the removed mac addresses on the specified open flow.
256     ${booleanValue}=    Run Keyword And Return Status    Verify macaddress    ${host1}    ${host2}    ${DUMPFLOWS}
257     Should Not Be Equal As Strings    ${booleanValue}    True
258
259 Verify macaddress
260     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
261     [Documentation]    Verify the source and destination mac address after ping in the dumpflows
262     write    ${host1} ifconfig -a | grep HWaddr
263     ${sourcemacaddr}    Read Until    mininet>
264     ${macaddress}=    Split String    ${sourcemacaddr}    ${SPACE}
265     ${sourcemacaddr}=    Get from List    ${macaddress}    ${index}
266     ${sourcemacaddress}=    Convert To Lowercase    ${sourcemacaddr}
267     write    ${host2} ifconfig -a | grep HWaddr
268     ${destmacaddr}    Read Until    mininet>
269     ${macaddress}=    Split String    ${destmacaddr}    ${SPACE}
270     ${destmacaddr}=    Get from List    ${macaddress}    ${index}
271     ${destmacaddress}=    Convert To Lowercase    ${destmacaddr}
272     write    ${DUMPFLOWS}
273     ${result}    Read Until    mininet>
274     Should Contain    ${result}    ${sourcemacaddress}
275     Should Contain    ${result}    ${destmacaddress}
276
277 Verify flowactions
278     [Arguments]    ${actions}    ${DUMPFLOWS}
279     [Documentation]    Verify the flowfilter actions after ping in the dumpflows
280     write    ${DUMPFLOWS}
281     ${result}    Read Until    mininet>
282     Should Contain    ${result}    ${actions}
283
284 Add a vtn flowfilter
285     [Arguments]    ${vtn_name}    ${vtnflowfilter_data}
286     [Documentation]    Create a flowfilter for a vtn
287     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-filter:set-flow-filter    data={"input": {"tenant-name": "${vtn_name}",${vtnflowfilter_data}}}
288     Should Be Equal As Strings    ${resp.status_code}    200
289
290 Add a vbr flowfilter
291     [Arguments]    ${vtn_name}    ${vBridge_name}    ${vbrflowfilter_data}
292     [Documentation]    Create a flowfilter for a vbr
293     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-filter:set-flow-filter    data={"input": {"tenant-name": "${vtn_name}", "bridge-name": "${vBridge_name}", ${vbrflowfilter_data}}}
294     Should Be Equal As Strings    ${resp.status_code}    200
295
296 Add a vbrif flowfilter
297     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${vbrif_flowfilter_data}
298     [Documentation]    Create a flowfilter for a vbrif
299     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-filter:set-flow-filter    data={"input": {"tenant-name": ${vtn_name}, "bridge-name": "${vBridge_name}","interface-name":"${interface_name}",${vbrif_flowfilter_data}}}
300     Should Be Equal As Strings    ${resp.status_code}    200
301
302 Verify Flow Entries for Flowfilter
303     [Arguments]    ${dumpflows}    @{flowfilter_actions}
304     [Documentation]    Verify switch flow entry using flowfilter for a vtn
305     ${booleanValue}=    Run Keyword And Return Status    Verify Actions on Flow Entry    ${dumpflows}    @{flowfilter_actions}
306     Should Be Equal As Strings    ${booleanValue}    True
307
308 Verify Removed Flow Entry for Inet Drop Flowfilter
309     [Arguments]    ${dumpflows}    @{flowfilter_actions}
310     [Documentation]    Verify removed switch flow entry using flowfilter drop for a vtn
311     ${booleanValue}=    Run Keyword And Return Status    Verify Actions on Flow Entry    ${dumpflows}    @{flowfilter_actions}
312     Should Be Equal As Strings    ${booleanValue}    True
313
314 Verify Actions on Flow Entry
315     [Arguments]    ${dumpflows}    @{flowfilter_actions}
316     [Documentation]    check flow action elements by giving dumpflows in mininet
317     write    ${dumpflows}
318     ${result}    Read Until    mininet>
319     : FOR    ${flowElement}    IN    @{flowfilter_actions}
320     \    should Contain    ${result}    ${flowElement}
321
322 Add a flowcondition
323     [Arguments]    ${flowcond_name}    ${flowconditiondata}
324     [Documentation]    Create a flowcondition using Restconfig Api
325     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-condition:set-flow-condition    data={"input":{"operation":"SET","present":"false","name":"${flowcond_name}",${flowconditiondata}}}
326     Should Be Equal As Strings    ${resp.status_code}    200
327
328 Get flowconditions
329     [Documentation]    Retrieve the list of flowconditions created
330     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-flow-condition:vtn-flow-conditions
331     Should Be Equal As Strings    ${resp.status_code}    200
332
333 Get flowcondition
334     [Arguments]    ${flowcond_name}    ${retrieve}
335     [Documentation]    Retrieve the flowcondition by name and to check the removed flowcondition we added "retrieve" argument to differentiate the status code,
336     ...    since after removing flowcondition name the status will be different compare to status code when the flowcondition name is present.
337     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-flow-condition:vtn-flow-conditions/vtn-flow-condition/${flowcond_name}
338     Run Keyword If    '${retrieve}' == 'retrieve'    Should Be Equal As Strings    ${resp.status_code}    200
339     ...    ELSE    Should Not Be Equal As Strings    ${resp.status_code}    200
340
341 Remove flowcondition
342     [Arguments]    ${flowcond_name}
343     [Documentation]    Remove the flowcondition by name
344     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-condition:remove-flow-condition    data={"input":{"name":"${flowcond_name}"}}
345     Should Be Equal As Strings    ${resp.status_code}    200