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 Resource ${CURDIR}/CompareStream.robot
35 Resource ${CURDIR}/KarafKeywords.robot
36 Resource ${CURDIR}/SSHKeywords.robot
37 Resource ${CURDIR}/TemplatedRequests.robot # for Get_As_Json_From_Uri
38 Resource ${CURDIR}/Utils.robot # for Run_Command_On_Controller
39 Resource ../variables/Variables.robot
42 ${ENTITY_OWNER_URI} restconf/operational/entity-owners:entity-owners
43 ${GC_LOG_PATH} ${KARAF_HOME}/data/log
44 ${JAVA_HOME} ${EMPTY} # releng/builder scripts should provide correct value
45 ${JOLOKIA_CONF_SHARD_MANAGER_URI} jolokia/read/org.opendaylight.controller:Category=ShardManager,name=shard-manager-config,type=DistributedConfigDatastore
46 ${JOLOKIA_OPER_SHARD_MANAGER_URI} jolokia/read/org.opendaylight.controller:Category=ShardManager,name=shard-manager-operational,type=DistributedOperationalDatastore
47 ${JOLOKIA_CONFIG_LOCAL_SHARDS_URI} jolokia/read/org.opendaylight.controller:type=DistributedConfigDatastore,Category=ShardManager,name=shard-manager-config/LocalShards
48 ${JOLOKIA_OPER_LOCAL_SHARDS_URI} jolokia/read/org.opendaylight.controller:type=DistributedOperationalDatastore,Category=ShardManager,name=shard-manager-operational/LocalShards
49 ${JOLOKIA_READ_URI} jolokia/read/org.opendaylight.controller
50 # Bug 9044 workaround: delete etc/host.key before restart.
51 @{ODL_DEFAULT_DATA_PATHS} tmp/ data/ cache/ snapshots/ journal/ etc/opendaylight/current/ etc/host.key
52 ${RESTCONF_MODULES_DIR} ${CURDIR}/../variables/restconf/modules
53 ${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=
54 ${SINGLETON_NETCONF_DEVICE_ID_SUFFIX} ]]]]}']
55 ${SINGLETON_BGPCEP_DEVICE_ID_PREFIX} /odl-general-entity:entity[odl-general-entity:name='
56 ${SINGLETON_BGPCEP_DEVICE_ID_SUFFIX} -service-group']
57 ${SINGLETON_ELECTION_ENTITY_TYPE} org.opendaylight.mdsal.ServiceEntityType
58 ${SINGLETON_CHANGE_OWNERSHIP_ENTITY_TYPE} org.opendaylight.mdsal.AsyncServiceCloseEntityType
59 ${NODE_ROLE_INDEX_START} 1
60 ${NODE_START_COMMAND} ${KARAF_HOME}/bin/start
61 ${NODE_STOP_COMMAND} ${KARAF_HOME}/bin/stop
62 ${NODE_KARAF_COUNT_COMMAND} ps axf | grep org.apache.karaf | grep -v grep | wc -l
63 ${NODE_KILL_COMMAND} ps axf | grep org.apache.karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
64 ${NODE_FREEZE_COMMAND} ps axf | grep org.apache.karaf | grep -v grep | awk '{print \"kill -STOP \" $1}' | sh
65 ${NODE_UNFREEZE_COMMAND} ps axf | grep org.apache.karaf | grep -v grep | awk '{print \"kill -CONT \" $1}' | sh
68 ClusterManagement_Setup
69 [Arguments] ${http_timeout}=${DEFAULT_TIMEOUT_HTTP} ${http_retries}=0
70 [Documentation] Detect repeated call, or detect number of members and initialize derived suite variables.
71 ... Http sessions are created with parameters to not waste time when ODL is no accepting connections properly.
72 # Avoid multiple initialization by several downstream libraries.
73 ${already_done} = BuiltIn.Get_Variable_Value \${ClusterManagement__has_setup_run} False
74 BuiltIn.Return_From_Keyword_If ${already_done}
75 BuiltIn.Set_Suite_Variable \${ClusterManagement__has_setup_run} True
76 ${cluster_size} = BuiltIn.Get_Variable_Value \${NUM_ODL_SYSTEM} 1
77 ${status} ${possibly_int_of_members} = BuiltIn.Run_Keyword_And_Ignore_Error BuiltIn.Convert_To_Integer ${cluster_size}
78 ${int_of_members} = BuiltIn.Set_Variable_If '${status}' != 'PASS' ${1} ${possibly_int_of_members}
79 ClusterManagement__Compute_Derived_Variables int_of_members=${int_of_members} http_timeout=${http_timeout} http_retries=${http_retries}
81 Check_Cluster_Is_In_Sync
82 [Arguments] ${member_index_list}=${EMPTY}
83 [Documentation] Fail if no-sync is detected on a member from list (or any).
84 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
85 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
86 \ ${status} = Get_Sync_Status_Of_Member member_index=${index}
87 \ BuiltIn.Continue_For_Loop_If 'True' == '${status}'
88 \ BuiltIn.Fail Index ${index} has incorrect status: ${status}
90 Get_Sync_Status_Of_Member
91 [Arguments] ${member_index}
92 [Documentation] Obtain IP, two GETs from jolokia URIs, return combined sync status as string.
93 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
94 ${conf_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${JOLOKIA_CONF_SHARD_MANAGER_URI} session=${session}
95 ${conf_status} = ClusterManagement__Parse_Sync_Status shard_manager_text=${conf_text}
96 BuiltIn.Return_From_Keyword_If 'False' == ${conf_status} False
97 ${oper_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${JOLOKIA_OPER_SHARD_MANAGER_URI} session=${session}
98 ${oper_status} = ClusterManagement__Parse_Sync_Status shard_manager_text=${oper_text}
99 [Return] ${oper_status}
101 Verify_Leader_Exists_For_Each_Shard
102 [Arguments] ${shard_name_list} ${shard_type}=operational ${member_index_list}=${EMPTY} ${verify_restconf}=True
103 [Documentation] For each shard name, call Get_Leader_And_Followers_For_Shard.
104 ... Not much logic there, but single Keyword is useful when using BuiltIn.Wait_Until_Keyword_Succeeds.
105 : FOR ${shard_name} IN @{shard_name_list}
106 \ 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}
108 Get_Leader_And_Followers_For_Shard
109 [Arguments] ${shard_name}=default ${shard_type}=operational ${validate}=True ${member_index_list}=${EMPTY} ${verify_restconf}=True ${http_timeout}=${EMPTY}
110 [Documentation] Get role lists, validate there is one leader, return the leader and list of followers.
111 ... Optionally, issue GET to a simple restconf URL to make sure subsequent operations will not encounter 503.
112 ${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}
113 ... verify_restconf=${verify_restconf} http_timeout=${http_timeout}
114 ${leader_count} = BuiltIn.Get_Length ${leader_list}
115 BuiltIn.Run_Keyword_If ${leader_count} < 1 BuiltIn.Fail No leader found.
116 BuiltIn.Length_Should_Be ${leader_list} ${1} Too many Leaders.
117 ${leader} = Collections.Get_From_List ${leader_list} 0
118 [Return] ${leader} ${follower_list}
120 Get_State_Info_For_Shard
121 [Arguments] ${shard_name}=default ${shard_type}=operational ${validate}=False ${member_index_list}=${EMPTY} ${verify_restconf}=False ${http_timeout}=${EMPTY}
122 [Documentation] Return lists of Leader and Follower member indices from a given member index list
123 ... (or from the full list if empty). If \${shard_type} is not 'config', 'operational' is assumed.
124 ... If \${validate}, Fail if raft state is not Leader or Follower (for example on Candidate).
125 ... The biggest difference from Get_Leader_And_Followers_For_Shard
126 ... is that no check on number of Leaders is performed.
127 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
128 Collections.Sort_List ${index_list} # to guarantee return values are also sorted lists
129 # TODO: Support alternative capitalization of 'config'?
130 ${ds_type} = BuiltIn.Set_Variable_If '${shard_type}' != 'config' operational config
131 ${leader_list} = BuiltIn.Create_List
132 ${follower_list} = BuiltIn.Create_List
133 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
134 \ ${raft_state} = Get_Raft_State_Of_Shard_At_Member shard_name=${shard_name} shard_type=${ds_type} member_index=${index} verify_restconf=${verify_restconf}
135 \ ... http_timeout=${http_timeout}
136 \ BuiltIn.Run_Keyword_If 'Follower' == '${raft_state}' Collections.Append_To_List ${follower_list} ${index}
137 \ ... ELSE IF 'Leader' == '${raft_state}' Collections.Append_To_List ${leader_list} ${index}
138 \ ... ELSE IF ${validate} BuiltIn.Fail Unrecognized Raft state: ${raft_state}
139 [Return] ${leader_list} ${follower_list}
141 Get_Raft_State_Of_Shard_At_Member
142 [Arguments] ${shard_name} ${shard_type} ${member_index} ${verify_restconf}=False ${http_timeout}=${EMPTY}
143 [Documentation] Send request to Jolokia on indexed member, return extracted Raft status.
144 ... Optionally, check restconf works.
145 ${raft_state} = Get_Raft_Property_From_Shard_Member RaftState ${shard_name} ${shard_type} ${member_index} verify_restconf=${verify_restconf}
146 ... http_timeout=${http_timeout}
147 [Return] ${raft_state}
149 Get_Raft_Property_From_Shard_Member
150 [Arguments] ${property} ${shard_name} ${shard_type} ${member_index} ${verify_restconf}=False ${http_timeout}=${EMPTY}
151 [Documentation] Send request to Jolokia on indexed member, return extracted Raft property.
152 ... Optionally, check restconf works.
153 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
154 # TODO: Does the used URI tend to generate large data which floods log.html?
155 BuiltIn.Run_Keyword_If ${verify_restconf} TemplatedRequests.Get_As_Json_Templated session=${session} folder=${RESTCONF_MODULES_DIR} verify=False http_timeout=${http_timeout}
156 ${type_class} = Resolve_Shard_Type_Class shard_type=${shard_type}
157 ${cluster_index} = Evaluate ${member_index}+${NODE_ROLE_INDEX_START}-1
158 ${uri} = BuiltIn.Set_Variable ${JOLOKIA_READ_URI}:Category=Shards,name=member-${cluster_index}-shard-${shard_name}-${shard_type},type=${type_class}
159 ${data_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${uri} session=${session} http_timeout=${http_timeout}
160 ${data_object} = RequestsLibrary.To_Json ${data_text}
161 ${value} = Collections.Get_From_Dictionary ${data_object} value
162 ${raft_property} = Collections.Get_From_Dictionary ${value} ${property}
163 [Return] ${raft_property}
165 Verify_Shard_Leader_Elected
166 [Arguments] ${shard_name} ${shard_type} ${new_elected} ${old_leader} ${member_index_list}=${EMPTY} ${verify_restconf}=True
167 [Documentation] Verify new leader was elected or remained the same. Bool paramter ${new_elected} indicates if
168 ... new leader is elected or should remained the same as ${old_leader}
169 ${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}
170 BuiltIn.Run_Keyword_If ${new_elected} BuiltIn.Should_Not_Be_Equal_As_Numbers ${old_leader} ${leader}
171 BuiltIn.Run_Keyword_Unless ${new_elected} BuiltIn.Should_Be_Equal_As_numbers ${old_leader} ${leader}
172 BuiltIn.Return_From_Keyword ${leader} ${followers}
174 Verify_Owner_And_Successors_For_Device
175 [Arguments] ${device_name} ${device_type} ${member_index} ${candidate_list}=${EMPTY} ${after_stop}=False
176 [Documentation] Returns the owner and successors for the SB device ${device_name} of type ${device_type}. Request is sent to member ${member_index}.
177 ... For Boron and beyond, candidates are not removed on node down or isolation,
178 ... so this keyword expects candidates to be all members from Boron on.
179 ... Extra check is done to verify owner and successors are within the ${candidate_list}. This KW is useful when combined with WUKS.
180 ... ${candidate_list} minus owner is returned as ${successor list}.
181 ... Users can still use Get_Owner_And_Successors_For_Device if they are interested in downed candidates,
182 ... or for testing heterogeneous clusters.
183 ${index_list} = List_Indices_Or_All given_list=${candidate_list}
184 ${owner} ${successor_list} = Get_Owner_And_Successors_For_Device device_name=${device_name} device_type=${device_type} member_index=${member_index}
185 Collections.List_Should_Contain_Value ${index_list} ${owner} Owner ${owner} is not in candidate list ${index_list}
186 # In Beryllium or after stopping an instance, the removed instance does not show in the candidate list.
187 ${expected_candidate_list_origin} = BuiltIn.Set_Variable_If ${after_stop} ${index_list} ${ClusterManagement__member_index_list}
188 # We do not want to manipulate either origin list.
189 ${expected_successor_list} = BuiltIn.Create_List @{expected_candidate_list_origin}
190 Collections.Remove_Values_From_List ${expected_successor_list} ${owner}
191 Collections.Lists_Should_Be_Equal ${expected_successor_list} ${successor_list} Successor list ${successor_list} is not the came as expected ${expected_successor_list}
192 # User expects the returned successor list to be the provided candidate list minus the owner.
193 Collections.Remove_Values_From_List ${index_list} ${owner}
194 [Return] ${owner} ${index_list}
196 Get_Owner_And_Successors_For_Device
197 [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
198 [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}.
199 ... Successors are those device candidates not elected as owner. The list of successors = (list of candidates) - (owner).
200 ... The returned successor list is sorted numerically.
201 ... Note that "candidate list" definition currently differs between Beryllium and Boron.
202 ... Use Verify_Owner_And_Successors_For_Device if you want the older semantics (inaccessible nodes not present in the list).
203 # TODO: somewhere to introduce ${DEFAULT_RESTCONF_DATASTORE_TIMEOUT}. Value may depend on protocol (ask vs tell) and perhaps stream.
204 ${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}
205 ${successor_list} = BuiltIn.Create_List @{candidate_list} # Copy operation is not required, but new variable name requires a line anyway.
206 Collections.Remove_Values_From_List ${successor_list} ${owner}
207 [Return] ${owner} ${successor_list}
209 Get_Owner_And_Candidates_For_Device_Old
210 [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
211 [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}.
212 ... Candidates are all members that register to own a device, so the list of candiates includes the owner.
213 ... The returned candidate list is sorted numerically.
214 ... Note that "candidate list" definition currently differs between Beryllium and Boron.
215 ... It is recommended to use Get_Owner_And_Successors_For_Device instead of this keyword, see documentation there.
216 BuiltIn.Comment TODO: Can this implementation be changed to call Get_Owner_And_Candidates_For_Type_And_Id?
217 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
218 ${data} = TemplatedRequests.Get_As_Json_From_Uri uri=${ENTITY_OWNER_URI} session=${session} http_timeout=${http_timeout}
219 ${candidate_list} = BuiltIn.Create_List
220 ${entity_type} = BuiltIn.Set_Variable_If '${device_type}' == 'netconf' netconf-node/${device_name} ${device_type}
221 ${clear_data} = BuiltIn.Run_Keyword_If '${device_type}' == 'openflow' or '${device_type}' == 'netconf' Extract_OpenFlow_Device_Data ${data}
222 ... ELSE IF '${device_type}' == 'ovsdb' Extract_Ovsdb_Device_Data ${data}
223 ... ELSE IF '${device_type}' == 'org.opendaylight.mdsal.ServiceEntityType' Extract_Service_Entity_Type ${data}
224 ... ELSE Fail Not recognized device type: ${device_type}
225 ${json} = RequestsLibrary.To_Json ${clear_data}
226 ${entity_type_list} = Collections.Get_From_Dictionary &{json}[entity-owners] entity-type
227 ${entity_type_index} = Utils.Get_Index_From_List_Of_Dictionaries ${entity_type_list} type ${entity_type}
228 BuiltIn.Should_Not_Be_Equal_As_Integers ${entity_type_index} -1 No Entity Owner found for ${device_type}
229 ${entity_list} = Collections.Get_From_Dictionary @{entity_type_list}[${entity_type_index}] entity
230 ${entity_index} = Utils.Get_Index_From_List_Of_Dictionaries ${entity_list} id ${device_name}
231 BuiltIn.Should_Not_Be_Equal_As_Integers ${entity_index} -1 Device ${device_name} not found in Entity Owner ${device_type}
232 ${entity_owner} = Collections.Get_From_Dictionary @{entity_list}[${entity_index}] owner
233 BuiltIn.Should_Not_Be_Empty ${entity_owner} No owner found for ${device_name}
234 ${owner} = String.Replace_String ${entity_owner} member- ${EMPTY}
235 ${owner} = BuiltIn.Convert_To_Integer ${owner}
236 ${entity_candidates_list} = Collections.Get_From_Dictionary @{entity_list}[${entity_index}] candidate
237 : FOR ${entity_candidate} IN @{entity_candidates_list}
238 \ ${candidate} = String.Replace_String &{entity_candidate}[name] member- ${EMPTY}
239 \ ${candidate} = BuiltIn.Convert_To_Integer ${candidate}
240 \ Collections.Append_To_List ${candidate_list} ${candidate}
241 Collections.Sort_List ${candidate_list}
242 [Return] ${owner} ${candidate_list}
244 Get_Owner_And_Candidates_For_Device_Singleton
245 [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
246 [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}.
247 ... Parsing method is selected by device type
248 ... Separate kw for every supported device type must be defined
249 BuiltIn.Keyword_Should_Exist Get_Owner_And_Candidates_For_Device_Singleton_${device_type}
250 BuiltIn.Run_Keyword_And_Return Get_Owner_And_Candidates_For_Device_Singleton_${device_type} ${device_name} ${member_index} http_timeout=${http_timeout}
252 Get_Owner_And_Candidates_For_Device_Singleton_Netconf
253 [Arguments] ${device_name} ${member_index} ${http_timeout}=${EMPTY}
254 [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}.
255 ... Parsing method is set as netconf (using netconf device id prefix and suffix)
256 # Get election entity type results
257 ${type} = BuiltIn.Set_Variable ${SINGLETON_ELECTION_ENTITY_TYPE}
258 ${id} = BuiltIn.Set_Variable ${SINGLETON_NETCONF_DEVICE_ID_PREFIX}${device_name}${SINGLETON_NETCONF_DEVICE_ID_SUFFIX}
259 ${owner_1} ${candidate_list_1} = Get_Owner_And_Candidates_For_Type_And_Id ${type} ${id} ${member_index} http_timeout=${http_timeout}
260 # Get change ownership entity type results
261 ${type} = BuiltIn.Set_Variable ${SINGLETON_CHANGE_OWNERSHIP_ENTITY_TYPE}
262 ${id} = BuiltIn.Set_Variable ${SINGLETON_NETCONF_DEVICE_ID_PREFIX}${device_name}${SINGLETON_NETCONF_DEVICE_ID_SUFFIX}
263 ${owner_2} ${candidate_list_2} = Get_Owner_And_Candidates_For_Type_And_Id ${type} ${id} ${member_index} http_timeout=${http_timeout}
264 # Owners must be same, if not, there is still some election or change ownership in progress
265 BuiltIn.Should_Be_Equal_As_Integers ${owner_1} ${owner_2} Owners for device ${device_name} are not same
266 [Return] ${owner_1} ${candidate_list_1}
268 Get_Owner_And_Candidates_For_Device_Singleton_Bgpcep
269 [Arguments] ${device_name} ${member_index} ${http_timeout}=${EMPTY}
270 [Documentation] Returns the owner and a list of candidates for the SB device ${device_name}. Request is sent to member ${member_index}.
271 # Get election entity type results
272 ${type} = BuiltIn.Set_Variable ${SINGLETON_ELECTION_ENTITY_TYPE}
273 ${id} = BuiltIn.Set_Variable ${SINGLETON_BGPCEP_DEVICE_ID_PREFIX}${device_name}${SINGLETON_BGPCEP_DEVICE_ID_SUFFIX}
274 ${owner_1} ${candidate_list_1} = Get_Owner_And_Candidates_For_Type_And_Id ${type} ${id} ${member_index} http_timeout=${http_timeout}
275 # Get change ownership entity type results
276 ${type} = BuiltIn.Set_Variable ${SINGLETON_CHANGE_OWNERSHIP_ENTITY_TYPE}
277 ${id} = BuiltIn.Set_Variable ${SINGLETON_BGPCEP_DEVICE_ID_PREFIX}${device_name}${SINGLETON_BGPCEP_DEVICE_ID_SUFFIX}
278 ${owner_2} ${candidate_list_2} = Get_Owner_And_Candidates_For_Type_And_Id ${type} ${id} ${member_index} http_timeout=${http_timeout}
279 # Owners must be same, if not, there is still some election or change ownership in progress
280 BuiltIn.Should_Be_Equal_As_Integers ${owner_1} ${owner_2} Owners for device ${device_name} are not same
281 [Return] ${owner_1} ${candidate_list_1}
283 Get_Owner_And_Candidates_For_Device
284 [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
285 [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}.
286 ... If parsing as singleton failed, kw try to parse data in old way (without singleton).
287 ... Candidates are all members that register to own a device, so the list of candiates includes the owner.
288 ... The returned candidate list is sorted numerically.
289 ... Note that "candidate list" definition currently differs between Beryllium and Boron.
290 ... It is recommended to use Get_Owner_And_Successors_For_Device instead of this keyword, see documentation there.
292 ${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}
293 ... http_timeout=${http_timeout}
294 BuiltIn.Return_From_Keyword_If "${status}"=="PASS" ${results}
295 # If singleton failed, try parsing in old way
296 ${status} ${results} = BuiltIn.Run_Keyword_And_Ignore_Error Get_Owner_And_Candidates_For_Device_Old device_name=${device_name} device_type=${device_type} member_index=${member_index}
297 ... http_timeout=${http_timeout}
298 # previous 3 lines (BuilIn.Return.., # If singleton..., ${status}....) could be deleted when old way will not be supported anymore
299 BuiltIn.Run_Keyword_If '${status}'=='FAIL' BuiltIn.Fail Could not parse owner and candidates for device ${device_name}
302 Check_Old_Owner_Stays_Elected_For_Device
303 [Arguments] ${device_name} ${device_type} ${old_owner} ${node_to_ask} ${http_timeout}=${EMPTY}
304 [Documentation] Verify the owner remain the same as ${old_owner}
305 ${owner} ${candidates} = Get_Owner_And_Candidates_For_Device ${device_name} ${device_type} ${node_to_ask} http_timeout=${http_timeout}
306 BuiltIn.Should_Be_Equal_As_numbers ${old_owner} ${owner}
307 BuiltIn.Return_From_Keyword ${owner} ${candidates}
309 Check_New_Owner_Got_Elected_For_Device
310 [Arguments] ${device_name} ${device_type} ${old_owner} ${node_to_ask} ${http_timeout}=${EMPTY}
311 [Documentation] Verify new owner was elected comparing to ${old_owner}
312 ${owner} ${candidates} = Get_Owner_And_Candidates_For_Device ${device_name} ${device_type} ${node_to_ask} http_timeout=${http_timeout}
313 BuiltIn.Should_Not_Be_Equal_As_Numbers ${old_owner} ${owner}
314 BuiltIn.Return_From_Keyword ${owner} ${candidates}
316 Get_Owner_And_Candidates_For_Type_And_Id
317 [Arguments] ${type} ${id} ${member_index} ${require_candidate_list}=${EMPTY} ${http_timeout}=${EMPTY}
318 [Documentation] Returns the owner and a list of candidates for entity specified by ${type} and ${id}
319 ... Request is sent to member ${member_index}.
320 ... Candidates are all members that register to own a device, so the list of candiates includes the owner.
321 ... Bear in mind that for Boron and beyond, candidates are not removed on node down or isolation.
322 ... If ${require_candidate_list} is not \${EMPTY}, check whether the actual list of candidates matches.
323 ... Note that differs from "given list" semantics used in other keywords,
324 ... namely you cannot use \${EMPTY} to stand for "full list" in this keyword.
325 BuiltIn.Comment TODO: Find a way to unify and deduplicate code blocks in Get_Owner_And_Candidates_* keywords.
326 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
327 ${data} = TemplatedRequests.Get_As_Json_From_Uri uri=${ENTITY_OWNER_URI} session=${session} http_timeout=${http_timeout}
328 ${candidate_list} = BuiltIn.Create_List
329 ${json} = RequestsLibrary.To_Json ${data}
330 ${entity_type_list} = Collections.Get_From_Dictionary &{json}[entity-owners] entity-type
331 ${entity_type_index} = Utils.Get_Index_From_List_Of_Dictionaries ${entity_type_list} type ${type}
332 BuiltIn.Should_Not_Be_Equal_As_Integers ${entity_type_index} -1 No Entity Owner found for ${type}
333 ${entity_list} = Collections.Get_From_Dictionary @{entity_type_list}[${entity_type_index}] entity
334 ${entity_index} = Utils.Get_Index_From_List_Of_Dictionaries ${entity_list} id ${id}
335 BuiltIn.Should Not_Be_Equal_As_Integers ${entity_index} -1 Id ${id} not found in Entity Owner ${type}
336 ${entity_owner} = Collections.Get_From_Dictionary @{entity_list}[${entity_index}] owner
337 BuiltIn.Should_Not_Be_Empty ${entity_owner} No owner found for type=${type} id=${id}
338 ${owner} = String.Replace_String ${entity_owner} member- ${EMPTY}
339 ${owner} = BuiltIn.Convert_To_Integer ${owner}
340 ${entity_candidates_list} = Collections.Get_From_Dictionary @{entity_list}[${entity_index}] candidate
341 : FOR ${entity_candidate} IN @{entity_candidates_list}
342 \ ${candidate} = String.Replace_String &{entity_candidate}[name] member- ${EMPTY}
343 \ ${candidate} = BuiltIn.Convert_To_Integer ${candidate}
344 \ Collections.Append_To_List ${candidate_list} ${candidate}
345 Collections.Sort_List ${candidate_list}
346 BuiltIn.Comment TODO: Separate check lines into Verify_Owner_And_Candidates_For_Type_And_Id
347 BuiltIn.Run_Keyword_If """${require_candidate_list}""" BuiltIn.Should_Be_Equal ${require_candidate_list} ${candidate_list} Candidate list does not match: ${candidate_list} is not ${require_candidate_list}
348 [Return] ${owner} ${candidate_list}
350 Extract_Service_Entity_Type
352 [Documentation] Remove superfluous device data from Entity Owner printout.
353 ${clear_data} = String.Replace_String ${data} /odl-general-entity:entity[odl-general-entity:name=' ${EMPTY}
354 ${clear_data} = String.Replace_String ${clear_data} -service-group'] ${EMPTY}
356 [Return] ${clear_data}
358 Extract_OpenFlow_Device_Data
360 [Documentation] Remove superfluous OpenFlow device data from Entity Owner printout.
361 ${clear_data} = String.Replace_String ${data} org.opendaylight.mdsal.ServiceEntityType openflow
362 ${clear_data} = String.Replace_String ${clear_data} /odl-general-entity:entity[odl-general-entity:name=' ${EMPTY}
363 ${clear_data} = String.Replace_String ${clear_data} /general-entity:entity[general-entity:name=' ${EMPTY}
364 ${clear_data} = String.Replace_String ${clear_data} '] ${EMPTY}
366 [Return] ${clear_data}
368 Extract_Ovsdb_Device_Data
370 [Documentation] Remove superfluous OVSDB device data from Entity Owner printout.
371 ${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}
372 ${clear_data} = String.Replace_String ${clear_data} '] ${EMPTY}
374 [Return] ${clear_data}
377 [Arguments] ${member} ${original_index_list}=${EMPTY} ${confirm}=True
378 [Documentation] Convenience keyword that kills the specified member of the cluster.
379 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member}
380 ${index_list} = ClusterManagement__Build_List ${member}
381 ${member_ip} = Return_Member_IP ${member}
382 KarafKeywords.Log_Message_To_Controller_Karaf Killing ODL${member} ${member_ip}
383 ${updated_index_list} = Kill_Members_From_List_Or_All ${index_list} ${original_index_list} ${confirm}
384 [Return] ${updated_index_list}
386 Kill_Members_From_List_Or_All
387 [Arguments] ${member_index_list}=${EMPTY} ${original_index_list}=${EMPTY} ${confirm}=True
388 [Documentation] If the list is empty, kill all ODL instances. Otherwise, kill members based on \${kill_index_list}
389 ... If \${confirm} is True, sleep 1 second and verify killed instances are not there anymore.
390 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member_index_list}
391 ${kill_index_list} = List_Indices_Or_All given_list=${member_index_list}
392 ${index_list} = List_Indices_Or_All given_list=${original_index_list}
393 Run_Bash_Command_On_List_Or_All command=${NODE_KILL_COMMAND} member_index_list=${member_index_list}
394 ${updated_index_list} = BuiltIn.Create_List @{index_list}
395 Collections.Remove_Values_From_List ${updated_index_list} @{kill_index_list}
396 BuiltIn.Return_From_Keyword_If not ${confirm} ${updated_index_list}
397 # TODO: Convert to WUKS with configurable timeout if it turns out 1 second is not enough.
398 BuiltIn.Sleep 1s Kill -9 closes open files, which may take longer than ssh overhead, but not long enough to warrant WUKS.
399 : FOR ${index} IN @{kill_index_list}
400 \ Verify_Karaf_Is_Not_Running_On_Member member_index=${index}
401 Run_Bash_Command_On_List_Or_All command=netstat -pnatu | grep 2550
402 [Return] ${updated_index_list}
405 [Arguments] ${member} ${original_index_list}=${EMPTY} ${confirm}=True
406 [Documentation] Convenience keyword that stops the specified member of the cluster.
407 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member}
408 ${index_list} = ClusterManagement__Build_List ${member}
409 ${updated_index_list} = Stop_Members_From_List_Or_All ${index_list} ${original_index_list} ${confirm}
410 [Return] ${updated_index_list}
412 Stop_Members_From_List_Or_All
413 [Arguments] ${member_index_list}=${EMPTY} ${original_index_list}=${EMPTY} ${confirm}=True ${timeout}=120s
414 [Documentation] If the list is empty, stops all ODL instances. Otherwise stop members based on \${stop_index_list}
415 ... If \${confirm} is True, verify stopped instances are not there anymore.
416 ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member_index_list}
417 ${stop_index_list} = List_Indices_Or_All given_list=${member_index_list}
418 ${index_list} = List_Indices_Or_All given_list=${original_index_list}
419 Run_Bash_Command_On_List_Or_All command=${NODE_STOP_COMMAND} member_index_list=${member_index_list}
420 ${updated_index_list} = BuiltIn.Create_List @{index_list}
421 Collections.Remove_Values_From_List ${updated_index_list} @{stop_index_list}
422 BuiltIn.Return_From_Keyword_If not ${confirm} ${updated_index_list}
423 : FOR ${index} IN @{stop_index_list}
424 \ BuiltIn.Wait Until Keyword Succeeds ${timeout} 2s Verify_Karaf_Is_Not_Running_On_Member member_index=${index}
425 Run_Bash_Command_On_List_Or_All command=netstat -pnatu | grep 2550
426 [Return] ${updated_index_list}
429 [Arguments] ${member} ${wait_for_sync}=True ${timeout}=300s ${check_system_status}=False ${service_list}=@{EMPTY}
430 [Documentation] Convenience keyword that starts the specified member of the cluster.
431 ${index_list} = ClusterManagement__Build_List ${member}
432 Start_Members_From_List_Or_All ${index_list} ${wait_for_sync} ${timeout} check_system_status=${check_system_status} service_list=@{service_list}
434 Start_Members_From_List_Or_All
435 [Arguments] ${member_index_list}=${EMPTY} ${wait_for_sync}=True ${timeout}=300s ${karaf_home}=${EMPTY} ${export_java_home}=${EMPTY} ${gc_log_dir}=${EMPTY}
436 ... ${check_system_status}=False ${service_list}=@{EMPTY}
437 [Documentation] If the list is empty, start all cluster members. Otherwise, start members based on present indices.
438 ... If ${wait_for_sync}, wait for cluster sync on listed members.
439 ... Optionally karaf_home can be overriden. Optionally specific JAVA_HOME is used for starting.
440 ... Garbage collection is unconditionally logged to files. TODO: Make that reasonable conditional?
441 ${base_command} = BuiltIn.Set_Variable_If """${karaf_home}""" != "" ${karaf_home}/bin/start ${NODE_START_COMMAND}
442 ${command} = BuiltIn.Set_Variable_If """${export_java_home}""" != "" export JAVA_HOME="${export_java_home}"; ${base_command} ${base_command}
443 ${epoch} = DateTime.Get_Current_Date time_zone=UTC result_format=epoch exclude_millis=False
444 ${gc_filepath} = BuiltIn.Set_Variable_If """${karaf_home}""" != "" ${karaf_home}/data/log/gc_${epoch}.log ${GC_LOG_PATH}/gc_${epoch}.log
445 ${gc_options} = BuiltIn.Set_Variable_If "docker" not in """${node_start_command}""" -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:${gc_filepath} ${EMPTY}
446 Run_Bash_Command_On_List_Or_All command=${command} ${gc_options} member_index_list=${member_index_list}
447 BuiltIn.Return_From_Keyword_If not ${wait_for_sync}
448 BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} 10s Check_Cluster_Is_In_Sync member_index_list=${member_index_list}
449 BuiltIn.Return_From_Keyword_If not ${check_system_status}
450 CompareStream.Run_Keyword_If_At_Least_Oxygen Wait Until Keyword Succeeds 60 2 ClusterManagement.Check Status Of Services Is OPERATIONAL @{service_list}
451 [Teardown] Run_Bash_Command_On_List_Or_All command=netstat -pnatu | grep 2550
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}
483 Verify_Karaf_Is_Not_Running_On_Member
484 [Arguments] ${member_index}
485 [Documentation] Fail if non-zero karaf instances are counted on member of given index.
486 ${count} = Count_Running_Karafs_On_Member member_index=${member_index}
487 BuiltIn.Should_Be_Equal 0 ${count} Found running Karaf count: ${count}
489 Verify_Single_Karaf_Is_Running_On_Member
490 [Arguments] ${member_index}
491 [Documentation] Fail if number of karaf instances on member of given index is not one.
492 ${count} = Count_Running_Karafs_On_Member member_index=${member_index}
493 BuiltIn.Should_Be_Equal 1 ${count} Wrong number of Karafs running: ${count}
495 Count_Running_Karafs_On_Member
496 [Arguments] ${member_index}
497 [Documentation] Remotely execute grep for karaf process, return count as string.
498 ${command} = BuiltIn.Set_Variable ${NODE_KARAF_COUNT_COMMAND}
499 ${count} = Run_Bash_Command_On_Member command=${command} member_index=${member_index}
502 Isolate_Member_From_List_Or_All
503 [Arguments] ${isolate_member_index} ${member_index_list}=${EMPTY} ${protocol}=all ${port}=${EMPTY}
504 [Documentation] If the list is empty, isolate member from all ODL instances. Otherwise, isolate member based on present indices.
505 ... The KW will return a list of available members: \${updated index_list}=\${member_index_list}-\${isolate_member_index}
506 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
507 ${source} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${isolate_member_index}
508 ${dport} = BuiltIn.Set_Variable_If '${port}' != '${EMPTY}' --dport ${port} ${EMPTY}
509 : FOR ${index} IN @{index_list}
510 \ ${destination} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${index}
511 \ ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -I OUTPUT -p ${protocol} ${dport} --source ${source} --destination ${destination} -j DROP
512 \ BuiltIn.Run_Keyword_If "${index}" != "${isolate_member_index}" Run_Bash_Command_On_Member command=${command} member_index=${isolate_member_index}
513 ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -L -n
514 ${output} = Run_Bash_Command_On_Member command=${command} member_index=${isolate_member_index}
515 BuiltIn.Log ${output}
516 ${updated_index_list} = BuiltIn.Create_List @{index_list}
517 Collections.Remove_Values_From_List ${updated_index_list} ${isolate_member_index}
518 [Return] ${updated_index_list}
520 Rejoin_Member_From_List_Or_All
521 [Arguments] ${rejoin_member_index} ${member_index_list}=${EMPTY} ${protocol}=all ${port}=${EMPTY} ${timeout}=60s
522 [Documentation] If the list is empty, rejoin member from all ODL instances. Otherwise, rejoin member based on present indices.
523 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
524 ${source} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${rejoin_member_index}
525 ${dport} = BuiltIn.Set_Variable_If '${port}' != '${EMPTY}' --dport ${port} ${EMPTY}
526 : FOR ${index} IN @{index_list}
527 \ ${destination} = Collections.Get_From_Dictionary ${ClusterManagement__index_to_ip_mapping} ${index}
528 \ ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -D OUTPUT -p ${protocol} ${dport} --source ${source} --destination ${destination} -j DROP
529 \ BuiltIn.Run_Keyword_If "${index}" != "${rejoin_member_index}" Run_Bash_Command_On_Member command=${command} member_index=${rejoin_member_index}
530 ${command} = BuiltIn.Set_Variable sudo /sbin/iptables -L -n
531 ${output} = Run_Bash_Command_On_Member command=${command} member_index=${rejoin_member_index}
532 BuiltIn.Log ${output}
533 BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} 10s Check_Cluster_Is_In_Sync
535 Flush_Iptables_From_List_Or_All
536 [Arguments] ${member_index_list}=${EMPTY}
537 [Documentation] If the list is empty, flush IPTables in all ODL instances. Otherwise, flush member based on present indices.
538 ${command} = BuiltIn.Set_Variable sudo iptables -v -F
539 ${output} = Run_Bash_Command_On_List_Or_All command=${command} member_index_list=${member_index_list}
541 Check_Bash_Command_On_List_Or_All
542 [Arguments] ${command} ${member_index_list}=${EMPTY} ${return_success_only}=False ${log_on_success}=True ${log_on_failure}=True ${stderr_must_be_empty}=True
543 [Documentation] Cycle through indices (or all), run bash command on each, using temporary SSH session and restoring the previously active one.
544 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
545 : FOR ${index} IN @{index_list}
546 \ 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}
547 \ ... stderr_must_be_empty=${stderr_must_be_empty}
549 Check_Bash_Command_On_Member
550 [Arguments] ${command} ${member_index} ${return_success_only}=False ${log_on_success}=True ${log_on_failure}=True ${stderr_must_be_empty}=True
551 [Documentation] Open SSH session, call SSHKeywords.Execute_Command_Passes, close session, restore previously active session and return output.
552 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}
553 ... log_on_failure=${log_on_failure} stderr_must_be_empty=${stderr_must_be_empty}
555 Check_Unsafely_Bash_Command_On_Member
556 [Arguments] ${command} ${member_index} ${return_success_only}=False ${log_on_success}=True ${log_on_failure}=True ${stderr_must_be_empty}=True
557 [Documentation] Obtain Ip address, open session, call SSHKeywords.Execute_Command_Passes, close session and return output. This affects which SSH session is active.
558 ${member_ip} = Resolve_Ip_Address_For_Member ${member_index}
559 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}
560 ... log_on_failure=${log_on_failure} stderr_must_be_empty=${stderr_must_be_empty}
562 Run_Bash_Command_On_List_Or_All
563 [Arguments] ${command} ${member_index_list}=${EMPTY}
564 [Documentation] Cycle through indices (or all), run command on each.
565 # TODO: Migrate callers to Check_Bash_Command_*
566 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
567 : FOR ${index} IN @{index_list}
568 \ Run_Bash_Command_On_Member command=${command} member_index=${index}
570 Run_Bash_Command_On_Member
571 [Arguments] ${command} ${member_index}
572 [Documentation] Obtain IP, call Utils and return output. This keeps previous ssh session active.
573 # TODO: Migrate callers to Check_Bash_Command_*
574 ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_index}
575 ${output} = SSHKeywords.Run_Keyword_Preserve_Connection Utils.Run_Command_On_Controller ${member_ip} ${command}
579 Run_Karaf_Command_On_List_Or_All
580 [Arguments] ${command} ${member_index_list}=${EMPTY} ${timeout}=10s
581 [Documentation] Cycle through indices (or all), run karaf command on each.
582 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
583 : FOR ${index} IN @{index_list}
584 \ ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${index}
585 \ KarafKeywords.Safe_Issue_Command_On_Karaf_Console ${command} ${member_ip} timeout=${timeout}
587 Run_Karaf_Command_On_Member
588 [Arguments] ${command} ${member_index} ${timeout}=10s
589 [Documentation] Obtain IP address, call KarafKeywords and return output. This does not preserve active ssh session.
590 ... This keyword is not used by Run_Karaf_Command_On_List_Or_All, but returned output may be useful.
591 ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_index}
592 ${output} = KarafKeywords.Safe_Issue_Command_On_Karaf_Console ${command} controller=${member_ip} timeout=${timeout}
595 Install_Feature_On_List_Or_All
596 [Arguments] ${feature_name} ${member_index_list}=${EMPTY} ${timeout}=60s
597 [Documentation] Attempt installation on each member from list (or all). Then look for failures.
598 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
599 ${status_list} = BuiltIn.Create_List
600 : FOR ${index} IN @{index_list}
601 \ ${status} ${text} = BuiltIn.Run_Keyword_And_Ignore_Error Install_Feature_On_Member feature_name=${feature_name} member_index=${index}
602 \ ... timeout=${timeout}
603 \ BuiltIn.Log ${text}
604 \ Collections.Append_To_List ${status_list} ${status}
605 : FOR ${status} IN @{status_list}
606 \ BuiltIn.Run_Keyword_If "${status}" != "PASS" BuiltIn.Fail ${feature_name} installation failed, see log.
608 Install_Feature_On_Member
609 [Arguments] ${feature_name} ${member_index} ${timeout}=60s
610 [Documentation] Run feature:install karaf command, fail if installation was not successful. Return output.
611 ${status} ${output} = BuiltIn.Run_Keyword_And_Ignore_Error Run_Karaf_Command_On_Member command=feature:install ${feature_name} member_index=${member_index} timeout=${timeout}
612 BuiltIn.Run_Keyword_If "${status}" != "PASS" BuiltIn.Fail Failed to install ${feature_name}: ${output}
613 BuiltIn.Should_Not_Contain ${output} Can't install Failed to install ${feature_name}: ${output}
616 With_Ssh_To_List_Or_All_Run_Keyword
617 [Arguments] ${member_index_list} ${keyword_name} @{args} &{kwargs}
618 [Documentation] For each index in given list (or all): activate SSH connection, run given Keyword, close active connection. Return None.
619 ... Beware that in order to avoid "got positional argument after named arguments", first two arguments in the call should not be named.
620 BuiltIn.Comment This keyword is experimental and there is high risk of being replaced by another approach.
621 # TODO: For_Index_From_List_Or_All_Run_Keyword applied to With_Ssh_To_Member_Run_Keyword?
622 # TODO: Imagine another keyword, using ScalarClosures and adding member index as first argument for each call. Worth it?
623 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
624 : FOR ${member_index} IN @{index_list}
625 \ ${member_ip} = Resolve_IP_Address_For_Member ${member_index}
626 \ SSHKeywords.Run_Unsafely_Keyword_Over_Temporary_Odl_Session ${member_ip} ${keyword_name} @{args} &{kwargs}
628 Safe_With_Ssh_To_List_Or_All_Run_Keyword
629 [Arguments] ${member_index_list} ${keyword_name} @{args} &{kwargs}
630 [Documentation] Remember active ssh connection index, call With_Ssh_To_List_Or_All_Run_Keyword, return None. Restore the conection index on teardown.
631 SSHKeywords.Run_Keyword_Preserve_Connection With_Ssh_To_List_Or_All_Run_Keyword ${member_index_list} ${keyword_name} @{args} &{kwargs}
633 Clean_Directories_On_List_Or_All
634 [Arguments] ${member_index_list}=${EMPTY} ${directory_list}=${EMPTY} ${karaf_home}=${KARAF_HOME} ${tmp_dir}=${EMPTY}
635 [Documentation] Clear @{directory_list} or @{ODL_DEFAULT_DATA_PATHS} for members in given list or all. Return None.
636 ... If \${tmp_dir} is nonempty, use that location to preserve data/log/.
637 ... This is intended to return Karaf (offline) to the state it was upon the first boot.
638 ${path_list} = Builtin.Set Variable If "${directory_list}" == "${EMPTY}" ${ODL_DEFAULT_DATA_PATHS} ${directory_list}
639 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}
640 Safe_With_Ssh_To_List_Or_All_Run_Keyword ${member_index_list} ClusterManagement__Clean_Directories ${path_list} ${karaf_home}
641 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}
643 Store_Karaf_Log_On_List_Or_All
644 [Arguments] ${member_index_list}=${EMPTY} ${dst_dir}=/tmp ${karaf_home}=${KARAF_HOME}
645 [Documentation] Saves karaf.log to the ${dst_dir} for members in given list or all. Return None.
646 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}
648 Restore_Karaf_Log_On_List_Or_All
649 [Arguments] ${member_index_list}=${EMPTY} ${src_dir}=/tmp ${karaf_home}=${KARAF_HOME}
650 [Documentation] Places stored karaf.log to the ${karaf_home}/data/log for members in given list or all. Return None.
651 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/
653 ClusterManagement__Clean_Directories
654 [Arguments] ${relative_path_list} ${karaf_home}
655 [Documentation] For each relative path, remove files with respect to ${karaf_home}. Return None.
656 : FOR ${relative_path} IN @{relative_path_list}
657 \ SSHLibrary.Execute_Command rm -rf ${karaf_home}${/}${relative_path}
659 Put_As_Json_And_Check_Member_List_Or_All
660 [Arguments] ${uri} ${data} ${member_index} ${member_index_list}=${EMPTY}
661 [Documentation] Send a PUT with the supplied uri ${uri} and body ${data} to member ${member_index}.
662 ... Then check data is replicated in all or some members defined in ${member_index_list}.
663 ${response_text} = Put_As_Json_To_Member uri=${uri} data=${data} member_index=${member_index}
664 Wait Until Keyword Succeeds 5s 1s Check_Json_Member_List_Or_All uri=${uri} expected_data=${data} member_index_list=${member_index_list}
665 [Return] ${response_text}
667 Put_As_Json_To_Member
668 [Arguments] ${uri} ${data} ${member_index}
669 [Documentation] Send a PUT with the supplied uri and data to member ${member_index}.
670 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
671 ${response_text} = TemplatedRequests.Put_As_Json_To_Uri uri=${uri} data=${data} session=${session}
672 [Return] ${response_text}
674 Post_As_Json_To_Member
675 [Arguments] ${uri} ${data} ${member_index}
676 [Documentation] Send a POST with the supplied uri and data to member ${member_index}.
677 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
678 ${response_text} = TemplatedRequests.Post_As_Json_To_Uri uri=${uri} data=${data} session=${session}
679 [Return] ${response_text}
681 Delete_And_Check_Member_List_Or_All
682 [Arguments] ${uri} ${member_index} ${member_index_list}=${EMPTY}
683 [Documentation] Send a DELETE with the supplied uri to the member ${member_index}.
684 ... Then check the data is removed from all members in ${member_index_list}.
685 ${response_text} = Delete_From_Member ${uri} ${member_index}
686 BuiltIn.Wait_Until_Keyword_Succeeds 5s 1s Check_No_Content_Member_List_Or_All uri=${uri} member_index_list=${member_index_list}
687 [Return] ${response_text}
690 [Arguments] ${uri} ${member_index}
691 [Documentation] Send a DELETE with the supplied uri to member ${member_index}.
692 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
693 ${response_text} = TemplatedRequests.Delete_From_Uri uri=${uri} session=${session}
694 [Return] ${response_text}
696 Check_Json_Member_List_Or_All
697 [Arguments] ${uri} ${expected_data} ${member_index_list}=${EMPTY}
698 [Documentation] Send a GET with the supplied uri to all or some members defined in ${member_index_list}.
699 ... Then check received data is = ${expected data}.
700 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
701 : FOR ${index} IN @{index_list}
702 \ ${data} = Get_From_Member uri=${uri} member_index=${index}
703 \ TemplatedRequests.Normalize_Jsons_And_Compare ${expected_data} ${data}
705 Check_Item_Occurrence_Member_List_Or_All
706 [Arguments] ${uri} ${dictionary} ${member_index_list}=${EMPTY}
707 [Documentation] Send a GET with the supplied uri to all or some members defined in ${member_index_list}.
708 ... Then check received for occurrences of items expressed in a dictionary ${dictionary}.
709 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
710 : FOR ${index} IN @{index_list}
711 \ ${data} = Get_From_Member uri=${uri} member_index=${index}
712 \ Utils.Check Item Occurrence ${data} ${dictionary}
714 Check_No_Content_Member_List_Or_All
715 [Arguments] ${uri} ${member_index_list}=${EMPTY}
716 [Documentation] Send a GET with the supplied uri to all or some members defined in ${member_index_list}.
717 ... Then check there is no content.
718 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
719 : FOR ${index} IN @{index_list}
720 \ ${session} = Resolve_Http_Session_For_Member member_index=${index}
721 \ Utils.No_Content_From_URI ${session} ${uri}
724 [Arguments] ${uri} ${member_index} ${access}=${ACCEPT_EMPTY}
725 [Documentation] Send a GET with the supplied uri to member ${member_index}.
726 ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
727 ${response_text} = TemplatedRequests.Get_From_Uri uri=${uri} accept=${access} session=${session}
728 [Return] ${response_text}
730 Resolve_IP_Address_For_Member
731 [Arguments] ${member_index}
732 [Documentation] Return node IP address of given index.
733 ${ip_address} = Collections.Get From Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_index}
734 [Return] ${ip_address}
736 Resolve_IP_Address_For_Members
737 [Arguments] ${member_index_list}
738 [Documentation] Return a list of IP address of given indexes.
739 ${member_ip_list} = BuiltIn.Create_List
740 : FOR ${index} IN @{member_index_list}
741 \ ${ip_address} = Collections.Get From Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${index}
742 \ Collections.Append_To_List ${member_ip_list} ${ip_address}
743 [Return] ${member_ip_list}
745 Resolve_Http_Session_For_Member
746 [Arguments] ${member_index}
747 [Documentation] Return RequestsLibrary session alias pointing to node of given index.
748 ${session} = BuiltIn.Set_Variable ClusterManagement__session_${member_index}
751 Resolve_Shard_Type_Class
752 [Arguments] ${shard_type}
753 [Documentation] Simple lookup for class name corresponding to desired type.
754 BuiltIn.Run_Keyword_If '${shard_type}' == 'config' BuiltIn.Return_From_Keyword DistributedConfigDatastore
755 ... ELSE IF '${shard_type}' == 'operational' BuiltIn.Return_From_Keyword DistributedOperationalDatastore
756 BuiltIn.Fail Unrecognized shard type: ${shard_type}
758 ClusterManagement__Build_List
759 [Arguments] ${member}
760 ${member_int} = BuiltIn.Convert_To_Integer ${member}
761 ${index_list} = BuiltIn.Create_List ${member_int}
762 [Return] ${index_list}
764 ClusterManagement__Parse_Sync_Status
765 [Arguments] ${shard_manager_text}
766 [Documentation] Return sync status parsed out of given text. Called twice by Get_Sync_Status_Of_Member.
767 BuiltIn.Log ${shard_manager_text}
768 ${manager_object} = RequestsLibrary.To_Json ${shard_manager_text}
769 ${value_object} = Collections.Get_From_Dictionary dictionary=${manager_object} key=value
770 ${sync_status} = Collections.Get_From_Dictionary dictionary=${value_object} key=SyncStatus
771 [Return] ${sync_status}
774 [Documentation] Create a new list of all indices.
775 BuiltIn.Run_Keyword_And_Return List_Indices_Or_All
778 [Arguments] ${given_list}=${EMPTY}
779 [Documentation] Utility to allow \${EMPTY} as default argument value, as the internal list is computed at runtime.
780 ... This keyword always returns a (shallow) copy of given or default list,
781 ... so operations with the returned list should not affect other lists.
782 ... Also note that this keyword does not consider empty list to be \${EMPTY}.
783 ${return_list_reference} = BuiltIn.Set_Variable_If """${given_list}""" != "" ${given_list} ${ClusterManagement__member_index_list}
784 ${return_list_copy} = BuiltIn.Create_List @{return_list_reference}
785 [Return] ${return_list_copy}
787 List_Indices_Minus_Member
788 [Arguments] ${member_index} ${member_index_list}=${EMPTY}
789 [Documentation] Create a new list which contains indices from ${member_index_list} (or all) without ${member_index}.
790 ${index_list} = List_Indices_Or_All ${member_index_list}
791 Collections.Remove Values From List ${index_list} ${member_index}
792 [Return] ${index_list}
794 ClusterManagement__Compute_Derived_Variables
795 [Arguments] ${int_of_members} ${http_timeout}=${DEFAULT_TIMEOUT_HTTP} ${http_retries}=0
796 [Documentation] Construct index list, session list and IP mapping, publish them as suite variables.
797 @{member_index_list} = BuiltIn.Create_List
798 @{session_list} = BuiltIn.Create_List
799 &{index_to_ip_mapping} = BuiltIn.Create_Dictionary
800 : FOR ${index} IN RANGE 1 ${int_of_members+1}
801 \ ClusterManagement__Include_Member_Index ${index} ${member_index_list} ${session_list} ${index_to_ip_mapping} http_timeout=${http_timeout}
802 \ ... http_retries=${http_retries}
803 BuiltIn.Set_Suite_Variable \${ClusterManagement__member_index_list} ${member_index_list}
804 BuiltIn.Set_Suite_Variable \${ClusterManagement__index_to_ip_mapping} ${index_to_ip_mapping}
805 BuiltIn.Set_Suite_Variable \${ClusterManagement__session_list} ${session_list}
807 ClusterManagement__Include_Member_Index
808 [Arguments] ${index} ${member_index_list} ${session_list} ${index_to_ip_mapping} ${http_timeout}=${DEFAULT_TIMEOUT_HTTP} ${http_retries}=0
809 [Documentation] Add a corresponding item based on index into the last three arguments.
810 ... Create the Http session whose alias is added to list.
811 Collections.Append_To_List ${member_index_list} ${index}
812 ${member_ip} = BuiltIn.Set_Variable ${ODL_SYSTEM_${index}_IP}
813 # ${index} is int (not string) so "key=value" syntax does not work in the following line.
814 Collections.Set_To_Dictionary ${index_to_ip_mapping} ${index} ${member_ip}
815 # Http session, with ${AUTH}, without headers.
816 ${session_alias} = Resolve_Http_Session_For_Member member_index=${index}
817 RequestsLibrary.Create_Session ${session_alias} http://${member_ip}:${RESTCONFPORT} auth=${AUTH} timeout=${http_timeout} max_retries=${http_retries}
818 Collections.Append_To_List ${session_list} ${session_alias}
820 Sync_Status_Should_Be_False
821 [Arguments] ${controller_index}
822 [Documentation] Verify that cluster node is not in sync with others
823 ${status} Get_Sync_Status_Of_Member ${controller_index}
824 BuiltIn.Should_Not_Be_True ${status}
826 Sync_Status_Should_Be_True
827 [Arguments] ${controller_index}
828 [Documentation] Verify that cluster node is in sync with others
829 ${status} Get_Sync_Status_Of_Member ${controller_index}
830 BuiltIn.Should_Be_True ${status}
833 [Arguments] ${member_index}
834 [Documentation] Return the IP address of the member given the member_index.
835 ${member_int} = BuiltIn.Convert_To_Integer ${member_index}
836 ${member_ip} = Collections.Get_From_Dictionary dictionary=${ClusterManagement__index_to_ip_mapping} key=${member_int}
837 [Return] ${member_ip}
840 [Arguments] ${odl_ip} ${system_ready_state} ${service_state} @{service_list}
841 [Documentation] Issues the karaf shell command showSvcStatus to verify the ready and service states are the same as the arguments passed
842 ${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}
843 ... ELSE KarafKeywords.Issue_Command_On_Karaf_Console showSvcStatus ${odl_ip} ${KARAF_SHELL_PORT}
844 BuiltIn.Should Contain ${service_status_output} ${system_ready_state}
845 : FOR ${service} IN @{service_list}
846 \ BuiltIn.Should Match Regexp ${service_status_output} ${service} +: ${service_state}
848 Check Status Of Services Is OPERATIONAL
849 [Arguments] @{service_list}
850 [Documentation] This keyword will verify whether all the services are operational in all the ODL nodes
851 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
852 \ ClusterManagement.Check Service Status ${ODL_SYSTEM_${i+1}_IP} ACTIVE OPERATIONAL @{service_list}