2 Documentation Library containing Keywords used for SXP testing
4 Library RequestsLibrary
8 Resource KarafKeywords.robot
10 Variables ../variables/Variables.py
13 ${REST_CONTEXT} /restconf/operations/sxp-controller
17 [Arguments] ${session} ${path} ${DATA}
18 [Documentation] Post request to Controller and checks response
19 ${resp} Post Request ${session} ${REST_CONTEXT}:${path} data=${DATA} headers=${HEADERS_XML}
24 Should be Equal As Strings ${resp.status_code} 200
25 ${content} Evaluate json.loads('''${resp.content}''') json
26 ${content} Get From Dictionary ${content} output
27 ${content} Get From Dictionary ${content} result
28 Should Be True ${content}
31 [Arguments] ${node} ${password}=${EMPTY} ${version}=version4 ${port}=64999 ${session}=session ${ip}=${EMPTY}
32 [Documentation] Add node via RPC to ODL
33 ${DATA} Add Node Xml ${node} ${port} ${password} ${version} ${ip}
34 Post To Controller ${session} add-node ${DATA}
37 [Arguments] ${node} ${session}=session
38 [Documentation] Delete connection via RPC from node
39 ${DATA} Delete Node Xml ${node}
40 Post To Controller ${session} delete-node ${DATA}
43 [Arguments] ${version} ${mode} ${ip} ${port} ${node}=127.0.0.1 ${password}=${EMPTY}
44 ... ${session}=session ${domain}=global
45 [Documentation] Add connection via RPC to node
46 ${DATA} Add Connection Xml ${version} ${mode} ${ip} ${port} ${node}
47 ... ${password} ${domain}
48 Post To Controller ${session} add-connection ${DATA}
51 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
52 [Documentation] Gets all connections via RPC from node
53 ${DATA} Get Connections From Node Xml ${node} ${domain}
54 ${resp} Post Request ${session} ${REST_CONTEXT}:get-connections data=${DATA} headers=${HEADERS_XML}
55 Should be Equal As Strings ${resp.status_code} 200
56 [Return] ${resp.content}
59 [Arguments] ${ip} ${port} ${node}=127.0.0.1 ${session}=session ${domain}=global
60 [Documentation] Delete connection via RPC from node
61 ${DATA} Delete Connections Xml ${ip} ${port} ${node} ${domain}
62 Post To Controller ${session} delete-connection ${DATA}
65 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
66 [Documentation] Delete all connections via RPC from node
67 ${resp} Get Connections ${node} ${session} ${domain}
68 @{connections} Parse Connections ${resp}
69 : FOR ${connection} IN @{connections}
70 \ Delete Connections ${connection['peer-address']} ${connection['tcp-port']} ${node} ${session} ${domain}
73 [Arguments] ${version} ${mode} ${ip} ${port}=64999 ${node}=127.0.0.1 ${state}=on
74 ... ${session}=session ${domain}=global
75 [Documentation] Verify that connection is ON
76 ${resp} Get Connections ${node} ${session} ${domain}
77 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
80 [Arguments] ${sgt} ${prefix} ${node}=127.0.0.1 ${domain}=global ${session}=session
81 [Documentation] Add binding via RPC to Master DB of node
82 ${DATA} Add Entry Xml ${sgt} ${prefix} ${node} ${domain}
83 Post To Controller ${session} add-entry ${DATA}
86 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=all
87 [Documentation] Gets all binding via RPC from Master DB of node
88 ${DATA} Get Bindings From Node Xml ${node} ${scope} ${domain}
89 ${resp} Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Post Request ${session} ${REST_CONTEXT}:get-node-bindings data=${DATA}
90 ... headers=${HEADERS_XML}
91 ... ELSE Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/master-database/ headers=${HEADERS_XML}
92 Should be Equal As Strings ${resp.status_code} 200
93 [Return] ${resp.content}
96 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
97 [Documentation] Delete all bindings via RPC from Master DB of node
98 ${resp} Get Bindings ${node} ${session} ${domain} local
99 @{bindings} Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Parse Bindings ${resp}
100 ... ELSE Parse Prefix Groups ${resp} local
101 : FOR ${binding} IN @{bindings}
102 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Clean Binding ${binding['sgt']} ${binding['ip-prefix']} ${node}
103 \ ... ${session} ${domain}
104 \ ... ELSE Clean Binding ${binding} ${binding['binding']} ${node}
105 \ ... ${session} ${domain}
108 [Arguments] ${sgt} ${prefixes} ${node} ${session} ${domain}=global
109 [Documentation] Used for nester FOR loop
110 : FOR ${prefix} IN @{prefixes}
111 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Delete Binding ${sgt} ${prefix} ${node}
112 \ ... ${domain} ${session}
113 \ ... ELSE Delete Binding ${sgt['sgt']} ${prefix['ip-prefix']} ${node}
114 \ ... ${domain} ${session}
117 [Arguments] ${sgtOld} ${prefixOld} ${sgtNew} ${prefixNew} ${node}=127.0.0.1 ${session}=session
119 [Documentation] Updates value of binding via RPC in Master DB of node
120 ${DATA} Update Binding Xml ${sgtOld} ${prefixOld} ${sgtNew} ${prefixNew} ${node}
122 Post To Controller ${session} update-entry ${DATA}
125 [Arguments] ${sgt} ${prefix} ${node}=127.0.0.1 ${domain}=global ${session}=session
126 [Documentation] Delete binding via RPC from Master DB of node
127 ${DATA} Delete Binding Xml ${sgt} ${prefix} ${node} ${domain}
128 Post To Controller ${session} delete-entry ${DATA}
131 [Arguments] ${name} ${peers}= ${node}=127.0.0.1 ${session}=session
132 [Documentation] Adds new PeerGroup via RPC to Node
133 ${DATA} Add Peer Group Xml ${name} ${peers} ${node}
134 Post To Controller ${session} add-peer-group ${DATA}
137 [Arguments] ${name} ${node}=127.0.0.1 ${session}=session
138 [Documentation] Delete PeerGroup via RPC from Node
139 ${DATA} Delete Peer Group Xml ${name} ${node}
140 Post To Controller ${session} delete-peer-group ${DATA}
143 [Arguments] ${node}=127.0.0.1 ${session}=session
144 [Documentation] Gets all PeerGroups via RPC from node
145 ${DATA} Get Peer Groups From Node Xml ${node}
146 ${resp} Post Request ${session} ${REST_CONTEXT}:get-peer-groups data=${DATA} headers=${HEADERS_XML}
147 Should be Equal As Strings ${resp.status_code} 200
148 [Return] ${resp.content}
151 [Arguments] ${node}=127.0.0.1 ${session}=session
152 [Documentation] Delete all PeerGroups via RPC from node
153 ${resp} Get Peer Groups ${node} ${session}
154 @{prefixes} Parse Peer Groups ${resp}
155 : FOR ${group} IN @{prefixes}
156 \ Delete Peer Group ${group['name']} ${node} ${session}
159 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session
160 [Documentation] Add Filter via RPC from Node
161 ${DATA} Add Filter Xml ${name} ${type} ${entries} ${node}
162 Post To Controller ${session} add-filter ${DATA}
165 [Arguments] ${name} ${domains} ${entries} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
166 [Documentation] Add Domain Filter via RPC from Node
167 ${DATA} Add Domain Filter Xml ${name} ${domains} ${entries} ${node} ${filter_name}
168 Post To Controller ${session} add-domain-filter ${DATA}
171 [Arguments] ${name} ${type} ${node}=127.0.0.1 ${session}=session
172 [Documentation] Delete Filter via RPC from Node
173 ${DATA} Delete Filter Xml ${name} ${type} ${node}
174 Post To Controller ${session} delete-filter ${DATA}
177 [Arguments] ${name} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
178 [Documentation] Delete Filter via RPC from Node
179 ${DATA} Delete Domain Filter Xml ${name} ${node} ${filter_name}
180 Post To Controller ${session} delete-domain-filter ${DATA}
182 Should Contain Binding
183 [Arguments] ${resp} ${sgt} ${prefix} ${db_source}=any
184 [Documentation] Tests if data contains specified binding
185 ${out} Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Find Binding ${resp} ${sgt} ${prefix}
186 ... ELSE Find Binding Legacy ${resp} ${sgt} ${prefix} ${db_source}
188 Should Be True ${out} Doesn't have ${sgt} ${prefix}
190 Should Not Contain Binding
191 [Arguments] ${resp} ${sgt} ${prefix} ${db_source}=any
192 [Documentation] Tests if data doesn't contains specified binding
193 ${out} Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Find Binding ${resp} ${sgt} ${prefix}
194 ... ELSE Find Binding Legacy ${resp} ${sgt} ${prefix} ${db_source}
196 Should Not Be True ${out} Should't have ${sgt} ${prefix}
198 Should Contain Connection
199 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
200 [Documentation] Test if data contains specified connection
201 ${out} Find Connection ${resp} ${version} ${mode} ${ip} ${port}
203 Should Be True ${out} Doesn't have ${ip}:${port} ${mode} ${version}
205 Should Not Contain Connection
206 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
207 [Documentation] Test if data doesn't contains specified connection
208 ${out} Find Connection ${resp} ${version} ${mode} ${ip} ${port}
210 Should Not Be True ${out} Shouldn't have ${ip}:${port} ${mode} ${version}
212 Setup Topology Complex
213 [Arguments] ${version}=version4 ${PASSWORD}=none
214 : FOR ${node} IN RANGE 2 6
215 \ Add Connection ${version} both 127.0.0.1 64999 127.0.0.${node}
217 \ Add Connection ${version} both 127.0.0.${node} 64999 127.0.0.1
219 \ Wait Until Keyword Succeeds 15 1 Verify Connection ${version} both
220 \ ... 127.0.0.${node}
221 \ Add Binding ${node}0 10.10.10.${node}0/32 127.0.0.${node}
222 \ Add Binding ${node}0 10.10.${node}0.0/24 127.0.0.${node}
223 \ Add Binding ${node}0 10.${node}0.0.0/16 127.0.0.${node}
224 \ Add Binding ${node}0 ${node}0.0.0.0/8 127.0.0.${node}
225 Add Binding 10 10.10.10.10/32 127.0.0.1
226 Add Binding 10 10.10.10.0/24 127.0.0.1
227 Add Binding 10 10.10.0.0/16 127.0.0.1
228 Add Binding 10 10.0.0.0/8 127.0.0.1
230 Verify Snapshot Was Pushed
231 [Arguments] ${snapshot_string}=22-sxp-controller-one-node.xml
232 [Documentation] Will succeed if the ${snapshot_string} is found in the karaf logs
233 ${output} Run Command On Controller ${ODL_SYSTEM_IP} cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
234 Should Not Be Equal As Strings ${output} 0
237 [Arguments] ${session}=session ${controller}=${ODL_SYSTEM_IP}
238 [Documentation] Create session to Controller
239 Verify Feature Is Installed odl-sxp-controller ${controller}
240 Create Session ${session} url=http://${controller}:${RESTCONFPORT} auth=${AUTH} headers=${HEADERS_XML}
241 ${resp} RequestsLibrary.Get Request ${session} ${MODULES_API}
242 Should Be Equal As Strings ${resp.status_code} 200
243 Should Contain ${resp.content} ietf-restconf
246 [Documentation] Destroy created sessions
250 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
251 [Documentation] Add Domain via RPC
252 ${DATA} Add Domain Xml ${node} ${domain_name}
253 Post To Controller ${session} add-domain ${DATA}
256 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
257 [Documentation] Delete Domain via RPC
258 ${DATA} Delete Domain Xml ${node} ${domain_name}
259 Post To Controller ${session} delete-domain ${DATA}
262 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${session}=session ${domain}=global
263 [Documentation] Add bindings via RPC to Master DB of node
264 ${DATA} Add Bindings Xml ${node} ${domain} ${sgt} ${prefixes}
265 Post To Controller ${session} add-bindings ${DATA}
268 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${session}=session ${domain}=global
269 [Documentation] Delete bindings via RPC from Master DB of node
270 ${DATA} Delete Bindings Xml ${node} ${domain} ${sgt} ${prefixes}
271 Post To Controller ${session} delete-bindings ${DATA}
274 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
275 [Documentation] Add Bindings to Node specified by range
276 ${prefixes} Prefix Range ${start} ${size}
277 Add Bindings ${sgt} ${prefixes} ${node}
279 Delete Bindings Range
280 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
281 [Documentation] Delete Bindings to Node specified by range
282 ${prefixes} Prefix Range ${start} ${size}
283 Delete Bindings ${sgt} ${prefixes} ${node}
286 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
287 [Documentation] Check if Node contains Bindings specified by range
288 ${resp} Get Bindings ${node}
289 : FOR ${num} IN RANGE ${start} ${end}
290 \ ${ip} Get Ip From Number ${num}
291 \ Should Contain Binding ${resp} ${sgt} ${ip}/32
293 Check Binding Range Negative
294 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
295 [Documentation] Check if Node does not contains Bindings specified by range
296 ${resp} Get Bindings ${node}
297 : FOR ${num} IN RANGE ${start} ${end}
298 \ ${ip} Get Ip From Number ${num}
299 \ Should Not Contain Binding ${resp} ${sgt} ${ip}/32
301 Setup SXP Environment
302 [Arguments] ${node_range}=2
303 [Documentation] Create session to Controller, node_range parameter specifies number of nodes to be created plus one
305 : FOR ${num} IN RANGE 1 ${node_range}
306 \ ${ip} Get Ip From Number ${num}
307 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Add Node ${ip}
308 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Wait Until Keyword Succeeds 20 1 Check Node Started
312 [Arguments] ${node} ${port}=64999 ${system}=${ODL_SYSTEM_IP} ${session}=session ${ip}=${node}
313 [Documentation] Verify that SxpNode has data writed to Operational datastore
314 ${resp} RequestsLibrary.Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
315 Should Be Equal As Strings ${resp.status_code} 200
316 ${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}
317 Should Be Equal As Strings ${rc} 0
319 Clean SXP Environment
320 [Arguments] ${node_range}=2
321 [Documentation] Destroy created sessions
322 : FOR ${num} IN RANGE 1 ${node_range}
323 \ ${ip} Get Ip From Number ${num}
324 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Delete Node ${ip}