f80d370e36e41d62e639aa327e8dff5056cc6e44
[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          CompareStream.robot
9 Resource          KarafKeywords.robot
10 Resource          Utils.robot
11 Resource          TemplatedRequests.robot
12 Variables         ../variables/Variables.py
13
14 *** Variables ***
15 ${REST_CONTEXT}    /restconf/operations/sxp-controller
16
17 *** Keywords ***
18 Post To Controller
19     [Arguments]    ${session}    ${path}    ${DATA}
20     [Documentation]    Post request to Controller and checks response
21     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:${path}    data=${DATA}    headers=${HEADERS_XML}
22     Log    ${resp.content}
23     Log    ${session}
24     Log    ${path}
25     Log    ${DATA}
26     Should be Equal As Strings    ${resp.status_code}    200
27     ${content}    Evaluate    json.loads('''${resp.content}''')    json
28     ${content}    Get From Dictionary    ${content}    output
29     ${content}    Get From Dictionary    ${content}    result
30     Should Be True    ${content}
31
32 Add Node
33     [Arguments]    ${node}    ${password}=${EMPTY}    ${version}=version4    ${port}=64999    ${session}=session    ${ip}=${EMPTY}
34     ...    ${ssl_stores}=${EMPTY}    ${retry_open_timer}=1
35     [Documentation]    Add node via RPC to ODL
36     ${DATA}    Add Node Xml    ${node}    ${port}    ${password}    ${version}    ${ip}
37     ...    keystores=${ssl_stores}    retry_open_timer=${retry_open_timer}
38     Post To Controller    ${session}    add-node    ${DATA}
39
40 Delete Node
41     [Arguments]    ${node}    ${session}=session
42     [Documentation]    Delete connection via RPC from node
43     ${DATA}    Delete Node Xml    ${node}
44     Post To Controller    ${session}    delete-node    ${DATA}
45
46 Add Connection
47     [Arguments]    ${version}    ${mode}    ${ip}    ${port}    ${node}=127.0.0.1    ${password}=${EMPTY}
48     ...    ${session}=session    ${domain}=global    ${security_mode}=${EMPTY}
49     [Documentation]    Add connection via RPC to node
50     ${DATA}    Add Connection Xml    ${version}    ${mode}    ${ip}    ${port}    ${node}
51     ...    ${password}    ${domain}    security_mode=${security_mode}
52     Post To Controller    ${session}    add-connection    ${DATA}
53
54 Get Connections
55     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
56     [Documentation]    Gets all connections via RPC from node
57     ${DATA}    Get Connections From Node Xml    ${node}    ${domain}
58     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:get-connections    data=${DATA}    headers=${HEADERS_XML}
59     Should be Equal As Strings    ${resp.status_code}    200
60     [Return]    ${resp.content}
61
62 Delete Connections
63     [Arguments]    ${ip}    ${port}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
64     [Documentation]    Delete connection via RPC from node
65     ${DATA}    Delete Connections Xml    ${ip}    ${port}    ${node}    ${domain}
66     Post To Controller    ${session}    delete-connection    ${DATA}
67
68 Clean Connections
69     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
70     [Documentation]    Delete all connections via RPC from node
71     ${resp}    Get Connections    ${node}    ${session}    ${domain}
72     @{connections}    Parse Connections    ${resp}
73     : FOR    ${connection}    IN    @{connections}
74     \    Delete Connections    ${connection['peer-address']}    ${connection['tcp-port']}    ${node}    ${session}    ${domain}
75
76 Verify Connection
77     [Arguments]    ${version}    ${mode}    ${ip}    ${port}=64999    ${node}=127.0.0.1    ${state}=on
78     ...    ${session}=session    ${domain}=global
79     [Documentation]    Verify that connection is ON
80     ${resp}    Get Connections    ${node}    ${session}    ${domain}
81     Should Contain Connection    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}
82
83 Add Binding
84     [Arguments]    ${sgt}    ${prefix}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
85     [Documentation]    Add binding via RPC to Master DB of node
86     ${DATA}    Add Entry Xml    ${sgt}    ${prefix}    ${node}    ${domain}
87     Post To Controller    ${session}    add-entry    ${DATA}
88
89 Get Bindings
90     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global    ${scope}=all
91     [Documentation]    Gets all binding via RPC from Master DB of node
92     ${DATA}    Get Bindings From Node Xml    ${node}    ${scope}    ${domain}
93     ${resp}    TemplatedRequests.Post_To_Uri    ${REST_CONTEXT}:get-node-bindings    data=${DATA}    accept=${ACCEPT_JSON}    content_type=${HEADERS_XML}    session=${session}
94     [Return]    ${resp}
95
96 Clean Bindings
97     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
98     [Documentation]    Delete all bindings via RPC from Master DB of node
99     ${resp}    Get Bindings    ${node}    ${session}    ${domain}    local
100     @{bindings}    Parse Bindings    ${resp}
101     : FOR    ${binding}    IN    @{bindings}
102     \    Clean Binding Default    ${binding}    ${node}    ${session}    ${domain}
103
104 Clean Binding Default
105     [Arguments]    ${binding}    ${node}    ${session}    ${domain}
106     [Documentation]    Clean binding
107     Clean Binding    ${binding['sgt']}    ${binding['ip-prefix']}    ${node}    ${session}
108
109 Clean Binding At Most Be
110     [Arguments]    ${binding}    ${node}    ${session}    ${domain}
111     [Documentation]    Clean binding
112     Clean Binding    ${binding}    ${binding['binding']}    ${node}    ${session}
113
114 Clean Binding
115     [Arguments]    ${sgt}    ${prefixes}    ${node}    ${session}    ${domain}=global
116     [Documentation]    Used for nester FOR loop
117     : FOR    ${prefix}    IN    @{prefixes}
118     \    Delete Binding Default    ${sgt}    ${prefix}    ${node}    ${domain}    ${session}
119
120 Update Binding
121     [Arguments]    ${sgtOld}    ${prefixOld}    ${sgtNew}    ${prefixNew}    ${node}=127.0.0.1    ${session}=session
122     ...    ${domain}=global
123     [Documentation]    Updates value of binding via RPC in Master DB of node
124     ${DATA}    Update Binding Xml    ${sgtOld}    ${prefixOld}    ${sgtNew}    ${prefixNew}    ${node}
125     ...    ${domain}
126     Post To Controller    ${session}    update-entry    ${DATA}
127
128 Delete Binding Default
129     [Arguments]    ${sgt}    ${prefix}    ${node}    ${domain}    ${session}
130     [Documentation]    Delete binding via RPC
131     Delete Binding    ${sgt}    ${prefix}    ${node}    ${domain}    ${session}
132
133 Delete Binding Be
134     [Arguments]    ${sgt}    ${prefix}    ${node}    ${domain}    ${session}
135     [Documentation]    Delete binding via RPC
136     Delete Binding    ${sgt['sgt']}    ${prefix['ip-prefix']}    ${node}    ${domain}    ${session}
137
138 Delete Binding
139     [Arguments]    ${sgt}    ${prefix}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
140     [Documentation]    Delete binding via RPC from Master DB of node
141     ${DATA}    Delete Binding Xml    ${sgt}    ${prefix}    ${node}    ${domain}
142     Post To Controller    ${session}    delete-entry    ${DATA}
143
144 Add PeerGroup
145     [Arguments]    ${name}    ${peers}=    ${node}=127.0.0.1    ${session}=session
146     [Documentation]    Adds new PeerGroup via RPC to Node
147     ${DATA}    Add Peer Group Xml    ${name}    ${peers}    ${node}
148     Post To Controller    ${session}    add-peer-group    ${DATA}
149
150 Delete Peer Group
151     [Arguments]    ${name}    ${node}=127.0.0.1    ${session}=session
152     [Documentation]    Delete PeerGroup via RPC from Node
153     ${DATA}    Delete Peer Group Xml    ${name}    ${node}
154     Post To Controller    ${session}    delete-peer-group    ${DATA}
155
156 Get Peer Groups
157     [Arguments]    ${node}=127.0.0.1    ${session}=session
158     [Documentation]    Gets all PeerGroups via RPC from node
159     ${DATA}    Get Peer Groups From Node Xml    ${node}
160     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:get-peer-groups    data=${DATA}    headers=${HEADERS_XML}
161     Should be Equal As Strings    ${resp.status_code}    200
162     [Return]    ${resp.content}
163
164 Clean Peer Groups
165     [Arguments]    ${node}=127.0.0.1    ${session}=session
166     [Documentation]    Delete all PeerGroups via RPC from node
167     ${resp}    Get Peer Groups    ${node}    ${session}
168     @{prefixes}    Parse Peer Groups    ${resp}
169     : FOR    ${group}    IN    @{prefixes}
170     \    Delete Peer Group    ${group['name']}    ${node}    ${session}
171
172 Add Filter
173     [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${session}=session    ${policy}=auto-update
174     [Documentation]    Add Filter via RPC from Node
175     ${DATA}    Run_Keyword_If_At_Least_Else    carbon    Add Filter Xml    ${name}    ${type}    ${entries}
176     ...    ${node}    ${policy}
177     ...    ELSE    Add Filter Xml    ${name}    ${type}    ${entries}    ${node}
178     Post To Controller    ${session}    add-filter    ${DATA}
179
180 Add Domain Filter
181     [Arguments]    ${name}    ${domains}    ${entries}    ${node}=127.0.0.1    ${filter_name}=base-domain-filter    ${session}=session
182     [Documentation]    Add Domain Filter via RPC from Node
183     ${DATA}    Add Domain Filter Xml    ${name}    ${domains}    ${entries}    ${node}    ${filter_name}
184     Post To Controller    ${session}    add-domain-filter    ${DATA}
185
186 Delete Filter
187     [Arguments]    ${name}    ${type}    ${node}=127.0.0.1    ${session}=session
188     [Documentation]    Delete Filter via RPC from Node
189     ${DATA}    Delete Filter Xml    ${name}    ${type}    ${node}
190     Post To Controller    ${session}    delete-filter    ${DATA}
191
192 Delete Domain Filter
193     [Arguments]    ${name}    ${node}=127.0.0.1    ${filter_name}=base-domain-filter    ${session}=session
194     [Documentation]    Delete Filter via RPC from Node
195     ${DATA}    Delete Domain Filter Xml    ${name}    ${node}    ${filter_name}
196     Post To Controller    ${session}    delete-domain-filter    ${DATA}
197
198 Should Contain Binding
199     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
200     [Documentation]    Tests if data contains specified binding
201     ${out}    Find Binding    ${resp}    ${sgt}    ${prefix}
202     Should Be True    ${out}    Doesn't have ${sgt} ${prefix}
203
204 Should Not Contain Binding
205     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
206     [Documentation]    Tests if data doesn't contains specified binding
207     ${out}    Find Binding    ${resp}    ${sgt}    ${prefix}
208     Should Not Be True    ${out}    Should't have ${sgt} ${prefix}
209
210 Should Contain Connection
211     [Arguments]    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
212     [Documentation]    Test if data contains specified connection
213     ${out}    Find Connection    ${resp}    ${version}    ${mode}    ${ip}    ${port}
214     ...    ${state}
215     Should Be True    ${out}    Doesn't have ${ip}:${port} ${mode} ${version}
216
217 Should Not Contain Connection
218     [Arguments]    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
219     [Documentation]    Test if data doesn't contains specified connection
220     ${out}    Find Connection    ${resp}    ${version}    ${mode}    ${ip}    ${port}
221     ...    ${state}
222     Should Not Be True    ${out}    Shouldn't have ${ip}:${port} ${mode} ${version}
223
224 Bindings Should Contain
225     [Arguments]    ${sgt}    ${prefix}    ${db_source}=any
226     [Documentation]    Retrieves bindings and verifies they contain given binding
227     ${resp}    Get Bindings
228     Should Contain Binding    ${resp}    ${sgt}    ${prefix}    ${db_source}
229
230 Bindings Should Not Contain
231     [Arguments]    ${sgt}    ${prefix}    ${db_source}=any
232     [Documentation]    Retrieves bindings and verifies they do not contain given binding
233     ${resp}    Get Bindings
234     Should Not Contain Binding    ${resp}    ${sgt}    ${prefix}    ${db_source}
235
236 Connections Should Contain
237     [Arguments]    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
238     [Documentation]    Retrieves connections and verifies they contain given connection
239     ${resp}    Get Connections
240     Should Contain Connection    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}
241
242 Connections Should Not Contain
243     [Arguments]    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
244     [Documentation]    Retrieves connections and verifies they do not contain given connection
245     ${resp}    Get Connections
246     Should Not Contain Connection    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}
247
248 Setup Topology Complex
249     [Arguments]    ${version}=version4    ${PASSWORD}=none
250     : FOR    ${node}    IN RANGE    2    6
251     \    Add Connection    ${version}    both    127.0.0.1    64999    127.0.0.${node}
252     \    ...    ${PASSWORD}
253     \    Add Connection    ${version}    both    127.0.0.${node}    64999    127.0.0.1
254     \    ...    ${PASSWORD}
255     \    Wait Until Keyword Succeeds    15    1    Verify Connection    ${version}    both
256     \    ...    127.0.0.${node}
257     \    Add Binding    ${node}0    10.10.10.${node}0/32    127.0.0.${node}
258     \    Add Binding    ${node}0    10.10.${node}0.0/24    127.0.0.${node}
259     \    Add Binding    ${node}0    10.${node}0.0.0/16    127.0.0.${node}
260     \    Add Binding    ${node}0    ${node}0.0.0.0/8    127.0.0.${node}
261     Add Binding    10    10.10.10.10/32    127.0.0.1
262     Add Binding    10    10.10.10.0/24    127.0.0.1
263     Add Binding    10    10.10.0.0/16    127.0.0.1
264     Add Binding    10    10.0.0.0/8    127.0.0.1
265
266 Verify Snapshot Was Pushed
267     [Arguments]    ${snapshot_string}=22-sxp-controller-one-node.xml
268     [Documentation]    Will succeed if the ${snapshot_string} is found in the karaf logs
269     ${output}    Run Command On Controller    ${ODL_SYSTEM_IP}    cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
270     Should Not Be Equal As Strings    ${output}    0
271
272 Prepare SSH Keys On Karaf
273     [Arguments]    ${system}=${ODL_SYSTEM_IP}    ${user}=${ODL_SYSTEM_USER}    ${passwd}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}    ${system_workspace}=${WORKSPACE}
274     [Documentation]    Executes client login on karaf VM in so that SSH keys will be generated by defualt karaf callback,
275     ...    expecting echo affter succesfull login. TODO: test on multiple runs if this aproach reduce SSHExceptions in robotframework
276     ${stdout}    Run Command On Remote System    ${system}    ${system_workspace}${/}${BUNDLEFOLDER}/bin/client echo READY    ${user}    ${passwd}    prompt=${prompt}
277     Should Match    "${stdout}"    "*READY"
278
279 Setup SXP Session
280     [Arguments]    ${session}=session    ${controller}=${ODL_SYSTEM_IP}
281     [Documentation]    Create session to Controller
282     Verify Feature Is Installed    odl-sxp-controller    ${controller}
283     Create Session    ${session}    url=http://${controller}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
284     ${resp}    RequestsLibrary.Get Request    ${session}    ${MODULES_API}
285     Should Be Equal As Strings    ${resp.status_code}    200
286     Should Contain    ${resp.content}    ietf-restconf
287
288 Clean SXP Session
289     [Documentation]    Destroy created sessions
290     Delete All Sessions
291
292 Add Domain
293     [Arguments]    ${domain_name}    ${node}=127.0.0.1    ${session}=session
294     [Documentation]    Add Domain via RPC
295     ${DATA}    Add Domain Xml    ${node}    ${domain_name}
296     Post To Controller    ${session}    add-domain    ${DATA}
297
298 Delete Domain
299     [Arguments]    ${domain_name}    ${node}=127.0.0.1    ${session}=session
300     [Documentation]    Delete Domain via RPC
301     ${DATA}    Delete Domain Xml    ${node}    ${domain_name}
302     Post To Controller    ${session}    delete-domain    ${DATA}
303
304 Add Bindings
305     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
306     [Documentation]    Add bindings via RPC to Master DB of node
307     ${DATA}    Add Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}
308     Post To Controller    ${session}    add-bindings    ${DATA}
309
310 Delete Bindings
311     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
312     [Documentation]    Delete bindings via RPC from Master DB of node
313     ${DATA}    Delete Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}
314     Post To Controller    ${session}    delete-bindings    ${DATA}
315
316 Add Bindings Range
317     [Arguments]    ${sgt}    ${start}    ${size}    ${node}=127.0.0.1
318     [Documentation]    Add Bindings to Node specified by range
319     ${prefixes}    Prefix Range    ${start}    ${size}
320     Add Bindings    ${sgt}    ${prefixes}    ${node}
321
322 Delete Bindings Range
323     [Arguments]    ${sgt}    ${start}    ${size}    ${node}=127.0.0.1
324     [Documentation]    Delete Bindings to Node specified by range
325     ${prefixes}    Prefix Range    ${start}    ${size}
326     Delete Bindings    ${sgt}    ${prefixes}    ${node}
327
328 Check Binding Range
329     [Arguments]    ${sgt}    ${start}    ${end}    ${node}=127.0.0.1
330     [Documentation]    Check if Node contains Bindings specified by range
331     ${resp}    Get Bindings    ${node}
332     : FOR    ${num}    IN RANGE    ${start}    ${end}
333     \    ${ip}    Get Ip From Number    ${num}
334     \    Should Contain Binding    ${resp}    ${sgt}    ${ip}/32
335
336 Check Binding Range Negative
337     [Arguments]    ${sgt}    ${start}    ${end}    ${node}=127.0.0.1
338     [Documentation]    Check if Node does not contains Bindings specified by range
339     ${resp}    Get Bindings    ${node}
340     : FOR    ${num}    IN RANGE    ${start}    ${end}
341     \    ${ip}    Get Ip From Number    ${num}
342     \    Should Not Contain Binding    ${resp}    ${sgt}    ${ip}/32
343
344 Setup SXP Environment
345     [Arguments]    ${node_range}=2
346     [Documentation]    Create session to Controller, node_range parameter specifies number of nodes to be created plus one
347     Setup SXP Session
348     : FOR    ${num}    IN RANGE    1    ${node_range}
349     \    ${ip}    Get Ip From Number    ${num}
350     \    ${rnd_retry_time} =    Evaluate    random.randint(1, 10)    modules=random
351     \    Add Node    ${ip}    retry_open_timer=${rnd_retry_time}
352     \    Wait Until Keyword Succeeds    20    1    Check Node Started    ${ip}
353
354 Check Node Started
355     [Arguments]    ${node}    ${port}=64999    ${system}=${ODL_SYSTEM_IP}    ${session}=session    ${ip}=${node}
356     [Documentation]    Verify that SxpNode has data writed to Operational datastore
357     ${resp}    RequestsLibrary.Get Request    ${session}    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
358     Should Be Equal As Strings    ${resp.status_code}    200
359     ${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}
360     Should Be Equal As Strings    ${rc}    0
361
362 Clean SXP Environment
363     [Arguments]    ${node_range}=2
364     [Documentation]    Destroy created sessions
365     : FOR    ${num}    IN RANGE    1    ${node_range}
366     \    ${ip}    Get Ip From Number    ${num}
367     \    Delete Node    ${ip}
368     Clean SXP Session
369
370 Get Routing Configuration From Controller
371     [Arguments]    ${session}
372     [Documentation]    Get Routing configuration from config DS
373     ${resp}    RequestsLibrary.Get Request    ${session}    /restconf/config/sxp-cluster-route:sxp-cluster-route/    headers=${ACCEPT_XML}
374     ${data}    Set Variable If    "${resp.status_code}" == "200"    ${resp.content}    ${EMPTY}
375     [Return]    ${data}
376
377 Put Routing Configuration To Controller
378     [Arguments]    ${DATA}    ${session}
379     [Documentation]    Put Routing configuration to Config DS
380     ${resp}    RequestsLibrary.Put Request    ${session}    /restconf/config/sxp-cluster-route:sxp-cluster-route/    data=${DATA}    headers=${HEADERS_XML}
381     Should Match    "${resp.status_code}"    "20?"
382
383 Clean Routing Configuration To Controller
384     [Arguments]    ${session}
385     [Documentation]    Delete Routing configuration from Config DS
386     ${resp}    RequestsLibrary.Get Request    ${session}    /restconf/config/sxp-cluster-route:sxp-cluster-route/    headers=${ACCEPT_XML}
387     Run Keyword If    "${resp.status_code}" == "200"    RequestsLibrary.Delete Request    ${session}    /restconf/config/sxp-cluster-route:sxp-cluster-route/