e9543725b6e6e78e6e3e34137637afd9b9009507
[integration/test.git] / csit / libraries / controller / DdbCommons.robot
1 *** Settings ***
2 Documentation     DOMDataBroker testing: Common keywords
3 ...
4 ...               Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...               This resource file implements various test cases templates.
11 ...               FIXME: add a link to a document (when published) where the scenarios are defined
12 Library           ${CURDIR}/../MdsalLowlevelPy.py
13 Resource          ${CURDIR}/../ClusterAdmin.robot
14 Resource          ${CURDIR}/../ClusterManagement.robot
15 Resource          ${CURDIR}/../KarafKeywords.robot
16 Resource          ${CURDIR}/../MdsalLowlevel.robot
17 Resource          ${CURDIR}/../TemplatedRequests.robot
18 Resource          ${CURDIR}/../ShardStability.robot
19 Resource          ${CURDIR}/../WaitForFailure.robot
20
21 *** Variables ***
22 ${SHARD_NAME}     default
23 ${SHARD_TYPE}     config
24 ${TRANSACTION_RATE_1K}    ${1000}
25 ${DURATION_90S}    ${90}    #TODO: Rename to hint at the goal of waiting, instead of its default value.
26 ${DURATION_30S}    ${30}
27 ${DURATION_10S}    ${10}
28 ${ID_PREFIX}      prefix-
29 ${TRANSACTION_TIMEOUT}    ${30}
30 ${TRANSACTION_TIMEOUT_2X}    ${2*${TRANSACTION_TIMEOUT}}
31 ${SIMPLE_TX}      ${False}
32 ${CHAINED_TX}     ${True}
33 ${ISOLATED_TRANS_TRUE}    ${True}
34 ${ISOLATED_TRANS_FALSE}    ${False}
35 ${HARD_TIMEOUT}    ${120}
36 @{TRANSACTION_FAILED}    ${500}
37 ${PREF_BASED_SHARD}    id-ints
38 ${TEST_LOG_LEVEL}    info
39 @{TEST_LOG_COMPONENTS}    org.opendaylight.controller.cluster.sharding    org.opendaylight.controller.cluster.datastore
40 ${HEAL_WITHIN_TRANS_TIMEOUT}    ${0}
41
42 *** Keywords ***
43 Explicit_Leader_Movement_Test_Templ
44     [Arguments]    ${leader_from}    ${leader_to}    ${shard_name}=${SHARD_NAME}    ${shard_type}=${SHARD_TYPE}
45     [Documentation]    Implements explicit leader movement test scenario.
46     ${idx_from}    ${idx_to}    ${idx_trans} =    Get_Node_Indexes_For_The_ELM_Test    ${leader_from}    ${leader_to}    ${shard_name}
47     ...    ${shard_type}
48     ${ip_trans_as_list} =    BuiltIn.Create_List    ${ODL_SYSTEM_${idx_trans}_IP}
49     ${idx_trans_as_list} =    BuiltIn.Create_List    ${idx_trans}
50     MdsalLowlevelPy.Start_Write_Transactions_On_Nodes    ${ip_trans_as_list}    ${idx_trans_as_list}    ${ID_PREFIX}    ${DURATION_30S}    ${TRANSACTION_RATE_1K}    chained_flag=${CHAINED_TX}
51     BuiltIn.Sleep    5s
52     ClusterAdmin.Make_Leader_Local    ${idx_to}    ${shard_name}    ${shard_type}
53     ${new_leader}    ${new_followers} =    BuiltIn.Wait_Until_Keyword_Succeeds    30s    5s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}
54     ...    ${shard_type}    ${True}    ${idx_from}    verify_restconf=False
55     BuiltIn.Should_Be_Equal    ${idx_to}    ${new_leader}
56     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
57     TemplatedRequests.Check_Status_Code    @{resp_list}[0]
58
59 Explicit_Leader_Movement_PrefBasedShard_Test_Templ
60     [Arguments]    ${leader_from}    ${leader_to}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
61     [Documentation]    Implements explicit leader movement test scenario.
62     ${idx_from}    ${idx_to}    ${idx_trans} =    Get_Node_Indexes_For_The_ELM_Test    ${leader_from}    ${leader_to}    ${shard_name}!!
63     ...    ${shard_type}
64     ${ip_trans_as_list} =    BuiltIn.Create_List    ${ODL_SYSTEM_${idx_trans}_IP}
65     ${idx_trans_as_list} =    BuiltIn.Create_List    ${idx_trans}
66     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${ip_trans_as_list}    ${idx_trans_as_list}    ${ID_PREFIX}    ${DURATION_30S}    ${TRANSACTION_RATE_1K}
67     BuiltIn.Sleep    5s
68     MdsalLowlevel.Become_Prefix_Leader    ${idx_to}    ${shard_name}    ${ID_PREFIX}
69     ${new_leader}    ${new_followers} =    BuiltIn.Wait_Until_Keyword_Succeeds    30s    5s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}!!
70     ...    ${shard_type}    ${True}    ${idx_from}    verify_restconf=False
71     BuiltIn.Should_Be_Equal    ${idx_to}    ${new_leader}
72     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
73     TemplatedRequests.Check_Status_Code    @{resp_list}[0]
74
75 Get_Node_Indexes_For_The_ELM_Test
76     [Arguments]    ${leader_from}    ${leader_to}    ${shard_name}    ${shard_type}
77     [Documentation]    Return indexes for explicit leader movement test case, indexes of present to next leader node and index where transaction
78     ...    producer should be deployed.
79     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    verify_restconf=False
80     ${idx_from} =    BuiltIn.Set_Variable    ${leader}
81     ${idx_to} =    BuiltIn.Set_Variable    @{follower_list}[0]
82     ${idx_trans} =    BuiltIn.Set_Variable_If    "${leader_from}" == "remote" and "${leader_to}" == "remote"    @{follower_list}[1]    "${leader_from}" == "local"    ${leader}    "${leader_to}" == "local"
83     ...    @{follower_list}[0]
84     BuiltIn.Return_From_Keyword    ${idx_from}    ${idx_to}    ${idx_trans}
85
86 Clean_Leader_Shutdown_Test_Templ
87     [Arguments]    ${leader_location}    ${shard_name}=${SHARD_NAME}    ${shard_type}=${SHARD_TYPE}
88     [Documentation]    Implements clean leader shutdown test scenario.
89     ${removed} =    BuiltIn.Set_Variable    ${False}
90     ${producer_idx}    ${actual_leader}    ${follower_list} =    Get_Node_Indexes_For_Clean_Leader_Shutdown_Test    ${leader_location}    ${shard_name}    ${shard_type}
91     ${producer_ip_as_list} =    BuiltIn.Create_List    ${ODL_SYSTEM_${producer_idx}_IP}
92     ${producer_idx_as_list} =    BuiltIn.Create_List    ${producer_idx}
93     MdsalLowlevelPy.Start_Write_Transactions_On_Nodes    ${producer_ip_as_list}    ${producer_idx_as_list}    ${ID_PREFIX}    ${DURATION_30S}    ${TRANSACTION_RATE_1K}    chained_flag=${CHAINED_TX}
94     BuiltIn.Sleep    5s
95     ClusterAdmin.Remove_Shard_Replica    ${actual_leader}    ${shard_name}    member-${actual_leader}    ${shard_type}
96     ${removed} =    BuiltIn.Set_Variable    ${True}
97     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
98     TemplatedRequests.Check_Status_Code    @{resp_list}[0]
99     [Teardown]    BuiltIn.Run_Keywords    BuiltIn.Run_Keyword_And_Ignore_Error    BuiltIn.Wait_Until_Keyword_Succeeds    30s    3s    ClusterManagement.Get_Leader_And_Followers_For_Shard
100     ...    shard_name=${shard_name}    shard_type=${shard_type}    member_index_list=${follower_list}    verify_restconf=False
101     ...    AND    ClusterAdmin.Add_Shard_Replica    ${actual_leader}    ${shard_name}    ${shard_type}
102     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    30s    3s    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}
103     ...    verify_restconf=False    shard_type=${shard_type}
104
105 Clean_Leader_Shutdown_PrefBasedShard_Test_Templ
106     [Arguments]    ${leader_location}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
107     [Documentation]    Implements clean leader shutdown test scenario.
108     ${producer_idx}    ${actual_leader}    ${follower_list} =    Get_Node_Indexes_For_Clean_Leader_Shutdown_Test    ${leader_location}    ${shard_name}!!    ${shard_type}
109     ${producer_ip_as_list} =    BuiltIn.Create_List    ${ODL_SYSTEM_${producer_idx}_IP}
110     ${producer_idx_as_list} =    BuiltIn.Create_List    ${producer_idx}
111     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${producer_ip_as_list}    ${producer_idx_as_list}    ${ID_PREFIX}    ${DURATION_30S}    ${TRANSACTION_RATE_1K}
112     BuiltIn.Sleep    5s
113     ClusterAdmin.Remove_Prefix_Shard_Replica    ${actual_leader}    ${shard_name}    member-${actual_leader}    ${shard_type}
114     BuiltIn.Wait_Until_Keyword_Succeeds    15s    2s    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index_list=${follower_list}
115     ...    verify_restconf=False
116     BuiltIn.Run_Keyword_And_Ignore_Error    ClusterManagement.Get_Raft_State_Of_Shard_At_Member    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index=${actual_leader}
117     WaitForFailure.Confirm_Keyword_Fails_Within_Timeout    10s    2s    ClusterManagement.Get_Raft_State_Of_Shard_At_Member    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index=${actual_leader}
118     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
119     TemplatedRequests.Check_Status_Code    @{resp_list}[0]
120     [Teardown]    BuiltIn.Run_Keywords    BuiltIn.Run_Keyword_And_Ignore_Error    BuiltIn.Wait_Until_Keyword_Succeeds    30s    3s    ClusterManagement.Get_Leader_And_Followers_For_Shard
121     ...    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index_list=${follower_list}    verify_restconf=False
122     ...    AND    ClusterAdmin.Add_Prefix_Shard_Replica    ${actual_leader}    ${shard_name}    ${shard_type}
123     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    30s    3s    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}!!
124     ...    verify_restconf=False    shard_type=${shard_type}
125
126 Get_Node_Indexes_For_Clean_Leader_Shutdown_Test
127     [Arguments]    ${leader_location}    ${shard_name}    ${shard_type}
128     [Documentation]    Return indexes for clean leader shudown test case, index where transaction producer shoudl be deployed and a shard leader index.
129     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    verify_restconf=False
130     ${follower_list_leangth} =    BuiltIn.Evaluate    ${NUM_ODL_SYSTEM}-1
131     BuiltIn.Length_Should_Be    ${follower_list}    ${follower_list_leangth}
132     ${producer_idx} =    BuiltIn.Set_Variable_If    "${leader_location}" == "local"    ${leader}    @{follower_list}[0]
133     BuiltIn.Return_From_Keyword    ${producer_idx}    ${leader}    ${follower_list}
134
135 Leader_Isolation_Test_Templ
136     [Arguments]    ${heal_timeout}    ${shard_name}=${SHARD_NAME}    ${shard_type}=${SHARD_TYPE}
137     [Documentation]    Implements leader isolation test scenario.
138     ${li_isolated}    BuiltIn.Set_Variable    ${False}
139     ${producing_transactions_time} =    BuiltIn.Set_Variable    ${${heal_timeout}+60}
140     ${all_indices} =    ClusterManagement.List_All_Indices
141     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    member_index_list=${all_indices}    verify_restconf=False
142     ${all_ip_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${all_indices}
143     MdsalLowlevelPy.Start_Write_Transactions_On_Nodes    ${all_ip_list}    ${all_indices}    ${ID_PREFIX}    ${producing_transactions_time}    ${TRANSACTION_RATE_1K}    chained_flag=${CHAINED_TX}
144     BuiltIn.Sleep    5s
145     ${date_start} =    DateTime.Get_Current_Date
146     ${date_end} =    DateTime.Add_Time_To_Date    ${date_start}    ${producing_transactions_time}
147     KarafKeywords.Log_Message_To_Controller_Karaf    Isolating node ${leader}
148     ClusterManagement.Isolate_Member_From_List_Or_All    ${leader}
149     ${li_isolated}    BuiltIn.Set_Variable    ${True}
150     BuiltIn.Wait_Until_Keyword_Succeeds    45s    2s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}    ${shard_type}    ${True}
151     ...    ${leader}    member_index_list=${follower_list}
152     ${date_leader_elected} =    DateTime.Get_Current_Date
153     ${delta} =    DateTime.Subtract_Date_From_Date    ${date_leader_elected}    ${date_start}
154     # TODO: Consider extracting the block which depends on ${heal_timeout} value into two keywords, and have just one If to decide which one to call.
155     BuiltIn.Run_Keyword_If    ${heal_timeout}==${HEAL_WITHIN_TRANS_TIMEOUT} and ${delta} > ${TRANSACTION_TIMEOUT}    BuiltIn.Fail    We are not able to heal the cluster within transaction timout because new leader election took more time.
156     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
157     BuiltIn.Should_Be_Equal    ${resp}    ${NONE}    No response expected, received ${resp}
158     BuiltIn.Sleep    ${heal_timeout}
159     KarafKeywords.Log_Message_To_Controller_Karaf    Rejoining node ${leader}
160     ClusterManagement.Rejoin_Member_From_List_Or_All    ${leader}
161     ${li_isolated}    BuiltIn.Set_Variable    ${False}
162     BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
163     BuiltIn.Wait_Until_Keyword_Succeeds    15s    2s    ClusterManagement.Get_Leader_And_Followers_For_Shard    ${shard_name}    ${shard_type}    verify_restconf=False
164     ${time_to_finish} =    Get_Seconds_To_Time    ${date_end}
165     BuiltIn.Run_Keyword_If    ${heal_timeout} < ${TRANSACTION_TIMEOUT}    Leader_Isolation_Heal_Within_Tt
166     ...    ELSE    Module_Leader_Isolation_Heal_Default    ${leader}    ${time_to_finish}
167     [Teardown]    BuiltIn.Run_Keyword_If    ${li_isolated}    BuiltIn.Run_Keywords    ClusterManagement.Rejoin_Member_From_List_Or_All    ${leader}
168     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
169
170 Leader_Isolation_PrefBasedShard_Test_Templ
171     [Arguments]    ${heal_timeout}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
172     [Documentation]    Implements leader isolation test scenario.
173     ${li_isolated}    BuiltIn.Set_Variable    ${False}
174     ${producing_transactions_time} =    BuiltIn.Set_Variable    ${${heal_timeout}+60}
175     ${all_indices} =    ClusterManagement.List_All_Indices
176     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index_list=${all_indices}    verify_restconf=False
177     ${all_ip_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${all_indices}
178     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${all_ip_list}    ${all_indices}    ${ID_PREFIX}    ${producing_transactions_time}    ${TRANSACTION_RATE_1K}
179     BuiltIn.Sleep    5s
180     ${date_start} =    DateTime.Get_Current_Date
181     ${date_end} =    DateTime.Add_Time_To_Date    ${date_start}    ${producing_transactions_time}
182     KarafKeywords.Log_Message_To_Controller_Karaf    Isolating node ${leader}
183     ClusterManagement.Isolate_Member_From_List_Or_All    ${leader}
184     ${li_isolated}    BuiltIn.Set_Variable    ${True}
185     BuiltIn.Wait_Until_Keyword_Succeeds    45s    2s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}!!    ${shard_type}    ${True}
186     ...    ${leader}    member_index_list=${follower_list}
187     ${date_leader_elected} =    DateTime.Get_Current_Date
188     ${delta} =    DateTime.Subtract_Date_From_Date    ${date_leader_elected}    ${date_start}
189     # TODO: Consider extracting the block which depends on ${heal_timeout} value into two keywords, and have just one If to decide which one to call.
190     BuiltIn.Run_Keyword_If    ${heal_timeout}==${HEAL_WITHIN_TRANS_TIMEOUT} and ${delta} > ${TRANSACTION_TIMEOUT}    BuiltIn.Fail    We are not able to heal the cluster within transaction timout because new leader election took more time.
191     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
192     BuiltIn.Should_Be_Equal    ${resp}    ${NONE}    No response expected, received ${resp}
193     BuiltIn.Sleep    ${heal_timeout}
194     KarafKeywords.Log_Message_To_Controller_Karaf    Rejoining node ${leader}
195     ClusterManagement.Rejoin_Member_From_List_Or_All    ${leader}
196     ${li_isolated}    BuiltIn.Set_Variable    ${False}
197     BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
198     BuiltIn.Wait_Until_Keyword_Succeeds    15s    2s    ClusterManagement.Get_Leader_And_Followers_For_Shard    ${shard_name}!!    ${shard_type}    verify_restconf=False
199     ${time_to_finish} =    Get_Seconds_To_Time    ${date_end}
200     BuiltIn.Run_Keyword_If    ${heal_timeout} < ${TRANSACTION_TIMEOUT}    Leader_Isolation_Heal_Within_Tt
201     ...    ELSE    Prefix_Leader_Isolation_Heal_Default    ${leader}    ${time_to_finish}
202     [Teardown]    BuiltIn.Run_Keyword_If    ${li_isolated}    BuiltIn.Run_Keywords    ClusterManagement.Rejoin_Member_From_List_Or_All    ${leader}
203     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
204
205 Leader_Isolation_Heal_Within_Tt
206     [Documentation]    The leader isolation test case end if the heal happens within transaction timeout. All write transaction
207     ...    producers shoudl finish without error.
208     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
209     : FOR    ${resp}    IN    @{resp_list}
210     \    TemplatedRequests.Check_Status_Code    ${resp}
211
212 Module_Leader_Isolation_Heal_Default
213     [Arguments]    ${isolated_node}    ${time_to_finish}
214     [Documentation]    The leader isolation test case end. The transaction producer on isolated node should fail and should be restarted.
215     ...    Then all write transaction producers should finish without error.
216     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
217     BuiltIn.Log    ${resp}
218     # TODO: check on response status code
219     ${restart_producer_node_idx_as_list}    BuiltIn.Create_List    ${isolated_node}
220     ${restart_producer_node_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${isolated_node}
221     ${restart_producer_node_ip_as_list}    BuiltIn.Create_List    ${restart_producer_node_ip}
222     MdsalLowlevelPy.Start_Write_Transactions_On_Nodes    ${restart_producer_node_ip_as_list}    ${restart_producer_node_idx_as_list}    ${ID_PREFIX}    ${time_to_finish}    ${TRANSACTION_RATE_1K}    chained_flag=${CHAINED_TX}
223     ...    reset_globals=${False}
224     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
225     : FOR    ${resp}    IN    @{resp_list}
226     \    TemplatedRequests.Check_Status_Code    ${resp}
227
228 Prefix_Leader_Isolation_Heal_Default
229     [Arguments]    ${isolated_node}    ${time_to_finish}
230     [Documentation]    The leader isolation test case end. The transaction producer on isolated node shoudl fail and should be restarted.
231     Then all write transaction producers shoudl finish without error.
232     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
233     BuiltIn.Log    ${resp}
234     # TODO: check on response status code
235     ${restart_producer_node_idx_as_list}    BuiltIn.Create_List    ${isolated_node}
236     ${restart_producer_node_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${isolated_node}
237     ${restart_producer_node_ip_as_list}    BuiltIn.Create_List    ${restart_producer_node_ip}
238     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${restart_producer_node_ip_as_list}    ${restart_producer_node_idx_as_list}    ${ID_PREFIX}    ${time_to_finish}    ${TRANSACTION_RATE_1K}    reset_globals=${False}
239     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
240     : FOR    ${resp}    IN    @{resp_list}
241     \    TemplatedRequests.Check_Status_Code    ${resp}
242
243 Client_Isolation_Test_Templ
244     [Arguments]    ${listener_node_role}    ${trans_chain_flag}    ${shard_name}=${SHARD_NAME}    ${shard_type}=${SHARD_TYPE}
245     [Documentation]    Implements client isolation test scenario.
246     ${all_indices} =    ClusterManagement.List_All_Indices
247     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    member_index_list=${all_indices}    verify_restconf=False
248     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
249     ${client_node_dst} =    BuiltIn.Set_Variable_If    "${listener_node_role}" == "leader"    ${leader}    ${follower1}
250     ${client_node_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${client_node_dst}
251     ${client_node_ip_as_list}    BuiltIn.Create_List    ${client_node_ip}
252     ${client_node_idx_as_list}    BuiltIn.Create_List    ${client_node_dst}
253     MdsalLowlevelPy.Start_Write_Transactions_On_Nodes    ${client_node_ip_as_list}    ${client_node_idx_as_list}    ${ID_PREFIX}    ${DURATION_90S}    ${TRANSACTION_RATE_1K}    chained_flag=${trans_chain_flag}
254     BuiltIn.Sleep    5s
255     ${start_date}    DateTime.Get_Current_Date
256     ${timeout_date} =    DateTime.Add_Time_To_Date    ${start_date}    ${TRANSACTION_TIMEOUT}
257     ${abort_date} =    DateTime.Add_Time_To_Date    ${start_date}    ${HARD_TIMEOUT}
258     KarafKeywords.Log_Message_To_Controller_Karaf    Isolating node ${client_node_dst}
259     ClusterManagement.Isolate_Member_From_List_Or_All    ${client_node_dst}
260     ${trans_timeout} =    Get_Seconds_To_Time    ${timeout_date}
261     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${trans_timeout}    1s    Ongoing_Transactions_Not_Failed_Yet
262     ${hard_timeout} =    Get_Seconds_To_Time    ${abort_date}
263     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${hard_timeout}    1s    Ongoing_Transactions_Not_Failed_Yet
264     BuiltIn.Wait_Until_Keyword_Succeeds    20s    2s    Ongoing_Transactions_Failed
265     [Teardown]    BuiltIn.Run Keywords    KarafKeywords.Log_Message_To_Controller_Karaf    Rejoining node ${client_node_dst}
266     ...    AND    ClusterManagement.Rejoin_Member_From_List_Or_All    ${client_node_dst}
267     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
268     ...    AND    MdsalLowlevelPy.Wait_For_Transactions
269
270 Client_Isolation_PrefBasedShard_Test_Templ
271     [Arguments]    ${listener_node_role}    ${isolated_transactions_flag}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
272     [Documentation]    Implements client isolation test scenario.
273     ${all_indices} =    ClusterManagement.List_All_Indices
274     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index_list=${all_indices}    verify_restconf=False
275     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
276     ${client_node_dst} =    BuiltIn.Set_Variable_If    "${listener_node_role}" == "leader"    ${leader}    ${follower1}
277     ${client_node_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${client_node_dst}
278     ${client_node_ip_as_list}    BuiltIn.Create_List    ${client_node_ip}
279     ${client_node_idx_as_list}    BuiltIn.Create_List    ${client_node_dst}
280     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${client_node_ip_as_list}    ${client_node_idx_as_list}    ${ID_PREFIX}    ${DURATION_90S}    ${TRANSACTION_RATE_1K}    isolated_transactions_flag=${isolated_transactions_flag}
281     BuiltIn.Sleep    5s
282     ${start_date}    DateTime.Get_Current_Date
283     ${timeout_date} =    DateTime.Add_Time_To_Date    ${start_date}    ${TRANSACTION_TIMEOUT}
284     ${abort_date} =    DateTime.Add_Time_To_Date    ${start_date}    ${HARD_TIMEOUT}
285     KarafKeywords.Log_Message_To_Controller_Karaf    Isolating node ${client_node_dst}
286     ClusterManagement.Isolate_Member_From_List_Or_All    ${client_node_dst}
287     ${trans_timeout} =    Get_Seconds_To_Time    ${timeout_date}
288     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${trans_timeout}    1s    Ongoing_Transactions_Not_Failed_Yet
289     ${hard_timeout} =    Get_Seconds_To_Time    ${abort_date}
290     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${hard_timeout}    1s    Ongoing_Transactions_Not_Failed_Yet
291     BuiltIn.Wait_Until_Keyword_Succeeds    20s    2s    Ongoing_Transactions_Failed
292     [Teardown]    BuiltIn.Run Keywords    KarafKeywords.Log_Message_To_Controller_Karaf    Rejoining node ${client_node_dst}
293     ...    AND    ClusterManagement.Rejoin_Member_From_List_Or_All    ${client_node_dst}
294     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
295     ...    AND    MdsalLowlevelPy.Wait_For_Transactions
296
297 Ongoing_Transactions_Not_Failed_Yet
298     [Documentation]    Verify that no write-transaction rpc finished, means they are still running.
299     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
300     BuiltIn.Should_Be_Equal    ${None}    ${resp}    ${resp} not expected.
301
302 Ongoing_Transactions_Failed
303     [Documentation]    Verify if write-transaction failed.
304     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
305     Check_Status_Code    ${resp}    explicit_status_codes=${TRANSACTION_FAILED}
306
307 Get_Seconds_To_Time
308     [Arguments]    ${date_in_future}
309     [Documentation]    Return number of seconds remaining to ${date_in_future}.
310     ${date_now} =    DateTime.Get_Current_Date
311     ${duration} =    DateTime.Subtract_Date_From_Date    ${date_in_future}    ${date_now}
312     BuiltIn.Run_Keyword_And_Return    BuiltIn.Convert_To_Integer    ${duration}
313
314 Remote_Listener_Test_Templ
315     [Arguments]    ${listener_node_role}    ${shard_name}=${SHARD_NAME}    ${shard_type}=${SHARD_TYPE}
316     [Documentation]    Implements remote listener test scenario.
317     ${subscribed} =    BuiltIn.Set_Variable    ${False}
318     ${all_indices} =    ClusterManagement.List_All_Indices
319     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    member_index_list=${all_indices}    verify_restconf=False
320     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
321     ${follower2} =    Collections.Get_From_List    ${follower_list}    ${1}
322     ${listener_node_dst} =    BuiltIn.Set_Variable_If    "${listener_node_role}" == "leader"    ${leader}    ${follower1}
323     MdsalLowlevel.Subscribe_Dtcl    ${listener_node_dst}
324     ${subscribed} =    BuiltIn.Set_Variable    ${True}
325     ${all_ip_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${all_indices}
326     MdsalLowlevelPy.Start_Write_Transactions_On_Nodes    ${all_ip_list}    ${all_indices}    ${ID_PREFIX}    ${DURATION_10S}    ${TRANSACTION_RATE_1K}    chained_flag=${CHAINED_TX}
327     BuiltIn.Sleep    5s
328     ClusterAdmin.Make_Leader_Local    ${follower1}    ${shard_name}    ${shard_type}
329     BuiltIn.Wait_Until_Keyword_Succeeds    45s    2s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}    ${shard_type}    ${True}
330     ...    ${leader}
331     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
332     : FOR    ${resp}    IN    @{resp_list}
333     \    TemplatedRequests.Check_Status_Code    ${resp}
334     ${copy_matches} =    MdsalLowlevel.Unsubscribe_Dtcl    ${listener_node_dst}
335     ${subscribed} =    BuiltIn.Set_Variable    ${False}
336     BuiltIn.Should_Be_True    ${copy_matches}
337     [Teardown]    BuiltIn.Run_Keyword_If    ${subscribed}    MdsalLowlevel.Unsubscribe_Dtcl    ${listener_node_dst}
338
339 Remote_Listener_PrefBasedShard_Test_Templ
340     [Arguments]    ${listener_node_role}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
341     [Documentation]    Implements listener isolation test scenario.
342     ${subscribed} =    BuiltIn.Set_Variable    ${False}
343     ${all_indices} =    ClusterManagement.List_All_Indices
344     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index_list=${all_indices}    verify_restconf=False
345     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
346     ${follower2} =    Collections.Get_From_List    ${follower_list}    ${1}
347     ${listener_node_dst} =    BuiltIn.Set_Variable_If    "${listener_node_role}" == "leader"    ${leader}    ${follower1}
348     MdsalLowlevel.Subscribe_Ddtl    ${listener_node_dst}
349     ${subscribed} =    BuiltIn.Set_Variable    ${True}
350     ${all_ip_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${all_indices}
351     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${all_ip_list}    ${all_indices}    ${ID_PREFIX}    ${DURATION_10S}    ${TRANSACTION_RATE_1K}
352     BuiltIn.Sleep    5s
353     MdsalLowlevel.Become_Prefix_Leader    ${follower1}    ${shard_name}    ${ID_PREFIX}
354     BuiltIn.Wait_Until_Keyword_Succeeds    45s    2s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}!!    ${shard_type}    ${True}
355     ...    ${leader}
356     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
357     : FOR    ${resp}    IN    @{resp_list}
358     \    TemplatedRequests.Check_Status_Code    ${resp}
359     ${copy_matches} =    MdsalLowlevel.Unsubscribe_Ddtl    ${listener_node_dst}
360     ${subscribed} =    BuiltIn.Set_Variable    ${False}
361     BuiltIn.Should_Be_True    ${copy_matches}
362     [Teardown]    BuiltIn.Run_Keyword_If    ${subscribed}    MdsalLowlevel.Unsubscribe_Ddtl    ${listener_node_dst}
363
364 Create_Prefix_Based_Shard_And_Verify
365     [Arguments]    ${prefix}=${PREF_BASED_SHARD}
366     [Documentation]    Create prefix based shard with replicas on all nodes
367     ${all_indices} =    ClusterManagement.List_All_Indices
368     ${node_to_trigger} =    Collections.Get_From_List    ${all_indices}    ${0}
369     MdsalLowlevel.Create_Prefix_Shard    ${node_to_trigger}    ${prefix}    ${all_indices}
370     BuiltIn.Wait_Until_Keyword_Succeeds    30s    3s    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${prefix}!!    shard_type=${SHARD_TYPE}    member_index_list=${all_indices}
371     ...    verify_restconf=False
372
373 Remove_Prefix_Based_Shard_And_Verify
374     [Arguments]    ${prefix}=${PREF_BASED_SHARD}
375     [Documentation]    Remove prefix based shard with all replicas
376     ${all_indices} =    ClusterManagement.List_All_Indices
377     ${node_to_trigger} =    Collections.Get_From_List    ${all_indices}    ${0}
378     MdsalLowlevel.Remove_Prefix_Shard    ${node_to_trigger}    ${prefix}
379     : FOR    ${idx}    IN    @{all_indices}
380     \    BuiltIn.Wait_Until_Keyword_Succeeds    15s    2s    Verify_Shard_Replica_Removed    ${idx}    ${prefix}!!
381     \    ...    ${SHARD_TYPE}
382
383 Verify_Shard_Replica_Removed
384     [Arguments]    ${member_index}    ${shard_name}    ${shard_type}
385     [Documentation]    Verify that shard is removed. Jolokia return 404 for shard memeber.
386     ${session} =    Resolve_Http_Session_For_Member    member_index=${member_index}
387     ${type_class} =    Resolve_Shard_Type_Class    shard_type=${shard_type}
388     ${uri} =    BuiltIn.Set_Variable    /jolokia/read/org.opendaylight.controller:Category=Shards,name=member-${member_index}-shard-${shard_name}-${shard_type},type=${type_class}
389     ${text}    TemplatedRequests.Get_From_Uri    uri=${uri}    session=${session}
390     BuiltIn.Should_Contain    ${text}    "status":404    javax.management.InstanceNotFoundException
391
392 Restart_Test_Templ
393     [Documentation]    Kill every odl node and start again.
394     ClusterManagement.Kill_Members_From_List_Or_All
395     ClusterManagement.Clean_Directories_On_List_Or_All    tmp_dir=/tmp
396     ClusterManagement.Start_Members_From_List_Or_All
397     BuiltIn.Wait_Until_Keyword_Succeeds    300s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}    verify_restconf=True
398     ClusterManagement.Run_Bash_Command_On_List_Or_All    ps -ef | grep java