+Get_Raft_State_Of_Shard_At_Member
+ [Arguments] ${shard_name} ${shard_type} ${member_index} ${verify_restconf}=False
+ [Documentation] Send request to Jolokia on indexed member, return extracted Raft status.
+ ... Optionally, check restconf works.
+ ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
+ # TODO: Does the used URI tend to generate large data which floods log.html?
+ BuiltIn.Run_Keyword_If ${verify_restconf} TemplatedRequests.Get_As_Json_Templated session=${session} folder=${RESTCONF_MODULES_DIR} verify=False
+ ${type_class} = Resolve_Shard_Type_Class shard_type=${shard_type}
+ ${uri} = BuiltIn.Set_Variable ${JOLOKIA_READ_URI}:Category=Shards,name=member-${member_index}-shard-${shard_name}-${shard_type},type=${type_class}
+ ${data_text} = TemplatedRequests.Get_As_Json_From_Uri uri=${uri} session=${session}
+ ${data_object} = RequestsLibrary.To_Json ${data_text}
+ ${value} = Collections.Get_From_Dictionary ${data_object} value
+ ${raft_state} = Collections.Get_From_Dictionary ${value} RaftState
+ [Return] ${raft_state}
+
+Verify_Owner_And_Successors_For_Device
+ [Arguments] ${device_name} ${device_type} ${member_index} ${candidate_list}=${EMPTY}
+ [Documentation] Returns the owner and successors for the SB device ${device_name} of type ${device_type}. Request is sent to member ${member_index}.
+ ... For Boron and beyond, candidates are not removed on node down or isolation,
+ ... so this keyword expects candidates to be all members from Boron on.
+ ... Extra check is done to verify owner and successors are within the ${candidate_list}. This KW is useful when combined with WUKS.
+ ... ${candidate_list} minus owner is returned as ${successor list}.
+ ... Users can still use Get_Owner_And_Successors_For_Device if they are interested in downed candidates,
+ ... or for testing heterogeneous clusters.
+ ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${candidate_list}
+ ${owner} ${successor_list} = Get_Owner_And_Successors_For_Device device_name=${device_name} device_type=${device_type} member_index=${member_index}
+ Collections.List_Should_Contain_Value ${index_list} ${owner} Owner ${owner} is not in candidate list ${index_list}
+ ${expected_candidate_list_origin} = CompareStream.Set_Variable_If_At_Least_Boron ${ClusterManagement__member_index_list} ${index_list}
+ # We do not want to manipulate either origin list.
+ ${expected_successor_list} = BuiltIn.Create_List @{expected_candidate_list_origin}
+ Collections.Remove_Values_From_List ${expected_successor_list} ${owner}
+ Collections.Lists_Should_Be_Equal ${expected_successor_list} ${successor_list} Successor list ${successor_list} is not the came as expected ${expected_successor_list}
+ # User expects the returned successor list to be the provided candidate list minus the owner.
+ Collections.Remove_Values_From_List ${index_list} ${owner}
+ [Return] ${owner} ${index_list}
+
+Get_Owner_And_Successors_For_Device
+ [Arguments] ${device_name} ${device_type} ${member_index}
+ [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}.
+ ... Successors are those device candidates not elected as owner. The list of successors = (list of candidates) - (owner).
+ ... The returned successor list is sorted numerically.
+ ... Note that "candidate list" definition currently differs between Beryllium and Boron.
+ ... Use Verify_Owner_And_Successors_For_Device if you want the older semantics (inaccessible nodes not present in the list).
+ ${owner} ${candidate_list} = Get_Owner_And_Candidates_For_Device device_name=${device_name} device_type=${device_type} member_index=${member_index}
+ ${successor_list} = BuiltIn.Create_List @{candidate_list} # Copy operation is not required, but new variable name requires a line anyway.
+ Collections.Remove_Values_From_List ${successor_list} ${owner}
+ [Return] ${owner} ${successor_list}
+
+Get_Owner_And_Candidates_For_Device
+ [Arguments] ${device_name} ${device_type} ${member_index}
+ [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}.
+ ... Candidates are all members that register to own a device, so the list of candiates includes the owner.
+ ... The returned candidate list is sorted numerically.
+ ... Note that "candidate list" definition currently differs between Beryllium and Boron.
+ ... It is recommended to use Get_Owner_And_Successors_For_Device instead of this keyword, see documentation there.
+ ${session} = Resolve_Http_Session_For_Member member_index=${member_index}
+ ${data} = TemplatedRequests.Get_As_Json_From_Uri uri=${ENTITY_OWNER_URI} session=${session}
+ ${candidate_list} = BuiltIn.Create_List
+ ${entity_type} = BuiltIn.Set_Variable_If '${device_type}' == 'netconf' netconf-node/${device_name} ${device_type}
+ ${clear_data} = BuiltIn.Run_Keyword_If '${device_type}' == 'openflow' or '${device_type}' == 'netconf' Extract_OpenFlow_Device_Data ${data}
+ ... ELSE IF '${device_type}' == 'ovsdb' Extract_Ovsdb_Device_Data ${data}
+ ... ELSE IF '${device_type}' == 'org.opendaylight.mdsal.ServiceEntityType' Extract_Service_Entity_Type ${data}
+ ... ELSE Fail Not recognized device type: ${device_type}
+ ${json} = RequestsLibrary.To_Json ${clear_data}
+ ${entity_type_list} = Collections.Get_From_Dictionary &{json}[entity-owners] entity-type
+ ${entity_type_index} = Utils.Get_Index_From_List_Of_Dictionaries ${entity_type_list} type ${entity_type}
+ BuiltIn.Should_Not_Be_Equal ${entity_type_index} -1 No Entity Owner found for ${device_type}
+ ${entity_list} = Collections.Get_From_Dictionary @{entity_type_list}[${entity_type_index}] entity
+ ${entity_index} = Utils.Get_Index_From_List_Of_Dictionaries ${entity_list} id ${device_name}
+ BuiltIn.Should Not Be Equal ${entity_index} -1 Device ${device_name} not found in Entity Owner ${device_type}
+ ${entity_owner} = Collections.Get_From_Dictionary @{entity_list}[${entity_index}] owner
+ BuiltIn.Should_Not_Be_Empty ${entity_owner} No owner found for ${device_name}
+ ${owner} = String.Replace_String ${entity_owner} member- ${EMPTY}
+ ${owner} = BuiltIn.Convert_To_Integer ${owner}
+ ${entity_candidates_list} = Collections.Get_From_Dictionary @{entity_list}[${entity_index}] candidate
+ : FOR ${entity_candidate} IN @{entity_candidates_list}
+ \ ${candidate} = String.Replace_String &{entity_candidate}[name] member- ${EMPTY}
+ \ ${candidate} = BuiltIn.Convert_To_Integer ${candidate}
+ \ Collections.Append_To_List ${candidate_list} ${candidate}
+ Collections.Sort_List ${candidate_list}
+ [Return] ${owner} ${candidate_list}
+
+Extract_Service_Entity_Type
+ [Arguments] ${data}
+ [Documentation] Remove superfluous device data from Entity Owner printout.
+ ${clear_data} = String.Replace_String ${data} /odl-general-entity:entity[odl-general-entity:name='Uri [_value= ${EMPTY}
+ ${clear_data} = String.Replace_String ${clear_data} ]-service-group'] ${EMPTY}
+ Log ${clear_data}
+ [Return] ${clear_data}
+
+Extract_OpenFlow_Device_Data
+ [Arguments] ${data}
+ [Documentation] Remove superfluous OpenFlow device data from Entity Owner printout.
+ ${clear_data} = BuiltIn.Run Keyword If '${ODL_STREAM}' != 'beryllium' and '${ODL_OF_PLUGIN}' == 'lithium' String.Replace_String ${data} org.opendaylight.mdsal.ServiceEntityType openflow
+ ... ELSE BuiltIn.Set_Variable ${data}
+ ${clear_data} = String.Replace_String ${clear_data} /odl-general-entity:entity[odl-general-entity:name=' ${EMPTY}
+ ${clear_data} = String.Replace_String ${clear_data} /general-entity:entity[general-entity:name=' ${EMPTY}
+ ${clear_data} = String.Replace_String ${clear_data} '] ${EMPTY}
+ Log ${clear_data}
+ [Return] ${clear_data}
+
+Extract_Ovsdb_Device_Data
+ [Arguments] ${data}
+ [Documentation] Remove superfluous OVSDB device data from Entity Owner printout.
+ ${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}
+ ${clear_data} = String.Replace_String ${clear_data} '] ${EMPTY}
+ Log ${clear_data}
+ [Return] ${clear_data}
+
+Kill_Single_Member
+ [Arguments] ${member} ${original_index_list}=${EMPTY} ${confirm}=True
+ [Documentation] Convenience keyword that kills the specified member of the cluster.
+ ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member}
+ ${index_list} = ClusterManagement__Build_List ${member}
+ ${updated_index_list} = Kill_Members_From_List_Or_All ${index_list} ${original_index_list} ${confirm}
+ [Return] ${updated_index_list}
+
+Kill_Members_From_List_Or_All
+ [Arguments] ${member_index_list}=${EMPTY} ${original_index_list}=${EMPTY} ${confirm}=True
+ [Documentation] If the list is empty, kill all ODL instances. Otherwise, kill members based on \${kill_index_list}
+ ... If \${confirm} is True, sleep 1 second and verify killed instances are not there anymore.
+ ... The KW will return a list of available members: \${updated index_list}=\${original_index_list}-\${member_index_list}
+ ${kill_index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
+ ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${original_index_list}
+ ${command} = BuiltIn.Set_Variable ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
+ Run_Command_On_List_Or_All command=${command} member_index_list=${member_index_list}
+ ${updated_index_list} = BuiltIn.Create_List @{index_list}
+ Collections.Remove_Values_From_List ${updated_index_list} @{kill_index_list}
+ BuiltIn.Return_From_Keyword_If not ${confirm} ${updated_index_list}
+ # TODO: Convert to WUKS with configurable timeout if it turns out 1 second is not enough.
+ BuiltIn.Sleep 1s Kill -9 closes open files, which may take longer than ssh overhead, but not long enough to warrant WUKS.
+ : FOR ${index} IN @{kill_index_list}
+ \ Verify_Karaf_Is_Not_Running_On_Member member_index=${index}
+ [Return] ${updated_index_list}
+
+Start_Single_Member
+ [Arguments] ${member} ${wait_for_sync}=True ${timeout}=300s
+ [Documentation] Convenience keyword that starts the specified member of the cluster.
+ ${index_list} = ClusterManagement__Build_List ${member}
+ Start_Members_From_List_Or_All ${index_list} ${wait_for_sync} ${timeout}
+
+Start_Members_From_List_Or_All
+ [Arguments] ${member_index_list}=${EMPTY} ${wait_for_sync}=True ${timeout}=300s ${karaf_home}=${WORKSPACE}${/}${BUNDLEFOLDER} ${export_java_home}=${JAVA_HOME}
+ [Documentation] If the list is empty, start all cluster members. Otherwise, start members based on present indices.
+ ... If ${wait_for_sync}, wait for cluster sync on listed members.
+ ... Optionally karaf_home can be overriden. Optionally specific JAVA_HOME is used for starting.
+ ${base_command} = BuiltIn.Set_Variable ${karaf_home}/bin/start
+ ${command} = BuiltIn.Set_Variable_If "${export_java_home}" export JAVA_HOME="${export_java_home}"; ${base_command} ${base_command}
+ Run_Command_On_List_Or_All command=${command} member_index_list=${member_index_list}
+ BuiltIn.Return_From_Keyword_If not ${wait_for_sync}
+ BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} 1s Check_Cluster_Is_In_Sync member_index_list=${member_index_list}
+ # TODO: Do we also want to check Shard Leaders here?
+
+Clean_Journals_And_Snapshots_On_List_Or_All
+ [Arguments] ${member_index_list}=${EMPTY} ${karaf_home}=${WORKSPACE}${/}${BUNDLEFOLDER}
+ [Documentation] Delete journal and snapshots directories on every node listed (or all).