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, Stop 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
35 Library ClusterEntities.py
36 Resource ${CURDIR}/CompareStream.robot
37 Resource ${CURDIR}/KarafKeywords.robot
38 Resource ${CURDIR}/SSHKeywords.robot
39 Resource ${CURDIR}/TemplatedRequests.robot # for Get_As_Json_From_Uri
40 Resource ${CURDIR}/Utils.robot # for Run_Command_On_Controller
41 Resource ../variables/Variables.robot
45 ${GC_LOG_PATH} ${KARAF_HOME}/data/log
46 ${JAVA_HOME} ${EMPTY} # releng/builder scripts should provide correct value
47 ${JOLOKIA_CONF_SHARD_MANAGER_URI} jolokia/read/org.opendaylight.controller:Category=ShardManager,name=shard-manager-config,type=DistributedConfigDatastore
48 ${JOLOKIA_OPER_SHARD_MANAGER_URI} jolokia/read/org.opendaylight.controller:Category=ShardManager,name=shard-manager-operational,type=DistributedOperationalDatastore
49 ${JOLOKIA_CONFIG_LOCAL_SHARDS_URI} jolokia/read/org.opendaylight.controller:type=DistributedConfigDatastore,Category=ShardManager,name=shard-manager-config/LocalShards
50 ${JOLOKIA_OPER_LOCAL_SHARDS_URI} jolokia/read/org.opendaylight.controller:type=DistributedOperationalDatastore,Category=ShardManager,name=shard-manager-operational/LocalShards
51 ${JOLOKIA_READ_URI} jolokia/read/org.opendaylight.controller
52 # Bug 9044 workaround: delete etc/host.key before restart.
53 @{ODL_DEFAULT_DATA_PATHS} tmp/ data/ cache/ snapshots/ journal/ segmented-journal/ etc/opendaylight/current/ etc/host.key
54 ${RESTCONF_MODULES_DIR} ${CURDIR}/../variables/restconf/modules
55 ${SINGLETON_NETCONF_DEVICE_ID_PREFIX} KeyedInstanceIdentifier{targetType=interface org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node, path=[org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology, org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology[key=TopologyKey{_topologyId=Uri{_value=topology-netconf}}], org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node[key=NodeKey{_nodeId=Uri{_value=
56 ${SINGLETON_NETCONF_DEVICE_ID_SUFFIX} }}]]}
57 ${SINGLETON_BGPCEP_DEVICE_ID_SUFFIX} -service-group
58 &{SINGLETON_DEVICE_ID_PREFIX} bgpcep=${EMPTY} netconf=${SINGLETON_NETCONF_DEVICE_ID_PREFIX} openflow=${EMPTY} sxp=${EMPTY}
59 &{SINGLETON_DEVICE_ID_SUFFIX} bgpcep=${SINGLETON_BGPCEP_DEVICE_ID_SUFFIX} netconf=${SINGLETON_NETCONF_DEVICE_ID_SUFFIX} openflow=${EMPTY} sxp=${EMPTY}
60 ${SINGLETON_ELECTION_ENTITY_TYPE} org.opendaylight.mdsal.ServiceEntityType
61 ${SINGLETON_CHANGE_OWNERSHIP_ENTITY_TYPE} org.opendaylight.mdsal.AsyncServiceCloseEntityType
62 ${NODE_ROLE_INDEX_START} 1
63 ${NODE_START_COMMAND} ${KARAF_HOME}/bin/start
64 ${NODE_STOP_COMMAND} ${KARAF_HOME}/bin/stop
65 ${NODE_KARAF_COUNT_COMMAND} ps axf | grep org.apache.karaf | grep -v grep | wc -l
66 ${NODE_KILL_COMMAND} ps axf | grep org.apache.karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
67 ${NODE_FREEZE_COMMAND} ps axf | grep org.apache.karaf | grep -v grep | awk '{print \"kill -STOP \" $1}' | sh
68 ${NODE_UNFREEZE_COMMAND} ps axf | grep org.apache.karaf | grep -v grep | awk '{print \"kill -CONT \" $1}' | sh
71 ClusterManagement_Setup
72 [Arguments] ${http_timeout}=${DEFAULT_TIMEOUT_HTTP} ${http_retries}=0
73 [Documentation] Detect repeated call, or detect number of members and initialize derived suite variables.
74 ... Http sessions are created with parameters to not waste time when ODL is no accepting connections properly.
75 # Avoid multiple initialization by several downstream libraries.
76 ${already_done} = BuiltIn.Get_Variable_Value \${ClusterManagement__has_setup_run} False
77 BuiltIn.Return_From_Keyword_If ${already_done}
78 BuiltIn.Set_Suite_Variable \${ClusterManagement__has_setup_run} True
79 ${cluster_size} = BuiltIn.Get_Variable_Value \${NUM_ODL_SYSTEM} 1
80 ${status} ${possibly_int_of_members} = BuiltIn.Run_Keyword_And_Ignore_Error BuiltIn.Convert_To_Integer ${cluster_size}
81 ${int_of_members} = BuiltIn.Set_Variable_If '${status}' != 'PASS' ${1} ${possibly_int_of_members}
82 ClusterManagement__Compute_Derived_Variables int_of_members=${int_of_members} http_timeout=${http_timeout} http_retries=${http_retries}
84 Check_Cluster_Is_In_Sync
85 [Arguments] ${member_index_list}=${EMPTY}
86 [Documentation] Fail if no-sync is detected on a member from list (or any).
87 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
88 FOR ${index} IN @{index_list} # usually: 1, 2, 3.
89 ${status} = Get_Sync_Status_Of_Member member_index=${index}
90 BuiltIn.Continue_For_Loop_If 'True' == '${status}'
91 BuiltIn.Fail Index ${index} has incorrect status: ${status}
94 Get_Sync_Status_Of_Member
95 [Arguments] ${member_index}
96 [Documentation] Obtain IP, two GETs from jolokia URIs, return combined sync status as string.
97 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
98 ${conf_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${JOLOKIA_CONF_SHARD_MANAGER_URI} session=${session}
99 ${conf_status} = ClusterManagement__Parse_Sync_Status shard_manager_text=${conf_text}
100 BuiltIn.Return_From_Keyword_If 'False' == ${conf_status} False
101 ${oper_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${JOLOKIA_OPER_SHARD_MANAGER_URI} session=${session}
102 ${oper_status} = ClusterManagement__Parse_Sync_Status shard_manager_text=${oper_text}
103 [Return] ${oper_status}
105 Verify_Leader_Exists_For_Each_Shard
106 [Arguments] ${shard_name_list} ${shard_type}=operational ${member_index_list}=${EMPTY} ${verify_restconf}=True
107 [Documentation] For each shard name, call Get_Leader_And_Followers_For_Shard.
108 ... Not much logic there, but single Keyword is useful when using BuiltIn.Wait_Until_Keyword_Succeeds.
109 FOR ${shard_name} IN @{shard_name_list}
110 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}
113 Get_Leader_And_Followers_For_Shard
114 [Arguments] ${shard_name}=default ${shard_type}=operational ${validate}=True ${member_index_list}=${EMPTY} ${verify_restconf}=True ${http_timeout}=${EMPTY}
115 [Documentation] Get role lists, validate there is one leader, return the leader and list of followers.
116 ... Optionally, issue GET to a simple restconf URL to make sure subsequent operations will not encounter 503.
117 ${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}
118 ... verify_restconf=${verify_restconf} http_timeout=${http_timeout}
119 ${leader_count} = BuiltIn.Get_Length ${leader_list}
120 BuiltIn.Run_Keyword_If ${leader_count} < 1 BuiltIn.Fail No leader found.
121 BuiltIn.Length_Should_Be ${leader_list} ${1} Too many Leaders.
122 ${leader} = Collections.Get_From_List ${leader_list} 0
123 [Return] ${leader} ${follower_list}
125 Get_State_Info_For_Shard
126 [Arguments] ${shard_name}=default ${shard_type}=operational ${validate}=False ${member_index_list}=${EMPTY} ${verify_restconf}=False ${http_timeout}=${EMPTY}
127 [Documentation] Return lists of Leader and Follower member indices from a given member index list
128 ... (or from the full list if empty). If \${shard_type} is not 'config', 'operational' is assumed.
129 ... If \${validate}, Fail if raft state is not Leader or Follower (for example on Candidate).
130 ... The biggest difference from Get_Leader_And_Followers_For_Shard
131 ... is that no check on number of Leaders is performed.
132 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
133 Collections.Sort_List ${index_list} # to guarantee return values are also sorted lists
134 # TODO: Support alternative capitalization of 'config'?
135 ${ds_type} = BuiltIn.Set_Variable_If '${shard_type}' != 'config' operational config
136 ${leader_list} = BuiltIn.Create_List
137 ${follower_list} = BuiltIn.Create_List
138 FOR ${index} IN @{index_list} # usually: 1, 2, 3.
139 ${raft_state} = Get_Raft_State_Of_Shard_At_Member shard_name=${shard_name} shard_type=${ds_type} member_index=${index} verify_restconf=${verify_restconf}
140 ... http_timeout=${http_timeout}
141 BuiltIn.Run_Keyword_If 'Follower' == '${raft_state}' Collections.Append_To_List ${follower_list} ${index}
142 ... ELSE IF 'Leader' == '${raft_state}' Collections.Append_To_List ${leader_list} ${index}
143 ... ELSE IF ${validate} BuiltIn.Fail Unrecognized Raft state: ${raft_state}
145 [Return] ${leader_list} ${follower_list}
147 Get_Raft_State_Of_Shard_At_Member
148 [Arguments] ${shard_name} ${shard_type} ${member_index} ${verify_restconf}=False ${http_timeout}=${EMPTY}
149 [Documentation] Send request to Jolokia on indexed member, return extracted Raft status.
150 ... Optionally, check restconf works.
151 ${raft_state} = Get_Raft_Property_From_Shard_Member RaftState ${shard_name} ${shard_type} ${member_index} verify_restconf=${verify_restconf}
152 ... http_timeout=${http_timeout}
153 [Return] ${raft_state}
155 Get_Raft_State_Of_Shard_Of_All_Member_Nodes
156 [Arguments] ${shard_name}=default ${shard_type}=config ${member_index_list}=${EMPTY}
157 [Documentation] Get raft state of shard of all member nodes
158 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
159 Collections.Sort_List ${index_list}
160 FOR ${index} IN @{index_list}
161 ClusterManagement.Get Raft State Of Shard At Member shard_name=${shard_name} shard_type=${shard_type} member_index=${index}
164 Get_Raft_Property_From_Shard_Member
165 [Arguments] ${property} ${shard_name} ${shard_type} ${member_index} ${verify_restconf}=False ${http_timeout}=${EMPTY}
166 [Documentation] Send request to Jolokia on indexed member, return extracted Raft property.
167 ... Optionally, check restconf works.
168 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
169 # TODO: Does the used URI tend to generate large data which floods log.html?
170 BuiltIn.Run_Keyword_If ${verify_restconf} TemplatedRequests.Get_As_Json_Templated session=${session} folder=${RESTCONF_MODULES_DIR} verify=False http_timeout=${http_timeout}
171 ${type_class} = Resolve_Shard_Type_Class shard_type=${shard_type}
172 ${cluster_index} = Evaluate ${member_index}+${NODE_ROLE_INDEX_START}-1
173 ${uri} = BuiltIn.Set_Variable ${JOLOKIA_READ_URI}:Category=Shards,name=member-${cluster_index}-shard-${shard_name}-${shard_type},type=${type_class}
174 ${data_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${uri} session=${session} http_timeout=${http_timeout}
175 ${data_object} = RequestsLibrary.To_Json ${data_text}
176 ${value} = Collections.Get_From_Dictionary ${data_object} value
177 ${raft_property} = Collections.Get_From_Dictionary ${value} ${property}
178 [Return] ${raft_property}
180 Verify_Shard_Leader_Elected
181 [Arguments] ${shard_name} ${shard_type} ${new_elected} ${old_leader} ${member_index_list}=${EMPTY} ${verify_restconf}=True
182 [Documentation] Verify new leader was elected or remained the same. Bool paramter ${new_elected} indicates if
183 ... new leader is elected or should remained the same as ${old_leader}
184 ${leader} ${followers}= Get_Leader_And_Followers_For_Shard shard_name=${shard_name} shard_type=${shard_type} member_index_list=${member_index_list} verify_restconf=${verify_restconf}
185 BuiltIn.Run_Keyword_If ${new_elected} BuiltIn.Should_Not_Be_Equal_As_Numbers ${old_leader} ${leader}
186 BuiltIn.Run_Keyword_Unless ${new_elected} BuiltIn.Should_Be_Equal_As_numbers ${old_leader} ${leader}
187 BuiltIn.Return_From_Keyword ${leader} ${followers}
189 Verify_Owner_And_Successors_For_Device
190 [Arguments] ${device_name} ${device_type} ${member_index} ${candidate_list}=${EMPTY} ${after_stop}=False
191 [Documentation] Returns the owner and successors for the SB device ${device_name} of type ${device_type}. Request is sent to member ${member_index}.
192 ... For Boron and beyond, candidates are not removed on node down or isolation,
193 ... so this keyword expects candidates to be all members from Boron on.
194 ... Extra check is done to verify owner and successors are within the ${candidate_list}. This KW is useful when combined with WUKS.
195 ... ${candidate_list} minus owner is returned as ${successor list}.
196 ... Users can still use Get_Owner_And_Successors_For_Device if they are interested in downed candidates,
197 ... or for testing heterogeneous clusters.
198 ${index_list} = List_Indices_Or_All given_list=${candidate_list}
199 ${owner} ${successor_list} = Get_Owner_And_Successors_For_Device device_name=${device_name} device_type=${device_type} member_index=${member_index}
200 Collections.List_Should_Contain_Value ${index_list} ${owner} Owner ${owner} is not in candidate list ${index_list}
201 # In Beryllium or after stopping an instance, the removed instance does not show in the candidate list.
202 ${expected_candidate_list_origin} = BuiltIn.Set_Variable_If ${after_stop} ${index_list} ${ClusterManagement__member_index_list}
203 # We do not want to manipulate either origin list.
204 ${expected_successor_list} = BuiltIn.Create_List @{expected_candidate_list_origin}
205 Collections.Remove_Values_From_List ${expected_successor_list} ${owner}
206 Collections.Lists_Should_Be_Equal ${expected_successor_list} ${successor_list} Successor list ${successor_list} is not the came as expected ${expected_successor_list}
207 # User expects the returned successor list to be the provided candidate list minus the owner.
208 Collections.Remove_Values_From_List ${index_list} ${owner}
209 [Return] ${owner} ${index_list}
211 Get_Owner_And_Successors_For_Device
212 [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
213 [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}.
214 ... Successors are those device candidates not elected as owner. The list of successors = (list of candidates) - (owner).
215 ... The returned successor list is sorted numerically.
216 ... Note that "candidate list" definition currently differs between Beryllium and Boron.
217 ... Use Verify_Owner_And_Successors_For_Device if you want the older semantics (inaccessible nodes not present in the list).
218 # TODO: somewhere to introduce ${DEFAULT_RESTCONF_DATASTORE_TIMEOUT}. Value may depend on protocol (ask vs tell) and perhaps stream.
219 ${owner} ${candidate_list} = Get_Owner_And_Candidates_For_Device device_name=${device_name} device_type=${device_type} member_index=${member_index} http_timeout=${http_timeout}
220 ${successor_list} = BuiltIn.Create_List @{candidate_list} # Copy operation is not required, but new variable name requires a line anyway.
221 Collections.Remove_Values_From_List ${successor_list} ${owner}
222 [Return] ${owner} ${successor_list}
224 Get_Owner_And_Candidates_For_Device_Rpc
225 [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
226 [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}.
227 ... Candidates are all members that register to own a device, so the list of candiates includes the owner.
228 ... The returned candidate list is sorted numerically.
229 ... Note that "candidate list" definition currently differs between Beryllium and Boron.
230 ... It is recommended to use Get_Owner_And_Successors_For_Device instead of this keyword, see documentation there.
231 BuiltIn.Comment TODO: Can this implementation be changed to call Get_Owner_And_Candidates_For_Type_And_Id?
232 ${index} = BuiltIn.Convert_To_Integer ${member_index}
233 ${ip} = Resolve_IP_Address_For_Member member_index=${index}
234 ${entity_type} = BuiltIn.Set_Variable_If '${device_type}' == 'netconf' netconf-node/${device_name} ${device_type}
235 ${url} = BuiltIn.Catenate SEPARATOR= http:// ${ip} :8181/ ${RESTCONF_URI}
236 ${entity_result} = ClusterEntities.get entity ${url} ${entity_type} ${device_name}
237 ${entity_candidates} = Collections.Get_From_Dictionary ${entity_result} candidates
238 ${entity_owner} = Collections.Get_From_Dictionary ${entity_result} owner
239 BuiltIn.Should_Not_Be_Empty ${entity_owner} No owner found for ${device_name}
240 ${owner} = String.Replace_String ${entity_owner} member- ${EMPTY}
241 ${owner} = BuiltIn.Convert_To_Integer ${owner}
242 ${candidate_list} = BuiltIn.Create_List
243 FOR ${entity_candidate} IN @{entity_candidates}
244 ${candidate} = String.Replace_String ${entity_candidate} member- ${EMPTY}
245 ${candidate} = BuiltIn.Convert_To_Integer ${candidate}
246 Collections.Append_To_List ${candidate_list} ${candidate}
248 Collections.Sort_List ${candidate_list}
249 [Return] ${owner} ${candidate_list}
251 Get_Owner_And_Candidates_For_Device_Singleton
252 [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
253 [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}.
254 # Normalize device type to the lowercase as in ${SINGLETON_DEVICE_ID_PREFIX} & ${SINGLETON_DEVICE_ID_SUFFIX}
255 ${device_type} = String.Convert To Lower Case ${device_type}
256 # Set device ID prefix
257 Collections.Dictionary Should Contain Key ${SINGLETON_DEVICE_ID_PREFIX} ${device_type}
258 ${device_id_prefix} = Collections.Get From Dictionary ${SINGLETON_DEVICE_ID_PREFIX} ${device_type}
259 Log ${device_id_prefix}
260 # Set device ID suffix
261 Collections.Dictionary Should Contain Key ${SINGLETON_DEVICE_ID_SUFFIX} ${device_type}
262 ${device_id_suffix} = Collections.Get From Dictionary ${SINGLETON_DEVICE_ID_SUFFIX} ${device_type}
263 Log ${device_id_suffix}
265 ${id} = BuiltIn.Set_Variable ${device_id_prefix}${device_name}${device_id_suffix}
267 # Get election entity type results
268 ${type} = BuiltIn.Set_Variable ${SINGLETON_ELECTION_ENTITY_TYPE}
269 ${owner_1} ${candidate_list_1} = Get_Owner_And_Candidates_For_Type_And_Id ${type} ${id} ${member_index} http_timeout=${http_timeout}
270 # Get change ownership entity type results
271 ${type} = BuiltIn.Set_Variable ${SINGLETON_CHANGE_OWNERSHIP_ENTITY_TYPE}
272 ${owner_2} ${candidate_list_2} = Get_Owner_And_Candidates_For_Type_And_Id ${type} ${id} ${member_index} http_timeout=${http_timeout}
273 # Owners must be same, if not, there is still some election or change ownership in progress
274 BuiltIn.Should_Be_Equal_As_Integers ${owner_1} ${owner_2} Owners for device ${device_name} are not same
275 [Return] ${owner_1} ${candidate_list_1}
277 Get_Owner_And_Candidates_For_Device
278 [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
279 [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}.
280 ... If parsing as singleton failed, kw try to parse data in old way (without singleton).
281 ... Candidates are all members that register to own a device, so the list of candiates includes the owner.
282 ... The returned candidate list is sorted numerically.
283 ... Note that "candidate list" definition currently differs between Beryllium and Boron.
284 ... It is recommended to use Get_Owner_And_Successors_For_Device instead of this keyword, see documentation there.
286 ${status} ${results} = BuiltIn.Run_Keyword_And_Ignore_Error Get_Owner_And_Candidates_For_Device_Singleton device_name=${device_name} device_type=${device_type} member_index=${member_index}
287 ... http_timeout=${http_timeout}
288 BuiltIn.Return_From_Keyword_If "${status}"=="PASS" ${results}
289 # If singleton failed, try parsing in old way
290 ${status} ${results} = BuiltIn.Run_Keyword_And_Ignore_Error Get_Owner_And_Candidates_For_Device_Rpc device_name=${device_name} device_type=${device_type} member_index=${member_index}
291 ... http_timeout=${http_timeout}
292 # previous 3 lines (BuilIn.Return.., # If singleton..., ${status}....) could be deleted when old way will not be supported anymore
293 BuiltIn.Run_Keyword_If '${status}'=='FAIL' BuiltIn.Fail Could not parse owner and candidates for device ${device_name}
296 Check_Old_Owner_Stays_Elected_For_Device
297 [Arguments] ${device_name} ${device_type} ${old_owner} ${node_to_ask} ${http_timeout}=${EMPTY}
298 [Documentation] Verify the owner remain the same as ${old_owner}
299 ${owner} ${candidates} = Get_Owner_And_Candidates_For_Device ${device_name} ${device_type} ${node_to_ask} http_timeout=${http_timeout}
300 BuiltIn.Should_Be_Equal_As_numbers ${old_owner} ${owner}
301 BuiltIn.Return_From_Keyword ${owner} ${candidates}
303 Check_New_Owner_Got_Elected_For_Device
304 [Arguments] ${device_name} ${device_type} ${old_owner} ${node_to_ask} ${http_timeout}=${EMPTY}
305 [Documentation] Verify new owner was elected comparing to ${old_owner}
306 ${owner} ${candidates} = Get_Owner_And_Candidates_For_Device ${device_name} ${device_type} ${node_to_ask} http_timeout=${http_timeout}
307 BuiltIn.Should_Not_Be_Equal_As_Numbers ${old_owner} ${owner}
308 BuiltIn.Return_From_Keyword ${owner} ${candidates}
310 Get_Owner_And_Candidates_For_Type_And_Id
311 [Arguments] ${type} ${id} ${member_index} ${require_candidate_list}=${EMPTY} ${http_timeout}=${EMPTY}
312 [Documentation] Returns the owner and a list of candidates for entity specified by ${type} and ${id}
313 ... Request is sent to member ${member_index}.
314 ... Candidates are all members that register to own a device, so the list of candiates includes the owner.
315 ... Bear in mind that for Boron and beyond, candidates are not removed on node down or isolation.
316 ... If ${require_candidate_list} is not \${EMPTY}, check whether the actual list of candidates matches.
317 ... Note that differs from "given list" semantics used in other keywords,
318 ... namely you cannot use \${EMPTY} to stand for "full list" in this keyword.
319 BuiltIn.Comment TODO: Find a way to unify and deduplicate code blocks in Get_Owner_And_Candidates_* keywords.
320 ${owner} ${candidates} = Get_Owner_And_Candidates_For_Device_Rpc ${id} ${type} ${member_index} http_timeout=${http_timeout}
321 [Return] ${owner} ${candidates}
323 Extract_Service_Entity_Type
325 [Documentation] Remove superfluous device data from Entity Owner printout.
326 ${clear_data} = String.Replace_String ${data} /odl-general-entity:entity[odl-general-entity:name=' ${EMPTY}
327 ${clear_data} = String.Replace_String ${clear_data} -service-group'] ${EMPTY}
329 [Return] ${clear_data}
331 Extract_OpenFlow_Device_Data
333 [Documentation] Remove superfluous OpenFlow device data from Entity Owner printout.
334 ${clear_data} = String.Replace_String ${data} org.opendaylight.mdsal.ServiceEntityType openflow
335 ${clear_data} = String.Replace_String ${clear_data} /odl-general-entity:entity[odl-general-entity:name=' ${EMPTY}
336 ${clear_data} = String.Replace_String ${clear_data} /general-entity:entity[general-entity:name=' ${EMPTY}
337 ${clear_data} = String.Replace_String ${clear_data} '] ${EMPTY}
339 [Return] ${clear_data}
341 Extract_Ovsdb_Device_Data
343 [Documentation] Remove superfluous OVSDB device data from Entity Owner printout.
344 ${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}
345 ${clear_data} = String.Replace_String ${clear_data} '] ${EMPTY}
347 [Return] ${clear_data}
350 [Arguments] ${member} ${original_index_list}=${EMPTY} ${confirm}=True
351 [Documentation] Convenience keyword that kills the specified member of the cluster.
352 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member}
353 ${index_list} = ClusterManagement__Build_List ${member}
354 ${member_ip} = Return_Member_IP ${member}
355 KarafKeywords.Log_Message_To_Controller_Karaf Killing ODL${member} ${member_ip}
356 ${updated_index_list} = Kill_Members_From_List_Or_All ${index_list} ${original_index_list} ${confirm}
357 [Return] ${updated_index_list}
359 Kill_Members_From_List_Or_All
360 [Arguments] ${member_index_list}=${EMPTY} ${original_index_list}=${EMPTY} ${confirm}=True
361 [Documentation] If the list is empty, kill all ODL instances. Otherwise, kill members based on \${kill_index_list}
362 ... If \${confirm} is True, sleep 1 second and verify killed instances are not there anymore.
363 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member_index_list}
364 ${kill_index_list} = List_Indices_Or_All given_list=${member_index_list}
365 ${index_list} = List_Indices_Or_All given_list=${original_index_list}
366 Run_Bash_Command_On_List_Or_All command=${NODE_KILL_COMMAND} member_index_list=${member_index_list}
367 ${updated_index_list} = BuiltIn.Create_List @{index_list}
368 Collections.Remove_Values_From_List ${updated_index_list} @{kill_index_list}
369 BuiltIn.Return_From_Keyword_If not ${confirm} ${updated_index_list}
370 # TODO: Convert to WUKS with configurable timeout if it turns out 1 second is not enough.
371 BuiltIn.Sleep 1s Kill -9 closes open files, which may take longer than ssh overhead, but not long enough to warrant WUKS.
372 FOR ${index} IN @{kill_index_list}
373 Verify_Karaf_Is_Not_Running_On_Member member_index=${index}
375 Run_Bash_Command_On_List_Or_All command=netstat -pnatu | grep 2550
376 [Return] ${updated_index_list}
379 [Arguments] ${member} ${original_index_list}=${EMPTY} ${confirm}=True ${msg}=${EMPTY}
380 [Documentation] Convenience keyword that stops the specified member of the cluster.
381 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member}
382 ${index_list} = ClusterManagement__Build_List ${member}
383 ${member_ip} = Return_Member_IP ${member}
384 ${msg} = Builtin.Set Variable If "${msg}" == "${EMPTY}" Stopping ODL${member} ${member_ip} Stopping ODL${member} ${member_ip}, ${msg}
385 KarafKeywords.Log_Message_To_Controller_Karaf ${msg}
386 ${updated_index_list} = Stop_Members_From_List_Or_All ${index_list} ${original_index_list} ${confirm}
387 [Return] ${updated_index_list}
389 Stop_Members_From_List_Or_All
390 [Arguments] ${member_index_list}=${EMPTY} ${original_index_list}=${EMPTY} ${confirm}=True ${timeout}=360s
391 [Documentation] If the list is empty, stops all ODL instances. Otherwise stop members based on \${stop_index_list}
392 ... If \${confirm} is True, verify stopped instances are not there anymore.
393 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member_index_list}
394 ${stop_index_list} = List_Indices_Or_All given_list=${member_index_list}
395 ${index_list} = List_Indices_Or_All given_list=${original_index_list}
396 Run_Bash_Command_On_List_Or_All command=${NODE_STOP_COMMAND} member_index_list=${member_index_list}
397 ${updated_index_list} = BuiltIn.Create_List @{index_list}
398 Collections.Remove_Values_From_List ${updated_index_list} @{stop_index_list}
399 BuiltIn.Return_From_Keyword_If not ${confirm} ${updated_index_list}
400 FOR ${index} IN @{stop_index_list}
401 BuiltIn.Wait Until Keyword Succeeds ${timeout} 2s Verify_Karaf_Is_Not_Running_On_Member member_index=${index}
403 Run_Bash_Command_On_List_Or_All command=netstat -pnatu | grep 2550
404 [Return] ${updated_index_list}
407 [Arguments] ${member} ${wait_for_sync}=True ${timeout}=300s ${msg}=${EMPTY} ${check_system_status}=False ${verify_restconf}=True
408 ... ${service_list}=${EMPTY_LIST}
409 [Documentation] Convenience keyword that starts the specified member of the cluster.
410 ${index_list} = ClusterManagement__Build_List ${member}
411 ${member_ip} = Return_Member_IP ${member}
412 ${msg} = Builtin.Set Variable If "${msg}" == "${EMPTY}" Starting ODL${member} ${member_ip} Starting ODL${member} ${member_ip}, ${msg}
413 KarafKeywords.Log_Message_To_Controller_Karaf ${msg}
414 Start_Members_From_List_Or_All ${index_list} ${wait_for_sync} ${timeout} check_system_status=${check_system_status} verify_restconf=${verify_restconf} service_list=${service_list}
416 Start_Members_From_List_Or_All
417 [Arguments] ${member_index_list}=${EMPTY} ${wait_for_sync}=True ${timeout}=360s ${karaf_home}=${EMPTY} ${export_java_home}=${EMPTY} ${gc_log_dir}=${EMPTY}
418 ... ${check_system_status}=False ${verify_restconf}=True ${service_list}=${EMPTY_LIST}
419 [Documentation] If the list is empty, start all cluster members. Otherwise, start members based on present indices.
420 ... If ${wait_for_sync}, wait for cluster sync on listed members.
421 ... Optionally karaf_home can be overriden. Optionally specific JAVA_HOME is used for starting.
422 ... Garbage collection is unconditionally logged to files. TODO: Make that reasonable conditional?
423 ${base_command} = BuiltIn.Set_Variable_If """${karaf_home}""" != "" ${karaf_home}/bin/start ${NODE_START_COMMAND}
424 ${command} = BuiltIn.Set_Variable_If """${export_java_home}""" != "" export JAVA_HOME="${export_java_home}"; ${base_command} ${base_command}
425 ${epoch} = DateTime.Get_Current_Date time_zone=UTC result_format=epoch exclude_millis=False
426 ${gc_filepath} = BuiltIn.Set_Variable_If """${karaf_home}""" != "" ${karaf_home}/data/log/gc_${epoch}.log ${GC_LOG_PATH}/gc_${epoch}.log
427 ${gc_options} = BuiltIn.Set_Variable_If "docker" not in """${node_start_command}""" -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:${gc_filepath} ${EMPTY}
428 Run_Bash_Command_On_List_Or_All command=${command} ${gc_options} member_index_list=${member_index_list}
429 BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} 10s Verify_Members_Are_Ready ${member_index_list} ${wait_for_sync} ${verify_restconf}
430 ... ${check_system_status} ${service_list}
431 [Teardown] Run_Bash_Command_On_List_Or_All command=netstat -pnatu | grep 2550
433 Verify_Members_Are_Ready
434 [Arguments] ${member_index_list} ${verify_cluster_sync} ${verify_restconf} ${verify_system_status} ${service_list}
435 [Documentation] Verifies the specified readiness conditions for the given listed members after startup.
436 ... If ${verify_cluster_sync}, verifies the datastores have synced with the rest of the cluster.
437 ... If ${verify_restconf}, verifies RESTCONF is available.
438 ... If ${verify_system_status}, verifies the system services are OPERATIONAL.
439 BuiltIn.Run_Keyword_If ${verify_cluster_sync} Check_Cluster_Is_In_Sync ${member_index_list}
440 BuiltIn.Run_Keyword_If ${verify_restconf} Verify_Restconf_Is_Available ${member_index_list}
441 # for backward compatibility, some consumers might not be passing @{service_list}, but since we can't set a list to a default
442 # value, we need to check here if it's empty in order to skip the check which would throw an error
443 BuiltIn.Run_Keyword_If ${verify_system_status} and ("${service_list}" != "[[]]") ClusterManagement.Check Status Of Services Is OPERATIONAL @{service_list}
445 Verify_Restconf_Is_Available
446 [Arguments] ${member_index_list}
447 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
448 FOR ${index} IN @{index_list}
449 ${session} = Resolve_Http_Session_For_Member member_index=${index}
450 TemplatedRequests.Get_As_Json_Templated session=${session} folder=${RESTCONF_MODULES_DIR} verify=False
454 [Arguments] ${member}
455 [Documentation] Convenience keyword that stops the specified member of the cluster by freezing the jvm.
456 ${index_list} = ClusterManagement__Build_List ${member}
457 Freeze_Or_Unfreeze_Members_From_List_Or_All ${NODE_FREEZE_COMMAND} ${index_list}
459 Unfreeze_Single_Member
460 [Arguments] ${member} ${wait_for_sync}=True ${timeout}=60s
461 [Documentation] Convenience keyword that "continues" the specified member of the cluster by unfreezing the jvm.
462 ${index_list} = ClusterManagement__Build_List ${member}
463 Freeze_Or_Unfreeze_Members_From_List_Or_All ${NODE_UNFREEZE_COMMAND} ${index_list}
464 BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} 10s Check_Cluster_Is_In_Sync
466 Freeze_Or_Unfreeze_Members_From_List_Or_All
467 [Arguments] ${command} ${member_index_list}=${EMPTY}
468 [Documentation] If the list is empty, stops/runs all ODL instances. Otherwise stop/run members based on \${stop_index_list}
469 ... For command parameter only ${NODE_FREEZE_COMMAND} and ${NODE_UNFREEZE_COMMAND} should be used
470 ${freeze_index_list} = List_Indices_Or_All given_list=${member_index_list}
471 Run_Bash_Command_On_List_Or_All command=${command} member_index_list=${member_index_list}
473 Clean_Journals_Data_And_Snapshots_On_List_Or_All
474 [Arguments] ${member_index_list}=${EMPTY} ${karaf_home}=${KARAF_HOME}
475 [Documentation] Delete journal and snapshots directories on every node listed (or all).
476 ... BEWARE: If only a subset of members is cleaned, this causes RetiredGenerationException in Carbon after the affected node re-start.
477 ... See https://bugs.opendaylight.org/show_bug.cgi?id=8138
478 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
479 ${command} = Set Variable rm -rf "${karaf_home}/"*journal "${karaf_home}/snapshots" "${karaf_home}/data"
480 FOR ${index} IN @{index_list} # usually: 1, 2, 3.
481 Run_Bash_Command_On_Member command=${command} member_index=${index}
484 Verify_Karaf_Is_Not_Running_On_Member
485 [Arguments] ${member_index}
486 [Documentation] Fail if non-zero karaf instances are counted on member of given index.
487 ${count} = Count_Running_Karafs_On_Member member_index=${member_index}
488 BuiltIn.Should_Be_Equal 0 ${count} Found running Karaf count: ${count}
490 Verify_Single_Karaf_Is_Running_On_Member
491 [Arguments] ${member_index}
492 [Documentation] Fail if number of karaf instances on member of given index is not one.
493 ${count} = Count_Running_Karafs_On_Member member_index=${member_index}
494 BuiltIn.Should_Be_Equal 1 ${count} Wrong number of Karafs running: ${count}
496 Count_Running_Karafs_On_Member
497 [Arguments] ${member_index}
498 [Documentation] Remotely execute grep for karaf process, return count as string.
499 ${command} = BuiltIn.Set_Variable ${NODE_KARAF_COUNT_COMMAND}
500 ${count} = Run_Bash_Command_On_Member command=${command} member_index=${member_index}
503 Isolate_Member_From_List_Or_All
504 [Arguments] ${isolate_member_index} ${member_index_list}=${EMPTY} ${protocol}=all ${port}=${EMPTY}
505 [Documentation] If the list is empty, isolate member from all ODL instances. Otherwise, isolate member based on present indices.
506 ... The KW will return a list of available members: \${updated index_list}=\${member_index_list}-\${isolate_member_index}
507 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
508 ${source} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${isolate_member_index}
509 ${dport} = BuiltIn.Set_Variable_If '${port}' != '${EMPTY}' --dport ${port} ${EMPTY}
510 FOR ${index} IN @{index_list}
511 ${destination} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${index}
512 ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -I OUTPUT -p ${protocol} ${dport} --source ${source} --destination ${destination} -j DROP
513 BuiltIn.Run_Keyword_If "${index}" != "${isolate_member_index}" Run_Bash_Command_On_Member command=${command} member_index=${isolate_member_index}
515 ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -L -n
516 ${output} = Run_Bash_Command_On_Member command=${command} member_index=${isolate_member_index}
517 BuiltIn.Log ${output}
518 ${updated_index_list} = BuiltIn.Create_List @{index_list}
519 Collections.Remove_Values_From_List ${updated_index_list} ${isolate_member_index}
520 [Return] ${updated_index_list}
522 Rejoin_Member_From_List_Or_All
523 [Arguments] ${rejoin_member_index} ${member_index_list}=${EMPTY} ${protocol}=all ${port}=${EMPTY} ${timeout}=60s
524 [Documentation] If the list is empty, rejoin member from all ODL instances. Otherwise, rejoin member based on present indices.
525 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
526 ${source} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${rejoin_member_index}
527 ${dport} = BuiltIn.Set_Variable_If '${port}' != '${EMPTY}' --dport ${port} ${EMPTY}
528 FOR ${index} IN @{index_list}
529 ${destination} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${index}
530 ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -D OUTPUT -p ${protocol} ${dport} --source ${source} --destination ${destination} -j DROP
531 BuiltIn.Run_Keyword_If "${index}" != "${rejoin_member_index}" Run_Bash_Command_On_Member command=${command} member_index=${rejoin_member_index}
533 ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -L -n
534 ${output} = Run_Bash_Command_On_Member command=${command} member_index=${rejoin_member_index}
535 BuiltIn.Log ${output}
536 BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} 10s Check_Cluster_Is_In_Sync
538 Flush_Iptables_From_List_Or_All
539 [Arguments] ${member_index_list}=${EMPTY}
540 [Documentation] If the list is empty, flush IPTables in all ODL instances. Otherwise, flush member based on present indices.
541 ${command} = BuiltIn.Set_Variable sudo iptables -v -F
542 ${output} = Run_Bash_Command_On_List_Or_All command=${command} member_index_list=${member_index_list}
544 Check_Bash_Command_On_List_Or_All
545 [Arguments] ${command} ${member_index_list}=${EMPTY} ${return_success_only}=False ${log_on_success}=True ${log_on_failure}=True ${stderr_must_be_empty}=True
546 [Documentation] Cycle through indices (or all), run bash command on each, using temporary SSH session and restoring the previously active one.
547 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
548 FOR ${index} IN @{index_list}
549 Check_Bash_Command_On_Member command=${command} member_index=${index} return_success_only=${return_success_only} log_on_success=${log_on_success} log_on_failure=${log_on_failure}
550 ... stderr_must_be_empty=${stderr_must_be_empty}
553 Check_Bash_Command_On_Member
554 [Arguments] ${command} ${member_index} ${return_success_only}=False ${log_on_success}=True ${log_on_failure}=True ${stderr_must_be_empty}=True
555 [Documentation] Open SSH session, call SSHKeywords.Execute_Command_Passes, close session, restore previously active session and return output.
556 BuiltIn.Run_Keyword_And_Return SSHKeywords.Run_Keyword_Preserve_Connection Check_Unsafely_Bash_Command_On_Member ${command} ${member_index} return_success_only=${return_success_only} log_on_success=${log_on_success}
557 ... log_on_failure=${log_on_failure} stderr_must_be_empty=${stderr_must_be_empty}
559 Check_Unsafely_Bash_Command_On_Member
560 [Arguments] ${command} ${member_index} ${return_success_only}=False ${log_on_success}=True ${log_on_failure}=True ${stderr_must_be_empty}=True
561 [Documentation] Obtain Ip address, open session, call SSHKeywords.Execute_Command_Passes, close session and return output. This affects which SSH session is active.
562 ${member_ip} = Resolve_Ip_Address_For_Member ${member_index}
563 BuiltIn.Run_Keyword_And_Return SSHKeywords.Run_Unsafely_Keyword_Over_Temporary_Odl_Session ${member_ip} Execute_Command_Passes ${command} return_success_only=${return_success_only} log_on_success=${log_on_success}
564 ... log_on_failure=${log_on_failure} stderr_must_be_empty=${stderr_must_be_empty}
566 Run_Bash_Command_On_List_Or_All
567 [Arguments] ${command} ${member_index_list}=${EMPTY}
568 [Documentation] Cycle through indices (or all), run command on each.
569 # TODO: Migrate callers to Check_Bash_Command_*
570 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
571 FOR ${index} IN @{index_list}
572 Run_Bash_Command_On_Member command=${command} member_index=${index}
575 Run_Bash_Command_On_Member
576 [Arguments] ${command} ${member_index}
577 [Documentation] Obtain IP, call Utils and return output. This keeps previous ssh session active.
578 # TODO: Migrate callers to Check_Bash_Command_*
579 ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_index}
580 ${output} = SSHKeywords.Run_Keyword_Preserve_Connection Utils.Run_Command_On_Controller ${member_ip} ${command}
584 Run_Karaf_Command_On_List_Or_All
585 [Arguments] ${command} ${member_index_list}=${EMPTY} ${timeout}=10s
586 [Documentation] Cycle through indices (or all), run karaf command on each.
587 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
588 FOR ${index} IN @{index_list}
589 ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${index}
590 KarafKeywords.Safe_Issue_Command_On_Karaf_Console ${command} ${member_ip} timeout=${timeout}
593 Run_Karaf_Command_On_Member
594 [Arguments] ${command} ${member_index} ${timeout}=10s
595 [Documentation] Obtain IP address, call KarafKeywords and return output. This does not preserve active ssh session.
596 ... This keyword is not used by Run_Karaf_Command_On_List_Or_All, but returned output may be useful.
597 ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_index}
598 ${output} = KarafKeywords.Safe_Issue_Command_On_Karaf_Console ${command} controller=${member_ip} timeout=${timeout}
601 Install_Feature_On_List_Or_All
602 [Arguments] ${feature_name} ${member_index_list}=${EMPTY} ${timeout}=60s
603 [Documentation] Attempt installation on each member from list (or all). Then look for failures.
604 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
605 ${status_list} = BuiltIn.Create_List
606 FOR ${index} IN @{index_list}
607 ${status} ${text} = BuiltIn.Run_Keyword_And_Ignore_Error Install_Feature_On_Member feature_name=${feature_name} member_index=${index}
608 ... timeout=${timeout}
610 Collections.Append_To_List ${status_list} ${status}
612 FOR ${status} IN @{status_list}
613 BuiltIn.Run_Keyword_If "${status}" != "PASS" BuiltIn.Fail ${feature_name} installation failed, see log.
616 Install_Feature_On_Member
617 [Arguments] ${feature_name} ${member_index} ${timeout}=60s
618 [Documentation] Run feature:install karaf command, fail if installation was not successful. Return output.
619 ${status} ${output} = BuiltIn.Run_Keyword_And_Ignore_Error Run_Karaf_Command_On_Member command=feature:install ${feature_name} member_index=${member_index} timeout=${timeout}
620 BuiltIn.Run_Keyword_If "${status}" != "PASS" BuiltIn.Fail Failed to install ${feature_name}: ${output}
621 BuiltIn.Should_Not_Contain ${output} Can't install Failed to install ${feature_name}: ${output}
624 With_Ssh_To_List_Or_All_Run_Keyword
625 [Arguments] ${member_index_list} ${keyword_name} @{args} &{kwargs}
626 [Documentation] For each index in given list (or all): activate SSH connection, run given Keyword, close active connection. Return None.
627 ... Beware that in order to avoid "got positional argument after named arguments", first two arguments in the call should not be named.
628 BuiltIn.Comment This keyword is experimental and there is high risk of being replaced by another approach.
629 # TODO: For_Index_From_List_Or_All_Run_Keyword applied to With_Ssh_To_Member_Run_Keyword?
630 # TODO: Imagine another keyword, using ScalarClosures and adding member index as first argument for each call. Worth it?
631 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
632 FOR ${member_index} IN @{index_list}
633 ${member_ip} = Resolve_IP_Address_For_Member ${member_index}
634 SSHKeywords.Run_Unsafely_Keyword_Over_Temporary_Odl_Session ${member_ip} ${keyword_name} @{args} &{kwargs}
637 Safe_With_Ssh_To_List_Or_All_Run_Keyword
638 [Arguments] ${member_index_list} ${keyword_name} @{args} &{kwargs}
639 [Documentation] Remember active ssh connection index, call With_Ssh_To_List_Or_All_Run_Keyword, return None. Restore the conection index on teardown.
640 SSHKeywords.Run_Keyword_Preserve_Connection With_Ssh_To_List_Or_All_Run_Keyword ${member_index_list} ${keyword_name} @{args} &{kwargs}
642 Clean_Directories_On_List_Or_All
643 [Arguments] ${member_index_list}=${EMPTY} ${directory_list}=${EMPTY} ${karaf_home}=${KARAF_HOME} ${tmp_dir}=${EMPTY}
644 [Documentation] Clear @{directory_list} or @{ODL_DEFAULT_DATA_PATHS} for members in given list or all. Return None.
645 ... If \${tmp_dir} is nonempty, use that location to preserve data/log/.
646 ... This is intended to return Karaf (offline) to the state it was upon the first boot.
647 ${path_list} = Builtin.Set Variable If "${directory_list}" == "${EMPTY}" ${ODL_DEFAULT_DATA_PATHS} ${directory_list}
648 BuiltIn.Run_Keyword_If """${tmp_dir}""" != "" Check_Bash_Command_On_List_Or_All mkdir -p '${tmp_dir}' && rm -vrf '${tmp_dir}/log' && mv -vf '${karaf_home}/data/log' '${tmp_dir}/' ${member_index_list}
649 Safe_With_Ssh_To_List_Or_All_Run_Keyword ${member_index_list} ClusterManagement__Clean_Directories ${path_list} ${karaf_home}
650 BuiltIn.Run_Keyword_If """${tmp_dir}""" != "" Check_Bash_Command_On_List_Or_All mkdir -p '${karaf_home}/data' && rm -vrf '${karaf_home}/log' && mv -vf '${tmp_dir}/log' '${karaf_home}/data/' ${member_index_list}
652 Store_Karaf_Log_On_List_Or_All
653 [Arguments] ${member_index_list}=${EMPTY} ${dst_dir}=/tmp ${karaf_home}=${KARAF_HOME}
654 [Documentation] Saves karaf.log to the ${dst_dir} for members in given list or all. Return None.
655 Safe_With_Ssh_To_List_Or_All_Run_Keyword ${member_index_list} SSHKeywords.Execute_Command_Should_Pass cp ${karaf_home}/data/log/karaf.log ${dst_dir}
657 Restore_Karaf_Log_On_List_Or_All
658 [Arguments] ${member_index_list}=${EMPTY} ${src_dir}=/tmp ${karaf_home}=${KARAF_HOME}
659 [Documentation] Places stored karaf.log to the ${karaf_home}/data/log for members in given list or all. Return None.
660 Safe_With_Ssh_To_List_Or_All_Run_Keyword ${member_index_list} SSHKeywords.Execute_Command_Should_Pass cp ${src_dir}/karaf.log ${karaf_home}/data/log/
662 ClusterManagement__Clean_Directories
663 [Arguments] ${relative_path_list} ${karaf_home}
664 [Documentation] For each relative path, remove files with respect to ${karaf_home}. Return None.
665 FOR ${relative_path} IN @{relative_path_list}
666 SSHLibrary.Execute_Command rm -rf ${karaf_home}${/}${relative_path}
669 Put_As_Json_And_Check_Member_List_Or_All
670 [Arguments] ${uri} ${data} ${member_index} ${member_index_list}=${EMPTY}
671 [Documentation] Send a PUT with the supplied uri ${uri} and body ${data} to member ${member_index}.
672 ... Then check data is replicated in all or some members defined in ${member_index_list}.
673 ${response_text} = Put_As_Json_To_Member uri=${uri} data=${data} member_index=${member_index}
674 Wait Until Keyword Succeeds 5s 1s Check_Json_Member_List_Or_All uri=${uri} expected_data=${data} member_index_list=${member_index_list}
675 [Return] ${response_text}
677 Put_As_Json_And_Check_Member_List_Or_All_RFC8040
678 # FIXME: merge this keyword with Bierman02 version above when OVSDB test is migrated to RFC8040
679 [Arguments] ${uri} ${data} ${member_index} ${member_index_list}=${EMPTY}
680 [Documentation] Send a PUT with the supplied uri ${uri} and body ${data} to member ${member_index}.
681 ... Then check data is replicated in all or some members defined in ${member_index_list}.
682 ${response_text} = Put_As_Json_To_Member uri=${uri} data=${data} member_index=${member_index}
683 Wait Until Keyword Succeeds 5s 1s Check_Json_Member_List_Or_All uri=${uri}?content=config expected_data=${data} member_index_list=${member_index_list}
684 [Return] ${response_text}
686 Put_As_Json_To_Member
687 [Arguments] ${uri} ${data} ${member_index}
688 [Documentation] Send a PUT with the supplied uri and data to member ${member_index}.
689 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
690 ${response_text} = TemplatedRequests.Put_As_Json_To_Uri uri=${uri} data=${data} session=${session}
691 [Return] ${response_text}
693 Post_As_Json_To_Member
694 [Arguments] ${uri} ${data} ${member_index}
695 [Documentation] Send a POST with the supplied uri and data to member ${member_index}.
696 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
697 ${response_text} = TemplatedRequests.Post_As_Json_To_Uri uri=${uri} data=${data} session=${session}
698 [Return] ${response_text}
700 Delete_And_Check_Member_List_Or_All
701 [Arguments] ${uri} ${member_index} ${member_index_list}=${EMPTY}
702 [Documentation] Send a DELETE with the supplied uri to the member ${member_index}.
703 ... Then check the data is removed from all members in ${member_index_list}.
704 ${response_text} = Delete_From_Member ${uri} ${member_index}
705 BuiltIn.Wait_Until_Keyword_Succeeds 5s 1s Check_No_Content_Member_List_Or_All uri=${uri} member_index_list=${member_index_list}
706 [Return] ${response_text}
709 [Arguments] ${uri} ${member_index}
710 [Documentation] Send a DELETE with the supplied uri to member ${member_index}.
711 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
712 ${response_text} = TemplatedRequests.Delete_From_Uri uri=${uri} session=${session}
713 [Return] ${response_text}
715 Check_Json_Member_List_Or_All
716 [Arguments] ${uri} ${expected_data} ${member_index_list}=${EMPTY}
717 [Documentation] Send a GET with the supplied uri to all or some members defined in ${member_index_list}.
718 ... Then check received data is = ${expected data}.
719 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
720 FOR ${index} IN @{index_list}
721 ${data} = Get_From_Member uri=${uri} member_index=${index}
722 TemplatedRequests.Normalize_Jsons_And_Compare ${expected_data} ${data}
725 Check_Item_Occurrence_Member_List_Or_All
726 [Arguments] ${uri} ${dictionary} ${member_index_list}=${EMPTY}
727 [Documentation] Send a GET with the supplied uri to all or some members defined in ${member_index_list}.
728 ... Then check received for occurrences of items expressed in a dictionary ${dictionary}.
729 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
730 FOR ${index} IN @{index_list}
731 ${data} = Get_From_Member uri=${uri} member_index=${index}
732 Utils.Check Item Occurrence ${data} ${dictionary}
735 Check_No_Content_Member_List_Or_All
736 [Arguments] ${uri} ${member_index_list}=${EMPTY}
737 [Documentation] Send a GET with the supplied uri to all or some members defined in ${member_index_list}.
738 ... Then check there is no content.
739 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
740 FOR ${index} IN @{index_list}
741 ${session} = Resolve_Http_Session_For_Member member_index=${index}
742 Utils.No_Content_From_URI ${session} ${uri}
746 [Arguments] ${uri} ${member_index} ${access}=${ACCEPT_EMPTY}
747 [Documentation] Send a GET with the supplied uri to member ${member_index}.
748 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
749 ${response_text} = TemplatedRequests.Get_From_Uri uri=${uri} accept=${access} session=${session}
750 [Return] ${response_text}
752 Resolve_IP_Address_For_Member
753 [Arguments] ${member_index}
754 [Documentation] Return node IP address of given index.
755 ${ip_address} = Collections.Get From Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_index}
756 [Return] ${ip_address}
758 Resolve_IP_Address_For_Members
759 [Arguments] ${member_index_list}
760 [Documentation] Return a list of IP address of given indexes.
761 ${member_ip_list} = BuiltIn.Create_List
762 FOR ${index} IN @{member_index_list}
763 ${ip_address} = Collections.Get From Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${index}
764 Collections.Append_To_List ${member_ip_list} ${ip_address}
766 [Return] ${member_ip_list}
768 Resolve_Http_Session_For_Member
769 [Arguments] ${member_index}
770 [Documentation] Return RequestsLibrary session alias pointing to node of given index.
771 ${session} = BuiltIn.Set_Variable ClusterManagement__session_${member_index}
774 Resolve_Shard_Type_Class
775 [Arguments] ${shard_type}
776 [Documentation] Simple lookup for class name corresponding to desired type.
777 BuiltIn.Run_Keyword_If '${shard_type}' == 'config' BuiltIn.Return_From_Keyword DistributedConfigDatastore
778 ... ELSE IF '${shard_type}' == 'operational' BuiltIn.Return_From_Keyword DistributedOperationalDatastore
779 BuiltIn.Fail Unrecognized shard type: ${shard_type}
781 ClusterManagement__Build_List
782 [Arguments] ${member}
783 ${member_int} = BuiltIn.Convert_To_Integer ${member}
784 ${index_list} = BuiltIn.Create_List ${member_int}
785 [Return] ${index_list}
787 ClusterManagement__Parse_Sync_Status
788 [Arguments] ${shard_manager_text}
789 [Documentation] Return sync status parsed out of given text. Called twice by Get_Sync_Status_Of_Member.
790 BuiltIn.Log ${shard_manager_text}
791 ${manager_object} = RequestsLibrary.To_Json ${shard_manager_text}
792 ${value_object} = Collections.Get_From_Dictionary dictionary=${manager_object} key=value
793 ${sync_status} = Collections.Get_From_Dictionary dictionary=${value_object} key=SyncStatus
794 [Return] ${sync_status}
797 [Documentation] Create a new list of all indices.
798 BuiltIn.Run_Keyword_And_Return List_Indices_Or_All
801 [Arguments] ${given_list}=${EMPTY}
802 [Documentation] Utility to allow \${EMPTY} as default argument value, as the internal list is computed at runtime.
803 ... This keyword always returns a (shallow) copy of given or default list,
804 ... so operations with the returned list should not affect other lists.
805 ... Also note that this keyword does not consider empty list to be \${EMPTY}.
806 ${return_list_reference} = BuiltIn.Set_Variable_If """${given_list}""" != "" ${given_list} ${ClusterManagement__member_index_list}
807 ${return_list_copy} = BuiltIn.Create_List @{return_list_reference}
808 [Return] ${return_list_copy}
810 List_Indices_Minus_Member
811 [Arguments] ${member_index} ${member_index_list}=${EMPTY}
812 [Documentation] Create a new list which contains indices from ${member_index_list} (or all) without ${member_index}.
813 ${index_list} = List_Indices_Or_All ${member_index_list}
814 Collections.Remove Values From List ${index_list} ${member_index}
815 [Return] ${index_list}
817 ClusterManagement__Compute_Derived_Variables
818 [Arguments] ${int_of_members} ${http_timeout}=${DEFAULT_TIMEOUT_HTTP} ${http_retries}=0
819 [Documentation] Construct index list, session list and IP mapping, publish them as suite variables.
820 @{member_index_list} = BuiltIn.Create_List
821 @{session_list} = BuiltIn.Create_List
822 &{index_to_ip_mapping} = BuiltIn.Create_Dictionary
823 FOR ${index} IN RANGE 1 ${int_of_members+1}
824 ClusterManagement__Include_Member_Index ${index} ${member_index_list} ${session_list} ${index_to_ip_mapping} http_timeout=${http_timeout}
825 ... http_retries=${http_retries}
827 BuiltIn.Set_Suite_Variable \${ClusterManagement__member_index_list} ${member_index_list}
828 BuiltIn.Set_Suite_Variable \${ClusterManagement__index_to_ip_mapping} ${index_to_ip_mapping}
829 BuiltIn.Set_Suite_Variable \${ClusterManagement__session_list} ${session_list}
831 ClusterManagement__Include_Member_Index
832 [Arguments] ${index} ${member_index_list} ${session_list} ${index_to_ip_mapping} ${http_timeout}=${DEFAULT_TIMEOUT_HTTP} ${http_retries}=0
833 [Documentation] Add a corresponding item based on index into the last three arguments.
834 ... Create the Http session whose alias is added to list.
835 Collections.Append_To_List ${member_index_list} ${index}
836 ${member_ip} = BuiltIn.Set_Variable ${ODL_SYSTEM_${index}_IP}
837 # ${index} is int (not string) so "key=value" syntax does not work in the following line.
838 Collections.Set_To_Dictionary ${index_to_ip_mapping} ${index} ${member_ip}
839 # Http session, with ${AUTH}, without headers.
840 ${session_alias} = Resolve_Http_Session_For_Member member_index=${index}
841 RequestsLibrary.Create_Session ${session_alias} http://${member_ip}:${RESTCONFPORT} auth=${AUTH} timeout=${http_timeout} max_retries=${http_retries}
842 Collections.Append_To_List ${session_list} ${session_alias}
844 Sync_Status_Should_Be_False
845 [Arguments] ${controller_index}
846 [Documentation] Verify that cluster node is not in sync with others
847 ${status} Get_Sync_Status_Of_Member ${controller_index}
848 BuiltIn.Should_Not_Be_True ${status}
850 Sync_Status_Should_Be_True
851 [Arguments] ${controller_index}
852 [Documentation] Verify that cluster node is in sync with others
853 ${status} Get_Sync_Status_Of_Member ${controller_index}
854 BuiltIn.Should_Be_True ${status}
857 [Arguments] ${member_index}
858 [Documentation] Return the IP address of the member given the member_index.
859 ${member_int} = BuiltIn.Convert_To_Integer ${member_index}
860 ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_int}
861 [Return] ${member_ip}
864 [Arguments] ${odl_ip} ${system_ready_state} ${service_state} @{service_list}
865 [Documentation] Issues the karaf shell command showSvcStatus to verify the ready and service states are the same as the arguments passed
866 ${service_status_output} = BuiltIn.Run Keyword If ${NUM_ODL_SYSTEM} > 1 KarafKeywords.Issue_Command_On_Karaf_Console showSvcStatus -n ${odl_ip} ${odl_ip} ${KARAF_SHELL_PORT}
867 ... ELSE KarafKeywords.Issue_Command_On_Karaf_Console showSvcStatus ${odl_ip} ${KARAF_SHELL_PORT}
868 BuiltIn.Should Contain ${service_status_output} ${system_ready_state}
869 FOR ${service} IN @{service_list}
870 BuiltIn.Should Match Regexp ${service_status_output} ${service} +: ${service_state}
873 Check Status Of Services Is OPERATIONAL
874 [Arguments] @{service_list}
875 [Documentation] This keyword will verify whether all the services are operational in all the ODL nodes
876 FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
877 ClusterManagement.Check Service Status ${ODL_SYSTEM_${i+1}_IP} ACTIVE OPERATIONAL @{service_list}