85b514fd481df0cfe454fa6e27195d544ea15bab
[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}    ${2*${TRANSACTION_TIMEOUT}}
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     ClusterAdmin.Make_Leader_Local    ${idx_to}    ${shard_name}    ${shard_type}
52     ${new_leader}    ${new_followers} =    BuiltIn.Wait_Until_Keyword_Succeeds    30s    5s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}
53     ...    ${shard_type}    ${True}    ${idx_from}    verify_restconf=False
54     BuiltIn.Should_Be_Equal    ${idx_to}    ${new_leader}
55     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
56     TemplatedRequests.Check_Status_Code    @{resp_list}[0]
57
58 Explicit_Leader_Movement_PrefBasedShard_Test_Templ
59     [Arguments]    ${leader_from}    ${leader_to}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
60     [Documentation]    Implements explicit leader movement test scenario.
61     ${idx_from}    ${idx_to}    ${idx_trans} =    Get_Node_Indexes_For_The_ELM_Test    ${leader_from}    ${leader_to}    ${shard_name}!!
62     ...    ${shard_type}
63     ${ip_trans_as_list} =    BuiltIn.Create_List    ${ODL_SYSTEM_${idx_trans}_IP}
64     ${idx_trans_as_list} =    BuiltIn.Create_List    ${idx_trans}
65     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${ip_trans_as_list}    ${idx_trans_as_list}    ${ID_PREFIX}    ${DURATION_30S}    ${TRANSACTION_RATE_1K}
66     MdsalLowlevel.Become_Prefix_Leader    ${idx_to}    ${shard_name}    ${ID_PREFIX}
67     ${new_leader}    ${new_followers} =    BuiltIn.Wait_Until_Keyword_Succeeds    30s    5s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}!!
68     ...    ${shard_type}    ${True}    ${idx_from}    verify_restconf=False
69     BuiltIn.Should_Be_Equal    ${idx_to}    ${new_leader}
70     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
71     TemplatedRequests.Check_Status_Code    @{resp_list}[0]
72
73 Get_Node_Indexes_For_The_ELM_Test
74     [Arguments]    ${leader_from}    ${leader_to}    ${shard_name}    ${shard_type}
75     [Documentation]    Return indexes for explicit leader movement test case, indexes of present to next leader node and index where transaction
76     ...    producer should be deployed.
77     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    verify_restconf=False
78     ${idx_from} =    BuiltIn.Set_Variable    ${leader}
79     ${idx_to} =    BuiltIn.Set_Variable    @{follower_list}[0]
80     ${idx_trans} =    BuiltIn.Set_Variable_If    "${leader_from}" == "remote" and "${leader_to}" == "remote"    @{follower_list}[1]    "${leader_from}" == "local"    ${leader}    "${leader_to}" == "local"
81     ...    @{follower_list}[0]
82     BuiltIn.Return_From_Keyword    ${idx_from}    ${idx_to}    ${idx_trans}
83
84 Clean_Leader_Shutdown_Test_Templ
85     [Arguments]    ${leader_location}    ${shard_name}=${SHARD_NAME}    ${shard_type}=${SHARD_TYPE}
86     [Documentation]    Implements clean leader shutdown test scenario.
87     ${removed} =    BuiltIn.Set_Variable    ${False}
88     ${producer_idx}    ${actual_leader}    ${follower_list} =    Get_Node_Indexes_For_Clean_Leader_Shutdown_Test    ${leader_location}    ${shard_name}    ${shard_type}
89     ${producer_ip_as_list} =    BuiltIn.Create_List    ${ODL_SYSTEM_${producer_idx}_IP}
90     ${producer_idx_as_list} =    BuiltIn.Create_List    ${producer_idx}
91     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}
92     ClusterAdmin.Remove_Shard_Replica    ${actual_leader}    ${shard_name}    member-${actual_leader}    ${shard_type}
93     ${removed} =    BuiltIn.Set_Variable    ${True}
94     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
95     TemplatedRequests.Check_Status_Code    @{resp_list}[0]
96     [Teardown]    BuiltIn.Run_Keywords    BuiltIn.Run_Keyword_And_Ignore_Error    BuiltIn.Wait_Until_Keyword_Succeeds    30s    3s    ClusterManagement.Get_Leader_And_Followers_For_Shard
97     ...    shard_name=${shard_name}    shard_type=${shard_type}    member_index_list=${follower_list}    verify_restconf=False
98     ...    AND    ClusterAdmin.Add_Shard_Replica    ${actual_leader}    ${shard_name}    ${shard_type}
99     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    30s    3s    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}
100     ...    verify_restconf=False    shard_type=${shard_type}
101
102 Clean_Leader_Shutdown_PrefBasedShard_Test_Templ
103     [Arguments]    ${leader_location}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
104     [Documentation]    Implements clean leader shutdown test scenario.
105     ${producer_idx}    ${actual_leader}    ${follower_list} =    Get_Node_Indexes_For_Clean_Leader_Shutdown_Test    ${leader_location}    ${shard_name}!!    ${shard_type}
106     ${producer_ip_as_list} =    BuiltIn.Create_List    ${ODL_SYSTEM_${producer_idx}_IP}
107     ${producer_idx_as_list} =    BuiltIn.Create_List    ${producer_idx}
108     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${producer_ip_as_list}    ${producer_idx_as_list}    ${ID_PREFIX}    ${DURATION_30S}    ${TRANSACTION_RATE_1K}
109     ClusterAdmin.Remove_Prefix_Shard_Replica    ${actual_leader}    ${shard_name}    member-${actual_leader}    ${shard_type}
110     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}
111     ...    verify_restconf=False
112     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}
113     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}
114     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
115     TemplatedRequests.Check_Status_Code    @{resp_list}[0]
116     [Teardown]    BuiltIn.Run_Keywords    BuiltIn.Run_Keyword_And_Ignore_Error    BuiltIn.Wait_Until_Keyword_Succeeds    30s    3s    ClusterManagement.Get_Leader_And_Followers_For_Shard
117     ...    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index_list=${follower_list}    verify_restconf=False
118     ...    AND    ClusterAdmin.Add_Prefix_Shard_Replica    ${actual_leader}    ${shard_name}    ${shard_type}
119     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    30s    3s    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}!!
120     ...    verify_restconf=False    shard_type=${shard_type}
121
122 Get_Node_Indexes_For_Clean_Leader_Shutdown_Test
123     [Arguments]    ${leader_location}    ${shard_name}    ${shard_type}
124     [Documentation]    Return indexes for clean leader shudown test case, index where transaction producer shoudl be deployed and a shard leader index.
125     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    verify_restconf=False
126     ${follower_list_leangth} =    BuiltIn.Evaluate    ${NUM_ODL_SYSTEM}-1
127     BuiltIn.Length_Should_Be    ${follower_list}    ${follower_list_leangth}
128     ${producer_idx} =    BuiltIn.Set_Variable_If    "${leader_location}" == "local"    ${leader}    @{follower_list}[0]
129     BuiltIn.Return_From_Keyword    ${producer_idx}    ${leader}    ${follower_list}
130
131 Leader_Isolation_Test_Templ
132     [Arguments]    ${heal_timeout}    ${shard_name}=${SHARD_NAME}    ${shard_type}=${SHARD_TYPE}
133     [Documentation]    Implements leader isolation test scenario.
134     ${li_isolated}    BuiltIn.Set_Variable    ${False}
135     ${producing_transactions_time} =    BuiltIn.Set_Variable    ${${heal_timeout}+60}
136     ${all_indices} =    ClusterManagement.List_All_Indices
137     ${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
138     ${all_ip_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${all_indices}
139     MdsalLowlevelPy.Start_Write_Transactions_On_Nodes    ${all_ip_list}    ${all_indices}    ${ID_PREFIX}    ${producing_transactions_time}    ${TRANSACTION_RATE_1K}    chained_flag=${CHAINED_TX}
140     ${date_start} =    DateTime.Get_Current_Date
141     ${date_end} =    DateTime.Add_Time_To_Date    ${date_start}    ${producing_transactions_time}
142     KarafKeywords.Log_Message_To_Controller_Karaf    Isolating node ${leader}
143     ClusterManagement.Isolate_Member_From_List_Or_All    ${leader}
144     ${li_isolated}    BuiltIn.Set_Variable    ${True}
145     BuiltIn.Wait_Until_Keyword_Succeeds    45s    2s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}    ${shard_type}    ${True}
146     ...    ${leader}    member_index_list=${follower_list}
147     ${date_leader_elected} =    DateTime.Get_Current_Date
148     ${delta} =    DateTime.Subtract_Date_From_Date    ${date_leader_elected}    ${date_start}
149     # 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.
150     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.
151     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
152     BuiltIn.Should_Be_Equal    ${resp}    ${NONE}    No response expected, received ${resp}
153     BuiltIn.Sleep    ${heal_timeout}
154     KarafKeywords.Log_Message_To_Controller_Karaf    Rejoining node ${leader}
155     ClusterManagement.Rejoin_Member_From_List_Or_All    ${leader}
156     ${li_isolated}    BuiltIn.Set_Variable    ${False}
157     BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
158     BuiltIn.Wait_Until_Keyword_Succeeds    15s    2s    ClusterManagement.Get_Leader_And_Followers_For_Shard    ${shard_name}    ${shard_type}    verify_restconf=False
159     ${time_to_finish} =    Get_Seconds_To_Time    ${date_end}
160     BuiltIn.Run_Keyword_If    ${heal_timeout} < ${TRANSACTION_TIMEOUT}    Leader_Isolation_Heal_Within_Tt
161     ...    ELSE    Module_Leader_Isolation_Heal_Default    ${leader}    ${time_to_finish}
162     [Teardown]    BuiltIn.Run_Keyword_If    ${li_isolated}    BuiltIn.Run_Keywords    ClusterManagement.Rejoin_Member_From_List_Or_All    ${leader}
163     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
164
165 Leader_Isolation_PrefBasedShard_Test_Templ
166     [Arguments]    ${heal_timeout}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
167     [Documentation]    Implements leader isolation test scenario.
168     ${li_isolated}    BuiltIn.Set_Variable    ${False}
169     ${producing_transactions_time} =    BuiltIn.Set_Variable    ${${heal_timeout}+60}
170     ${all_indices} =    ClusterManagement.List_All_Indices
171     ${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
172     ${all_ip_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${all_indices}
173     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${all_ip_list}    ${all_indices}    ${ID_PREFIX}    ${producing_transactions_time}    ${TRANSACTION_RATE_1K}
174     ${date_start} =    DateTime.Get_Current_Date
175     ${date_end} =    DateTime.Add_Time_To_Date    ${date_start}    ${producing_transactions_time}
176     KarafKeywords.Log_Message_To_Controller_Karaf    Isolating node ${leader}
177     ClusterManagement.Isolate_Member_From_List_Or_All    ${leader}
178     ${li_isolated}    BuiltIn.Set_Variable    ${True}
179     BuiltIn.Wait_Until_Keyword_Succeeds    45s    2s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}!!    ${shard_type}    ${True}
180     ...    ${leader}    member_index_list=${follower_list}
181     ${date_leader_elected} =    DateTime.Get_Current_Date
182     ${delta} =    DateTime.Subtract_Date_From_Date    ${date_leader_elected}    ${date_start}
183     # 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.
184     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.
185     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
186     BuiltIn.Should_Be_Equal    ${resp}    ${NONE}    No response expected, received ${resp}
187     BuiltIn.Sleep    ${heal_timeout}
188     KarafKeywords.Log_Message_To_Controller_Karaf    Rejoining node ${leader}
189     ClusterManagement.Rejoin_Member_From_List_Or_All    ${leader}
190     ${li_isolated}    BuiltIn.Set_Variable    ${False}
191     BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
192     BuiltIn.Wait_Until_Keyword_Succeeds    15s    2s    ClusterManagement.Get_Leader_And_Followers_For_Shard    ${shard_name}!!    ${shard_type}    verify_restconf=False
193     ${time_to_finish} =    Get_Seconds_To_Time    ${date_end}
194     BuiltIn.Run_Keyword_If    ${heal_timeout} < ${TRANSACTION_TIMEOUT}    Leader_Isolation_Heal_Within_Tt
195     ...    ELSE    Prefix_Leader_Isolation_Heal_Default    ${leader}    ${time_to_finish}
196     [Teardown]    BuiltIn.Run_Keyword_If    ${li_isolated}    BuiltIn.Run_Keywords    ClusterManagement.Rejoin_Member_From_List_Or_All    ${leader}
197     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
198
199 Leader_Isolation_Heal_Within_Tt
200     [Documentation]    The leader isolation test case end if the heal happens within transaction timeout. All write transaction
201     ...    producers shoudl finish without error.
202     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
203     : FOR    ${resp}    IN    @{resp_list}
204     \    TemplatedRequests.Check_Status_Code    ${resp}
205
206 Module_Leader_Isolation_Heal_Default
207     [Arguments]    ${isolated_node}    ${time_to_finish}
208     [Documentation]    The leader isolation test case end. The transaction producer on isolated node should fail and should be restarted.
209     ...    Then all write transaction producers should finish without error.
210     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
211     BuiltIn.Log    ${resp}
212     # TODO: check on response status code
213     ${restart_producer_node_idx_as_list}    BuiltIn.Create_List    ${isolated_node}
214     ${restart_producer_node_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${isolated_node}
215     ${restart_producer_node_ip_as_list}    BuiltIn.Create_List    ${restart_producer_node_ip}
216     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}
217     ...    reset_globals=${False}
218     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
219     : FOR    ${resp}    IN    @{resp_list}
220     \    TemplatedRequests.Check_Status_Code    ${resp}
221
222 Prefix_Leader_Isolation_Heal_Default
223     [Arguments]    ${isolated_node}    ${time_to_finish}
224     [Documentation]    The leader isolation test case end. The transaction producer on isolated node shoudl fail and should be restarted.
225     Then all write transaction producers shoudl finish without error.
226     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
227     BuiltIn.Log    ${resp}
228     # TODO: check on response status code
229     ${restart_producer_node_idx_as_list}    BuiltIn.Create_List    ${isolated_node}
230     ${restart_producer_node_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${isolated_node}
231     ${restart_producer_node_ip_as_list}    BuiltIn.Create_List    ${restart_producer_node_ip}
232     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}
233     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
234     : FOR    ${resp}    IN    @{resp_list}
235     \    TemplatedRequests.Check_Status_Code    ${resp}
236
237 Client_Isolation_Test_Templ
238     [Arguments]    ${listener_node_role}    ${trans_chain_flag}    ${shard_name}=${SHARD_NAME}    ${shard_type}=${SHARD_TYPE}
239     [Documentation]    Implements client isolation test scenario.
240     ${all_indices} =    ClusterManagement.List_All_Indices
241     ${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
242     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
243     ${client_node_dst} =    BuiltIn.Set_Variable_If    "${listener_node_role}" == "leader"    ${leader}    ${follower1}
244     ${client_node_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${client_node_dst}
245     ${client_node_ip_as_list}    BuiltIn.Create_List    ${client_node_ip}
246     ${client_node_idx_as_list}    BuiltIn.Create_List    ${client_node_dst}
247     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}
248     ${start_date}    DateTime.Get_Current_Date
249     ${timeout_date} =    DateTime.Add_Time_To_Date    ${start_date}    ${TRANSACTION_TIMEOUT}
250     ${abort_date} =    DateTime.Add_Time_To_Date    ${start_date}    ${HARD_TIMEOUT}
251     KarafKeywords.Log_Message_To_Controller_Karaf    Isolating node ${client_node_dst}
252     ClusterManagement.Isolate_Member_From_List_Or_All    ${client_node_dst}
253     ${trans_timeout} =    Get_Seconds_To_Time    ${timeout_date}
254     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${trans_timeout}    1s    Ongoing_Transactions_Not_Failed_Yet
255     ${hard_timeout} =    Get_Seconds_To_Time    ${abort_date}
256     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${hard_timeout}    1s    Ongoing_Transactions_Not_Failed_Yet
257     BuiltIn.Wait_Until_Keyword_Succeeds    20s    2s    Ongoing_Transactions_Failed
258     [Teardown]    BuiltIn.Run Keywords    KarafKeywords.Log_Message_To_Controller_Karaf    Rejoining node ${client_node_dst}
259     ...    AND    ClusterManagement.Rejoin_Member_From_List_Or_All    ${client_node_dst}
260     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
261     ...    AND    MdsalLowlevelPy.Wait_For_Transactions
262
263 Client_Isolation_PrefBasedShard_Test_Templ
264     [Arguments]    ${listener_node_role}    ${isolated_transactions_flag}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
265     [Documentation]    Implements client isolation test scenario.
266     ${all_indices} =    ClusterManagement.List_All_Indices
267     ${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
268     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
269     ${client_node_dst} =    BuiltIn.Set_Variable_If    "${listener_node_role}" == "leader"    ${leader}    ${follower1}
270     ${client_node_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${client_node_dst}
271     ${client_node_ip_as_list}    BuiltIn.Create_List    ${client_node_ip}
272     ${client_node_idx_as_list}    BuiltIn.Create_List    ${client_node_dst}
273     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}
274     ${start_date}    DateTime.Get_Current_Date
275     ${timeout_date} =    DateTime.Add_Time_To_Date    ${start_date}    ${TRANSACTION_TIMEOUT}
276     ${abort_date} =    DateTime.Add_Time_To_Date    ${start_date}    ${HARD_TIMEOUT}
277     KarafKeywords.Log_Message_To_Controller_Karaf    Isolating node ${client_node_dst}
278     ClusterManagement.Isolate_Member_From_List_Or_All    ${client_node_dst}
279     ${trans_timeout} =    Get_Seconds_To_Time    ${timeout_date}
280     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${trans_timeout}    1s    Ongoing_Transactions_Not_Failed_Yet
281     ${hard_timeout} =    Get_Seconds_To_Time    ${abort_date}
282     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${hard_timeout}    1s    Ongoing_Transactions_Not_Failed_Yet
283     BuiltIn.Wait_Until_Keyword_Succeeds    20s    2s    Ongoing_Transactions_Failed
284     [Teardown]    BuiltIn.Run Keywords    KarafKeywords.Log_Message_To_Controller_Karaf    Rejoining node ${client_node_dst}
285     ...    AND    ClusterManagement.Rejoin_Member_From_List_Or_All    ${client_node_dst}
286     ...    AND    BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
287     ...    AND    MdsalLowlevelPy.Wait_For_Transactions
288
289 Ongoing_Transactions_Not_Failed_Yet
290     [Documentation]    Verify that no write-transaction rpc finished, means they are still running.
291     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
292     BuiltIn.Should_Be_Equal    ${None}    ${resp}    ${resp} not expected.
293
294 Ongoing_Transactions_Failed
295     [Documentation]    Verify if write-transaction failed.
296     ${resp} =    MdsalLowlevelPy.Get_Next_Transactions_Response
297     Check_Status_Code    ${resp}    explicit_status_codes=${TRANSACTION_FAILED}
298
299 Get_Seconds_To_Time
300     [Arguments]    ${date_in_future}
301     [Documentation]    Return number of seconds remaining to ${date_in_future}.
302     ${date_now} =    DateTime.Get_Current_Date
303     ${duration} =    DateTime.Subtract_Date_From_Date    ${date_in_future}    ${date_now}
304     BuiltIn.Run_Keyword_And_Return    BuiltIn.Convert_To_Integer    ${duration}
305
306 Remote_Listener_Test_Templ
307     [Arguments]    ${listener_node_role}    ${shard_name}=${SHARD_NAME}    ${shard_type}=${SHARD_TYPE}
308     [Documentation]    Implements remote listener test scenario.
309     ${subscribed} =    BuiltIn.Set_Variable    ${False}
310     ${all_indices} =    ClusterManagement.List_All_Indices
311     ${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
312     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
313     ${follower2} =    Collections.Get_From_List    ${follower_list}    ${1}
314     ${listener_node_dst} =    BuiltIn.Set_Variable_If    "${listener_node_role}" == "leader"    ${leader}    ${follower1}
315     MdsalLowlevel.Subscribe_Dtcl    ${listener_node_dst}
316     ${subscribed} =    BuiltIn.Set_Variable    ${True}
317     ${all_ip_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${all_indices}
318     MdsalLowlevelPy.Start_Write_Transactions_On_Nodes    ${all_ip_list}    ${all_indices}    ${ID_PREFIX}    ${DURATION_10S}    ${TRANSACTION_RATE_1K}    chained_flag=${CHAINED_TX}
319     ClusterAdmin.Make_Leader_Local    ${follower1}    ${shard_name}    ${shard_type}
320     BuiltIn.Wait_Until_Keyword_Succeeds    45s    2s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}    ${shard_type}    ${True}
321     ...    ${leader}
322     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
323     : FOR    ${resp}    IN    @{resp_list}
324     \    TemplatedRequests.Check_Status_Code    ${resp}
325     ${copy_matches} =    MdsalLowlevel.Unsubscribe_Dtcl    ${listener_node_dst}
326     ${subscribed} =    BuiltIn.Set_Variable    ${False}
327     BuiltIn.Should_Be_True    ${copy_matches}
328     [Teardown]    BuiltIn.Run_Keyword_If    ${subscribed}    MdsalLowlevel.Unsubscribe_Dtcl    ${listener_node_dst}
329
330 Remote_Listener_PrefBasedShard_Test_Templ
331     [Arguments]    ${listener_node_role}    ${shard_name}=${PREF_BASED_SHARD}    ${shard_type}=${SHARD_TYPE}
332     [Documentation]    Implements listener isolation test scenario.
333     ${subscribed} =    BuiltIn.Set_Variable    ${False}
334     ${all_indices} =    ClusterManagement.List_All_Indices
335     ${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
336     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
337     ${follower2} =    Collections.Get_From_List    ${follower_list}    ${1}
338     ${listener_node_dst} =    BuiltIn.Set_Variable_If    "${listener_node_role}" == "leader"    ${leader}    ${follower1}
339     MdsalLowlevel.Subscribe_Ddtl    ${listener_node_dst}
340     ${subscribed} =    BuiltIn.Set_Variable    ${True}
341     ${all_ip_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${all_indices}
342     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${all_ip_list}    ${all_indices}    ${ID_PREFIX}    ${DURATION_10S}    ${TRANSACTION_RATE_1K}
343     MdsalLowlevel.Become_Prefix_Leader    ${follower1}    ${shard_name}    ${ID_PREFIX}
344     BuiltIn.Wait_Until_Keyword_Succeeds    45s    2s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}!!    ${shard_type}    ${True}
345     ...    ${leader}
346     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
347     : FOR    ${resp}    IN    @{resp_list}
348     \    TemplatedRequests.Check_Status_Code    ${resp}
349     ${copy_matches} =    MdsalLowlevel.Unsubscribe_Ddtl    ${listener_node_dst}
350     ${subscribed} =    BuiltIn.Set_Variable    ${False}
351     BuiltIn.Should_Be_True    ${copy_matches}
352     [Teardown]    BuiltIn.Run_Keyword_If    ${subscribed}    MdsalLowlevel.Unsubscribe_Ddtl    ${listener_node_dst}
353
354 Create_Prefix_Based_Shard_And_Verify
355     [Arguments]    ${prefix}=${PREF_BASED_SHARD}
356     [Documentation]    Create prefix based shard with replicas on all nodes
357     ${all_indices} =    ClusterManagement.List_All_Indices
358     ${node_to_trigger} =    Collections.Get_From_List    ${all_indices}    ${0}
359     MdsalLowlevel.Create_Prefix_Shard    ${node_to_trigger}    ${prefix}    ${all_indices}
360     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}
361     ...    verify_restconf=False
362
363 Remove_Prefix_Based_Shard_And_Verify
364     [Arguments]    ${prefix}=${PREF_BASED_SHARD}
365     [Documentation]    Remove prefix based shard with all replicas
366     ${all_indices} =    ClusterManagement.List_All_Indices
367     ${node_to_trigger} =    Collections.Get_From_List    ${all_indices}    ${0}
368     MdsalLowlevel.Remove_Prefix_Shard    ${node_to_trigger}    ${prefix}
369     : FOR    ${idx}    IN    @{all_indices}
370     \    BuiltIn.Wait_Until_Keyword_Succeeds    15s    2s    Verify_Shard_Replica_Removed    ${idx}    ${prefix}!!
371     \    ...    ${SHARD_TYPE}
372
373 Verify_Shard_Replica_Removed
374     [Arguments]    ${member_index}    ${shard_name}    ${shard_type}
375     [Documentation]    Verify that shard is removed. Jolokia return 404 for shard memeber.
376     ${session} =    Resolve_Http_Session_For_Member    member_index=${member_index}
377     ${type_class} =    Resolve_Shard_Type_Class    shard_type=${shard_type}
378     ${uri} =    BuiltIn.Set_Variable    /jolokia/read/org.opendaylight.controller:Category=Shards,name=member-${member_index}-shard-${shard_name}-${shard_type},type=${type_class}
379     ${text}    TemplatedRequests.Get_From_Uri    uri=${uri}    session=${session}
380     BuiltIn.Should_Contain    ${text}    "status":404    javax.management.InstanceNotFoundException
381
382 Restart_Test_Templ
383     [Documentation]    Kill every odl node and start again.
384     ClusterManagement.Kill_Members_From_List_Or_All
385     ClusterManagement.Clean_Directories_On_List_Or_All    tmp_dir=/tmp
386     ClusterManagement.Start_Members_From_List_Or_All
387     BuiltIn.Wait_Until_Keyword_Succeeds    300s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}    verify_restconf=True
388     ClusterManagement.Run_Bash_Command_On_List_Or_All    ps -ef | grep java