Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / libraries / controller / DrbCommons.robot
1 *** Settings ***
2 Documentation     DOMRpcBroker 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 ...               The aim of this resource is to groups reusable blocks of commands into
11 ...               keywords. It should be initiated by DrbCommons_Init. It creates
12 ...               ${all_indices}, ${registered_indices}, ${nonregistered_indices} and
13 ...               ${possible_constants} suite variables.
14 ...               ${registered_indices} - list of indexes where rpc is registered; including
15 ...               isolated mebers; exluding killed/stopped members
16 ...               ${nonregistered_indices} - list of indexes where rpc is not registrated;
17 ...               including isolated mebers; exluding killed/stopped
18 ...               members
19 ...               ${possible_constants} - list of valid constants responded from the cluster;
20 ...               constant from isolated node with regirered rpc is
21 ...               invalid
22 ...               ${active_indices} - list of indexes of non-isolated, non-stopped/killed nodes
23 ...
24 ...               Akka can create spurious UnreachableMember events, see
25 ...               https://bugs.opendaylight.org/show_bug.cgi?id=8430
26 ...               so some keywords contain "tolerance" argument which applies BuiltIn.Wait_Until_Keyword_Succeeds.
27 ...
28 ...               The delay before subsequent ReachableMember is significantly higher than
29 ...               RPC registration delay documented at
30 ...               http://docs.opendaylight.org/en/latest/developer-guide/controller.html#rpcs-and-cluster
31 Library           Collections
32 Resource          ${CURDIR}/../ClusterManagement.robot
33 Resource          ${CURDIR}/../MdsalLowlevel.robot
34 Resource          ${CURDIR}/../ShardStability.robot
35
36 *** Variables ***
37 ${CONSTANT_PREFIX}    constant-
38 ${CONTEXT}        context
39 ${BUG_8430_TOLERANCE}    10
40
41 *** Keywords ***
42 DrbCommons_Init
43     [Documentation]    Resouce initial keyword. Creates several suite variables which are
44     ...    used in other keywords and should be used im the test suites.
45     ${all_indices} =    ClusterManagement.List_All_Indices
46     BuiltIn.Set_Suite_Variable    ${all_indices}
47     ${nonregistered_indices} =    ClusterManagement.List_All_Indices
48     BuiltIn.Set_Suite_Variable    ${nonregistered_indices}
49     ${active_indices} =    ClusterManagement.List_All_Indices
50     BuiltIn.Set_Suite_Variable    ${active_indices}
51     ${possible_constants} =    BuiltIn.Create_List
52     BuiltIn.Set_Suite_Variable    ${possible_constants}
53     ${registered_indices} =    BuiltIn.Create_List
54     BuiltIn.Set_Suite_Variable    ${registered_indices}
55
56 Register_Rpc_And_Update_Possible_Constants
57     [Arguments]    ${member_index}
58     [Documentation]    Register global rpc on given node of the cluster.
59     MdsalLowlevel.Register_Constant    ${member_index}    ${CONSTANT_PREFIX}${member_index}
60     DrbCommons__Add_Possible_Constant    ${member_index}
61     DrbCommons__Register_Index    ${member_index}
62
63 Unregister_Rpc_And_Update_Possible_Constants
64     [Arguments]    ${member_index}
65     [Documentation]    Unregister global rpc on given node of the cluster.
66     MdsalLowlevel.Unregister_Constant    ${member_index}
67     DrbCommons__Rem_Possible_Constant    ${member_index}
68     DrbCommons__Deregister_Index    ${member_index}
69
70 Register_Action_And_Update_Possible_Constants
71     [Arguments]    ${member_index}
72     [Documentation]    Register routed rpc on given node of the cluster.
73     MdsalLowlevel.Register_Bound_Constant    ${member_index}    ${CONTEXT}    ${CONSTANT_PREFIX}${member_index}
74     DrbCommons__Add_Possible_Constant    ${member_index}
75     DrbCommons__Register_Index    ${member_index}
76
77 Unregister_Action_And_Update_Possible_Constants
78     [Arguments]    ${member_index}
79     [Documentation]    Unregister routed rpc on given node of the cluster.
80     MdsalLowlevel.Unregister_Bound_Constant    ${member_index}    ${CONTEXT}
81     DrbCommons__Rem_Possible_Constant    ${member_index}
82     DrbCommons__Deregister_Index    ${member_index}
83
84 Register_Rpc_On_Nodes
85     [Arguments]    ${index_list}
86     [Documentation]    Register global rpc on given nodes of the cluster.
87     FOR    ${index}    IN    @{index_list}
88         Register_Rpc_And_Update_Possible_Constants    ${index}
89     END
90
91 Unregister_Rpc_On_Nodes
92     [Arguments]    ${index_list}
93     [Documentation]    Unregister global rpc on given nodes of the cluster.
94     FOR    ${index}    IN    @{index_list}
95         Unregister_Rpc_And_Update_Possible_Constants    ${index}
96     END
97
98 Register_Action_On_Nodes
99     [Arguments]    ${index_list}
100     [Documentation]    Register global rpc on given nodes of the cluster.
101     FOR    ${index}    IN    @{index_list}
102         Register_Action_And_Update_Possible_Constants    ${index}
103     END
104
105 Unregister_Action_On_Nodes
106     [Arguments]    ${index_list}
107     [Documentation]    Unregister global rpc on given nodes of the cluster.
108     FOR    ${index}    IN    @{index_list}
109         Unregister_Action_And_Update_Possible_Constants    ${index}
110     END
111
112 Verify_Constant_On_Registered_Node
113     [Arguments]    ${member_index}
114     [Documentation]    Verify that the rpc response comes from the local node.
115     ${constant} =    MdsalLowlevel.Get_Constant    ${member_index}
116     BuiltIn.Should_Be_Equal_As_Strings    ${CONSTANT_PREFIX}${member_index}    ${constant}
117     BuiltIn.Return_From_Keyword    ${constant}
118
119 Verify_Constant_On_Unregistered_Node
120     [Arguments]    ${member_index}
121     [Documentation]    Verify that the response comes from other nodes with rpc registered. Verification
122     ...    passes for registered nodes too.
123     ${constant} =    MdsalLowlevel.Get_Constant    ${member_index}
124     Collections.List_Should_Contain_Value    ${possible_constants}    ${constant}
125     BuiltIn.Return_From_Keyword    ${constant}
126
127 Verify_Contexted_Constant_On_Registered_Node
128     [Arguments]    ${member_index}
129     [Documentation]    Verify that the rpc response comes from the local node.
130     ${constant} =    MdsalLowlevel.Get_Contexted_Constant    ${member_index}    ${CONTEXT}
131     BuiltIn.Should_Be_Equal_As_Strings    ${CONSTANT_PREFIX}${member_index}    ${constant}
132     BuiltIn.Return_From_Keyword    ${constant}
133
134 Verify_Contexted_Constant_On_Unregistered_Node
135     [Arguments]    ${member_index}
136     [Documentation]    Verify that the response comes from other nodes with rpc registered. Verification
137     ...    passes for registered nodes too.
138     ${constant} =    MdsalLowlevel.Get_Contexted_Constant    ${member_index}    ${CONTEXT}
139     Collections.List_Should_Contain_Value    ${possible_constants}    ${constant}
140     BuiltIn.Return_From_Keyword    ${constant}
141
142 Verify_Constant_On_Registered_Nodes
143     [Arguments]    ${index_list}
144     [Documentation]    Verify that the rpc response comes from the local node for every node in the list.
145     FOR    ${index}    IN    @{index_list}
146         Verify_Constant_On_Registered_Node    ${index}
147     END
148
149 Verify_Contexted_Constant_On_Registered_Nodes
150     [Arguments]    ${index_list}
151     [Documentation]    Verify that the rpc response comes from the local node for every node in the list.
152     FOR    ${index}    IN    @{index_list}
153         Verify_Contexted_Constant_On_Registered_Node    ${index}
154     END
155
156 Verify_Constant_On_Unregistered_Nodes
157     [Arguments]    ${index_list}
158     [Documentation]    Verify that the rpc response comes from the remote node for every node in the list.
159     FOR    ${index}    IN    @{index_list}
160         Verify_Constant_On_Unregistered_Node    ${index}
161     END
162
163 Verify_Constant_On_Active_Nodes
164     [Arguments]    ${tolerance}=${BUG_8430_TOLERANCE}
165     [Documentation]    Verify that the rpc response comes from the local node for every node in the list.
166     ...    As a workaround for Bug 8430, \${tolerance} can be set as duration (number of seconds) for WUKS.
167     # TODO: Rename most Verify_* keywords to Check_* and use the Verify prefix for the WUKS versions.
168     BuiltIn.Run_Keyword_And_Return_If    ${tolerance}    BuiltIn.Wait_Until_Keyword_Succeeds    ${tolerance}    1s    Verify_Constant_On_Active_Nodes    tolerance=0
169     FOR    ${index}    IN    @{active_indices}
170         BuiltIn.Run_Keyword_If    ${index} in ${registered_indices}    Verify_Constant_On_Registered_Node    ${index}
171         ...    ELSE    Verify_Constant_On_Unregistered_Node    ${index}
172     END
173
174 Verify_Contexted_Constant_On_Active_Nodes
175     [Arguments]    ${tolerance}=${BUG_8430_TOLERANCE}
176     [Documentation]    Verify that the rpc response comes from the local node for every node in the list.
177     ...    As a workaround for Bug 8430, \${tolerance} can be set as duration (number of seconds) for WUKS.
178     # TODO: Rename most Verify_* keywords to Check_* and use the Verify prefix for the WUKS versions.
179     BuiltIn.Run_Keyword_And_Return_If    ${tolerance}    BuiltIn.Wait_Until_Keyword_Succeeds    ${tolerance}    1s    Verify_Contexted_Constant_On_Active_Nodes    tolerance=0
180     FOR    ${index}    IN    @{active_indices}
181         BuiltIn.Run_Keyword_If    ${index} in ${registered_indices}    Verify_Contexted_Constant_On_Registered_Node    ${index}
182         ...    ELSE    Verify_Contexted_Constant_On_Unregistered_Node    ${index}
183     END
184
185 Verify_Expected_Constant_On_Nodes
186     [Arguments]    ${index_list}    ${exp_constant}
187     [Documentation]    Verify that the rpc response comes only from one node only for every node in the list.
188     FOR    ${index}    IN    @{index_list}
189         ${const_index} =    Get_Constant_Index_From_Node    ${index}
190         BuiltIn.Should_Be_Equal_As_Strings    ${exp_constant}    ${CONSTANT_PREFIX}${const_index}
191     END
192
193 Get_Constant_Index_From_Node
194     [Arguments]    ${member_index}
195     [Documentation]    Ivoke get-constant rpc on given member index. Returns the index of
196     ...    the node where the constant came from.
197     ${constant} =    MdsalLowlevel.Get_Constant    ${member_index}
198     ${index} =    String.Replace_String    ${constant}    ${CONSTANT_PREFIX}    ${EMPTY}
199     ${index} =    BuiltIn.Convert_To_Integer    ${index}
200     BuiltIn.Return_From_Keyword    ${index}
201
202 Get_Contexted_Constant_Index_From_Node
203     [Arguments]    ${member_index}
204     [Documentation]    Ivoke get-contexted-constant rpc on given member index. Returns the index of
205     ...    the node where the constant came from.
206     ${constant} =    MdsalLowlevel.Get_Contexted_Constant    ${member_index}    ${CONTEXT}
207     ${index} =    String.Replace_String    ${constant}    ${CONSTANT_PREFIX}    ${EMPTY}
208     ${index} =    BuiltIn.Convert_To_Integer    ${index}
209     BuiltIn.Return_From_Keyword    ${index}
210
211 Isolate_Node
212     [Arguments]    ${member_index}
213     [Documentation]    Isolate a member and update appropriate suite variables.
214     ClusterManagement.Isolate_Member_From_List_Or_All    ${member_index}
215     DrbCommons__Update_Active_Nodes_List    deactivate_idx=${member_index}
216     BuiltIn.Return_From_Keyword_If    ${member_index} not in ${registered_indices}
217     DrbCommons__Rem_Possible_Constant    ${member_index}
218
219 Rejoin_Node
220     [Arguments]    ${member_index}
221     [Documentation]    Rejoin a member and update appropriate suite variables.
222     ClusterManagement.Rejoin_Member_From_List_Or_All    ${member_index}
223     BuiltIn.Wait_Until_Keyword_Succeeds    70s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
224     DrbCommons__Update_Active_Nodes_List    activate_idx=${member_index}
225     BuiltIn.Return_From_Keyword_If    ${member_index} not in ${registered_indices}
226     DrbCommons__Add_Possible_Constant    ${member_index}
227
228 DrbCommons__Update_Active_Nodes_List
229     [Arguments]    ${activate_idx}=${EMPTY}    ${deactivate_idx}=${EMPTY}
230     [Documentation]    Add or remove member index to/from the list of active nodes.
231     BuiltIn.Run_Keyword_If    "${activate_idx}" != "${EMPTY}"    Collections.Append_To_List    ${active_indices}    ${activate_idx}
232     BuiltIn.Run_Keyword_If    "${deactivate_idx}" != "${EMPTY}"    Collections.Remove_Values_From_List    ${active_indices}    ${deactivate_idx}
233     Collections.Sort_List    ${active_indices}
234
235 DrbCommons__Register_Index
236     [Arguments]    ${member_index}
237     [Documentation]    Add member index to the list of indices with registered rpc.
238     ...    Isolated nodes are included in the list.
239     Collections.Append_To_List    ${registered_indices}    ${member_index}
240     Collections.Remove_Values_From_List    ${nonregistered_indices}    ${member_index}
241     Collections.Sort_List    ${registered_indices}
242     Collections.Sort_List    ${nonregistered_indices}
243
244 DrbCommons__Deregister_Index
245     [Arguments]    ${member_index}
246     [Documentation]    Remove member index from the list of indices with registered rpc.
247     ...    Isolated nodes are included in the list.
248     Collections.Remove_Values_From_List    ${registered_indices}    ${member_index}
249     Collections.Append_To_List    ${nonregistered_indices}    ${member_index}
250     Collections.Sort_List    ${registered_indices}
251     Collections.Sort_List    ${nonregistered_indices}
252
253 DrbCommons__Add_Possible_Constant
254     [Arguments]    ${member_index}
255     [Documentation]    Add a constant to the ${possible_constants} list. The list is about to maintain
256     ...    all valid constants possibly responded from the odl cluster (excluding isolated nodes).
257     Collections.Append_To_List    ${possible_constants}    ${CONSTANT_PREFIX}${member_index}
258     Collections.Sort_List    ${possible_constants}
259
260 DrbCommons__Rem_Possible_Constant
261     [Arguments]    ${member_index}
262     [Documentation]    Remove a constant from the ${possible_constants} list. The list is about to maintain
263     ...    all valid constants possibly responded from the odl cluster (excluding isolated nodes).
264     Collections.Remove_Values_From_List    ${possible_constants}    ${CONSTANT_PREFIX}${member_index}