2 Library RequestsLibrary
5 Library ClusterStateLibrary.py
6 Library ./HsfJson/hsf_json.py
10 ${jolokia_conf} /jolokia/read/org.opendaylight.controller:Category=ShardManager,name=shard-manager-config,type=DistributedConfigDatastore
11 ${jolokia_oper} /jolokia/read/org.opendaylight.controller:Category=ShardManager,name=shard-manager-operational,type=DistributedOperationalDatastore
12 ${jolokia_read} /jolokia/read/org.opendaylight.controller
15 Create Controller Index List
16 [Documentation] Reads number of controllers and returns a list with all controllers indexes.
17 ${controller_index_list} Create List
18 ${NUM_ODL_SYSTEM}= Convert to Integer ${NUM_ODL_SYSTEM}
19 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
20 \ Append To List ${controller_index_list} ${i+1}
21 [Return] ${controller_index_list}
23 Create Controller Sessions
24 [Documentation] Creates REST session to all controller instances.
25 ${NUM_ODL_SYSTEM}= Convert to Integer ${NUM_ODL_SYSTEM}
26 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
27 \ Log Create Session ${ODL_SYSTEM_${i+1}_IP}
28 \ RequestsLibrary.Create Session controller${i+1} http://${ODL_SYSTEM_${i+1}_IP}:${RESTCONFPORT} auth=${AUTH}
30 Get Cluster Shard Status
31 [Arguments] ${controller_index_list} ${shard_type} ${shard}
32 [Documentation] Checks ${shard} status and returns Leader index and a list of Followers from a ${controller_index_list}.
33 ... ${shard_type} is either config or operational.
34 ${lenght}= Get Length ${controller_index_list}
35 Run Keyword If '${shard_type}' == 'config' Set Test Variable ${type} DistributedConfigDatastore
36 Run Keyword If '${shard_type}' == 'operational' Set Test Variable ${type} DistributedOperationalDatastore
37 Should Not Be Empty ${type} Wrong type, valid values are config and operational.
38 ${leader}= Set Variable 0
39 ${follower_list}= Create List
40 : FOR ${i} IN @{controller_index_list}
41 \ ${data}= Utils.Get Data From URI controller${i} ${jolokia_read}:Category=Shards,name=member-${i}-shard-${shard}-${shard_type},type=${type}
43 \ ${json}= RequestsLibrary.To Json ${data}
44 \ ${status}= Get From Dictionary &{json}[value] RaftState
45 \ Log Controller ${ODL_SYSTEM_${i}_IP} is ${status} for shard ${shard}
46 \ Run Keyword If '${status}' == 'Leader' Set Test Variable ${leader} ${i}
47 \ Run Keyword If '${status}' == 'Follower' Append To List ${follower_list} ${i}
48 Should Not Be Equal ${leader} 0 No Leader elected in shard ${shard_type} ${shard}
49 Length Should Be ${follower_list} ${lenght-1} Not enough or too many Followers in shard ${shard_type} ${shard}
50 [Return] ${leader} ${follower_list}
52 Get Cluster Entity Owner
53 [Arguments] ${controller_index_list} ${device_type} ${device}
54 [Documentation] Checks Entity Owner status for a ${device} and returns owner index and list of candidates from a ${controller_index_list}.
55 ... ${device_type} can be openflow, ovsdb, etc.
56 ${owner} ${candidates_list}= Get Device Entity Owner And Candidates Indexes controller@{controller_index_list}[0] ${device_type} ${device}
57 List Should Contain Value ${controller_index_list} ${owner} Owner ${owner} not exisiting in ${controller_index_list}
58 List Should Contain Sublist ${candidates_list} ${controller_index_list} Candidates are missing in ${candidates_list}
59 Remove Values From List ${candidates_list} ${owner}
60 [Return] ${owner} ${candidates_list}
62 Get Device Entity Owner And Followers Indexes
63 [Arguments] ${session} ${device_type} ${device}
64 [Documentation] Returns the owner and followers indexes for a ${device}. Follower list = candidate list - owner
65 ${owner} ${candidates_list}= Get Device Entity Owner And Candidates Indexes ${session} ${device_type} ${device}
66 Remove Values From List ${candidates_list} ${owner}
67 [Return] ${owner} ${candidates_list}
69 Get Device Entity Owner And Candidates Indexes
70 [Arguments] ${session} ${device_type} ${device}
71 [Documentation] Returns the owner and candidates indexes for a ${device}. Returns raw information, does not check missing
72 ... cluster nodes or so.
73 ${candidates_list}= Create List
74 ${data}= Utils.Get Data From URI ${session} /restconf/operational/entity-owners:entity-owners
76 ${clear_data}= Run Keyword If '${device_type}' == 'openflow' Extract OpenFlow Device Data ${data}
77 ... ELSE IF '${device_type}' == 'ovsdb' Extract Ovsdb Device Data ${data}
78 ... ELSE Fail Not recognized device type: ${device_type}
79 ${json}= RequestsLibrary.To Json ${clear_data}
80 ${entity_type_list}= Get From Dictionary &{json}[entity-owners] entity-type
81 ${entity_type_index}= Get Index From List Of Dictionaries ${entity_type_list} type ${device_type}
82 Should Not Be Equal ${entity_type_index} -1 No Entity Owner found for ${device_type}
83 ${entity_list}= Get From Dictionary @{entity_type_list}[${entity_type_index}] entity
84 ${entity_index}= Utils.Get Index From List Of Dictionaries ${entity_list} id ${device}
85 Should Not Be Equal ${entity_index} -1 Device ${device} not found in Entity Owner ${device_type}
86 ${entity_owner}= Get From Dictionary @{entity_list}[${entity_index}] owner
87 Should Not Be Empty ${entity_owner} No owner found for ${device}
88 ${owner}= Replace String ${entity_owner} member- ${EMPTY}
89 ${owner}= Convert To Integer ${owner}
90 ${entity_candidates_list}= Get From Dictionary @{entity_list}[${entity_index}] candidate
91 : FOR ${entity_candidate} IN @{entity_candidates_list}
92 \ ${candidate}= Replace String &{entity_candidate}[name] member- ${EMPTY}
93 \ ${candidate}= Convert To Integer ${candidate}
94 \ Append To List ${candidates_list} ${candidate}
95 [Return] ${owner} ${candidates_list}
97 Extract OpenFlow Device Data
99 [Documentation] Remove superfluous OpenFlow device data from Entity Owner printout.
100 ${clear_data}= Replace String ${data} /general-entity:entity[general-entity:name=' ${EMPTY}
101 ${clear_data}= Replace String ${clear_data} '] ${EMPTY}
103 [Return] ${clear_data}
105 Extract Ovsdb Device Data
107 [Documentation] Remove superfluous OVSDB device data from Entity Owner printout.
108 ${clear_data}= Replace String ${data} /network-topology:network-topology/network-topology:topology[network-topology:topology-id='ovsdb:1']/network-topology:node[network-topology:node-id=' ${EMPTY}
109 ${clear_data}= Replace String ${clear_data} '] ${EMPTY}
111 [Return] ${clear_data}
113 Check Item Occurrence At URI In Cluster
114 [Arguments] ${controller_index_list} ${dictionary_item_occurrence} ${uri}
115 [Documentation] Send a GET with the supplied ${uri} to all cluster instances in ${controller_index_list}
116 ... and check for occurrences of items expressed in a dictionary ${dictionary_item_occurrence}.
117 : FOR ${i} IN @{controller_index_list}
118 \ ${data} Utils.Get Data From URI controller${i} ${uri}
120 \ Utils.Check Item Occurrence ${data} ${dictionary_item_occurrence}
122 Put And Check At URI In Cluster
123 [Arguments] ${controller_index_list} ${controller_index} ${uri} ${body}
124 [Documentation] Send a PUT with the supplied ${uri} and ${body} (json string) to a ${controller_index}
125 ... and check the data is replicated in all instances in ${controller_index_list}.
126 ${expected_body}= Hsf Json ${body}
128 ${resp} RequestsLibrary.Put Request controller${controller_index} ${uri} data=${body} headers=${HEADERS_YANG_JSON}
130 Log ${resp.status_code}
131 ${status_code}= Convert To String ${resp.status_code}
132 Should Match Regexp ${status_code} 20(0|1)
133 : FOR ${i} IN @{controller_index_list}
134 \ ${data} Wait Until Keyword Succeeds 5s 1s Get Data From URI controller${i}
137 \ ${received_body} Hsf Json ${data}
138 \ Should Be Equal ${expected_body} ${received_body}
140 Delete And Check At URI In Cluster
141 [Arguments] ${controller_index_list} ${controller_index} ${uri}
142 [Documentation] Send a DELETE with the supplied ${uri} to a ${controller_index}
143 ... and check the data is removed from all instances in ${controller_index_list}.
144 ${resp} RequestsLibrary.Delete Request controller${controller_index} ${uri}
145 Should Be Equal As Strings ${resp.status_code} 200
146 : FOR ${i} IN @{controller_index_list}
147 \ Wait Until Keyword Succeeds 5s 1s No Content From URI controller${i} ${uri}
149 Kill Multiple Controllers
150 [Arguments] @{controller_index_list}
151 [Documentation] Give this keyword a scalar or list of controllers to be stopped.
152 : FOR ${i} IN @{controller_index_list}
153 \ ${output}= Utils.Run Command On Controller ${ODL_SYSTEM_${i}_IP} ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
154 \ ClusterKeywords.Controller Down Check ${ODL_SYSTEM_${i}_IP}
156 Start Multiple Controllers
157 [Arguments] ${timeout} @{controller_index_list}
158 [Documentation] Give this keyword a scalar or list of controllers to be started.
159 : FOR ${i} IN @{controller_index_list}
160 \ ${output}= Utils.Run Command On Controller ${ODL_SYSTEM_${i}_IP} ${WORKSPACE}/${BUNDLEFOLDER}/bin/start
161 : FOR ${i} IN @{controller_index_list}
162 \ ClusterKeywords.Wait For Controller Sync ${timeout} ${ODL_SYSTEM_${i}_IP}
165 [Arguments] ${exclude_controller}=${EMPTY}
166 [Documentation] Creates a list of all controllers minus any excluded controller.
167 Log ${exclude_controller}
168 @{searchlist} Create List ${ODL_SYSTEM_IP} ${ODL_SYSTEM_2_IP} ${ODL_SYSTEM_3_IP}
169 Remove Values From List ${searchlist} ${exclude_controller}
171 [Return] ${searchlist}
173 Get Leader And Verify
174 [Arguments] ${shard_name} ${old_leader}=${EMPTY}
175 [Documentation] Returns the IP addr or hostname of the leader of the specified shard.
176 ... Controllers are specifed in the pybot command line.
177 ${searchlist} Get Controller List ${old_leader}
178 ${leader} GetLeader ${shard_name} ${3} ${3} ${1} ${RESTCONFPORT}
180 Should Not Be Equal As Strings ${leader} None
181 Run Keyword If '${old_leader}'!='${EMPTY}' Should Not Be Equal ${old_leader} ${leader}
185 [Arguments] ${shard_name}
186 [Documentation] No leader is elected in the car shard
187 ${leader} GetLeader ${shard_name} ${3} ${1} ${1} ${RESTCONFPORT}
188 ... ${CURRENT_CAR_LEADER}
189 Should Be Equal As Strings ${leader} None
192 [Arguments] ${shard_name} ${exclude_controller}=${EMPTY}
193 [Documentation] Returns the IP addresses or hostnames of all followers of the specified shard.
194 ${searchlist} Get Controller List ${exclude_controller}
195 ${followers} GetFollowers ${shard_name} ${3} ${3} ${1} ${RESTCONFPORT}
198 Should Not Be Empty ${followers}
199 [Return] ${followers}
201 Stop One Or More Controllers
202 [Arguments] @{controllers}
203 [Documentation] Give this keyword a scalar or list of controllers to be stopped.
204 ${cmd} = Set Variable ${KARAF_HOME}/bin/stop
205 : FOR ${ip} IN @{controllers}
206 \ Run Command On Remote System ${ip} ${cmd}
208 Stop Controller Node And Verify
210 [Documentation] Stops the given node
211 @{leader_list}= BuiltIn.Create List ${node}
212 Kill One Or More Controllers @{leader_list}
213 Controller Down Check ${node}
215 Kill One Or More Controllers
216 [Arguments] @{controllers}
217 [Documentation] Give this keyword a scalar or list of controllers to be stopped.
218 ${cmd} = Set Variable ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
220 : FOR ${ip} IN @{controllers}
221 \ Run Command On Remote System ${ip} ${cmd}
223 Wait For Cluster Down
224 [Arguments] ${timeout} @{controllers}
225 [Documentation] Waits for one or more clustered controllers to be down.
226 : FOR ${ip} IN @{controllers}
227 \ ${status}= Run Keyword And Return Status Wait For Controller Down ${timeout} ${ip}
228 \ Exit For Loop If '${status}' == 'FAIL'
230 Wait For Controller Down
231 [Arguments] ${timeout} ${ip}
232 [Documentation] Waits for one controllers to be down.
233 Wait Until Keyword Succeeds ${timeout} 2s Controller Down Check ${ip}
235 Controller Down Check
237 [Documentation] Checks to see if a controller is down by verifying that the karaf process isn't present.
238 ${cmd} = Set Variable ps axf | grep karaf | grep -v grep | wc -l
239 ${response} Run Command On COntroller ${ip} ${cmd}
240 Log Number of controller instances running: ${response}
241 Should Start With ${response} 0 Controller process found or there may be extra instances of karaf running on the host machine.
243 Start One Or More Controllers
244 [Arguments] @{controllers}
245 [Documentation] Give this keyword a scalar or list of controllers to be started.
246 ${cmd} = Set Variable ${KARAF_HOME}/bin/start
247 : FOR ${ip} IN @{controllers}
248 \ Run Command On Remote System ${ip} ${cmd}
250 Start Controller Node And Verify
251 [Arguments] ${node} ${start_timeout}
252 [Documentation] Starts the given node
253 @{controllers}= BuiltIn.CreateList ${node}
254 Start One Or More Controllers @{controllers}
255 Wait For Controller Sync ${start_timeout} @{controllers}
257 Wait For Cluster Sync
258 [Arguments] ${timeout} @{controllers}
259 [Documentation] Waits for one or more clustered controllers to report Sync Status as true.
260 : FOR ${ip} IN @{controllers}
261 \ ${status}= Run Keyword And Return Status Wait For Controller Sync ${timeout} ${ip}
262 \ Exit For Loop If '${status}' == 'FAIL'
264 Wait For Controller Sync
265 [Arguments] ${timeout} ${ip}
266 [Documentation] Waits for one controllers to report Sync Status as true.
267 Wait Until Keyword Succeeds ${timeout} 2s Controller Sync Status Should Be True ${ip}
269 Controller Sync Status Should Be True
271 [Documentation] Checks if Sync Status is true.
272 ${SyncStatus}= Get Controller Sync Status ${ip}
273 Should Be Equal ${SyncStatus} ${TRUE}
275 Controller Sync Status Should Be False
277 [Documentation] Checks if Sync Status is false.
278 ${SyncStatus}= Get Controller Sync Status ${ip}
279 Should Be Equal ${SyncStatus} ${FALSE}
281 Get Controller Sync Status
282 [Arguments] ${controller_ip}
283 [Documentation] Return Sync Status.
284 Create_Session session http://${controller_ip}:${RESTCONFPORT} headers=${HEADERS} auth=${AUTH} max_retries=0
285 ${data}= Get Data From URI session ${jolokia_conf}
287 ${json}= To Json ${data}
288 ${value}= Get From Dictionary ${json} value
289 ${ConfSyncStatus}= Get From Dictionary ${value} SyncStatus
290 Log Configuration Sync Status: ${ConfSyncStatus}
291 ${data}= Get Data From URI session ${jolokia_oper}
293 ${json}= To Json ${data}
294 ${value}= Get From Dictionary ${json} value
295 ${OperSyncStatus}= Get From Dictionary ${value} SyncStatus
296 Log Operational Sync Status: ${OperSyncStatus}
297 Run Keyword If ${OperSyncStatus} and ${ConfSyncStatus} Set Test Variable ${SyncStatus} ${TRUE}
298 ... ELSE Set Test Variable ${SyncStatus} ${FALSE}
299 [Return] ${SyncStatus}
301 Clean One Or More Journals
302 [Arguments] @{controllers}
303 [Documentation] Give this keyword a scalar or list of controllers on which to clean journals.
304 ${del_cmd} = Set Variable rm -rf ${KARAF_HOME}/journal
305 : FOR ${ip} IN @{controllers}
306 \ Run Command On Remote System ${ip} ${del_cmd}
308 Clean One Or More Snapshots
309 [Arguments] @{controllers}
310 [Documentation] Give this keyword a scalar or list of controllers on which to clean snapshots.
311 ${del_cmd} = Set Variable rm -rf ${KARAF_HOME}/snapshots
312 : FOR ${ip} IN @{controllers}
313 \ Run Command On Remote System ${ip} ${del_cmd}
315 Show Cluster Configuation Files
316 [Arguments] @{controllers}
317 [Documentation] Prints out the cluster configuration files for one or more controllers.
318 Log controllers: @{controllers}
319 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/akka.conf
320 : FOR ${ip} IN @{controllers}
321 \ Run Command On Remote System ${ip} ${cmd}
322 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/modules.conf
323 : FOR ${ip} IN @{controllers}
324 \ Run Command On Remote System ${ip} ${cmd}
325 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/module-shards.conf
326 : FOR ${ip} IN @{controllers}
327 \ Run Command On Remote System ${ip} ${cmd}
328 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/jolokia.xml
329 : FOR ${ip} IN @{controllers}
330 \ Run Command On Remote System ${ip} ${cmd}
331 ${cmd} = Set Variable cat ${KARAF_HOME}/etc/initial/org.apache.karaf.management.cfg
332 : FOR ${ip} IN @{controllers}
333 \ Run Command On Remote System ${ip} ${cmd}
334 ${cmd} = Set Variable cat ${KARAF_HOME}/etc/org.apache.karaf.features.cfg
335 : FOR ${ip} IN @{controllers}
336 \ Run Command On Remote System ${ip} ${cmd}
338 Isolate a Controller From Cluster
339 [Arguments] ${isolated controller} @{controllers}
340 [Documentation] Use IPTables to isolate one controller from the cluster.
341 ... On the isolated controller it blocks IP traffic to and from each of the other controllers.
342 : FOR ${controller} IN @{controllers}
343 \ ${other controller}= Evaluate "${isolated controller}" != "${controller}"
344 \ Run Keyword If ${other controller} Isolate One Controller From Another ${isolated controller} ${controller}
346 Rejoin a Controller To Cluster
347 [Arguments] ${isolated controller} @{controllers}
348 [Documentation] Use IPTables to rejoin one controller to the cluster.
349 ... On the isolated controller it unblocks IP traffic to and from each of the other controllers.
350 : FOR ${controller} IN @{controllers}
351 \ ${other controller}= Evaluate "${isolated controller}" != "${controller}"
352 \ Run Keyword If ${other controller} Rejoin One Controller To Another ${isolated controller} ${controller}
354 Isolate One Controller From Another
355 [Arguments] ${isolated controller} ${controller}
356 [Documentation] Inserts an IPTable rule to disconnect one controller from another controller in the cluster.
357 Modify IPTables ${isolated controller} ${controller} -I
359 Rejoin One Controller To Another
360 [Arguments] ${isolated controller} ${controller}
361 [Documentation] Deletes an IPTable rule, allowing one controller to reconnect to another controller in the cluster.
362 Modify IPTables ${isolated controller} ${controller} -D
365 [Arguments] ${isolated controller} ${controller} ${rule type}
366 [Documentation] Adds a rule, usually inserting or deleting an entry between two controllers.
367 ${base string} Set Variable sudo /sbin/iptables ${rule type} OUTPUT -p all --source
368 ${cmd string} Catenate ${base string} ${isolated controller} --destination ${controller} -j DROP
369 Run Command On Remote System ${isolated controller} ${cmd string}
370 ${cmd string} Catenate ${base string} ${controller} --destination ${isolated controller} -j DROP
371 Run Command On Remote System ${isolated controller} ${cmd string}
372 ${cmd string} Set Variable sudo /sbin/iptables -L -n
373 ${return string}= Run Command On Remote System ${isolated controller} ${cmd string}
375 Run Keyword If "${rule type}" == '-I' Should Match Regexp ${return string} [\s\S]*DROP *all *-- *${isolated controller} *${controller}[\s\S]*
376 Run Keyword If "${rule type}" == '-I' Should Match Regexp ${return string} [\s\S]*DROP *all *-- *${controller} *${isolated controller}[\s\S]*
378 Run Keyword If "${rule type}" == '-D' Should Match Regexp ${return string} (?![\s\S]*DROP *all *-- *${isolated controller} *${controller}[\s\S]*)
379 Run Keyword If "${rule type}" == '-D' Should Match Regexp ${return string} (?![\s\S]*DROP *all *-- *${controller} *${isolated controller}[\s\S]*)
381 Rejoin All Isolated Controllers
382 [Arguments] @{controllers}
383 [Documentation] Wipe all IPTables rules from all controllers, thus rejoining all controllers.
384 : FOR ${isolated controller} IN @{controllers}
385 \ Flush IPTables ${isolated controller}
388 [Arguments] ${isolated controller}
389 [Documentation] This keyword is generally not called from a test case but supports a complete wipe of all rules on
391 ${cmd string} Set Variable sudo /sbin/iptables -v -F
392 ${return string}= Run Command On Remote System ${isolated controller} ${cmd string}
393 Log return: ${return string}
394 Should Contain ${return string} Flushing chain `INPUT'
395 Should Contain ${return string} Flushing chain `FORWARD'
396 Should Contain ${return string} Flushing chain `OUTPUT'