8121de019cce291856003a35117f3ce093364844
[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 Library           Collections
24 Resource          ${CURDIR}/../ClusterManagement.robot
25 Resource          ${CURDIR}/../MdsalLowlevel.robot
26 Resource          ${CURDIR}/../ShardStability.robot
27
28 *** Variables ***
29 ${CONSTANT_PREFIX}    constant-
30
31 *** Keywords ***
32 DrbCommons_Init
33     [Documentation]    Resouce initial keyword. Creates several suite variables which are
34     ...    used in other keywords and should be used im the test suites.
35     ${all_indices} =    ClusterManagement.List_All_Indices
36     BuiltIn.Set_Suite_Variable    ${all_indices}
37     ${nonregistered_indices} =    ClusterManagement.List_All_Indices
38     BuiltIn.Set_Suite_Variable    ${nonregistered_indices}
39     ${active_indices} =    ClusterManagement.List_All_Indices
40     BuiltIn.Set_Suite_Variable    ${active_indices}
41     ${possible_constants} =    BuiltIn.Create_List
42     BuiltIn.Set_Suite_Variable    ${possible_constants}
43     ${registered_indices} =    BuiltIn.Create_List
44     BuiltIn.Set_Suite_Variable    ${registered_indices}
45
46 Register_Rpc_And_Update_Possible_Constants
47     [Arguments]    ${member_index}
48     [Documentation]    Register global rpc on given node of the cluster.
49     MdsalLowlevel.Register_Constant    ${member_index}    ${CONSTANT_PREFIX}${member_index}
50     DrbCommons__Add_Possible_Constant    ${member_index}
51     DrbCommons__Register_Index    ${member_index}
52
53 Unregister_Rpc_And_Update_Possible_Constants
54     [Arguments]    ${member_index}
55     [Documentation]    Unregister global rpc on given node of the cluster.
56     MdsalLowlevel.Unregister_Constant    ${member_index}
57     DrbCommons__Rem_Possible_Constant    ${member_index}
58     DrbCommons__Deregister_Index    ${member_index}
59
60 Register_Rpc_On_Nodes
61     [Arguments]    ${index_list}
62     [Documentation]    Register global rpc on given nodes of the cluster.
63     : FOR    ${index}    IN    @{index_list}
64     \    Register_Rpc_And_Update_Possible_Constants    ${index}
65
66 Unregister_Rpc_On_Nodes
67     [Arguments]    ${index_list}
68     [Documentation]    Unregister global rpc on given nodes of the cluster.
69     : FOR    ${index}    IN    @{index_list}
70     \    Unregister_Rpc_And_Update_Possible_Constants    ${index}
71
72 Verify_Constant_On_Registered_Node
73     [Arguments]    ${member_index}
74     [Documentation]    Verify that the rpc response comes from the local node.
75     ${constant} =    MdsalLowlevel.Get_Constant    ${member_index}
76     BuiltIn.Should_Be_Equal_As_Strings    ${CONSTANT_PREFIX}${member_index}    ${constant}
77     BuiltIn.Return_From_Keyword    ${constant}
78
79 Verify_Constant_On_Unregistered_Node
80     [Arguments]    ${member_index}
81     [Documentation]    Verify that the response comes from other nodes with rpc registered. Verification
82     ...    passes for registered nodes too.
83     ${constant} =    MdsalLowlevel.Get_Constant    ${member_index}
84     Collections.List_Should_Contain_Value    ${possible_constants}    ${constant}
85     BuiltIn.Return_From_Keyword    ${constant}
86
87 Verify_Constant_On_Registered_Nodes
88     [Arguments]    ${index_list}
89     [Documentation]    Verify that the rpc response comes from the local node for every node in the list.
90     : FOR    ${index}    IN    @{index_list}
91     \    Verify_Constant_On_Registered_Node    ${index}
92
93 Verify_Constant_On_Unregistered_Nodes
94     [Arguments]    ${index_list}
95     [Documentation]    Verify that the rpc response comes from the remote node for every node in the list.
96     : FOR    ${index}    IN    @{index_list}
97     \    Verify_Constant_On_Unregistered_Node    ${index}
98
99 Verify_Constant_On_Active_Nodes
100     [Documentation]    Verify that the rpc response comes from the local node for every node in the list.
101     : FOR    ${index}    IN    @{active_indices}
102     \    BuiltIn.Run_Keyword_If    ${index} in ${registered_indices}    Verify_Constant_On_Registered_Node    ${index}
103     \    ...    ELSE    Verify_Constant_On_Unregistered_Node    ${index}
104
105 Verify_Expected_Constant_On_Nodes
106     [Arguments]    ${index_list}    ${exp_constant}
107     [Documentation]    Verify that the rpc response comes only from one node only for every node in the list.
108     : FOR    ${index}    IN    @{index_list}
109     \    ${const_index} =    Get_Constant_Index_From_Node    ${index}
110     \    BuiltIn.Should_Be_Equal_As_Strings    ${exp_constant}    ${CONSTANT_PREFIX}${const_index}
111
112 Get_Constant_Index_From_Node
113     [Arguments]    ${member_index}
114     [Documentation]    Ivoke get-constant rpc on given member index. Returns the index of
115     ...    the node where the constant came from.
116     ${constant} =    MdsalLowlevel.Get_Constant    ${member_index}
117     ${index} =    String.Replace_String    ${constant}    ${CONSTANT_PREFIX}    ${EMPTY}
118     ${index} =    BuiltIn.Convert_To_Integer    ${index}
119     BuiltIn.Return_From_Keyword    ${index}
120
121 Isolate_Node
122     [Arguments]    ${member_index}
123     [Documentation]    Isolate a member and update appropriate suite variables.
124     ClusterManagement.Isolate_Member_From_List_Or_All    ${member_index}
125     DrbCommons__Upadte_Active_Nodes_List    deactivate_idx=${member_index}
126     BuiltIn.Return_From_Keyword_If    ${member_index} not in ${registered_indices}
127     DrbCommons__Rem_Possible_Constant    ${member_index}
128
129 Rejoin_Node
130     [Arguments]    ${member_index}
131     [Documentation]    Rejoin a member and update appropriate suite variables.
132     ClusterManagement.Rejoin_Member_From_List_Or_All    ${member_index}
133     BuiltIn.Wait_Until_Keyword_Succeeds    60s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
134     DrbCommons__Upadte_Active_Nodes_List    activate_idx=${member_index}
135     BuiltIn.Return_From_Keyword_If    ${member_index} not in ${registered_indices}
136     DrbCommons__Add_Possible_Constant    ${member_index}
137
138 DrbCommons__Upadte_Active_Nodes_List
139     [Arguments]    ${activate_idx}=${EMPTY}    ${deactivate_idx}=${EMPTY}
140     [Documentation]    Add or remove member index to/from the list of active nodes.
141     BuiltIn.Run_Keyword_If    "${activate_idx}" != "${EMPTY}"    Collections.Append_To_List    ${active_indices}    ${activate_idx}
142     BuiltIn.Run_Keyword_If    "${deactivate_idx}" != "${EMPTY}"    Collections.Remove_Values_From_List    ${active_indices}    ${deactivate_idx}
143     Collections.Sort_List    ${active_indices}
144
145 DrbCommons__Register_Index
146     [Arguments]    ${member_index}
147     [Documentation]    Add member index to the list of indices with registered rpc.
148     ...    Isolated nodes are included in the list.
149     Collections.Append_To_List    ${registered_indices}    ${member_index}
150     Collections.Remove_Values_From_List    ${nonregistered_indices}    ${member_index}
151     Collections.Sort_List    ${registered_indices}
152     Collections.Sort_List    ${nonregistered_indices}
153
154 DrbCommons__Deregister_Index
155     [Arguments]    ${member_index}
156     [Documentation]    Remove member index from the list of indices with registered rpc.
157     ...    Isolated nodes are included in the list.
158     Collections.Remove_Values_From_List    ${registered_indices}    ${member_index}
159     Collections.Append_To_List    ${nonregistered_indices}    ${member_index}
160     Collections.Sort_List    ${registered_indices}
161     Collections.Sort_List    ${nonregistered_indices}
162
163 DrbCommons__Add_Possible_Constant
164     [Arguments]    ${member_index}
165     [Documentation]    Add a constant to the ${possible_constants} list. The list is about to maintain
166     ...    all valid constants possibly responded from the odl cluster (excluding isolated nodes).
167     Collections.Append_To_List    ${possible_constants}    ${CONSTANT_PREFIX}${member_index}
168     Collections.Sort_List    ${possible_constants}
169
170 DrbCommons__Rem_Possible_Constant
171     [Arguments]    ${member_index}
172     [Documentation]    Remove a constant from the ${possible_constants} list. The list is about to maintain
173     ...    all valid constants possibly responded from the odl cluster (excluding isolated nodes).
174     Collections.Remove_Values_From_List    ${possible_constants}    ${CONSTANT_PREFIX}${member_index}