2 Documentation Resource housing Keywords common to several suites for cluster functional testing.
4 ... Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
5 ... Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
7 ... This program and the accompanying materials are made available under the
8 ... terms of the Eclipse Public License v1.0 which accompanies this distribution,
9 ... and is available at http://www.eclipse.org/legal/epl-v10.html
12 ... This resource holds private state (in suite variables),
13 ... which is generated once at Setup with ClusterManagement_Setup KW.
14 ... The state includes member indexes, IP addresses and Http (RequestsLibrary) sessions.
15 ... Cluster Keywords normally use member index, member list or nothing (all members) as argument.
17 ... All index lists returned should be sorted numerically, fix if not.
20 ... odl-jolokia is assumed to be installed.
22 ... Keywords are ordered as follows:
24 ... - Shard state, leader and followers
25 ... - Entity Owner, candidates and successors
26 ... - Kill and Start Member
27 ... - Isolate and Rejoin Member
28 ... - Run Commands On Member
29 ... - REST requests and checks on Members
31 ... TODO: Unify capitalization of Leaders and Followers.
32 Library RequestsLibrary # for Create_Session and To_Json
34 Resource ${CURDIR}/CompareStream.robot
35 Resource ${CURDIR}/TemplatedRequests.robot # for Get_As_Json_From_Uri
36 Resource ${CURDIR}/Utils.robot # for Run_Command_On_Controller
39 ${JAVA_HOME} ${EMPTY} # releng/builder scripts should provide correct value
40 ${JOLOKIA_CONF_SHARD_MANAGER_URI} jolokia/read/org.opendaylight.controller:Category=ShardManager,name=shard-manager-config,type=DistributedConfigDatastore
41 ${JOLOKIA_OPER_SHARD_MANAGER_URI} jolokia/read/org.opendaylight.controller:Category=ShardManager,name=shard-manager-operational,type=DistributedOperationalDatastore
42 ${JOLOKIA_READ_URI} jolokia/read/org.opendaylight.controller
43 ${ENTITY_OWNER_URI} restconf/operational/entity-owners:entity-owners
44 ${RESTCONF_MODULES_DIR} ${CURDIR}/../variables/restconf/modules
47 ClusterManagement_Setup
48 [Documentation] Detect repeated call, or detect number of members and initialize derived suite variables.
49 # Avoid multiple initialization by several downstream libraries.
50 ${already_done} = BuiltIn.Get_Variable_Value \${ClusterManagement__has_setup_run} False
51 BuiltIn.Return_From_Keyword_If ${already_done}
52 BuiltIn.Set_Suite_Variable \${ClusterManagement__has_setup_run} True
53 ${cluster_size} = BuiltIn.Get_Variable_Value \${NUM_ODL_SYSTEM} 1
54 ${status} ${possibly_int_of_members} = BuiltIn.Run_Keyword_And_Ignore_Error BuiltIn.Convert_To_Integer ${cluster_size}
55 ${int_of_members} = BuiltIn.Set_Variable_If '${status}' != 'PASS' ${1} ${possibly_int_of_members}
56 ClusterManagement__Compute_Derived_Variables int_of_members=${int_of_members}
58 Check_Cluster_Is_In_Sync
59 [Arguments] ${member_index_list}=${EMPTY}
60 [Documentation] Fail if no-sync is detected on a member from list (or any).
61 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
62 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
63 \ ${status} = Get_Sync_Status_Of_Member member_index=${index}
64 \ BuiltIn.Continue_For_Loop_If 'True' == '${status}'
65 \ BuiltIn.Fail Index ${index} has incorrect status: ${status}
67 Get_Sync_Status_Of_Member
68 [Arguments] ${member_index}
69 [Documentation] Obtain IP, two GETs from jolokia URIs, return combined sync status as string.
70 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
71 ${conf_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${JOLOKIA_CONF_SHARD_MANAGER_URI} session=${session}
72 ${conf_status} = ClusterManagement__Parse_Sync_Status shard_manager_text=${conf_text}
73 BuiltIn.Return_From_Keyword_If 'False' == ${conf_status} False
74 ${oper_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${JOLOKIA_OPER_SHARD_MANAGER_URI} session=${session}
75 ${oper_status} = ClusterManagement__Parse_Sync_Status shard_manager_text=${oper_text}
76 [Return] ${oper_status}
78 Verify_Leader_Exists_For_Each_Shard
79 [Arguments] ${shard_name_list} ${shard_type}=operational ${member_index_list}=${EMPTY} ${verify_restconf}=True
80 [Documentation] For each shard name, call Get_Leader_And_Followers_For_Shard.
81 ... Not much logic there, but single Keyword is useful when using BuiltIn.Wait_Until_Keyword_Succeeds.
82 : FOR ${shard_name} IN @{shard_name_list}
83 \ Get_Leader_And_Followers_For_Shard shard_name=${shard_name} shard_type=${shard_type} validate=True member_index_list=${member_index_list} verify_restconf=${verify_restconf}
85 Get_Leader_And_Followers_For_Shard
86 [Arguments] ${shard_name}=default ${shard_type}=operational ${validate}=True ${member_index_list}=${EMPTY} ${verify_restconf}=True
87 [Documentation] Get role lists, validate there is one leader, return the leader and list of followers.
88 ... Optionally, issue GET to a simple restconf URL to make sure subsequent operations will not encounter 503.
89 ${leader_list} ${follower_list} = Get_State_Info_For_Shard shard_name=${shard_name} shard_type=${shard_type} validate=True member_index_list=${member_index_list}
90 ... verify_restconf=${verify_restconf}
91 ${leader_count} = BuiltIn.Get_Length ${leader_list}
92 BuiltIn.Run_Keyword_If ${leader_count} < 1 BuiltIn.Fail No leader found.
93 BuiltIn.Length_Should_Be ${leader_list} ${1} Too many Leaders.
94 ${leader} = Collections.Get_From_List ${leader_list} 0
95 [Return] ${leader} ${follower_list}
97 Get_State_Info_For_Shard
98 [Arguments] ${shard_name}=default ${shard_type}=operational ${validate}=False ${member_index_list}=${EMPTY} ${verify_restconf}=False
99 [Documentation] Return lists of Leader and Follower member indices from a given member index list
100 ... (or from the full list if empty). If \${shard_type} is not 'config', 'operational' is assumed.
101 ... If \${validate}, Fail if raft state is not Leader or Follower (for example on Candidate).
102 ... The biggest difference from Get_Leader_And_Followers_For_Shard
103 ... is that no check on number of Leaders is performed.
104 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
105 Collections.Sort_List ${index_list} # to guarantee return values are also sorted lists
106 # TODO: Support alternative capitalization of 'config'?
107 ${ds_type} = BuiltIn.Set_Variable_If '${shard_type}' != 'config' operational config
108 ${leader_list} = BuiltIn.Create_List
109 ${follower_list} = BuiltIn.Create_List
110 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
111 \ ${raft_state} = Get_Raft_State_Of_Shard_At_Member shard_name=${shard_name} shard_type=${ds_type} member_index=${index} verify_restconf=${verify_restconf}
112 \ BuiltIn.Run_Keyword_If 'Follower' == '${raft_state}' Collections.Append_To_List ${follower_list} ${index}
113 \ ... ELSE IF 'Leader' == '${raft_state}' Collections.Append_To_List ${leader_list} ${index}
114 \ ... ELSE IF ${validate} BuiltIn.Fail Unrecognized Raft state: ${raft_state}
115 [Return] ${leader_list} ${follower_list}
117 Get_Raft_State_Of_Shard_At_Member
118 [Arguments] ${shard_name} ${shard_type} ${member_index} ${verify_restconf}=False
119 [Documentation] Send request to Jolokia on indexed member, return extracted Raft status.
120 ... Optionally, check restconf works.
121 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
122 # TODO: Does the used URI tend to generate large data which floods log.html?
123 BuiltIn.Run_Keyword_If ${verify_restconf} TemplatedRequests.Get_As_Json_Templated session=${session} folder=${RESTCONF_MODULES_DIR} verify=False
124 ${type_class} = Resolve_Shard_Type_Class shard_type=${shard_type}
125 ${uri} = BuiltIn.Set_Variable ${JOLOKIA_READ_URI}:Category=Shards,name=member-${member_index}-shard-${shard_name}-${shard_type},type=${type_class}
126 ${data_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${uri} session=${session}
127 ${data_object} = RequestsLibrary.To_Json ${data_text}
128 ${value} = Collections.Get_From_Dictionary ${data_object} value
129 ${raft_state} = Collections.Get_From_Dictionary ${value} RaftState
130 [Return] ${raft_state}
132 Verify_Owner_And_Successors_For_Device
133 [Arguments] ${device_name} ${device_type} ${member_index} ${candidate_list}=${EMPTY}
134 [Documentation] Returns the owner and successors for the SB device ${device_name} of type ${device_type}. Request is sent to member ${member_index}.
135 ... For Boron and beyond, candidates are not removed on node down or isolation,
136 ... so this keyword expects candidates to be all members from Boron on.
137 ... Extra check is done to verify owner and successors are within the ${candidate_list}. This KW is useful when combined with WUKS.
138 ... ${candidate_list} minus owner is returned as ${successor list}.
139 ... Users can still use Get_Owner_And_Successors_For_Device if they are interested in downed candidates,
140 ... or for testing heterogeneous clusters.
141 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${candidate_list}
142 ${owner} ${successor_list} = Get_Owner_And_Successors_For_Device device_name=${device_name} device_type=${device_type} member_index=${member_index}
143 Collections.List_Should_Contain_Value ${index_list} ${owner} Owner ${owner} is not in candidate list ${index_list}
144 ${expected_candidate_list_origin} = CompareStream.Set_Variable_If_At_Least_Boron ${ClusterManagement__member_index_list} ${index_list}
145 # We do not want to manipulate either origin list.
146 ${expected_successor_list} = BuiltIn.Create_List @{expected_candidate_list_origin}
147 Collections.Remove_Values_From_List ${expected_successor_list} ${owner}
148 Collections.Lists_Should_Be_Equal ${expected_successor_list} ${successor_list} Successor list ${successor_list} is not the came as expected ${expected_successor_list}
149 # User expects the returned successor list to be the provided candidate list minus the owner.
150 Collections.Remove_Values_From_List ${index_list} ${owner}
151 [Return] ${owner} ${index_list}
153 Get_Owner_And_Successors_For_Device
154 [Arguments] ${device_name} ${device_type} ${member_index}
155 [Documentation] Returns the owner and a list of successors for the SB device ${device_name} of type ${device_type}. Request is sent to member ${member_index}.
156 ... Successors are those device candidates not elected as owner. The list of successors = (list of candidates) - (owner).
157 ... The returned successor list is sorted numerically.
158 ... Note that "candidate list" definition currently differs between Beryllium and Boron.
159 ... Use Verify_Owner_And_Successors_For_Device if you want the older semantics (inaccessible nodes not present in the list).
160 ${owner} ${candidate_list} = Get_Owner_And_Candidates_For_Device device_name=${device_name} device_type=${device_type} member_index=${member_index}
161 ${successor_list} = BuiltIn.Create_List @{candidate_list} # Copy operation is not required, but new variable name requires a line anyway.
162 Collections.Remove_Values_From_List ${successor_list} ${owner}
163 [Return] ${owner} ${successor_list}
165 Get_Owner_And_Candidates_For_Device
166 [Arguments] ${device_name} ${device_type} ${member_index}
167 [Documentation] Returns the owner and a list of candidates for the SB device ${device_name} of type ${device_type}. Request is sent to member ${member_index}.
168 ... Candidates are all members that register to own a device, so the list of candiates includes the owner.
169 ... The returned candidate list is sorted numerically.
170 ... Note that "candidate list" definition currently differs between Beryllium and Boron.
171 ... It is recommended to use Get_Owner_And_Successors_For_Device instead of this keyword, see documentation there.
172 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
173 ${data} = TemplatedRequests.Get_As_Json_From_Uri uri=${ENTITY_OWNER_URI} session=${session}
174 ${candidate_list} = BuiltIn.Create_List
175 ${entity_type} = BuiltIn.Set_Variable_If '${device_type}' == 'netconf' netconf-node/${device_name} ${device_type}
176 ${clear_data} = BuiltIn.Run_Keyword_If '${device_type}' == 'openflow' or '${device_type}' == 'netconf' Extract_OpenFlow_Device_Data ${data}
177 ... ELSE IF '${device_type}' == 'ovsdb' Extract_Ovsdb_Device_Data ${data}
178 ... ELSE IF '${device_type}' == 'org.opendaylight.mdsal.ServiceEntityType' Extract_Service_Entity_Type ${data}
179 ... ELSE Fail Not recognized device type: ${device_type}
180 ${json} = RequestsLibrary.To_Json ${clear_data}
181 ${entity_type_list} = Collections.Get_From_Dictionary &{json}[entity-owners] entity-type
182 ${entity_type_index} = Utils.Get_Index_From_List_Of_Dictionaries ${entity_type_list} type ${entity_type}
183 BuiltIn.Should_Not_Be_Equal ${entity_type_index} -1 No Entity Owner found for ${device_type}
184 ${entity_list} = Collections.Get_From_Dictionary @{entity_type_list}[${entity_type_index}] entity
185 ${entity_index} = Utils.Get_Index_From_List_Of_Dictionaries ${entity_list} id ${device_name}
186 BuiltIn.Should Not Be Equal ${entity_index} -1 Device ${device_name} not found in Entity Owner ${device_type}
187 ${entity_owner} = Collections.Get_From_Dictionary @{entity_list}[${entity_index}] owner
188 BuiltIn.Should_Not_Be_Empty ${entity_owner} No owner found for ${device_name}
189 ${owner} = String.Replace_String ${entity_owner} member- ${EMPTY}
190 ${owner} = BuiltIn.Convert_To_Integer ${owner}
191 ${entity_candidates_list} = Collections.Get_From_Dictionary @{entity_list}[${entity_index}] candidate
192 : FOR ${entity_candidate} IN @{entity_candidates_list}
193 \ ${candidate} = String.Replace_String &{entity_candidate}[name] member- ${EMPTY}
194 \ ${candidate} = BuiltIn.Convert_To_Integer ${candidate}
195 \ Collections.Append_To_List ${candidate_list} ${candidate}
196 Collections.Sort_List ${candidate_list}
197 [Return] ${owner} ${candidate_list}
199 Extract_Service_Entity_Type
201 [Documentation] Remove superfluous device data from Entity Owner printout.
202 ${clear_data} = String.Replace_String ${data} /odl-general-entity:entity[odl-general-entity:name='Uri [_value= ${EMPTY}
203 ${clear_data} = String.Replace_String ${clear_data} ]-service-group'] ${EMPTY}
205 [Return] ${clear_data}
207 Extract_OpenFlow_Device_Data
209 [Documentation] Remove superfluous OpenFlow device data from Entity Owner printout.
210 ${clear_data} = BuiltIn.Run Keyword If '${ODL_STREAM}' != 'beryllium' and '${ODL_OF_PLUGIN}' == 'lithium' String.Replace_String ${data} org.opendaylight.mdsal.ServiceEntityType openflow
211 ... ELSE BuiltIn.Set_Variable ${data}
212 ${clear_data} = String.Replace_String ${clear_data} /odl-general-entity:entity[odl-general-entity:name=' ${EMPTY}
213 ${clear_data} = String.Replace_String ${clear_data} /general-entity:entity[general-entity:name=' ${EMPTY}
214 ${clear_data} = String.Replace_String ${clear_data} '] ${EMPTY}
216 [Return] ${clear_data}
218 Extract_Ovsdb_Device_Data
220 [Documentation] Remove superfluous OVSDB device data from Entity Owner printout.
221 ${clear_data} = String.Replace_String ${data} /network-topology:network-topology/network-topology:topology[network-topology:topology-id='ovsdb:1']/network-topology:node[network-topology:node-id=' ${EMPTY}
222 ${clear_data} = String.Replace_String ${clear_data} '] ${EMPTY}
224 [Return] ${clear_data}
227 [Arguments] ${member} ${original_index_list}=${EMPTY} ${confirm}=True
228 [Documentation] Convenience keyword that kills the specified member of the cluster.
229 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member}
230 ${index_list} = ClusterManagement__Build_List ${member}
231 ${updated_index_list} = Kill_Members_From_List_Or_All ${index_list} ${original_index_list} ${confirm}
232 [Return] ${updated_index_list}
234 Kill_Members_From_List_Or_All
235 [Arguments] ${member_index_list}=${EMPTY} ${original_index_list}=${EMPTY} ${confirm}=True
236 [Documentation] If the list is empty, kill all ODL instances. Otherwise, kill members based on \${kill_index_list}
237 ... If \${confirm} is True, sleep 1 second and verify killed instances are not there anymore.
238 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member_index_list}
239 ${kill_index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
240 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${original_index_list}
241 ${command} = BuiltIn.Set_Variable ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
242 Run_Command_On_List_Or_All command=${command} member_index_list=${member_index_list}
243 ${updated_index_list} = BuiltIn.Create_List @{index_list}
244 Collections.Remove_Values_From_List ${updated_index_list} @{kill_index_list}
245 BuiltIn.Return_From_Keyword_If not ${confirm} ${updated_index_list}
246 # TODO: Convert to WUKS with configurable timeout if it turns out 1 second is not enough.
247 BuiltIn.Sleep 1s Kill -9 closes open files, which may take longer than ssh overhead, but not long enough to warrant WUKS.
248 : FOR ${index} IN @{kill_index_list}
249 \ Verify_Karaf_Is_Not_Running_On_Member member_index=${index}
250 [Return] ${updated_index_list}
253 [Arguments] ${member} ${wait_for_sync}=True ${timeout}=300s
254 [Documentation] Convenience keyword that starts the specified member of the cluster.
255 ${index_list} = ClusterManagement__Build_List ${member}
256 Start_Members_From_List_Or_All ${index_list} ${wait_for_sync} ${timeout}
258 Start_Members_From_List_Or_All
259 [Arguments] ${member_index_list}=${EMPTY} ${wait_for_sync}=True ${timeout}=300s ${karaf_home}=${WORKSPACE}${/}${BUNDLEFOLDER} ${export_java_home}=${JAVA_HOME}
260 [Documentation] If the list is empty, start all cluster members. Otherwise, start members based on present indices.
261 ... If ${wait_for_sync}, wait for cluster sync on listed members.
262 ... Optionally karaf_home can be overriden. Optionally specific JAVA_HOME is used for starting.
263 ${base_command} = BuiltIn.Set_Variable ${karaf_home}/bin/start
264 ${command} = BuiltIn.Set_Variable_If "${export_java_home}" export JAVA_HOME="${export_java_home}"; ${base_command} ${base_command}
265 Run_Command_On_List_Or_All command=${command} member_index_list=${member_index_list}
266 BuiltIn.Return_From_Keyword_If not ${wait_for_sync}
267 BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} 1s Check_Cluster_Is_In_Sync member_index_list=${member_index_list}
268 # TODO: Do we also want to check Shard Leaders here?
270 Clean_Journals_And_Snapshots_On_List_Or_All
271 [Arguments] ${member_index_list}=${EMPTY} ${karaf_home}=${WORKSPACE}${/}${BUNDLEFOLDER}
272 [Documentation] Delete journal and snapshots directories on every node listed (or all).
273 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
274 ${command} = Set Variable rm -rf "${karaf_home}/journal" "${karaf_home}/snapshots"
275 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
276 \ Run_Command_On_Member command=${command} member_index=${index}
278 Verify_Karaf_Is_Not_Running_On_Member
279 [Arguments] ${member_index}
280 [Documentation] Fail if non-zero karaf instances are counted on member of given index.
281 ${count} = Count_Running_Karafs_On_Member member_index=${member_index}
282 BuiltIn.Should_Be_Equal 0 ${count} Found running Karaf count: ${count}
284 Verify_Single_Karaf_Is_Running_On_Member
285 [Arguments] ${member_index}
286 [Documentation] Fail if number of karaf instances on member of given index is not one.
287 ${count} = Count_Running_Karafs_On_Member member_index=${member_index}
288 BuiltIn.Should_Be_Equal 1 ${count} Wrong number of Karafs running: ${count}
290 Count_Running_Karafs_On_Member
291 [Arguments] ${member_index}
292 [Documentation] Remotely execute grep for karaf process, return count as string.
293 ${command} = BuiltIn.Set_Variable ps axf | grep karaf | grep -v grep | wc -l
294 ${count} = Run_Command_On_Member command=${command} member_index=${member_index}
297 Isolate_Member_From_List_Or_All
298 [Arguments] ${isolate_member_index} ${member_index_list}=${EMPTY}
299 [Documentation] If the list is empty, isolate member from all ODL instances. Otherwise, isolate member based on present indices.
300 ... The KW will return a list of available members: \${updated index_list}=\${member_index_list}-\${isolate_member_index}
301 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
302 ${source} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${isolate_member_index}
303 : FOR ${index} IN @{index_list}
304 \ ${destination} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${index}
305 \ ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -I OUTPUT -p all --source ${source} --destination ${destination} -j DROP
306 \ BuiltIn.Run_Keyword_If "${index}" != "${isolate_member_index}" Run_Command_On_Member command=${command} member_index=${isolate_member_index}
307 ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -L -n
308 ${output} = Run_Command_On_Member command=${command} member_index=${isolate_member_index}
309 BuiltIn.Log ${output}
310 ${updated_index_list} = BuiltIn.Create_List @{index_list}
311 Collections.Remove_Values_From_List ${updated_index_list} ${isolate_member_index}
312 [Return] ${updated_index_list}
314 Rejoin_Member_From_List_Or_All
315 [Arguments] ${rejoin_member_index} ${member_index_list}=${EMPTY}
316 [Documentation] If the list is empty, rejoin member from all ODL instances. Otherwise, rejoin member based on present indices.
317 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
318 ${source} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${rejoin_member_index}
319 : FOR ${index} IN @{index_list}
320 \ ${destination} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${index}
321 \ ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -D OUTPUT -p all --source ${source} --destination ${destination} -j DROP
322 \ BuiltIn.Run_Keyword_If "${index}" != "${rejoin_member_index}" Run_Command_On_Member command=${command} member_index=${rejoin_member_index}
323 ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -L -n
324 ${output} = Run_Command_On_Member command=${command} member_index=${rejoin_member_index}
325 BuiltIn.Log ${output}
327 Flush_Iptables_From_List_Or_All
328 [Arguments] ${member_index_list}=${EMPTY}
329 [Documentation] If the list is empty, flush IPTables in all ODL instances. Otherwise, flush member based on present indices.
330 ${command} = BuiltIn.Set_Variable sudo iptables -v -F
331 ${output} = Run_Command_On_List_Or_All command=${command} member_index_list=${member_index_list}
333 Run_Command_On_List_Or_All
334 [Arguments] ${command} ${member_index_list}=${EMPTY}
335 [Documentation] Cycle through indices (or all), run command on each.
336 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
337 : FOR ${index} IN @{index_list}
338 \ Run_Command_On_Member command=${command} member_index=${index}
340 Run_Karaf_Command_On_List_Or_All
341 [Arguments] ${command} ${member_index_list}=${EMPTY}
342 [Documentation] Cycle through indices (or all), run karaf command on each.
343 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
344 : FOR ${index} IN @{index_list}
345 \ ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${index}
346 \ KarafKeywords.Issue Command On Karaf Console ${command} ${member_ip}
348 Run_Command_On_Member
349 [Arguments] ${command} ${member_index}
350 [Documentation] Obtain IP, call Utils and return output. This does not preserve active ssh session.
351 ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_index}
352 ${output} = Utils.Run_Command_On_Controller ${member_ip} ${command}
355 Put_As_Json_And_Check_Member_List_Or_All
356 [Arguments] ${uri} ${data} ${member_index} ${member_index_list}=${EMPTY}
357 [Documentation] Send a PUT with the supplied uri ${uri} and body ${data} to member ${member_index}.
358 ... Then check data is replicated in all or some members defined in ${member_index_list}.
359 ${response_text} = Put_As_Json_To_Member uri=${uri} data=${data} member_index=${member_index}
360 Wait Until Keyword Succeeds 5s 1s Check_Json_Member_List_Or_All uri=${uri} expected_data=${data} member_index_list=${member_index_list}
361 [Return] ${response_text}
363 Put_As_Json_To_Member
364 [Arguments] ${uri} ${data} ${member_index}
365 [Documentation] Send a PUT with the supplied uri and data to member ${member_index}.
366 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
367 ${response_text} = TemplatedRequests.Put_As_Json_To_Uri uri=${uri} data=${data} session=${session}
368 [Return] ${response_text}
370 Post_As_Json_To_Member
371 [Arguments] ${uri} ${data} ${member_index}
372 [Documentation] Send a POST with the supplied uri and data to member ${member_index}.
373 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
374 ${response_text} = TemplatedRequests.Post_As_Json_To_Uri uri=${uri} data=${data} session=${session}
375 [Return] ${response_text}
377 Delete_And_Check_Member_List_Or_All
378 [Arguments] ${uri} ${member_index} ${member_index_list}=${EMPTY}
379 [Documentation] Send a DELETE with the supplied uri to the member ${member_index}.
380 ... Then check the data is removed from all members in ${member_index_list}.
381 ${response_text} = Delete_From_Member ${uri} ${member_index}
382 BuiltIn.Wait_Until_Keyword_Succeeds 5s 1s Check_No_Content_Member_List_Or_All uri=${uri} member_index_list=${member_index_list}
383 [Return] ${response_text}
386 [Arguments] ${uri} ${member_index}
387 [Documentation] Send a DELETE with the supplied uri to member ${member_index}.
388 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
389 ${response_text} = TemplatedRequests.Delete_From_Uri uri=${uri} session=${session}
390 [Return] ${response_text}
392 Check_Json_Member_List_Or_All
393 [Arguments] ${uri} ${expected_data} ${member_index_list}=${EMPTY}
394 [Documentation] Send a GET with the supplied uri to all or some members defined in ${member_index_list}.
395 ... Then check received data is = ${expected data}.
396 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
397 : FOR ${index} IN @{index_list}
398 \ ${data} = Get_From_Member uri=${uri} member_index=${index}
399 \ TemplatedRequests.Normalize_Jsons_And_Compare ${expected_data} ${data}
401 Check_Item_Occurrence_Member_List_Or_All
402 [Arguments] ${uri} ${dictionary} ${member_index_list}=${EMPTY}
403 [Documentation] Send a GET with the supplied uri to all or some members defined in ${member_index_list}.
404 ... Then check received for occurrences of items expressed in a dictionary ${dictionary}.
405 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
406 : FOR ${index} IN @{index_list}
407 \ ${data} = Get_From_Member uri=${uri} member_index=${index}
408 \ Utils.Check Item Occurrence ${data} ${dictionary}
410 Check_No_Content_Member_List_Or_All
411 [Arguments] ${uri} ${member_index_list}=${EMPTY}
412 [Documentation] Send a GET with the supplied uri to all or some members defined in ${member_index_list}.
413 ... Then check there is no content.
414 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
415 : FOR ${index} IN @{index_list}
416 \ ${session} = Resolve_Http_Session_For_Member member_index=${index}
417 \ Utils.No_Content_From_URI ${session} ${uri}
420 [Arguments] ${uri} ${member_index} ${access}=${ACCEPT_EMPTY}
421 [Documentation] Send a GET with the supplied uri to member ${member_index}.
422 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
423 ${response_text} = TemplatedRequests.Get_From_Uri uri=${uri} accept=${access} session=${session}
424 [Return] ${response_text}
426 Resolve_IP_Address_For_Member
427 [Arguments] ${member_index}
428 [Documentation] Return node IP address of given index.
429 ${ip_address} = Collections.Get From Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_index}
430 [Return] ${ip_address}
432 Resolve_Http_Session_For_Member
433 [Arguments] ${member_index}
434 [Documentation] Return RequestsLibrary session alias pointing to node of given index.
435 ${session} = BuiltIn.Set_Variable ClusterManagement__session_${member_index}
438 Resolve_Shard_Type_Class
439 [Arguments] ${shard_type}
440 [Documentation] Simple lookup for class name corresponding to desired type.
441 BuiltIn.Run_Keyword_If '${shard_type}' == 'config' BuiltIn.Return_From_Keyword DistributedConfigDatastore
442 ... ELSE IF '${shard_type}' == 'operational' BuiltIn.Return_From_Keyword DistributedOperationalDatastore
443 BuiltIn.Fail Unrecognized shard type: ${shard_type}
445 ClusterManagement__Build_List
446 [Arguments] ${member}
447 ${member_int} = BuiltIn.Convert_To_Integer ${member}
448 ${index_list} = BuiltIn.Create_List ${member_int}
449 [Return] ${index_list}
451 ClusterManagement__Parse_Sync_Status
452 [Arguments] ${shard_manager_text}
453 [Documentation] Return sync status parsed out of given text. Called twice by Get_Sync_Status_Of_Member.
454 BuiltIn.Log ${shard_manager_text}
455 ${manager_object} = RequestsLibrary.To_Json ${shard_manager_text}
456 ${value_object} = Collections.Get_From_Dictionary dictionary=${manager_object} key=value
457 ${sync_status} = Collections.Get_From_Dictionary dictionary=${value_object} key=SyncStatus
458 [Return] ${sync_status}
460 ClusterManagement__Given_Or_Internal_Index_List
461 [Arguments] ${given_list}=${EMPTY}
462 [Documentation] Utility to allow \${EMPTY} as default argument value, as the internal list is computed at runtime.
463 ... This keyword always return a (shallow) copy of given or default list,
464 ... so operations with the returned list should not affect other lists.
465 ... Also note that this keyword does not consider empty list to be \${EMPTY}.
466 ${return_list_reference} = BuiltIn.Set_Variable_If """${given_list}""" != "" ${given_list} ${ClusterManagement__member_index_list}
467 ${return_list_copy} = BuiltIn.Create_List @{return_list_reference}
468 [Return] ${return_list_copy}
470 ClusterManagement__Given_Or_Empty_List
471 [Arguments] ${given_list}=${EMPTY}
472 [Documentation] Utility to allow \${EMPTY} as default argument value, as an empty list is computed at runtime.
473 ${empty_list} = BuiltIn.Create_List
474 ${given_length} = BuiltIn.Get_Length ${given_list}
475 ${return_list} = BuiltIn.Set_Variable_If ${given_length} > 0 ${given_list} ${empty_list}
476 [Return] ${return_list}
478 ClusterManagement__Compute_Derived_Variables
479 [Arguments] ${int_of_members}
480 [Documentation] Construct index list, session list and IP mapping, publish them as suite variables.
481 @{member_index_list} = BuiltIn.Create_List
482 @{session_list} = BuiltIn.Create_List
483 &{index_to_ip_mapping} = BuiltIn.Create_Dictionary
484 : FOR ${index} IN RANGE 1 ${int_of_members+1}
485 \ ClusterManagement__Include_Member_Index ${index} ${member_index_list} ${session_list} ${index_to_ip_mapping}
486 BuiltIn.Set_Suite_Variable \${ClusterManagement__member_index_list} ${member_index_list}
487 BuiltIn.Set_Suite_Variable \${ClusterManagement__index_to_ip_mapping} ${index_to_ip_mapping}
488 BuiltIn.Set_Suite_Variable \${ClusterManagement__session_list} ${session_list}
490 ClusterManagement__Include_Member_Index
491 [Arguments] ${index} ${member_index_list} ${session_list} ${index_to_ip_mapping}
492 [Documentation] Add a corresponding item based on index into the last three arguments.
493 ... Create the Http session whose alias is added to list.
494 Collections.Append_To_List ${member_index_list} ${index}
495 ${member_ip} = BuiltIn.Set_Variable ${ODL_SYSTEM_${index}_IP}
496 # ${index} is int (not string) so "key=value" syntax does not work in the following line.
497 Collections.Set_To_Dictionary ${index_to_ip_mapping} ${index} ${member_ip}
498 # Http session, with ${AUTH}, without headers.
499 ${session_alias} = Resolve_Http_Session_For_Member member_index=${index}
500 RequestsLibrary.Create_Session ${session_alias} http://${member_ip}:${RESTCONFPORT} auth=${AUTH} max_retries=0
501 Collections.Append_To_List ${session_list} ${session_alias}