2 Documentation Library containing Keywords used for SXP testing
4 Library RequestsLibrary
8 Resource KarafKeywords.robot
10 Resource CompareStream.robot
11 Variables ../variables/Variables.py
14 ${REST_CONTEXT} /restconf/operations/sxp-controller
18 [Arguments] ${session} ${path} ${DATA}
19 [Documentation] Post request to Controller and checks response
20 ${resp} Post Request ${session} ${REST_CONTEXT}:${path} data=${DATA} headers=${HEADERS_XML}
25 Should be Equal As Strings ${resp.status_code} 200
26 ${content} Evaluate json.loads('''${resp.content}''') json
27 ${content} Get From Dictionary ${content} output
28 ${content} Get From Dictionary ${content} result
29 Should Be True ${content}
32 [Arguments] ${node} ${password}=${EMPTY} ${version}=version4 ${port}=64999 ${session}=session ${ip}=${EMPTY}
33 [Documentation] Add node via RPC to ODL
34 ${DATA} Add Node Xml ${node} ${port} ${password} ${version} ${ip}
35 Post To Controller ${session} add-node ${DATA}
38 [Arguments] ${node} ${session}=session
39 [Documentation] Delete connection via RPC from node
40 ${DATA} Delete Node Xml ${node}
41 Post To Controller ${session} delete-node ${DATA}
44 [Arguments] ${version} ${mode} ${ip} ${port} ${node}=127.0.0.1 ${password}=${EMPTY}
45 ... ${session}=session ${domain}=global
46 [Documentation] Add connection via RPC to node
47 ${DATA} Add Connection Xml ${version} ${mode} ${ip} ${port} ${node}
48 ... ${password} ${domain}
49 Post To Controller ${session} add-connection ${DATA}
52 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
53 [Documentation] Gets all connections via RPC from node
54 ${DATA} Get Connections From Node Xml ${node} ${domain}
55 ${resp} Post Request ${session} ${REST_CONTEXT}:get-connections data=${DATA} headers=${HEADERS_XML}
56 Should be Equal As Strings ${resp.status_code} 200
57 [Return] ${resp.content}
60 [Arguments] ${ip} ${port} ${node}=127.0.0.1 ${session}=session ${domain}=global
61 [Documentation] Delete connection via RPC from node
62 ${DATA} Delete Connections Xml ${ip} ${port} ${node} ${domain}
63 Post To Controller ${session} delete-connection ${DATA}
66 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
67 [Documentation] Delete all connections via RPC from node
68 ${resp} Get Connections ${node} ${session} ${domain}
69 @{connections} Parse Connections ${resp}
70 : FOR ${connection} IN @{connections}
71 \ Delete Connections ${connection['peer-address']} ${connection['tcp-port']} ${node} ${session} ${domain}
74 [Arguments] ${version} ${mode} ${ip} ${port}=64999 ${node}=127.0.0.1 ${state}=on
75 ... ${session}=session ${domain}=global
76 [Documentation] Verify that connection is ON
77 ${resp} Get Connections ${node} ${session} ${domain}
78 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
81 [Arguments] ${sgt} ${prefix} ${node}=127.0.0.1 ${domain}=global ${session}=session
82 [Documentation] Add binding via RPC to Master DB of node
83 ${DATA} Add Entry Xml ${sgt} ${prefix} ${node} ${domain}
84 Post To Controller ${session} add-entry ${DATA}
87 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=all
88 [Documentation] Gets all binding via RPC from Master DB of node
89 ${DATA} Get Bindings From Node Xml ${node} ${scope} ${domain}
90 ${resp} Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Post Request ${session} ${REST_CONTEXT}:get-node-bindings data=${DATA}
91 ... headers=${HEADERS_XML}
92 ... ELSE Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/master-database/ headers=${HEADERS_XML}
93 Should be Equal As Strings ${resp.status_code} 200
94 [Return] ${resp.content}
97 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
98 [Documentation] Delete all bindings via RPC from Master DB of node
99 ${resp} Get Bindings ${node} ${session} ${domain} local
100 @{bindings} Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Parse Bindings ${resp}
101 ... ELSE Parse Prefix Groups ${resp} local
102 : FOR ${binding} IN @{bindings}
103 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Clean Binding ${binding['sgt']} ${binding['ip-prefix']} ${node}
104 \ ... ${session} ${domain}
105 \ ... ELSE Clean Binding ${binding} ${binding['binding']} ${node}
106 \ ... ${session} ${domain}
109 [Arguments] ${sgt} ${prefixes} ${node} ${session} ${domain}=global
110 [Documentation] Used for nester FOR loop
111 : FOR ${prefix} IN @{prefixes}
112 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Delete Binding ${sgt} ${prefix} ${node}
113 \ ... ${domain} ${session}
114 \ ... ELSE Delete Binding ${sgt['sgt']} ${prefix['ip-prefix']} ${node}
115 \ ... ${domain} ${session}
118 [Arguments] ${sgtOld} ${prefixOld} ${sgtNew} ${prefixNew} ${node}=127.0.0.1 ${session}=session
120 [Documentation] Updates value of binding via RPC in Master DB of node
121 ${DATA} Update Binding Xml ${sgtOld} ${prefixOld} ${sgtNew} ${prefixNew} ${node}
123 Post To Controller ${session} update-entry ${DATA}
126 [Arguments] ${sgt} ${prefix} ${node}=127.0.0.1 ${domain}=global ${session}=session
127 [Documentation] Delete binding via RPC from Master DB of node
128 ${DATA} Delete Binding Xml ${sgt} ${prefix} ${node} ${domain}
129 Post To Controller ${session} delete-entry ${DATA}
132 [Arguments] ${name} ${peers}= ${node}=127.0.0.1 ${session}=session
133 [Documentation] Adds new PeerGroup via RPC to Node
134 ${DATA} Add Peer Group Xml ${name} ${peers} ${node}
135 Post To Controller ${session} add-peer-group ${DATA}
138 [Arguments] ${name} ${node}=127.0.0.1 ${session}=session
139 [Documentation] Delete PeerGroup via RPC from Node
140 ${DATA} Delete Peer Group Xml ${name} ${node}
141 Post To Controller ${session} delete-peer-group ${DATA}
144 [Arguments] ${node}=127.0.0.1 ${session}=session
145 [Documentation] Gets all PeerGroups via RPC from node
146 ${DATA} Get Peer Groups From Node Xml ${node}
147 ${resp} Post Request ${session} ${REST_CONTEXT}:get-peer-groups data=${DATA} headers=${HEADERS_XML}
148 Should be Equal As Strings ${resp.status_code} 200
149 [Return] ${resp.content}
152 [Arguments] ${node}=127.0.0.1 ${session}=session
153 [Documentation] Delete all PeerGroups via RPC from node
154 ${resp} Get Peer Groups ${node} ${session}
155 @{prefixes} Parse Peer Groups ${resp}
156 : FOR ${group} IN @{prefixes}
157 \ Delete Peer Group ${group['name']} ${node} ${session}
160 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session ${policy}=auto-update
161 [Documentation] Add Filter via RPC from Node
162 ${DATA} Run_Keyword_If_At_Least_Else carbon Add Filter Xml ${name} ${type} ${entries}
163 ... ${node} ${policy}
164 ... ELSE Add Filter Xml ${name} ${type} ${entries} ${node}
165 Post To Controller ${session} add-filter ${DATA}
168 [Arguments] ${name} ${domains} ${entries} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
169 [Documentation] Add Domain Filter via RPC from Node
170 ${DATA} Add Domain Filter Xml ${name} ${domains} ${entries} ${node} ${filter_name}
171 Post To Controller ${session} add-domain-filter ${DATA}
174 [Arguments] ${name} ${type} ${node}=127.0.0.1 ${session}=session
175 [Documentation] Delete Filter via RPC from Node
176 ${DATA} Delete Filter Xml ${name} ${type} ${node}
177 Post To Controller ${session} delete-filter ${DATA}
180 [Arguments] ${name} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
181 [Documentation] Delete Filter via RPC from Node
182 ${DATA} Delete Domain Filter Xml ${name} ${node} ${filter_name}
183 Post To Controller ${session} delete-domain-filter ${DATA}
185 Should Contain Binding
186 [Arguments] ${resp} ${sgt} ${prefix} ${db_source}=any
187 [Documentation] Tests if data contains specified binding
188 ${out} Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Find Binding ${resp} ${sgt} ${prefix}
189 ... ELSE Find Binding Legacy ${resp} ${sgt} ${prefix} ${db_source}
191 Should Be True ${out} Doesn't have ${sgt} ${prefix}
193 Should Not Contain Binding
194 [Arguments] ${resp} ${sgt} ${prefix} ${db_source}=any
195 [Documentation] Tests if data doesn't contains specified binding
196 ${out} Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Find Binding ${resp} ${sgt} ${prefix}
197 ... ELSE Find Binding Legacy ${resp} ${sgt} ${prefix} ${db_source}
199 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} Find Connection ${resp} ${version} ${mode} ${ip} ${port}
206 Should Be True ${out} Doesn't have ${ip}:${port} ${mode} ${version}
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} Find Connection ${resp} ${version} ${mode} ${ip} ${port}
213 Should Not Be True ${out} Shouldn't have ${ip}:${port} ${mode} ${version}
215 Setup Topology Complex
216 [Arguments] ${version}=version4 ${PASSWORD}=none
217 : FOR ${node} IN RANGE 2 6
218 \ Add Connection ${version} both 127.0.0.1 64999 127.0.0.${node}
220 \ Add Connection ${version} both 127.0.0.${node} 64999 127.0.0.1
222 \ Wait Until Keyword Succeeds 15 1 Verify Connection ${version} both
223 \ ... 127.0.0.${node}
224 \ Add Binding ${node}0 10.10.10.${node}0/32 127.0.0.${node}
225 \ Add Binding ${node}0 10.10.${node}0.0/24 127.0.0.${node}
226 \ Add Binding ${node}0 10.${node}0.0.0/16 127.0.0.${node}
227 \ Add Binding ${node}0 ${node}0.0.0.0/8 127.0.0.${node}
228 Add Binding 10 10.10.10.10/32 127.0.0.1
229 Add Binding 10 10.10.10.0/24 127.0.0.1
230 Add Binding 10 10.10.0.0/16 127.0.0.1
231 Add Binding 10 10.0.0.0/8 127.0.0.1
233 Verify Snapshot Was Pushed
234 [Arguments] ${snapshot_string}=22-sxp-controller-one-node.xml
235 [Documentation] Will succeed if the ${snapshot_string} is found in the karaf logs
236 ${output} Run Command On Controller ${ODL_SYSTEM_IP} cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
237 Should Not Be Equal As Strings ${output} 0
240 [Arguments] ${session}=session ${controller}=${ODL_SYSTEM_IP}
241 [Documentation] Create session to Controller
242 Verify Feature Is Installed odl-sxp-controller ${controller}
243 Create Session ${session} url=http://${controller}:${RESTCONFPORT} auth=${AUTH} headers=${HEADERS_XML}
244 ${resp} RequestsLibrary.Get Request ${session} ${MODULES_API}
245 Should Be Equal As Strings ${resp.status_code} 200
246 Should Contain ${resp.content} ietf-restconf
249 [Documentation] Destroy created sessions
253 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
254 [Documentation] Add Domain via RPC
255 ${DATA} Add Domain Xml ${node} ${domain_name}
256 Post To Controller ${session} add-domain ${DATA}
259 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
260 [Documentation] Delete Domain via RPC
261 ${DATA} Delete Domain Xml ${node} ${domain_name}
262 Post To Controller ${session} delete-domain ${DATA}
265 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${session}=session ${domain}=global
266 [Documentation] Add bindings via RPC to Master DB of node
267 ${DATA} Add Bindings Xml ${node} ${domain} ${sgt} ${prefixes}
268 Post To Controller ${session} add-bindings ${DATA}
271 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${session}=session ${domain}=global
272 [Documentation] Delete bindings via RPC from Master DB of node
273 ${DATA} Delete Bindings Xml ${node} ${domain} ${sgt} ${prefixes}
274 Post To Controller ${session} delete-bindings ${DATA}
277 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
278 [Documentation] Add Bindings to Node specified by range
279 ${prefixes} 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} 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} 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} Get Ip From Number ${num}
302 \ Should Not Contain Binding ${resp} ${sgt} ${ip}/32
304 Setup SXP Environment
305 [Arguments] ${node_range}=2
306 [Documentation] Create session to Controller, node_range parameter specifies number of nodes to be created plus one
308 : FOR ${num} IN RANGE 1 ${node_range}
309 \ ${ip} Get Ip From Number ${num}
310 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Add Node ${ip}
311 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Wait Until Keyword Succeeds 20 1 Check Node Started
315 [Arguments] ${node} ${port}=64999 ${system}=${ODL_SYSTEM_IP} ${session}=session ${ip}=${node}
316 [Documentation] Verify that SxpNode has data writed to Operational datastore
317 ${resp} RequestsLibrary.Get Request ${session} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
318 Should Be Equal As Strings ${resp.status_code} 200
319 ${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}
320 Should Be Equal As Strings ${rc} 0
322 Clean SXP Environment
323 [Arguments] ${node_range}=2
324 [Documentation] Destroy created sessions
325 : FOR ${num} IN RANGE 1 ${node_range}
326 \ ${ip} Get Ip From Number ${num}
327 \ Run Keyword If '${ODL_STREAM}' not in ['beryllium', 'stable-lithium'] Delete Node ${ip}