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 \ 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}= Get Data From URI controller${i} ${jolokia_read}:Category=Shards,name=member-${i}-shard-${shard}-${shard_type},type=${type}
43 \ ${json}= 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 Status
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} is openflow, ovsdb, etc...
56 ${length}= Get Length ${controller_index_list}
57 ${candidates_list}= Create List
58 ${data}= Get Data From URI controller@{controller_index_list}[0] /restconf/operational/entity-owners:entity-owners
60 ${data}= Replace String ${data} /general-entity:entity[general-entity:name=' ${EMPTY}
61 ${clear_data}= Replace String ${data} '] ${EMPTY}
63 ${json}= To Json ${clear_data}
64 ${entity_type_list}= Get From Dictionary &{json}[entity-owners] entity-type
65 ${entity_type_index}= Get Index From List Of Dictionaries ${entity_type_list} type ${device_type}
66 Should Not Be Equal ${entity_type_index} -1 No Entity Owner found for ${device_type}
67 ${entity_list}= Get From Dictionary @{entity_type_list}[${entity_type_index}] entity
68 ${entity_index}= Get Index From List Of Dictionaries ${entity_list} id ${device}
69 Should Not Be Equal ${entity_index} -1 Device ${device} not found in Entity Owner ${device_type}
70 ${entity_owner}= Get From Dictionary @{entity_list}[${entity_index}] owner
71 Should Not Be Empty ${entity_owner} No owner found for ${device}
72 ${owner}= Replace String ${entity_owner} member- ${EMPTY}
73 ${owner}= Convert To Integer ${owner}
74 List Should Contain Value ${controller_index_list} ${owner} Owner ${owner} not exisiting in ${controller_index_list}
75 ${entity_candidates_list}= Get From Dictionary @{entity_list}[${entity_index}] candidate
76 ${list_length}= Get Length ${entity_candidates_list}
77 : FOR ${entity_candidate} IN @{entity_candidates_list}
78 \ ${candidate}= Replace String &{entity_candidate}[name] member- ${EMPTY}
79 \ ${candidate}= Convert To Integer ${candidate}
80 \ List Should Contain Value ${controller_index_list} ${candidate} Candidate ${candidate} not exisiting in ${controller_index_list}
81 \ Run Keyword If '${candidate}' != '${owner}' Append To List ${candidates_list} ${candidate}
82 [Return] ${owner} ${candidates_list}
84 Check Item Occurrence At URI In Cluster
85 [Arguments] ${controller_index_list} ${dictionary_item_occurrence} ${uri}
86 [Documentation] Send a GET with the supplied ${uri} to all cluster instances in ${controller_index_list}
87 ... and check for occurrences of items expressed in a dictionary ${dictionary_item_occurrence}.
88 : FOR ${i} IN @{controller_index_list}
89 \ ${data} Get Data From URI controller${i} ${uri}
91 \ Check Item Occurrence ${data} ${dictionary_item_occurrence}
93 Put And Check At URI In Cluster
94 [Arguments] ${controller_index_list} ${controller_index} ${uri} ${body}
95 [Documentation] Send a PUT with the supplied ${uri} and ${body} (json string) to a ${controller_index}
96 ... and check the data is replicated in all instances in ${controller_index_list}.
97 ${expected_body}= Hsf Json ${body}
99 ${resp} RequestsLibrary.Put Request controller${controller_index} ${uri} ${body} ${HEADERS_YANG_JSON}
101 Log ${resp.status_code}
102 ${status_code}= Convert To String ${resp.status_code}
103 Should Match Regexp ${status_code} 20(0|1)
104 : FOR ${i} IN @{controller_index_list}
105 \ ${data} Wait Until Keyword Succeeds 5s 1s Get Data From URI controller${i}
108 \ ${received_body} Hsf Json ${data}
109 \ Should Be Equal ${expected_body} ${received_body}
111 Delete And Check At URI In Cluster
112 [Arguments] ${controller_index_list} ${controller_index} ${uri}
113 [Documentation] Send a DELETE with the supplied ${uri} to a ${controller_index}
114 ... and check the data is removed from all instances in ${controller_index_list}.
115 ${resp} RequestsLibrary.Delete Request controller${controller_index} ${uri}
116 Should Be Equal As Strings ${resp.status_code} 200
117 : FOR ${i} IN @{controller_index_list}
118 \ Wait Until Keyword Succeeds 5s 1s No Content From URI controller${i} ${uri}
120 Kill Multiple Controllers
121 [Arguments] @{controller_index_list}
122 [Documentation] Give this keyword a scalar or list of controllers to be stopped.
123 : FOR ${i} IN @{controller_index_list}
124 \ ${output}= Run Command On Controller ${ODL_SYSTEM_${i}_IP} ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
125 \ Controller Down Check ${ODL_SYSTEM_${i}_IP}
127 Start Multiple Controllers
128 [Arguments] ${timeout} @{controller_index_list}
129 [Documentation] Give this keyword a scalar or list of controllers to be started.
130 : FOR ${i} IN @{controller_index_list}
131 \ ${output}= Run Command On Controller ${ODL_SYSTEM_${i}_IP} ${WORKSPACE}/${BUNDLEFOLDER}/bin/start
132 \ Wait For Controller Sync ${timeout} ${ODL_SYSTEM_${i}_IP}
135 [Arguments] ${exclude_controller}=${EMPTY}
136 [Documentation] Creates a list of all controllers minus any excluded controller.
137 Log ${exclude_controller}
138 @{searchlist} Create List ${CONTROLLER} ${CONTROLLER1} ${CONTROLLER2}
139 Remove Values From List ${searchlist} ${exclude_controller}
141 [Return] ${searchlist}
143 Get Leader And Verify
144 [Arguments] ${shard_name} ${old_leader}=${EMPTY}
145 [Documentation] Returns the IP addr or hostname of the leader of the specified shard.
146 ... Controllers are specifed in the pybot command line.
147 ${searchlist} Get Controller List ${old_leader}
148 ${leader} GetLeader ${shard_name} ${3} ${3} ${1} ${RESTCONFPORT}
150 Should Not Be Equal As Strings ${leader} None
151 Run Keyword If '${old_leader}'!='${EMPTY}' Should Not Be Equal ${old_leader} ${leader}
155 [Arguments] ${shard_name}
156 [Documentation] No leader is elected in the car shard
157 ${leader} GetLeader ${shard_name} ${3} ${1} ${1} ${RESTCONFPORT}
158 ... ${CURRENT_CAR_LEADER}
159 Should Be Equal As Strings ${leader} None
162 [Arguments] ${shard_name} ${exclude_controller}=${EMPTY}
163 [Documentation] Returns the IP addresses or hostnames of all followers of the specified shard.
164 ${searchlist} Get Controller List ${exclude_controller}
165 ${followers} GetFollowers ${shard_name} ${3} ${3} ${1} ${RESTCONFPORT}
168 Should Not Be Empty ${followers}
169 [Return] ${followers}
171 Stop One Or More Controllers
172 [Arguments] @{controllers}
173 [Documentation] Give this keyword a scalar or list of controllers to be stopped.
174 ${cmd} = Set Variable ${KARAF_HOME}/bin/stop
175 : FOR ${ip} IN @{controllers}
176 \ Run Command On Remote System ${ip} ${cmd}
178 Kill One Or More Controllers
179 [Arguments] @{controllers}
180 [Documentation] Give this keyword a scalar or list of controllers to be stopped.
181 ${cmd} = Set Variable ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
183 : FOR ${ip} IN @{controllers}
184 \ Run Command On Remote System ${ip} ${cmd}
186 Wait For Cluster Down
187 [Arguments] ${timeout} @{controllers}
188 [Documentation] Waits for one or more clustered controllers to be down.
189 : FOR ${ip} IN @{controllers}
190 \ ${status}= Run Keyword And Return Status Wait For Controller Down ${timeout} ${ip}
191 \ Exit For Loop If '${status}' == 'FAIL'
193 Wait For Controller Down
194 [Arguments] ${timeout} ${ip}
195 [Documentation] Waits for one controllers to be down.
196 Wait Until Keyword Succeeds ${timeout} 2s Controller Down Check ${ip}
198 Controller Down Check
200 [Documentation] Checks to see if a controller is down by verifying that the karaf process isn't present.
201 ${cmd} = Set Variable ps axf | grep karaf | grep -v grep | wc -l
202 ${response} Run Command On COntroller ${ip} ${cmd}
203 Log Number of controller instances running: ${response}
204 Should Start With ${response} 0 Controller process found or there may be extra instances of karaf running on the host machine.
206 Start One Or More Controllers
207 [Arguments] @{controllers}
208 [Documentation] Give this keyword a scalar or list of controllers to be started.
209 ${cmd} = Set Variable ${KARAF_HOME}/bin/start
210 : FOR ${ip} IN @{controllers}
211 \ Run Command On Remote System ${ip} ${cmd}
213 Wait For Cluster Sync
214 [Arguments] ${timeout} @{controllers}
215 [Documentation] Waits for one or more clustered controllers to report Sync Status as true.
216 : FOR ${ip} IN @{controllers}
217 \ ${status}= Run Keyword And Return Status Wait For Controller Sync ${timeout} ${ip}
218 \ Exit For Loop If '${status}' == 'FAIL'
220 Wait For Controller Sync
221 [Arguments] ${timeout} ${ip}
222 [Documentation] Waits for one controllers to report Sync Status as true.
223 Wait Until Keyword Succeeds ${timeout} 2s Controller Sync Status Should Be True ${ip}
225 Controller Sync Status Should Be True
227 [Documentation] Checks if Sync Status is true.
228 ${SyncStatus}= Get Controller Sync Status ${ip}
229 Should Be Equal ${SyncStatus} ${TRUE}
231 Controller Sync Status Should Be False
233 [Documentation] Checks if Sync Status is false.
234 ${SyncStatus}= Get Controller Sync Status ${ip}
235 Should Be Equal ${SyncStatus} ${FALSE}
237 Get Controller Sync Status
238 [Arguments] ${controller_ip}
239 [Documentation] Return Sync Status.
240 Create_Session session http://${controller_ip}:${RESTCONFPORT} headers=${HEADERS} auth=${AUTH}
241 ${data}= Get Data From URI session ${jolokia_conf}
243 ${json}= To Json ${data}
244 ${value}= Get From Dictionary ${json} value
245 ${ConfSyncStatus}= Get From Dictionary ${value} SyncStatus
246 Log Configuration Sync Status: ${ConfSyncStatus}
247 ${data}= Get Data From URI session ${jolokia_oper}
249 ${json}= To Json ${data}
250 ${value}= Get From Dictionary ${json} value
251 ${OperSyncStatus}= Get From Dictionary ${value} SyncStatus
252 Log Operational Sync Status: ${OperSyncStatus}
253 Run Keyword If ${OperSyncStatus} and ${ConfSyncStatus} Set Test Variable ${SyncStatus} ${TRUE}
254 ... ELSE Set Test Variable ${SyncStatus} ${FALSE}
255 [Return] ${SyncStatus}
257 Clean One Or More Journals
258 [Arguments] @{controllers}
259 [Documentation] Give this keyword a scalar or list of controllers on which to clean journals.
260 ${del_cmd} = Set Variable rm -rf ${KARAF_HOME}/journal
261 : FOR ${ip} IN @{controllers}
262 \ Run Command On Remote System ${ip} ${del_cmd}
264 Clean One Or More Snapshots
265 [Arguments] @{controllers}
266 [Documentation] Give this keyword a scalar or list of controllers on which to clean snapshots.
267 ${del_cmd} = Set Variable rm -rf ${KARAF_HOME}/snapshots
268 : FOR ${ip} IN @{controllers}
269 \ Run Command On Remote System ${ip} ${del_cmd}
271 Show Cluster Configuation Files
272 [Arguments] @{controllers}
273 [Documentation] Prints out the cluster configuration files for one or more controllers.
274 Log controllers: @{controllers}
275 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/akka.conf
276 : FOR ${ip} IN @{controllers}
277 \ Run Command On Remote System ${ip} ${cmd}
278 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/modules.conf
279 : FOR ${ip} IN @{controllers}
280 \ Run Command On Remote System ${ip} ${cmd}
281 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/module-shards.conf
282 : FOR ${ip} IN @{controllers}
283 \ Run Command On Remote System ${ip} ${cmd}
284 ${cmd} = Set Variable cat ${KARAF_HOME}/configuration/initial/jolokia.xml
285 : FOR ${ip} IN @{controllers}
286 \ Run Command On Remote System ${ip} ${cmd}
287 ${cmd} = Set Variable cat ${KARAF_HOME}/etc/initial/org.apache.karaf.management.cfg
288 : FOR ${ip} IN @{controllers}
289 \ Run Command On Remote System ${ip} ${cmd}
290 ${cmd} = Set Variable cat ${KARAF_HOME}/etc/org.apache.karaf.features.cfg
291 : FOR ${ip} IN @{controllers}
292 \ Run Command On Remote System ${ip} ${cmd}
294 Isolate a Controller From Cluster
295 [Arguments] ${isolated controller} @{controllers}
296 [Documentation] Use IPTables to isolate one controller from the cluster.
297 ... On the isolated controller it blocks IP traffic to and from each of the other controllers.
298 : FOR ${controller} IN @{controllers}
299 \ ${other controller}= Evaluate "${isolated controller}" != "${controller}"
300 \ Run Keyword If ${other controller} Isolate One Controller From Another ${isolated controller} ${controller}
302 Rejoin a Controller To Cluster
303 [Arguments] ${isolated controller} @{controllers}
304 [Documentation] Use IPTables to rejoin one controller to the cluster.
305 ... On the isolated controller it unblocks IP traffic to and from each of the other controllers.
306 : FOR ${controller} IN @{controllers}
307 \ ${other controller}= Evaluate "${isolated controller}" != "${controller}"
308 \ Run Keyword If ${other controller} Rejoin One Controller To Another ${isolated controller} ${controller}
310 Isolate One Controller From Another
311 [Arguments] ${isolated controller} ${controller}
312 [Documentation] Inserts an IPTable rule to disconnect one controller from another controller in the cluster.
313 Modify IPTables ${isolated controller} ${controller} -I
315 Rejoin One Controller To Another
316 [Arguments] ${isolated controller} ${controller}
317 [Documentation] Deletes an IPTable rule, allowing one controller to reconnect to another controller in the cluster.
318 Modify IPTables ${isolated controller} ${controller} -D
321 [Arguments] ${isolated controller} ${controller} ${rule type}
322 [Documentation] Adds a rule, usually inserting or deleting an entry between two controllers.
323 ${base string} Set Variable sudo iptables ${rule type} OUTPUT -p all --source
324 ${cmd string} Catenate ${base string} ${isolated controller} --destination ${controller} -j DROP
325 Run Command On Remote System ${isolated controller} ${cmd string}
326 ${cmd string} Catenate ${base string} ${controller} --destination ${isolated controller} -j DROP
327 Run Command On Remote System ${isolated controller} ${cmd string}
328 ${cmd string} Set Variable sudo iptables -L -n
329 ${return string}= Run Command On Remote System ${isolated controller} ${cmd string}
331 Run Keyword If "${rule type}" == '-I' Should Match Regexp ${return string} [\s\S]*DROP *all *-- *${isolated controller} *${controller}[\s\S]*
332 Run Keyword If "${rule type}" == '-I' Should Match Regexp ${return string} [\s\S]*DROP *all *-- *${controller} *${isolated controller}[\s\S]*
334 Run Keyword If "${rule type}" == '-D' Should Match Regexp ${return string} (?![\s\S]*DROP *all *-- *${isolated controller} *${controller}[\s\S]*)
335 Run Keyword If "${rule type}" == '-D' Should Match Regexp ${return string} (?![\s\S]*DROP *all *-- *${controller} *${isolated controller}[\s\S]*)
337 Rejoin All Isolated Controllers
338 [Arguments] @{controllers}
339 [Documentation] Wipe all IPTables rules from all controllers, thus rejoining all controllers.
340 : FOR ${isolated controller} IN @{controllers}
341 \ Flush IPTables ${isolated controller}
344 [Arguments] ${isolated controller}
345 [Documentation] This keyword is generally not called from a test case but supports a complete wipe of all rules on
347 ${cmd string} Set Variable sudo iptables -v -F
348 ${return string}= Run Command On Remote System ${isolated controller} ${cmd string}
349 Log return: ${return string}
350 Should Contain ${return string} Flushing chain `INPUT'
351 Should Contain ${return string} Flushing chain `FORWARD'
352 Should Contain ${return string} Flushing chain `OUTPUT'