2 Documentation Library containing Keywords used for SXP testing
4 Library RequestsLibrary
6 Resource CompareStream.robot
7 Resource KarafKeywords.robot
8 Resource TemplatedRequests.robot
10 Resource ../variables/Variables.robot
13 ${REST_CONTEXT} /restconf/operations/sxp-controller
17 [Arguments] ${session} ${path} ${data} ${rest_context}=${REST_CONTEXT}
18 [Documentation] Post request to Controller and checks response
19 ${resp} = RequestsLibrary.Post Request ${session} ${rest_context}:${path} data=${data} headers=${HEADERS_XML}
24 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
25 ${content} = BuiltIn.Evaluate json.loads('''${resp.content}''') json
26 ${output} = collections.Get From Dictionary ${content} output
27 ${result} = collections.Get From Dictionary ${output} result
28 BuiltIn.Should Be True ${result} RPC result is False
31 [Arguments] ${node} ${password}=${EMPTY} ${version}=version4 ${port}=64999 ${session}=session ${ip}=${node}
32 ... ${ssl_stores}=${EMPTY} ${retry_open_timer}=1
33 [Documentation] Add node via RPC to ODL
34 ${data} = Sxp.Add Node Xml ${node} ${port} ${password} ${version} ${ip}
35 ... keystores=${ssl_stores} retry_open_timer=${retry_open_timer}
36 Post To Controller ${session} add-node ${data}
39 [Arguments] ${node} ${session}=session
40 [Documentation] Delete connection via RPC from node
41 ${data} = Sxp.Delete Node Xml ${node}
42 Post To Controller ${session} delete-node ${data}
45 [Arguments] ${version} ${mode} ${ip} ${port} ${node}=127.0.0.1 ${password}=${EMPTY}
46 ... ${session}=session ${domain}=global ${security_mode}=${EMPTY}
47 [Documentation] Add connection via RPC to node
48 ${data} = Sxp.Add Connection Xml ${version} ${mode} ${ip} ${port} ${node}
49 ... ${password} ${domain} security_mode=${security_mode}
50 Post To Controller ${session} add-connection ${data}
53 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
54 [Documentation] Gets all connections via RPC from node
55 ${data} = Sxp.Get Connections From Node Xml ${node} ${domain}
56 ${resp} = RequestsLibrary.Post Request ${session} ${REST_CONTEXT}:get-connections data=${data} headers=${HEADERS_XML}
57 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
58 [Return] ${resp.content}
61 [Arguments] ${ip} ${port} ${node}=127.0.0.1 ${session}=session ${domain}=global
62 [Documentation] Delete connection via RPC from node
63 ${data} = Sxp.Delete Connections Xml ${ip} ${port} ${node} ${domain}
64 Post To Controller ${session} delete-connection ${data}
67 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
68 [Documentation] Delete all connections via RPC from node
69 ${resp} = Get Connections ${node} ${session} ${domain}
70 @{connections} = Sxp.Parse Connections ${resp}
71 FOR ${connection} IN @{connections}
72 Delete Connections ${connection['peer-address']} ${connection['tcp-port']} ${node} ${session} ${domain}
76 [Arguments] ${version} ${mode} ${ip} ${port}=64999 ${node}=127.0.0.1 ${state}=on
77 ... ${session}=session ${domain}=global
78 [Documentation] Verify that connection is ON
79 ${resp} = Get Connections ${node} ${session} ${domain}
80 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
83 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${session}=session ${domain}=global ${origin}=LOCAL
84 [Documentation] Based on ODL version decide if bindings will be added with or without origin type (introduced in Fluorine)
85 CompareStream.Run_Keyword_If_At_Least_Fluorine Add Bindings Fluorine ${sgt} ${prefixes} ${node} ${session} ${domain}
87 CompareStream.Run_Keyword_If_At_Most_Oxygen Add Bindings Oxygen ${sgt} ${prefixes} ${node} ${session} ${domain}
90 [Arguments] ${sgt} ${prefixes} ${node} ${session} ${domain} ${origin}
91 [Documentation] Add/Update one or more bindings with origin type via RPC to Master DB of the node
92 ${data} = Sxp.Add Bindings Xml Fluorine ${node} ${domain} ${sgt} ${prefixes} ${origin}
93 Post To Controller ${session} add-bindings ${data}
96 [Arguments] ${sgt} ${prefixes} ${node} ${session} ${domain}
97 [Documentation] Add/Update one or more bindings without origin type via RPC to Master DB of the node
98 ${data} = Sxp.Add Bindings Xml Oxygen ${node} ${domain} ${sgt} ${prefixes}
99 Post To Controller ${session} add-bindings ${data}
102 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=all
103 [Documentation] Gets all binding via RPC from Master DB of node
104 ${data} = Sxp.Get Bindings From Node Xml ${node} ${scope} ${domain}
105 ${resp} = TemplatedRequests.Post_To_Uri ${REST_CONTEXT}:get-node-bindings data=${data} accept=${ACCEPT_JSON} content_type=${HEADERS_XML} session=${session}
109 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=local
110 [Documentation] Delete all bindings via RPC from Master DB of node
111 ${resp} = Get Bindings ${node} ${session} ${domain} ${scope}
112 @{bindings} = Sxp.Parse Bindings ${resp}
113 FOR ${binding} IN @{bindings}
114 @{prefixes_list} = collections.Get From Dictionary ${binding} ip-prefix
115 ${prefixes} = BuiltIn.Catenate SEPARATOR=, @{prefixes_list}
116 Delete Bindings ${binding['sgt']} ${prefixes} ${node} ${domain} ${session}
120 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${domain}=global ${session}=session
121 [Documentation] Delete one or more bindings via RPC from Master DB of node
122 ${data} = Sxp.Delete Bindings Xml ${node} ${domain} ${sgt} ${prefixes}
123 Post To Controller ${session} delete-bindings ${data}
126 [Arguments] ${name} ${peers}= ${node}=127.0.0.1 ${session}=session
127 [Documentation] Adds new PeerGroup via RPC to Node
128 ${data} = Sxp.Add Peer Group Xml ${name} ${peers} ${node}
129 Post To Controller ${session} add-peer-group ${data}
132 [Arguments] ${name} ${node}=127.0.0.1 ${session}=session
133 [Documentation] Delete PeerGroup via RPC from Node
134 ${data} = Sxp.Delete Peer Group Xml ${name} ${node}
135 Post To Controller ${session} delete-peer-group ${data}
138 [Arguments] ${node}=127.0.0.1 ${session}=session
139 [Documentation] Gets all PeerGroups via RPC from node
140 ${data} = Sxp.Get Peer Groups From Node Xml ${node}
141 ${resp} = RequestsLibrary.Post Request ${session} ${REST_CONTEXT}:get-peer-groups data=${data} headers=${HEADERS_XML}
142 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
143 [Return] ${resp.content}
146 [Arguments] ${node}=127.0.0.1 ${session}=session
147 [Documentation] Delete all PeerGroups via RPC from node
148 ${resp} = Get Peer Groups ${node} ${session}
149 @{prefixes} = Sxp.Parse Peer Groups ${resp}
150 FOR ${group} IN @{prefixes}
151 Delete Peer Group ${group['name']} ${node} ${session}
155 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session ${policy}=auto-update
156 [Documentation] Add Filter via RPC from Node
157 ${data} = Prepare Add/Update Filter Data ${name} ${type} ${entries} ${node} ${policy}
158 Post To Controller ${session} add-filter ${data}
161 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session ${policy}=auto-update
162 [Documentation] Update Filter via RPC
163 ${data} = Prepare Add/Update Filter Data ${name} ${type} ${entries} ${node} ${policy}
164 Post To Controller ${session} update-filter ${data}
166 Prepare Add/Update Filter Data
167 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${policy}=auto-update
168 [Documentation] Prepare XML payload for add-filter and update-filter RPCs. Payloads for both RPCs are the same.
169 ${data} = CompareStream.Run_Keyword_If_At_Least_Else carbon Add Filter Xml ${name} ${type} ${entries}
170 ... ${node} ${policy}
171 ... ELSE Add Filter Xml ${name} ${type} ${entries} ${node}
175 [Arguments] ${name} ${domains} ${entries} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
176 [Documentation] Add Domain Filter via RPC from Node
177 ${data} = Sxp.Add Domain Filter Xml ${name} ${domains} ${entries} ${node} ${filter_name}
178 Post To Controller ${session} add-domain-filter ${data}
181 [Arguments] ${name} ${type} ${node}=127.0.0.1 ${session}=session
182 [Documentation] Delete Filter via RPC from Node
183 ${data} = Sxp.Delete Filter Xml ${name} ${type} ${node}
184 Post To Controller ${session} delete-filter ${data}
187 [Arguments] ${name} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
188 [Documentation] Delete Filter via RPC from Node
189 ${data} = Sxp.Delete Domain Filter Xml ${name} ${node} ${filter_name}
190 Post To Controller ${session} delete-domain-filter ${data}
192 Should Contain Binding
193 [Arguments] ${resp} ${sgt} ${prefix}
194 [Documentation] Tests if data contains specified binding
195 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
196 BuiltIn.Should Be True ${out} Doesn't have ${sgt} ${prefix}
198 Should Not Contain Binding
199 [Arguments] ${resp} ${sgt} ${prefix}
200 [Documentation] Tests if data doesn't contains specified binding
201 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
202 BuiltIn.Should Not Be True ${out} Should't have ${sgt} ${prefix}
204 Should Contain Connection
205 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
206 [Documentation] Test if data contains specified connection
207 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
209 BuiltIn.Should Be True ${out} Doesn't have ${ip}:${port} ${mode} ${version} in state ${state}
211 Should Not Contain Connection
212 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
213 [Documentation] Test if data doesn't contains specified connection
214 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
216 BuiltIn.Should Not Be True ${out} Shouldn't have ${ip}:${port} ${mode} ${version}
218 Bindings Should Contain
219 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
220 [Documentation] Retrieves bindings and verifies they contain given binding
221 ${resp} = Get Bindings domain=${domain} scope=${scope}
222 Should Contain Binding ${resp} ${sgt} ${prefix}
224 Bindings Should Not Contain
225 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
226 [Documentation] Retrieves bindings and verifies they do not contain given binding
227 ${resp} = Get Bindings domain=${domain} scope=${scope}
228 Should Not Contain Binding ${resp} ${sgt} ${prefix}
230 Connections Should Contain
231 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
232 [Documentation] Retrieves connections and verifies they contain given connection
233 ${resp} = Get Connections
234 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
236 Connections Should Not Contain
237 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
238 [Documentation] Retrieves connections and verifies they do not contain given connection
239 ${resp} = Get Connections
240 Should Not Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
242 Setup Topology Complex
243 [Arguments] ${version}=version4 ${password}=none
244 FOR ${node} IN RANGE 2 6
245 Add Connection ${version} both 127.0.0.1 64999 127.0.0.${node}
247 Add Connection ${version} both 127.0.0.${node} 64999 127.0.0.1
249 BuiltIn.Wait Until Keyword Succeeds 15 1 Verify Connection ${version} both
251 Add Bindings ${node}0 10.10.10.${node}0/32 127.0.0.${node}
252 Add Bindings ${node}0 10.10.${node}0.0/24 127.0.0.${node}
253 Add Bindings ${node}0 10.${node}0.0.0/16 127.0.0.${node}
254 Add Bindings ${node}0 ${node}0.0.0.0/8 127.0.0.${node}
256 Add Bindings 10 10.10.10.10/32 127.0.0.1
257 Add Bindings 10 10.10.10.0/24 127.0.0.1
258 Add Bindings 10 10.10.0.0/16 127.0.0.1
259 Add Bindings 10 10.0.0.0/8 127.0.0.1
261 Verify Snapshot Was Pushed
262 [Arguments] ${snapshot_string}=22-sxp-controller-one-node.xml
263 [Documentation] Will succeed if the ${snapshot_string} is found in the karaf logs
264 ${output} = Utils.Run Command On Controller ${ODL_SYSTEM_IP} cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
265 BuiltIn.Should Not Be Equal As Strings ${output} 0
268 [Arguments] ${domain_name} ${sgt}=None ${prefixes}=None ${origin}=LOCAL ${node}=127.0.0.1 ${session}=session
269 [Documentation] Based on ODL version decide if domain's bindings will be added with or without origin type (introduced in Fluorine)
270 CompareStream.Run_Keyword_If_At_Least_Fluorine Add Domain Fluorine ${domain_name} ${sgt} ${prefixes} ${origin} ${node}
272 CompareStream.Run_Keyword_If_At_Most_Oxygen Add Domain Oxygen ${domain_name} ${sgt} ${prefixes} ${node} ${session}
275 [Arguments] ${domain_name} ${sgt} ${prefixes} ${origin} ${node} ${session}
276 [Documentation] Add Domain with bindings (with origin) via RPC
277 ${data} = Sxp.Add Domain Xml Fluorine ${node} ${domain_name} ${sgt} ${prefixes} ${origin}
278 Post To Controller ${session} add-domain ${data}
281 [Arguments] ${domain_name} ${sgt} ${prefixes} ${node} ${session}
282 [Documentation] Add Domain with bindings (without origin) via RPC
283 ${data} = Sxp.Add Domain Xml Oxygen ${node} ${domain_name} ${sgt} ${prefixes}
284 Post To Controller ${session} add-domain ${data}
287 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
288 [Documentation] Delete Domain via RPC
289 ${data} = Sxp.Delete Domain Xml ${node} ${domain_name}
290 Post To Controller ${session} delete-domain ${data}
293 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
294 [Documentation] Add Bindings to Node specified by range
295 ${prefixes} = Sxp.Prefix Range ${start} ${size}
296 Add Bindings ${sgt} ${prefixes} ${node}
298 Delete Bindings Range
299 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
300 [Documentation] Delete Bindings to Node specified by range
301 ${prefixes} = Sxp.Prefix Range ${start} ${size}
302 Delete Bindings ${sgt} ${prefixes} ${node}
305 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
306 [Documentation] Check if Node contains Bindings specified by range
307 ${resp} = Get Bindings ${node}
308 FOR ${num} IN RANGE ${start} ${end}
309 ${ip} = Sxp.Get Ip From Number ${num}
310 Should Contain Binding ${resp} ${sgt} ${ip}/32
313 Check Binding Range Negative
314 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
315 [Documentation] Check if Node does not contains Bindings specified by range
316 ${resp} = Get Bindings ${node}
317 FOR ${num} IN RANGE ${start} ${end}
318 ${ip} = Sxp.Get Ip From Number ${num}
319 Should Not Contain Binding ${resp} ${sgt} ${ip}/32
322 Setup SXP Environment
323 [Arguments] ${node_range}=1
324 [Documentation] Create session to Controller, ${node_range} parameter specifies number of localhost nodes to be created on ${ODL_SYSTEM_IP}.
325 RequestsLibrary.Create Session session http://${ODL_SYSTEM_IP}:${RESTCONFPORT} auth=${AUTH} timeout=${DEFAULT_TIMEOUT_HTTP} max_retries=0
326 FOR ${num} IN RANGE 1 ${node_range}+1
327 ${node} = Sxp.Get Ip From Number ${num}
328 Add Node ${node} retry_open_timer=${num}
329 BuiltIn.Wait Until Keyword Succeeds 20 1 Check Node Started ${node} system=${ODL_SYSTEM_IP}
333 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
334 [Documentation] Verify that SxpNode has data writen to Operational datastore and is running
335 ${resp} = RequestsLibrary.Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
336 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
337 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
338 BuiltIn.Should Be Equal As Strings ${rc} 0
341 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
342 [Documentation] Verify that SxpNode has data removed from Operational datastore and is not running
343 ${resp} = RequestsLibrary.Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
344 BuiltIn.Should Be Equal As Strings ${resp.status_code} 404
345 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
346 BuiltIn.Should Be Equal As Strings ${rc} 1
348 Get Node Running Status
349 [Arguments] ${node} ${port} ${system} ${session} ${ip}
350 [Documentation] Get status if node is running by checking that netty server is running
351 ${rc} = Utils.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}
354 Clean SXP Environment
355 [Arguments] ${node_range}=1
356 [Documentation] Destroy created sessions
357 FOR ${num} IN RANGE 1 ${node_range}+1
358 ${ip} = Sxp.Get Ip From Number ${num}
360 BuiltIn.Wait Until Keyword Succeeds 12x 10s Check Node Stopped ${ip} system=${ODL_SYSTEM_IP}
362 RequestsLibrary.Delete All Sessions
364 Get Routing Configuration From Controller
365 [Arguments] ${session}
366 [Documentation] Get Routing configuration from config DS
367 ${resp} = RequestsLibrary.Get Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ headers=${ACCEPT_XML}
368 ${data} = BuiltIn.Set Variable If "${resp.status_code}" == "200" ${resp.content} ${EMPTY}
371 Put Routing Configuration To Controller
372 [Arguments] ${data} ${session}
373 [Documentation] Put Routing configuration to Config DS
374 ${resp} = RequestsLibrary.Put Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ data=${data} headers=${HEADERS_XML}
376 BuiltIn.Should Match "${resp.status_code}" "20?"
378 Clean Routing Configuration To Controller
379 [Arguments] ${session}
380 [Documentation] Delete Routing configuration from Config DS
381 ${resp} = RequestsLibrary.Get Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ headers=${ACCEPT_XML}
382 BuiltIn.Run Keyword If "${resp.status_code}" == "200" RequestsLibrary.Delete Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/