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