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 ${device_style}= BuiltIn.Set_Variable_If '${device_type}' == 'netconf' openflow ${device_type}
77 ${entity_type}= BuiltIn.Set_Variable_If '${device_type}' == 'netconf' netconf-node/${device} ${device_type}
78 ${clear_data}= Run Keyword If '${device_style}' == 'openflow' Extract OpenFlow Device Data ${data}
79 ... ELSE IF '${device_style}' == 'ovsdb' Extract Ovsdb Device Data ${data}
80 ... ELSE Fail Not recognized device type: ${device_type}
81 ${json}= RequestsLibrary.To Json ${clear_data}
82 ${entity_type_list}= Get From Dictionary &{json}[entity-owners] entity-type
83 ${entity_type_index}= Get Index From List Of Dictionaries ${entity_type_list} type ${entity_type}
84 Should Not Be Equal ${entity_type_index} -1 No Entity Owner found for ${device_type}
85 ${entity_list}= Get From Dictionary @{entity_type_list}[${entity_type_index}] entity
86 ${entity_index}= Utils.Get Index From List Of Dictionaries ${entity_list} id ${device}
87 Should Not Be Equal ${entity_index} -1 Device ${device} not found in Entity Owner ${device_type}
88 ${entity_owner}= Get From Dictionary @{entity_list}[${entity_index}] owner
89 Should Not Be Empty ${entity_owner} No owner found for ${device}
90 ${owner}= Replace String ${entity_owner} member- ${EMPTY}
91 ${owner}= Convert To Integer ${owner}
92 ${entity_candidates_list}= Get From Dictionary @{entity_list}[${entity_index}] candidate
93 : FOR ${entity_candidate} IN @{entity_candidates_list}
94 \ ${candidate}= Replace String &{entity_candidate}[name] member- ${EMPTY}
95 \ ${candidate}= Convert To Integer ${candidate}
96 \ Append To List ${candidates_list} ${candidate}
97 [Return] ${owner} ${candidates_list}
99 Extract OpenFlow Device Data
101 [Documentation] Remove superfluous OpenFlow device data from Entity Owner printout.
102 ${clear_data}= Replace String ${data} /general-entity:entity[general-entity:name=' ${EMPTY}
103 ${clear_data}= Replace String ${clear_data} '] ${EMPTY}
105 [Return] ${clear_data}
107 Extract Ovsdb Device Data
109 [Documentation] Remove superfluous OVSDB device data from Entity Owner printout.
110 ${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}
111 ${clear_data}= Replace String ${clear_data} '] ${EMPTY}
113 [Return] ${clear_data}
115 Check Item Occurrence At URI In Cluster
116 [Arguments] ${controller_index_list} ${dictionary_item_occurrence} ${uri}
117 [Documentation] Send a GET with the supplied ${uri} to all cluster instances in ${controller_index_list}
118 ... and check for occurrences of items expressed in a dictionary ${dictionary_item_occurrence}.
119 : FOR ${i} IN @{controller_index_list}
120 \ ${data} Utils.Get Data From URI controller${i} ${uri}
122 \ Utils.Check Item Occurrence ${data} ${dictionary_item_occurrence}
124 Put And Check At URI In Cluster
125 [Arguments] ${controller_index_list} ${controller_index} ${uri} ${body}
126 [Documentation] Wrapper keyword for "Create Data And Check At URI In Cluster" using PUT
127 Create Data And Check At URI In Cluster ${controller_index_list} ${controller_index} ${uri} ${body} PUT
129 Post And Check At URI In Cluster
130 [Arguments] ${controller_index_list} ${controller_index} ${uri} ${body}
131 [Documentation] Wrapper keyword for "Create Data And Check At URI In Cluster" using POST
132 Create Data And Check At URI In Cluster ${controller_index_list} ${controller_index} ${uri} ${body} POST
134 Create Data And Check At URI In Cluster
135 [Arguments] ${controller_index_list} ${controller_index} ${uri} ${body} ${create_method}=PUT
136 [Documentation] Send a ${create_method} REST call with the supplied ${uri} and ${body} (json string) to a
137 ... ${controller_index} and check the data is replicated in all instances in ${controller_index_list}.
138 ${expected_body}= Hsf Json ${body}
140 ${resp} Run Keyword If "${create_method}" == "POST" RequestsLibrary.Post Request controller${controller_index} ${uri} data=${body}
141 ... headers=${HEADERS}
142 ... ELSE RequestsLibrary.Put Request controller${controller_index} ${uri} data=${body} headers=${HEADERS_YANG_JSON}
144 Log ${resp.status_code}
145 ${status_code}= Convert To String ${resp.status_code}
146 Should Match Regexp ${status_code} 20(0|1)
147 : FOR ${i} IN @{controller_index_list}
148 \ ${data} Wait Until Keyword Succeeds 5s 1s Get Data From URI controller${i}
151 \ ${received_body} Hsf Json ${data}
152 \ Should Be Equal ${expected_body} ${received_body}
154 Delete And Check At URI In Cluster
155 [Arguments] ${controller_index_list} ${controller_index} ${uri}
156 [Documentation] Send a DELETE with the supplied ${uri} to a ${controller_index}
157 ... and check the data is removed from all instances in ${controller_index_list}.
158 ${resp} RequestsLibrary.Delete Request controller${controller_index} ${uri}
159 Should Be Equal As Strings ${resp.status_code} 200
160 : FOR ${i} IN @{controller_index_list}
161 \ Wait Until Keyword Succeeds 5s 1s No Content From URI controller${i} ${uri}
163 Kill Multiple Controllers
164 [Arguments] @{controller_index_list}
165 [Documentation] Give this keyword a scalar or list of controllers to be stopped.
166 : FOR ${i} IN @{controller_index_list}
167 \ ${output}= Utils.Run Command On Controller ${ODL_SYSTEM_${i}_IP} ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
168 \ ClusterKeywords.Controller Down Check ${ODL_SYSTEM_${i}_IP}
170 Start Multiple Controllers
171 [Arguments] ${timeout} @{controller_index_list}
172 [Documentation] Give this keyword a scalar or list of controllers to be started.
173 : FOR ${i} IN @{controller_index_list}
174 \ ${output}= Utils.Run Command On Controller ${ODL_SYSTEM_${i}_IP} ${WORKSPACE}/${BUNDLEFOLDER}/bin/start
175 : FOR ${i} IN @{controller_index_list}
176 \ ClusterKeywords.Wait For Controller Sync ${timeout} ${ODL_SYSTEM_${i}_IP}
179 [Arguments] ${exclude_controller}=${EMPTY}
180 [Documentation] Creates a list of all controllers minus any excluded controller.
181 Log ${exclude_controller}
182 @{searchlist} Create List ${ODL_SYSTEM_IP} ${ODL_SYSTEM_2_IP} ${ODL_SYSTEM_3_IP}
183 Remove Values From List ${searchlist} ${exclude_controller}
185 [Return] ${searchlist}
187 Get Leader And Verify
188 [Arguments] ${shard_name} ${old_leader}=${EMPTY}
189 [Documentation] Returns the IP addr or hostname of the leader of the specified shard.
190 ... Controllers are specifed in the pybot command line.
191 ${searchlist} Get Controller List ${old_leader}
192 ${leader} GetLeader ${shard_name} ${3} ${3} ${1} ${RESTCONFPORT}
194 Should Not Be Equal As Strings ${leader} None
195 Run Keyword If '${old_leader}'!='${EMPTY}' Should Not Be Equal ${old_leader} ${leader}
199 [Arguments] ${shard_name}
200 [Documentation] No leader is elected in the car shard
201 ${leader} GetLeader ${shard_name} ${3} ${1} ${1} ${RESTCONFPORT}
202 ... ${CURRENT_CAR_LEADER}
203 Should Be Equal As Strings ${leader} None
206 [Arguments] ${shard_name} ${exclude_controller}=${EMPTY}
207 [Documentation] Returns the IP addresses or hostnames of all followers of the specified shard.
208 ${searchlist} Get Controller List ${exclude_controller}
209 ${followers} GetFollowers ${shard_name} ${3} ${3} ${1} ${RESTCONFPORT}
212 Should Not Be Empty ${followers}
213 [Return] ${followers}
215 Stop 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 ${KARAF_HOME}/bin/stop
219 : FOR ${ip} IN @{controllers}
220 \ Run Command On Remote System ${ip} ${cmd}
222 Stop Controller Node And Verify
224 [Documentation] Stops the given node
225 @{leader_list}= BuiltIn.Create List ${node}
226 Kill One Or More Controllers @{leader_list}
227 Controller Down Check ${node}
229 Kill One Or More Controllers
230 [Arguments] @{controllers}
231 [Documentation] Give this keyword a scalar or list of controllers to be stopped.
232 ${cmd} = Set Variable ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
234 : FOR ${ip} IN @{controllers}
235 \ Run Command On Remote System ${ip} ${cmd}
237 Wait For Cluster Down
238 [Arguments] ${timeout} @{controllers}
239 [Documentation] Waits for one or more clustered controllers to be down.
240 : FOR ${ip} IN @{controllers}
241 \ ${status}= Run Keyword And Return Status Wait For Controller Down ${timeout} ${ip}
242 \ Exit For Loop If '${status}' == 'FAIL'
244 Wait For Controller Down
245 [Arguments] ${timeout} ${ip}
246 [Documentation] Waits for one controllers to be down.
247 Wait Until Keyword Succeeds ${timeout} 2s Controller Down Check ${ip}
249 Controller Down Check
251 [Documentation] Checks to see if a controller is down by verifying that the karaf process isn't present.
252 ${cmd} = Set Variable ps axf | grep karaf | grep -v grep | wc -l
253 ${response} Run Command On COntroller ${ip} ${cmd}
254 Log Number of controller instances running: ${response}
255 Should Start With ${response} 0 Controller process found or there may be extra instances of karaf running on the host machine.
257 Start One Or More Controllers
258 [Arguments] @{controllers}
259 [Documentation] Give this keyword a scalar or list of controllers to be started.
260 ${cmd} = Set Variable ${KARAF_HOME}/bin/start
261 : FOR ${ip} IN @{controllers}
262 \ Run Command On Remote System ${ip} ${cmd}
264 Start Controller Node And Verify
265 [Arguments] ${node} ${start_timeout}
266 [Documentation] Starts the given node
267 @{controllers}= BuiltIn.CreateList ${node}
268 Start One Or More Controllers @{controllers}
269 Wait For Controller Sync ${start_timeout} @{controllers}
271 Wait For Cluster Sync
272 [Arguments] ${timeout} @{controllers}
273 [Documentation] Waits for one or more clustered controllers to report Sync Status as true.
274 : FOR ${ip} IN @{controllers}
275 \ ${status}= Run Keyword And Return Status Wait For Controller Sync ${timeout} ${ip}
276 \ Exit For Loop If '${status}' == 'FAIL'
278 Wait For Controller Sync
279 [Arguments] ${timeout} ${ip}
280 [Documentation] Waits for one controllers to report Sync Status as true.
281 Wait Until Keyword Succeeds ${timeout} 2s Controller Sync Status Should Be True ${ip}
283 Controller Sync Status Should Be True
285 [Documentation] Checks if Sync Status is true.
286 ${SyncStatus}= Get Controller Sync Status ${ip}
287 Should Be Equal ${SyncStatus} ${TRUE}
289 Controller Sync Status Should Be False
291 [Documentation] Checks if Sync Status is false.
292 ${SyncStatus}= Get Controller Sync Status ${ip}
293 Should Be Equal ${SyncStatus} ${FALSE}
295 Get Controller Sync Status
296 [Arguments] ${controller_ip}
297 [Documentation] Return Sync Status.
298 Create_Session session http://${controller_ip}:${RESTCONFPORT} headers=${HEADERS} auth=${AUTH} max_retries=0
299 ${data}= Get Data From URI session ${jolokia_conf}
301 ${json}= To Json ${data}
302 ${value}= Get From Dictionary ${json} value
303 ${ConfSyncStatus}= Get From Dictionary ${value} SyncStatus
304 Log Configuration Sync Status: ${ConfSyncStatus}
305 ${data}= Get Data From URI session ${jolokia_oper}
307 ${json}= To Json ${data}
308 ${value}= Get From Dictionary ${json} value
309 ${OperSyncStatus}= Get From Dictionary ${value} SyncStatus
310 Log Operational Sync Status: ${OperSyncStatus}
311 Run Keyword If ${OperSyncStatus} and ${ConfSyncStatus} Set Test Variable ${SyncStatus} ${TRUE}
312 ... ELSE Set Test Variable ${SyncStatus} ${FALSE}
313 [Return] ${SyncStatus}
315 Clean One Or More Journals
316 [Arguments] @{controllers}
317 [Documentation] Give this keyword a scalar or list of controllers on which to clean journals.
318 ${del_cmd} = Set Variable rm -rf ${KARAF_HOME}/journal
319 : FOR ${ip} IN @{controllers}
320 \ Run Command On Remote System ${ip} ${del_cmd}
322 Clean One Or More Snapshots
323 [Arguments] @{controllers}
324 [Documentation] Give this keyword a scalar or list of controllers on which to clean snapshots.
325 ${del_cmd} = Set Variable rm -rf ${KARAF_HOME}/snapshots
326 : FOR ${ip} IN @{controllers}
327 \ Run Command On Remote System ${ip} ${del_cmd}
329 Show Cluster Configuation Files
330 [Arguments] @{controllers}
331 [Documentation] Prints out the cluster configuration files for one or more controllers.
332 Log controllers: @{controllers}
333 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/akka.conf
334 : FOR ${ip} IN @{controllers}
335 \ Run Command On Remote System ${ip} ${cmd}
336 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/modules.conf
337 : FOR ${ip} IN @{controllers}
338 \ Run Command On Remote System ${ip} ${cmd}
339 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/module-shards.conf
340 : FOR ${ip} IN @{controllers}
341 \ Run Command On Remote System ${ip} ${cmd}
342 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/jolokia.xml
343 : FOR ${ip} IN @{controllers}
344 \ Run Command On Remote System ${ip} ${cmd}
345 ${cmd} = Set Variable cat ${KARAF_HOME}/etc/initial/org.apache.karaf.management.cfg
346 : FOR ${ip} IN @{controllers}
347 \ Run Command On Remote System ${ip} ${cmd}
348 ${cmd} = Set Variable cat ${KARAF_HOME}/etc/org.apache.karaf.features.cfg
349 : FOR ${ip} IN @{controllers}
350 \ Run Command On Remote System ${ip} ${cmd}
352 Isolate a Controller From Cluster
353 [Arguments] ${isolated controller} @{controllers}
354 [Documentation] Use IPTables to isolate one controller from the cluster.
355 ... On the isolated controller it blocks IP traffic to and from each of the other controllers.
356 : FOR ${controller} IN @{controllers}
357 \ ${other controller}= Evaluate "${isolated controller}" != "${controller}"
358 \ Run Keyword If ${other controller} Isolate One Controller From Another ${isolated controller} ${controller}
360 Rejoin a Controller To Cluster
361 [Arguments] ${isolated controller} @{controllers}
362 [Documentation] Use IPTables to rejoin one controller to the cluster.
363 ... On the isolated controller it unblocks IP traffic to and from each of the other controllers.
364 : FOR ${controller} IN @{controllers}
365 \ ${other controller}= Evaluate "${isolated controller}" != "${controller}"
366 \ Run Keyword If ${other controller} Rejoin One Controller To Another ${isolated controller} ${controller}
368 Isolate One Controller From Another
369 [Arguments] ${isolated controller} ${controller}
370 [Documentation] Inserts an IPTable rule to disconnect one controller from another controller in the cluster.
371 Modify IPTables ${isolated controller} ${controller} -I
373 Rejoin One Controller To Another
374 [Arguments] ${isolated controller} ${controller}
375 [Documentation] Deletes an IPTable rule, allowing one controller to reconnect to another controller in the cluster.
376 Modify IPTables ${isolated controller} ${controller} -D
379 [Arguments] ${isolated controller} ${controller} ${rule type}
380 [Documentation] Adds a rule, usually inserting or deleting an entry between two controllers.
381 ${base string} Set Variable sudo /sbin/iptables ${rule type} OUTPUT -p all --source
382 ${cmd string} Catenate ${base string} ${isolated controller} --destination ${controller} -j DROP
383 Run Command On Remote System ${isolated controller} ${cmd string}
384 ${cmd string} Catenate ${base string} ${controller} --destination ${isolated controller} -j DROP
385 Run Command On Remote System ${isolated controller} ${cmd string}
386 ${cmd string} Set Variable sudo /sbin/iptables -L -n
387 ${return string}= Run Command On Remote System ${isolated controller} ${cmd string}
389 Run Keyword If "${rule type}" == '-I' Should Match Regexp ${return string} [\s\S]*DROP *all *-- *${isolated controller} *${controller}[\s\S]*
390 Run Keyword If "${rule type}" == '-I' Should Match Regexp ${return string} [\s\S]*DROP *all *-- *${controller} *${isolated controller}[\s\S]*
392 Run Keyword If "${rule type}" == '-D' Should Match Regexp ${return string} (?![\s\S]*DROP *all *-- *${isolated controller} *${controller}[\s\S]*)
393 Run Keyword If "${rule type}" == '-D' Should Match Regexp ${return string} (?![\s\S]*DROP *all *-- *${controller} *${isolated controller}[\s\S]*)
395 Rejoin All Isolated Controllers
396 [Arguments] @{controllers}
397 [Documentation] Wipe all IPTables rules from all controllers, thus rejoining all controllers.
398 : FOR ${isolated controller} IN @{controllers}
399 \ Flush IPTables ${isolated controller}
402 [Arguments] ${isolated controller}
403 [Documentation] This keyword is generally not called from a test case but supports a complete wipe of all rules on
405 ${cmd string} Set Variable sudo /sbin/iptables -v -F
406 ${return string}= Run Command On Remote System ${isolated controller} ${cmd string}
407 Log return: ${return string}
408 Should Contain ${return string} Flushing chain `INPUT'
409 Should Contain ${return string} Flushing chain `FORWARD'
410 Should Contain ${return string} Flushing chain `OUTPUT'