Cleanup of SXP libraries
[integration/test.git] / csit / libraries / SxpLib.robot
1 *** Settings ***
2 Documentation     Library containing Keywords used for SXP testing
3 Library           Collections
4 Library           RequestsLibrary
5 Library           SSHLibrary
6 Library           String
7 Library           ./Sxp.py
8 Resource          KarafKeywords.robot
9 Resource          Utils.robot
10 Variables         ../variables/Variables.py
11
12 *** Variables ***
13 ${REST_CONTEXT}    /restconf/operations/sxp-controller
14
15 *** Keywords ***
16 Post To Controller
17     [Arguments]    ${session}    ${path}    ${DATA}
18     [Documentation]    Post request to Controller and checks response
19     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:${path}    data=${DATA}    headers=${HEADERS_XML}
20     Log    ${resp.content}
21     Log    ${session}
22     Log    ${path}
23     Log    ${DATA}
24     Should be Equal As Strings    ${resp.status_code}    200
25     ${content}    Evaluate    json.loads('''${resp.content}''')    json
26     ${content}    Get From Dictionary    ${content}    output
27     ${content}    Get From Dictionary    ${content}    result
28     Should Be True    ${content}
29
30 Add Node
31     [Arguments]    ${node}    ${password}=${EMPTY}    ${version}=version4    ${port}=64999    ${session}=session    ${ip}=${EMPTY}
32     [Documentation]    Add node via RPC to ODL
33     ${DATA}    Add Node Xml    ${node}    ${port}    ${password}    ${version}    ${ip}
34     Post To Controller    ${session}    add-node    ${DATA}
35
36 Delete Node
37     [Arguments]    ${node}    ${session}=session
38     [Documentation]    Delete connection via RPC from node
39     ${DATA}    Delete Node Xml    ${node}
40     Post To Controller    ${session}    delete-node    ${DATA}
41
42 Add Connection
43     [Arguments]    ${version}    ${mode}    ${ip}    ${port}    ${node}=127.0.0.1    ${password}=${EMPTY}
44     ...    ${session}=session    ${domain}=global
45     [Documentation]    Add connection via RPC to node
46     ${DATA}    Add Connection Xml    ${version}    ${mode}    ${ip}    ${port}    ${node}
47     ...    ${password}    ${domain}
48     Post To Controller    ${session}    add-connection    ${DATA}
49
50 Get Connections
51     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
52     [Documentation]    Gets all connections via RPC from node
53     ${DATA}    Get Connections From Node Xml    ${node}    ${domain}
54     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:get-connections    data=${DATA}    headers=${HEADERS_XML}
55     Should be Equal As Strings    ${resp.status_code}    200
56     [Return]    ${resp.content}
57
58 Delete Connections
59     [Arguments]    ${ip}    ${port}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
60     [Documentation]    Delete connection via RPC from node
61     ${DATA}    Delete Connections Xml    ${ip}    ${port}    ${node}    ${domain}
62     Post To Controller    ${session}    delete-connection    ${DATA}
63
64 Clean Connections
65     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
66     [Documentation]    Delete all connections via RPC from node
67     ${resp}    Get Connections    ${node}    ${session}    ${domain}
68     @{connections}    Parse Connections    ${resp}
69     : FOR    ${connection}    IN    @{connections}
70     \    Delete Connections    ${connection['peer-address']}    ${connection['tcp-port']}    ${node}    ${session}    ${domain}
71
72 Verify Connection
73     [Arguments]    ${version}    ${mode}    ${ip}    ${port}=64999    ${node}=127.0.0.1    ${state}=on
74     ...    ${session}=session    ${domain}=global
75     [Documentation]    Verify that connection is ON
76     ${resp}    Get Connections    ${node}    ${session}    ${domain}
77     Should Contain Connection    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}
78
79 Add Binding
80     [Arguments]    ${sgt}    ${prefix}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
81     [Documentation]    Add binding via RPC to Master DB of node
82     ${DATA}    Add Entry Xml    ${sgt}    ${prefix}    ${node}    ${domain}
83     Post To Controller    ${session}    add-entry    ${DATA}
84
85 Get Bindings
86     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global    ${scope}=all
87     [Documentation]    Gets all binding via RPC from Master DB of node
88     ${DATA}    Get Bindings From Node Xml    ${node}    ${scope}    ${domain}
89     ${resp}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Post Request    ${session}    ${REST_CONTEXT}:get-node-bindings    data=${DATA}
90     ...    headers=${HEADERS_XML}
91     ...    ELSE    Get Request    ${session}    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/master-database/    headers=${HEADERS_XML}
92     Should be Equal As Strings    ${resp.status_code}    200
93     [Return]    ${resp.content}
94
95 Clean Bindings
96     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
97     [Documentation]    Delete all bindings via RPC from Master DB of node
98     ${resp}    Get Bindings    ${node}    ${session}    ${domain}    local
99     @{bindings}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Parse Bindings    ${resp}
100     ...    ELSE    Parse Prefix Groups    ${resp}    local
101     : FOR    ${binding}    IN    @{bindings}
102     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Clean Binding    ${binding['sgt']}    ${binding['ip-prefix']}    ${node}
103     \    ...    ${session}    ${domain}
104     \    ...    ELSE    Clean Binding    ${binding}    ${binding['binding']}    ${node}
105     \    ...    ${session}    ${domain}
106
107 Clean Binding
108     [Arguments]    ${sgt}    ${prefixes}    ${node}    ${session}    ${domain}=global
109     [Documentation]    Used for nester FOR loop
110     : FOR    ${prefix}    IN    @{prefixes}
111     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Delete Binding    ${sgt}    ${prefix}    ${node}
112     \    ...    ${domain}    ${session}
113     \    ...    ELSE    Delete Binding    ${sgt['sgt']}    ${prefix['ip-prefix']}    ${node}
114     \    ...    ${domain}    ${session}
115
116 Update Binding
117     [Arguments]    ${sgtOld}    ${prefixOld}    ${sgtNew}    ${prefixNew}    ${node}=127.0.0.1    ${session}=session
118     ...    ${domain}=global
119     [Documentation]    Updates value of binding via RPC in Master DB of node
120     ${DATA}    Update Binding Xml    ${sgtOld}    ${prefixOld}    ${sgtNew}    ${prefixNew}    ${node}
121     ...    ${domain}
122     Post To Controller    ${session}    update-entry    ${DATA}
123
124 Delete Binding
125     [Arguments]    ${sgt}    ${prefix}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
126     [Documentation]    Delete binding via RPC from Master DB of node
127     ${DATA}    Delete Binding Xml    ${sgt}    ${prefix}    ${node}    ${domain}
128     Post To Controller    ${session}    delete-entry    ${DATA}
129
130 Add PeerGroup
131     [Arguments]    ${name}    ${peers}=    ${node}=127.0.0.1    ${session}=session
132     [Documentation]    Adds new PeerGroup via RPC to Node
133     ${DATA}    Add Peer Group Xml    ${name}    ${peers}    ${node}
134     Post To Controller    ${session}    add-peer-group    ${DATA}
135
136 Delete Peer Group
137     [Arguments]    ${name}    ${node}=127.0.0.1    ${session}=session
138     [Documentation]    Delete PeerGroup via RPC from Node
139     ${DATA}    Delete Peer Group Xml    ${name}    ${node}
140     Post To Controller    ${session}    delete-peer-group    ${DATA}
141
142 Get Peer Groups
143     [Arguments]    ${node}=127.0.0.1    ${session}=session
144     [Documentation]    Gets all PeerGroups via RPC from node
145     ${DATA}    Get Peer Groups From Node Xml    ${node}
146     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:get-peer-groups    data=${DATA}    headers=${HEADERS_XML}
147     Should be Equal As Strings    ${resp.status_code}    200
148     [Return]    ${resp.content}
149
150 Clean Peer Groups
151     [Arguments]    ${node}=127.0.0.1    ${session}=session
152     [Documentation]    Delete all PeerGroups via RPC from node
153     ${resp}    Get Peer Groups    ${node}    ${session}
154     @{prefixes}    Parse Peer Groups    ${resp}
155     : FOR    ${group}    IN    @{prefixes}
156     \    Delete Peer Group    ${group['name']}    ${node}    ${session}
157
158 Add Filter
159     [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${session}=session
160     [Documentation]    Add Filter via RPC from Node
161     ${DATA}    Add Filter Xml    ${name}    ${type}    ${entries}    ${node}
162     Post To Controller    ${session}    add-filter    ${DATA}
163
164 Add Domain Filter
165     [Arguments]    ${name}    ${domains}    ${entries}    ${node}=127.0.0.1    ${filter_name}=base-domain-filter    ${session}=session
166     [Documentation]    Add Domain Filter via RPC from Node
167     ${DATA}    Add Domain Filter Xml    ${name}    ${domains}    ${entries}    ${node}    ${filter_name}
168     Post To Controller    ${session}    add-domain-filter    ${DATA}
169
170 Delete Filter
171     [Arguments]    ${name}    ${type}    ${node}=127.0.0.1    ${session}=session
172     [Documentation]    Delete Filter via RPC from Node
173     ${DATA}    Delete Filter Xml    ${name}    ${type}    ${node}
174     Post To Controller    ${session}    delete-filter    ${DATA}
175
176 Delete Domain Filter
177     [Arguments]    ${name}    ${node}=127.0.0.1    ${filter_name}=base-domain-filter    ${session}=session
178     [Documentation]    Delete Filter via RPC from Node
179     ${DATA}    Delete Domain Filter Xml    ${name}    ${node}    ${filter_name}
180     Post To Controller    ${session}    delete-domain-filter    ${DATA}
181
182 Should Contain Binding
183     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
184     [Documentation]    Tests if data contains specified binding
185     ${out}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Find Binding    ${resp}    ${sgt}    ${prefix}
186     ...    ELSE    Find Binding Legacy    ${resp}    ${sgt}    ${prefix}    ${db_source}
187     ...    add
188     Should Be True    ${out}    Doesn't have ${sgt} ${prefix}
189
190 Should Not Contain Binding
191     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
192     [Documentation]    Tests if data doesn't contains specified binding
193     ${out}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Find Binding    ${resp}    ${sgt}    ${prefix}
194     ...    ELSE    Find Binding Legacy    ${resp}    ${sgt}    ${prefix}    ${db_source}
195     ...    add
196     Should Not Be True    ${out}    Should't have ${sgt} ${prefix}
197
198 Should Contain Connection
199     [Arguments]    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
200     [Documentation]    Test if data contains specified connection
201     ${out}    Find Connection    ${resp}    ${version}    ${mode}    ${ip}    ${port}
202     ...    ${state}
203     Should Be True    ${out}    Doesn't have ${ip}:${port} ${mode} ${version}
204
205 Should Not Contain Connection
206     [Arguments]    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
207     [Documentation]    Test if data doesn't contains specified connection
208     ${out}    Find Connection    ${resp}    ${version}    ${mode}    ${ip}    ${port}
209     ...    ${state}
210     Should Not Be True    ${out}    Shouldn't have ${ip}:${port} ${mode} ${version}
211
212 Setup Topology Complex
213     [Arguments]    ${version}=version4    ${PASSWORD}=none
214     : FOR    ${node}    IN RANGE    2    6
215     \    Add Connection    ${version}    both    127.0.0.1    64999    127.0.0.${node}
216     \    ...    ${PASSWORD}
217     \    Add Connection    ${version}    both    127.0.0.${node}    64999    127.0.0.1
218     \    ...    ${PASSWORD}
219     \    Wait Until Keyword Succeeds    15    1    Verify Connection    ${version}    both
220     \    ...    127.0.0.${node}
221     \    Add Binding    ${node}0    10.10.10.${node}0/32    127.0.0.${node}
222     \    Add Binding    ${node}0    10.10.${node}0.0/24    127.0.0.${node}
223     \    Add Binding    ${node}0    10.${node}0.0.0/16    127.0.0.${node}
224     \    Add Binding    ${node}0    ${node}0.0.0.0/8    127.0.0.${node}
225     Add Binding    10    10.10.10.10/32    127.0.0.1
226     Add Binding    10    10.10.10.0/24    127.0.0.1
227     Add Binding    10    10.10.0.0/16    127.0.0.1
228     Add Binding    10    10.0.0.0/8    127.0.0.1
229
230 Verify Snapshot Was Pushed
231     [Arguments]    ${snapshot_string}=22-sxp-controller-one-node.xml
232     [Documentation]    Will succeed if the ${snapshot_string} is found in the karaf logs
233     ${output}    Run Command On Controller    ${ODL_SYSTEM_IP}    cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
234     Should Not Be Equal As Strings    ${output}    0
235
236 Setup SXP Session
237     [Arguments]    ${session}=session    ${controller}=${ODL_SYSTEM_IP}
238     [Documentation]    Create session to Controller
239     Verify Feature Is Installed    odl-sxp-controller    ${controller}
240     Create Session    ${session}    url=http://${controller}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
241     ${resp}    RequestsLibrary.Get Request    ${session}    ${MODULES_API}
242     Should Be Equal As Strings    ${resp.status_code}    200
243     Should Contain    ${resp.content}    ietf-restconf
244
245 Clean SXP Session
246     [Documentation]    Destroy created sessions
247     Delete All Sessions
248
249 Add Domain
250     [Arguments]    ${domain_name}    ${node}=127.0.0.1    ${session}=session
251     [Documentation]    Add Domain via RPC
252     ${DATA}    Add Domain Xml    ${node}    ${domain_name}
253     Post To Controller    ${session}    add-domain    ${DATA}
254
255 Delete Domain
256     [Arguments]    ${domain_name}    ${node}=127.0.0.1    ${session}=session
257     [Documentation]    Delete Domain via RPC
258     ${DATA}    Delete Domain Xml    ${node}    ${domain_name}
259     Post To Controller    ${session}    delete-domain    ${DATA}
260
261 Add Bindings
262     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
263     [Documentation]    Add bindings via RPC to Master DB of node
264     ${DATA}    Add Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}
265     Post To Controller    ${session}    add-bindings    ${DATA}
266
267 Delete Bindings
268     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
269     [Documentation]    Delete bindings via RPC from Master DB of node
270     ${DATA}    Delete Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}
271     Post To Controller    ${session}    delete-bindings    ${DATA}
272
273 Add Bindings Range
274     [Arguments]    ${sgt}    ${start}    ${size}    ${node}=127.0.0.1
275     [Documentation]    Add Bindings to Node specified by range
276     ${prefixes}    Prefix Range    ${start}    ${size}
277     Add Bindings    ${sgt}    ${prefixes}    ${node}
278
279 Delete Bindings Range
280     [Arguments]    ${sgt}    ${start}    ${size}    ${node}=127.0.0.1
281     [Documentation]    Delete Bindings to Node specified by range
282     ${prefixes}    Prefix Range    ${start}    ${size}
283     Delete Bindings    ${sgt}    ${prefixes}    ${node}
284
285 Check Binding Range
286     [Arguments]    ${sgt}    ${start}    ${end}    ${node}=127.0.0.1
287     [Documentation]    Check if Node contains Bindings specified by range
288     ${resp}    Get Bindings    ${node}
289     : FOR    ${num}    IN RANGE    ${start}    ${end}
290     \    ${ip}    Get Ip From Number    ${num}
291     \    Should Contain Binding    ${resp}    ${sgt}    ${ip}/32
292
293 Check Binding Range Negative
294     [Arguments]    ${sgt}    ${start}    ${end}    ${node}=127.0.0.1
295     [Documentation]    Check if Node does not contains Bindings specified by range
296     ${resp}    Get Bindings    ${node}
297     : FOR    ${num}    IN RANGE    ${start}    ${end}
298     \    ${ip}    Get Ip From Number    ${num}
299     \    Should Not Contain Binding    ${resp}    ${sgt}    ${ip}/32
300
301 Setup SXP Environment
302     [Arguments]    ${node_range}=2
303     [Documentation]    Create session to Controller, node_range parameter specifies number of nodes to be created plus one
304     Setup SXP Session
305     : FOR    ${num}    IN RANGE    1    ${node_range}
306     \    ${ip}    Get Ip From Number    ${num}
307     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Add Node    ${ip}
308     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Wait Until Keyword Succeeds    20    1    Check Node Started
309     \    ...    ${ip}
310
311 Check Node Started
312     [Arguments]    ${node}    ${port}=64999    ${system}=${ODL_SYSTEM_IP}    ${session}=session    ${ip}=${node}
313     [Documentation]    Verify that SxpNode has data writed to Operational datastore
314     ${resp}    RequestsLibrary.Get Request    ${session}    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
315     Should Be Equal As Strings    ${resp.status_code}    200
316     ${rc}    Run Command On Remote System    ${system}    netstat -tln | grep -q ${ip}:${port} && echo 0 || echo 1    ${ODL_SYSTEM_USER}    ${ODL_SYSTEM_PASSWORD}    prompt=${ODL_SYSTEM_PROMPT}
317     Should Be Equal As Strings    ${rc}    0
318
319 Clean SXP Environment
320     [Arguments]    ${node_range}=2
321     [Documentation]    Destroy created sessions
322     : FOR    ${num}    IN RANGE    1    ${node_range}
323     \    ${ip}    Get Ip From Number    ${num}
324     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Delete Node    ${ip}
325     Clean SXP Session