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