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} = 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} in state ${state}
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
252 [Arguments] ${domain_name} ${sgt}=None ${prefixes}=None ${origin}=LOCAL ${node}=127.0.0.1 ${session}=session
253 [Documentation] Based on ODL version decide if domain's bindings will be added with or without origin type (introduced in Fluorine)
254 CompareStream.Run_Keyword_If_At_Least_Fluorine Add Domain Fluorine ${domain_name} ${sgt} ${prefixes} ${origin} ${node}
256 CompareStream.Run_Keyword_If_At_Most_Oxygen Add Domain Oxygen ${domain_name} ${sgt} ${prefixes} ${node} ${session}
259 [Arguments] ${domain_name} ${sgt} ${prefixes} ${origin} ${node} ${session}
260 [Documentation] Add Domain with bindings (with origin) via RPC
261 ${data} = Sxp.Add Domain Xml Fluorine ${node} ${domain_name} ${sgt} ${prefixes} ${origin}
262 Post To Controller ${session} add-domain ${data}
265 [Arguments] ${domain_name} ${sgt} ${prefixes} ${node} ${session}
266 [Documentation] Add Domain with bindings (without origin) via RPC
267 ${data} = Sxp.Add Domain Xml Oxygen ${node} ${domain_name} ${sgt} ${prefixes}
268 Post To Controller ${session} add-domain ${data}
271 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
272 [Documentation] Delete Domain via RPC
273 ${data} = Sxp.Delete Domain Xml ${node} ${domain_name}
274 Post To Controller ${session} delete-domain ${data}
277 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
278 [Documentation] Add Bindings to Node specified by range
279 ${prefixes} = Sxp.Prefix Range ${start} ${size}
280 Add Bindings ${sgt} ${prefixes} ${node}
282 Delete Bindings Range
283 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
284 [Documentation] Delete Bindings to Node specified by range
285 ${prefixes} = Sxp.Prefix Range ${start} ${size}
286 Delete Bindings ${sgt} ${prefixes} ${node}
289 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
290 [Documentation] Check if Node contains Bindings specified by range
291 ${resp} = Get Bindings ${node}
292 : FOR ${num} IN RANGE ${start} ${end}
293 \ ${ip} = Sxp.Get Ip From Number ${num}
294 \ Should Contain Binding ${resp} ${sgt} ${ip}/32
296 Check Binding Range Negative
297 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
298 [Documentation] Check if Node does not contains Bindings specified by range
299 ${resp} = Get Bindings ${node}
300 : FOR ${num} IN RANGE ${start} ${end}
301 \ ${ip} = Sxp.Get Ip From Number ${num}
302 \ Should Not Contain Binding ${resp} ${sgt} ${ip}/32
304 Setup SXP Environment
305 [Arguments] ${node_range}=1
306 [Documentation] Create session to Controller, ${node_range} parameter specifies number of localhost nodes to be created on ${ODL_SYSTEM_IP}.
307 RequestsLibrary.Create Session session http://${ODL_SYSTEM_IP}:${RESTCONFPORT} auth=${AUTH} timeout=${DEFAULT_TIMEOUT_HTTP} max_retries=0
308 : FOR ${num} IN RANGE 1 ${node_range}+1
309 \ ${node} = Sxp.Get Ip From Number ${num}
310 \ ${rnd_retry_time} = BuiltIn.Evaluate random.randint(1, 10) modules=random
311 \ Add Node ${node} retry_open_timer=${rnd_retry_time}
312 \ BuiltIn.Wait Until Keyword Succeeds 20 1 Check Node Started ${node} system=${ODL_SYSTEM_IP}
315 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
316 [Documentation] Verify that SxpNode has data writen to Operational datastore and is running
317 ${resp} = RequestsLibrary.Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
318 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
319 ${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}
320 BuiltIn.Should Be Equal As Strings ${rc} 0
322 Clean SXP Environment
323 [Arguments] ${node_range}=1
324 [Documentation] Destroy created sessions
325 : FOR ${num} IN RANGE 1 ${node_range}+1
326 \ ${ip} = Sxp.Get Ip From Number ${num}
328 RequestsLibrary.Delete All Sessions
330 Get Routing Configuration From Controller
331 [Arguments] ${session}
332 [Documentation] Get Routing configuration from config DS
333 ${resp} = RequestsLibrary.Get Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ headers=${ACCEPT_XML}
334 ${data} = BuiltIn.Set Variable If "${resp.status_code}" == "200" ${resp.content} ${EMPTY}
337 Put Routing Configuration To Controller
338 [Arguments] ${data} ${session}
339 [Documentation] Put Routing configuration to Config DS
340 ${resp} = RequestsLibrary.Put Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ data=${data} headers=${HEADERS_XML}
341 BuiltIn.Should Match "${resp.status_code}" "20?"
343 Clean Routing Configuration To Controller
344 [Arguments] ${session}
345 [Documentation] Delete Routing configuration from Config DS
346 ${resp} = RequestsLibrary.Get Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/ headers=${ACCEPT_XML}
347 BuiltIn.Run Keyword If "${resp.status_code}" == "200" RequestsLibrary.Delete Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/