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}
75 [Arguments] ${version} ${mode} ${ip} ${port}=64999 ${node}=127.0.0.1 ${state}=on
76 ... ${session}=session ${domain}=global
77 [Documentation] Verify that connection is ON
78 ${resp} = Get Connections ${node} ${session} ${domain}
79 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
82 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${session}=session ${domain}=global ${origin}=LOCAL
83 [Documentation] Based on ODL version decide if bindings will be added with or without origin type (introduced in Fluorine)
84 CompareStream.Run_Keyword_If_At_Least_Fluorine Add Bindings Fluorine ${sgt} ${prefixes} ${node} ${session} ${domain}
86 CompareStream.Run_Keyword_If_At_Most_Oxygen Add Bindings Oxygen ${sgt} ${prefixes} ${node} ${session} ${domain}
89 [Arguments] ${sgt} ${prefixes} ${node} ${session} ${domain} ${origin}
90 [Documentation] Add/Update one or more bindings with origin type via RPC to Master DB of the node
91 ${data} = Sxp.Add Bindings Xml Fluorine ${node} ${domain} ${sgt} ${prefixes} ${origin}
92 Post To Controller ${session} add-bindings ${data}
95 [Arguments] ${sgt} ${prefixes} ${node} ${session} ${domain}
96 [Documentation] Add/Update one or more bindings without origin type via RPC to Master DB of the node
97 ${data} = Sxp.Add Bindings Xml Oxygen ${node} ${domain} ${sgt} ${prefixes}
98 Post To Controller ${session} add-bindings ${data}
101 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=all
102 [Documentation] Gets all binding via RPC from Master DB of node
103 ${data} = Sxp.Get Bindings From Node Xml ${node} ${scope} ${domain}
104 ${resp} = TemplatedRequests.Post_To_Uri ${REST_CONTEXT}:get-node-bindings data=${data} accept=${ACCEPT_JSON} content_type=${HEADERS_XML} session=${session}
108 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=local
109 [Documentation] Delete all bindings via RPC from Master DB of node
110 ${resp} = Get Bindings ${node} ${session} ${domain} ${scope}
111 @{bindings} = Sxp.Parse Bindings ${resp}
112 : FOR ${binding} IN @{bindings}
113 \ @{prefixes_list} = collections.Get From Dictionary ${binding} ip-prefix
114 \ ${prefixes} = BuiltIn.Catenate SEPARATOR=, @{prefixes_list}
115 \ Delete Bindings ${binding['sgt']} ${prefixes} ${node} ${domain} ${session}
118 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${domain}=global ${session}=session
119 [Documentation] Delete one or more bindings via RPC from Master DB of node
120 ${data} = Sxp.Delete Bindings Xml ${node} ${domain} ${sgt} ${prefixes}
121 Post To Controller ${session} delete-bindings ${data}
124 [Arguments] ${name} ${peers}= ${node}=127.0.0.1 ${session}=session
125 [Documentation] Adds new PeerGroup via RPC to Node
126 ${data} = Sxp.Add Peer Group Xml ${name} ${peers} ${node}
127 Post To Controller ${session} add-peer-group ${data}
130 [Arguments] ${name} ${node}=127.0.0.1 ${session}=session
131 [Documentation] Delete PeerGroup via RPC from Node
132 ${data} = Sxp.Delete Peer Group Xml ${name} ${node}
133 Post To Controller ${session} delete-peer-group ${data}
136 [Arguments] ${node}=127.0.0.1 ${session}=session
137 [Documentation] Gets all PeerGroups via RPC from node
138 ${data} = Sxp.Get Peer Groups From Node Xml ${node}
139 ${resp} = RequestsLibrary.Post Request ${session} ${REST_CONTEXT}:get-peer-groups data=${data} headers=${HEADERS_XML}
140 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
141 [Return] ${resp.content}
144 [Arguments] ${node}=127.0.0.1 ${session}=session
145 [Documentation] Delete all PeerGroups via RPC from node
146 ${resp} = Get Peer Groups ${node} ${session}
147 @{prefixes} = Sxp.Parse Peer Groups ${resp}
148 : FOR ${group} IN @{prefixes}
149 \ Delete Peer Group ${group['name']} ${node} ${session}
152 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session ${policy}=auto-update
153 [Documentation] Add Filter via RPC from Node
154 ${data} = Prepare Add/Update Filter Data ${name} ${type} ${entries} ${node} ${policy}
155 Post To Controller ${session} add-filter ${data}
158 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session ${policy}=auto-update
159 [Documentation] Update Filter via RPC
160 ${data} = Prepare Add/Update Filter Data ${name} ${type} ${entries} ${node} ${policy}
161 Post To Controller ${session} update-filter ${data}
163 Prepare Add/Update Filter Data
164 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${policy}=auto-update
165 [Documentation] Prepare XML payload for add-filter and update-filter RPCs. Payloads for both RPCs are the same.
166 ${data} = CompareStream.Run_Keyword_If_At_Least_Else carbon Add Filter Xml ${name} ${type} ${entries}
167 ... ${node} ${policy}
168 ... ELSE Add Filter Xml ${name} ${type} ${entries} ${node}
172 [Arguments] ${name} ${domains} ${entries} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
173 [Documentation] Add Domain Filter via RPC from Node
174 ${data} = Sxp.Add Domain Filter Xml ${name} ${domains} ${entries} ${node} ${filter_name}
175 Post To Controller ${session} add-domain-filter ${data}
178 [Arguments] ${name} ${type} ${node}=127.0.0.1 ${session}=session
179 [Documentation] Delete Filter via RPC from Node
180 ${data} = Sxp.Delete Filter Xml ${name} ${type} ${node}
181 Post To Controller ${session} delete-filter ${data}
184 [Arguments] ${name} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
185 [Documentation] Delete Filter via RPC from Node
186 ${data} = Sxp.Delete Domain Filter Xml ${name} ${node} ${filter_name}
187 Post To Controller ${session} delete-domain-filter ${data}
189 Should Contain Binding
190 [Arguments] ${resp} ${sgt} ${prefix}
191 [Documentation] Tests if data contains specified binding
192 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
193 BuiltIn.Should Be True ${out} Doesn't have ${sgt} ${prefix}
195 Should Not Contain Binding
196 [Arguments] ${resp} ${sgt} ${prefix}
197 [Documentation] Tests if data doesn't contains specified binding
198 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
199 BuiltIn.Should Not Be True ${out} Should't have ${sgt} ${prefix}
201 Should Contain Connection
202 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
203 [Documentation] Test if data contains specified connection
204 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
206 BuiltIn.Should Be True ${out} Doesn't have ${ip}:${port} ${mode} ${version} in state ${state}
208 Should Not Contain Connection
209 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
210 [Documentation] Test if data doesn't contains specified connection
211 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
213 BuiltIn.Should Not Be True ${out} Shouldn't have ${ip}:${port} ${mode} ${version}
215 Bindings Should Contain
216 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
217 [Documentation] Retrieves bindings and verifies they contain given binding
218 ${resp} = Get Bindings domain=${domain} scope=${scope}
219 Should Contain Binding ${resp} ${sgt} ${prefix}
221 Bindings Should Not Contain
222 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
223 [Documentation] Retrieves bindings and verifies they do not contain given binding
224 ${resp} = Get Bindings domain=${domain} scope=${scope}
225 Should Not Contain Binding ${resp} ${sgt} ${prefix}
227 Connections Should Contain
228 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
229 [Documentation] Retrieves connections and verifies they contain given connection
230 ${resp} = Get Connections
231 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
233 Connections Should Not Contain
234 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
235 [Documentation] Retrieves connections and verifies they do not contain given connection
236 ${resp} = Get Connections
237 Should Not Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
239 Setup Topology Complex
240 [Arguments] ${version}=version4 ${password}=none
241 : FOR ${node} IN RANGE 2 6
242 \ Add Connection ${version} both 127.0.0.1 64999 127.0.0.${node}
244 \ Add Connection ${version} both 127.0.0.${node} 64999 127.0.0.1
246 \ BuiltIn.Wait Until Keyword Succeeds 15 1 Verify Connection ${version} both
247 \ ... 127.0.0.${node}
248 \ Add Bindings ${node}0 10.10.10.${node}0/32 127.0.0.${node}
249 \ Add Bindings ${node}0 10.10.${node}0.0/24 127.0.0.${node}
250 \ Add Bindings ${node}0 10.${node}0.0.0/16 127.0.0.${node}
251 \ Add Bindings ${node}0 ${node}0.0.0.0/8 127.0.0.${node}
252 Add Bindings 10 10.10.10.10/32 127.0.0.1
253 Add Bindings 10 10.10.10.0/24 127.0.0.1
254 Add Bindings 10 10.10.0.0/16 127.0.0.1
255 Add Bindings 10 10.0.0.0/8 127.0.0.1
257 Verify Snapshot Was Pushed
258 [Arguments] ${snapshot_string}=22-sxp-controller-one-node.xml
259 [Documentation] Will succeed if the ${snapshot_string} is found in the karaf logs
260 ${output} = Utils.Run Command On Controller ${ODL_SYSTEM_IP} cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
261 BuiltIn.Should Not Be Equal As Strings ${output} 0
264 [Arguments] ${domain_name} ${sgt}=None ${prefixes}=None ${origin}=LOCAL ${node}=127.0.0.1 ${session}=session
265 [Documentation] Based on ODL version decide if domain's bindings will be added with or without origin type (introduced in Fluorine)
266 CompareStream.Run_Keyword_If_At_Least_Fluorine Add Domain Fluorine ${domain_name} ${sgt} ${prefixes} ${origin} ${node}
268 CompareStream.Run_Keyword_If_At_Most_Oxygen Add Domain Oxygen ${domain_name} ${sgt} ${prefixes} ${node} ${session}
271 [Arguments] ${domain_name} ${sgt} ${prefixes} ${origin} ${node} ${session}
272 [Documentation] Add Domain with bindings (with origin) via RPC
273 ${data} = Sxp.Add Domain Xml Fluorine ${node} ${domain_name} ${sgt} ${prefixes} ${origin}
274 Post To Controller ${session} add-domain ${data}
277 [Arguments] ${domain_name} ${sgt} ${prefixes} ${node} ${session}
278 [Documentation] Add Domain with bindings (without origin) via RPC
279 ${data} = Sxp.Add Domain Xml Oxygen ${node} ${domain_name} ${sgt} ${prefixes}
280 Post To Controller ${session} add-domain ${data}
283 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
284 [Documentation] Delete Domain via RPC
285 ${data} = Sxp.Delete Domain Xml ${node} ${domain_name}
286 Post To Controller ${session} delete-domain ${data}
289 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
290 [Documentation] Add Bindings to Node specified by range
291 ${prefixes} = Sxp.Prefix Range ${start} ${size}
292 Add Bindings ${sgt} ${prefixes} ${node}
294 Delete Bindings Range
295 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
296 [Documentation] Delete Bindings to Node specified by range
297 ${prefixes} = Sxp.Prefix Range ${start} ${size}
298 Delete Bindings ${sgt} ${prefixes} ${node}
301 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
302 [Documentation] Check if Node contains Bindings specified by range
303 ${resp} = Get Bindings ${node}
304 : FOR ${num} IN RANGE ${start} ${end}
305 \ ${ip} = Sxp.Get Ip From Number ${num}
306 \ Should Contain Binding ${resp} ${sgt} ${ip}/32
308 Check Binding Range Negative
309 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
310 [Documentation] Check if Node does not contains Bindings specified by range
311 ${resp} = Get Bindings ${node}
312 : FOR ${num} IN RANGE ${start} ${end}
313 \ ${ip} = Sxp.Get Ip From Number ${num}
314 \ Should Not Contain Binding ${resp} ${sgt} ${ip}/32
316 Setup SXP Environment
317 [Arguments] ${node_range}=1
318 [Documentation] Create session to Controller, ${node_range} parameter specifies number of localhost nodes to be created on ${ODL_SYSTEM_IP}.
319 RequestsLibrary.Create Session session http://${ODL_SYSTEM_IP}:${RESTCONFPORT} auth=${AUTH} timeout=${DEFAULT_TIMEOUT_HTTP} max_retries=0
320 : FOR ${num} IN RANGE 1 ${node_range}+1
321 \ ${node} = Sxp.Get Ip From Number ${num}
322 \ Add Node ${node} retry_open_timer=${num}
323 \ BuiltIn.Wait Until Keyword Succeeds 20 1 Check Node Started ${node} system=${ODL_SYSTEM_IP}
326 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
327 [Documentation] Verify that SxpNode has data writen to Operational datastore and is running
328 ${resp} = RequestsLibrary.Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
329 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
330 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
331 BuiltIn.Should Be Equal As Strings ${rc} 0
334 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
335 [Documentation] Verify that SxpNode has data removed from Operational datastore and is not running
336 ${resp} = RequestsLibrary.Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
337 BuiltIn.Should Be Equal As Strings ${resp.status_code} 404
338 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
339 BuiltIn.Should Be Equal As Strings ${rc} 1
341 Get Node Running Status
342 [Arguments] ${node} ${port} ${system} ${session} ${ip}
343 [Documentation] Get status if node is running by checking that netty server is running
344 ${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}
347 Clean SXP Environment
348 [Arguments] ${node_range}=1
349 [Documentation] Destroy created sessions
350 : FOR ${num} IN RANGE 1 ${node_range}+1
351 \ ${ip} = Sxp.Get Ip From Number ${num}
353 \ BuiltIn.Wait Until Keyword Succeeds 12x 10s Check Node Stopped ${ip} system=${ODL_SYSTEM_IP}
354 RequestsLibrary.Delete All Sessions
356 Get Routing Configuration From Controller
357 [Arguments] ${session}
358 [Documentation] Get Routing configuration from config DS
359 ${resp} = RequestsLibrary.Get Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ headers=${ACCEPT_XML}
360 ${data} = BuiltIn.Set Variable If "${resp.status_code}" == "200" ${resp.content} ${EMPTY}
363 Put Routing Configuration To Controller
364 [Arguments] ${data} ${session}
365 [Documentation] Put Routing configuration to Config DS
366 ${resp} = RequestsLibrary.Put Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ data=${data} headers=${HEADERS_XML}
368 BuiltIn.Should Match "${resp.status_code}" "20?"
370 Clean Routing Configuration To Controller
371 [Arguments] ${session}
372 [Documentation] Delete Routing configuration from Config DS
373 ${resp} = RequestsLibrary.Get Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ headers=${ACCEPT_XML}
374 BuiltIn.Run Keyword If "${resp.status_code}" == "200" RequestsLibrary.Delete Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/