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}=${EMPTY}
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} = CompareStream.Run_Keyword_If_At_Least_Else carbon Add Filter Xml ${name} ${type} ${entries}
155 ... ${node} ${policy}
156 ... ELSE Add Filter Xml ${name} ${type} ${entries} ${node}
157 Post To Controller ${session} add-filter ${data}
160 [Arguments] ${name} ${domains} ${entries} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
161 [Documentation] Add Domain Filter via RPC from Node
162 ${data} = Sxp.Add Domain Filter Xml ${name} ${domains} ${entries} ${node} ${filter_name}
163 Post To Controller ${session} add-domain-filter ${data}
166 [Arguments] ${name} ${type} ${node}=127.0.0.1 ${session}=session
167 [Documentation] Delete Filter via RPC from Node
168 ${data} = Sxp.Delete Filter Xml ${name} ${type} ${node}
169 Post To Controller ${session} delete-filter ${data}
172 [Arguments] ${name} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
173 [Documentation] Delete Filter via RPC from Node
174 ${data} = Sxp.Delete Domain Filter Xml ${name} ${node} ${filter_name}
175 Post To Controller ${session} delete-domain-filter ${data}
177 Should Contain Binding
178 [Arguments] ${resp} ${sgt} ${prefix}
179 [Documentation] Tests if data contains specified binding
180 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
181 BuiltIn.Should Be True ${out} Doesn't have ${sgt} ${prefix}
183 Should Not Contain Binding
184 [Arguments] ${resp} ${sgt} ${prefix}
185 [Documentation] Tests if data doesn't contains specified binding
186 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
187 BuiltIn.Should Not Be True ${out} Should't have ${sgt} ${prefix}
189 Should Contain Connection
190 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
191 [Documentation] Test if data contains specified connection
192 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
194 BuiltIn.Should Be True ${out} Doesn't have ${ip}:${port} ${mode} ${version}
196 Should Not Contain Connection
197 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
198 [Documentation] Test if data doesn't contains specified connection
199 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
201 BuiltIn.Should Not Be True ${out} Shouldn't have ${ip}:${port} ${mode} ${version}
203 Bindings Should Contain
204 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
205 [Documentation] Retrieves bindings and verifies they contain given binding
206 ${resp} = Get Bindings domain=${domain} scope=${scope}
207 Should Contain Binding ${resp} ${sgt} ${prefix}
209 Bindings Should Not Contain
210 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
211 [Documentation] Retrieves bindings and verifies they do not contain given binding
212 ${resp} = Get Bindings domain=${domain} scope=${scope}
213 Should Not Contain Binding ${resp} ${sgt} ${prefix}
215 Connections Should Contain
216 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
217 [Documentation] Retrieves connections and verifies they contain given connection
218 ${resp} = Get Connections
219 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
221 Connections Should Not Contain
222 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
223 [Documentation] Retrieves connections and verifies they do not contain given connection
224 ${resp} = Get Connections
225 Should Not Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
227 Setup Topology Complex
228 [Arguments] ${version}=version4 ${password}=none
229 : FOR ${node} IN RANGE 2 6
230 \ Add Connection ${version} both 127.0.0.1 64999 127.0.0.${node}
232 \ Add Connection ${version} both 127.0.0.${node} 64999 127.0.0.1
234 \ BuiltIn.Wait Until Keyword Succeeds 15 1 Verify Connection ${version} both
235 \ ... 127.0.0.${node}
236 \ Add Bindings ${node}0 10.10.10.${node}0/32 127.0.0.${node}
237 \ Add Bindings ${node}0 10.10.${node}0.0/24 127.0.0.${node}
238 \ Add Bindings ${node}0 10.${node}0.0.0/16 127.0.0.${node}
239 \ Add Bindings ${node}0 ${node}0.0.0.0/8 127.0.0.${node}
240 Add Bindings 10 10.10.10.10/32 127.0.0.1
241 Add Bindings 10 10.10.10.0/24 127.0.0.1
242 Add Bindings 10 10.10.0.0/16 127.0.0.1
243 Add Bindings 10 10.0.0.0/8 127.0.0.1
245 Verify Snapshot Was Pushed
246 [Arguments] ${snapshot_string}=22-sxp-controller-one-node.xml
247 [Documentation] Will succeed if the ${snapshot_string} is found in the karaf logs
248 ${output} = Utils.Run Command On Controller ${ODL_SYSTEM_IP} cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
249 BuiltIn.Should Not Be Equal As Strings ${output} 0
251 Prepare SSH Keys On Karaf
252 [Arguments] ${system}=${ODL_SYSTEM_IP} ${user}=${ODL_SYSTEM_USER} ${passwd}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT} ${system_workspace}=${WORKSPACE}
253 [Documentation] Executes client login on karaf VM in so that SSH keys will be generated by defualt karaf callback,
254 ... expecting echo affter succesfull login. TODO: test on multiple runs if this aproach reduce SSHExceptions in robotframework
255 ${stdout} = Utils.Run Command On Remote System ${system} ${system_workspace}${/}${BUNDLEFOLDER}/bin/client echo READY ${user} ${passwd} prompt=${prompt}
256 BuiltIn.Should Match "${stdout}" "*READY"
259 [Arguments] ${session}=session ${controller}=${ODL_SYSTEM_IP}
260 [Documentation] Create session to Controller
261 KarafKeywords.Verify Feature Is Installed odl-sxp-controller ${controller}
262 RequestsLibrary.Create Session ${session} url=http://${controller}:${RESTCONFPORT} auth=${AUTH} headers=${HEADERS_XML}
263 ${resp} = RequestsLibrary.Get Request ${session} ${MODULES_API}
264 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
265 BuiltIn.Should Contain ${resp.content} ietf-restconf
268 [Documentation] Destroy created sessions
269 RequestsLibrary.Delete All Sessions
272 [Arguments] ${domain_name} ${sgt}=None ${prefixes}=None ${origin}=LOCAL ${node}=127.0.0.1 ${session}=session
273 [Documentation] Based on ODL version decide if domain's bindings will be added with or without origin type (introduced in Fluorine)
274 CompareStream.Run_Keyword_If_At_Least_Fluorine Add Domain Fluorine ${domain_name} ${sgt} ${prefixes} ${origin} ${node}
276 CompareStream.Run_Keyword_If_At_Most_Oxygen Add Domain Oxygen ${domain_name} ${sgt} ${prefixes} ${node} ${session}
279 [Arguments] ${domain_name} ${sgt} ${prefixes} ${origin} ${node} ${session}
280 [Documentation] Add Domain with bindings (with origin) via RPC
281 ${data} = Sxp.Add Domain Xml Fluorine ${node} ${domain_name} ${sgt} ${prefixes} ${origin}
282 Post To Controller ${session} add-domain ${data}
285 [Arguments] ${domain_name} ${sgt} ${prefixes} ${node} ${session}
286 [Documentation] Add Domain with bindings (without origin) via RPC
287 ${data} = Sxp.Add Domain Xml Oxygen ${node} ${domain_name} ${sgt} ${prefixes}
288 Post To Controller ${session} add-domain ${data}
291 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
292 [Documentation] Delete Domain via RPC
293 ${data} = Sxp.Delete Domain Xml ${node} ${domain_name}
294 Post To Controller ${session} delete-domain ${data}
297 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
298 [Documentation] Add Bindings to Node specified by range
299 ${prefixes} = Sxp.Prefix Range ${start} ${size}
300 Add Bindings ${sgt} ${prefixes} ${node}
302 Delete Bindings Range
303 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
304 [Documentation] Delete Bindings to Node specified by range
305 ${prefixes} = Sxp.Prefix Range ${start} ${size}
306 Delete Bindings ${sgt} ${prefixes} ${node}
309 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
310 [Documentation] Check if Node 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 Contain Binding ${resp} ${sgt} ${ip}/32
316 Check Binding Range Negative
317 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
318 [Documentation] Check if Node does not contains Bindings specified by range
319 ${resp} = Get Bindings ${node}
320 : FOR ${num} IN RANGE ${start} ${end}
321 \ ${ip} = Sxp.Get Ip From Number ${num}
322 \ Should Not Contain Binding ${resp} ${sgt} ${ip}/32
324 Setup SXP Environment
325 [Arguments] ${node_range}=2
326 [Documentation] Create session to Controller, node_range parameter specifies number of nodes to be created plus one
328 : FOR ${num} IN RANGE 1 ${node_range}
329 \ ${ip} = Sxp.Get Ip From Number ${num}
330 \ ${rnd_retry_time} = BuiltIn.Evaluate random.randint(1, 10) modules=random
331 \ Add Node ${ip} retry_open_timer=${rnd_retry_time}
332 \ BuiltIn.Wait Until Keyword Succeeds 20 1 Check Node Started ${ip}
335 [Arguments] ${node} ${port}=64999 ${system}=${ODL_SYSTEM_IP} ${session}=session ${ip}=${node}
336 [Documentation] Verify that SxpNode has data writed to Operational datastore
337 ${resp} = RequestsLibrary.Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
338 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
339 ${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}
340 BuiltIn.Should Be Equal As Strings ${rc} 0
342 Clean SXP Environment
343 [Arguments] ${node_range}=2
344 [Documentation] Destroy created sessions
345 : FOR ${num} IN RANGE 1 ${node_range}
346 \ ${ip} = Sxp.Get Ip From Number ${num}
350 Get Routing Configuration From Controller
351 [Arguments] ${session}
352 [Documentation] Get Routing configuration from config DS
353 ${resp} = RequestsLibrary.Get Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ headers=${ACCEPT_XML}
354 ${data} = BuiltIn.Set Variable If "${resp.status_code}" == "200" ${resp.content} ${EMPTY}
357 Put Routing Configuration To Controller
358 [Arguments] ${data} ${session}
359 [Documentation] Put Routing configuration to Config DS
360 ${resp} = RequestsLibrary.Put Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ data=${data} headers=${HEADERS_XML}
361 BuiltIn.Should Match "${resp.status_code}" "20?"
363 Clean Routing Configuration To Controller
364 [Arguments] ${session}
365 [Documentation] Delete Routing configuration from Config DS
366 ${resp} = RequestsLibrary.Get Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ headers=${ACCEPT_XML}
367 BuiltIn.Run Keyword If "${resp.status_code}" == "200" RequestsLibrary.Delete Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/