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