+ RETURN ${owner} ${candidate_list}
+
+Get_Owner_And_Candidates_For_Device_Singleton
+ [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}.
+ [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
+ # Normalize device type to the lowercase as in ${SINGLETON_DEVICE_ID_PREFIX} & ${SINGLETON_DEVICE_ID_SUFFIX}
+ ${device_type} = String.Convert To Lower Case ${device_type}
+ # Set device ID prefix
+ Collections.Dictionary Should Contain Key ${SINGLETON_DEVICE_ID_PREFIX} ${device_type}
+ ${device_id_prefix} = Collections.Get From Dictionary ${SINGLETON_DEVICE_ID_PREFIX} ${device_type}
+ Log ${device_id_prefix}
+ # Set device ID suffix
+ Collections.Dictionary Should Contain Key ${SINGLETON_DEVICE_ID_SUFFIX} ${device_type}
+ ${device_id_suffix} = Collections.Get From Dictionary ${SINGLETON_DEVICE_ID_SUFFIX} ${device_type}
+ Log ${device_id_suffix}
+ # Set device ID
+ ${id} = BuiltIn.Set_Variable ${device_id_prefix}${device_name}${device_id_suffix}
+ Log ${id}
+ # Get election entity type results
+ ${type} = BuiltIn.Set_Variable ${SINGLETON_ELECTION_ENTITY_TYPE}
+ ${owner_1} ${candidate_list_1} = Get_Owner_And_Candidates_For_Type_And_Id
+ ... ${type}
+ ... ${id}
+ ... ${member_index}
+ ... http_timeout=${http_timeout}
+ # Get change ownership entity type results
+ ${type} = BuiltIn.Set_Variable ${SINGLETON_CHANGE_OWNERSHIP_ENTITY_TYPE}
+ ${owner_2} ${candidate_list_2} = Get_Owner_And_Candidates_For_Type_And_Id
+ ... ${type}
+ ... ${id}
+ ... ${member_index}
+ ... http_timeout=${http_timeout}
+ # Owners must be same, if not, there is still some election or change ownership in progress
+ BuiltIn.Should_Be_Equal_As_Integers ${owner_1} ${owner_2} Owners for device ${device_name} are not same
+ RETURN ${owner_1} ${candidate_list_1}
+
+Get_Owner_And_Candidates_For_Device
+ [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}.
+ ... If parsing as singleton failed, kw try to parse data in old way (without singleton).
+ ... 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.
+ [Arguments] ${device_name} ${device_type} ${member_index} ${http_timeout}=${EMPTY}
+ # Try singleton
+ ${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}
+ ... http_timeout=${http_timeout}
+ IF "${status}"=="PASS" RETURN ${results}
+ # If singleton failed, try parsing in old way
+ ${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}
+ ... http_timeout=${http_timeout}
+ # previous 3 lines (BuilIn.Return.., # If singleton..., ${status}....) could be deleted when old way will not be supported anymore
+ IF '${status}'=='FAIL'
+ BuiltIn.Fail Could not parse owner and candidates for device ${device_name}
+ END
+ RETURN @{results}
+
+Check_Old_Owner_Stays_Elected_For_Device
+ [Documentation] Verify the owner remain the same as ${old_owner}
+ [Arguments] ${device_name} ${device_type} ${old_owner} ${node_to_ask} ${http_timeout}=${EMPTY}
+ ${owner} ${candidates} = Get_Owner_And_Candidates_For_Device
+ ... ${device_name}
+ ... ${device_type}
+ ... ${node_to_ask}
+ ... http_timeout=${http_timeout}
+ BuiltIn.Should_Be_Equal_As_numbers ${old_owner} ${owner}
+ RETURN ${owner} ${candidates}
+
+Check_New_Owner_Got_Elected_For_Device
+ [Documentation] Verify new owner was elected comparing to ${old_owner}
+ [Arguments] ${device_name} ${device_type} ${old_owner} ${node_to_ask} ${http_timeout}=${EMPTY}
+ ${owner} ${candidates} = Get_Owner_And_Candidates_For_Device
+ ... ${device_name}
+ ... ${device_type}
+ ... ${node_to_ask}
+ ... http_timeout=${http_timeout}
+ BuiltIn.Should_Not_Be_Equal_As_Numbers ${old_owner} ${owner}
+ RETURN ${owner} ${candidates}