42e9818a69ce72404742d8a4a9b12d661dcf5753
[integration/test.git] / csit / libraries / controller / CsCommon.robot
1 *** Settings ***
2 Documentation     Cluster Singleton 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 ...               Cluster Singleton service is designed to ensure that only one instance of an
11 ...               application is registered globally in the cluster.
12 ...
13 ...               Creates and uses the following suite variables:
14 ...               Created by Cluster_Singleton_Init:
15 ...               ${cs_all_indices}
16 ...               ${cs_exp_candidates}
17 ...               Created by Get_And_Save_Present_CsOwner_And_CsCandidates:
18 ...               ${cs_owner}
19 ...               ${cs_candidates}
20 ...               Created by Isolate_Owner_And_Verify_Isolated
21 ...               ${cs_isolated_index}
22 Library           Collections
23 Resource          ${CURDIR}/../ClusterManagement.robot
24 Resource          ${CURDIR}/../MdsalLowlevel.robot
25 Resource          ${CURDIR}/../ShardStability.robot
26 Resource          ${CURDIR}/../WaitForFailure.robot
27
28 *** Variables ***
29 ${CS_DEVICE_NAME}    get-singleton-constant-service']
30 ${CS_DEVICE_TYPE}    org.opendaylight.mdsal.ServiceEntityType
31 ${CS_CONSTANT_PREFIX}    constant-
32
33 *** Keywords ***
34 Cluster_Singleton_Init
35     [Documentation]    Resouce initial keyword. Creates {cs_exp_candidates} and {cs_all_indices} suite variables which are
36     ...    used in other keywords.
37     ${cs_exp_candidates} =    BuiltIn.Create_List
38     BuiltIn.Set_Suite_Variable    ${cs_exp_candidates}
39     ${cs_all_indices} =    ClusterManagement.List_All_Indices
40     BuiltIn.Set_Suite_Variable    ${cs_all_indices}
41
42 Register_Singleton_And_Update_Expected_Candidates
43     [Arguments]    ${member_index}    ${constant}
44     [Documentation]    Register the singleton candidate and add it to the list of ${cs_exp_candidates}.
45     MdsalLowlevel.Register_Singleton_Constant    ${member_index}    ${constant}
46     Collections.Append_To_List    ${cs_exp_candidates}    ${member_index}
47     Collections.Sort_List    ${cs_exp_candidates}
48
49 Unregister_Singleton_And_Update_Expected_Candidates
50     [Arguments]    ${member_index}
51     [Documentation]    Unregister the singleton candidate. Also remove it from the list of ${cs_exp_candidates}.
52     MdsalLowlevel.Unregister_Singleton_Constant    ${member_index}
53     Collections.Remove_Values_From_List    ${cs_exp_candidates}    ${member_index}
54
55 Verify_Owner_And_Candidates_Stable
56     [Arguments]    ${owner_index}
57     [Documentation]    Fail if the actual owner is different from ${owner_index} or if the actual candidate list is different from ${cs_exp_candidates}.
58     ${actual_owner}    ${actual_candidates}    ClusterManagement.Check_Old_Owner_Stays_Elected_For_Device    ${CS_DEVICE_NAME}    ${CS_DEVICE_TYPE}    ${owner_index}    ${owner_index}
59     Collections.Lists_Should_Be_Equal    ${cs_exp_candidates}    ${actual_candidates}
60
61 Monitor_Owner_And_Candidates_Stability
62     [Arguments]    ${monitoring_duration}    ${owner_index}
63     [Documentation]    Verify that the owner remains on the same node after non-owner candidate is unregistered.
64     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${monitoring_duration}    3s    Verify_Owner_And_Candidates_Stable    ${owner_index}
65
66 Register_Singleton_Constant_On_Nodes
67     [Arguments]    ${index_list}
68     [Documentation]    Register a candidate application on given nodes.
69     : FOR    ${index}    IN    @{index_list}
70     \    Register_Singleton_And_Update_Expected_Candidates    ${index}    ${CS_CONSTANT_PREFIX}${index}
71
72 Unregister_Singleton_Constant_On_Nodes
73     [Arguments]    ${index_list}
74     [Documentation]    Unregister the application from given nodes.
75     : FOR    ${index}    IN    @{index_list}
76     \    Unregister_Singleton_And_Update_Expected_Candidates    ${index}
77
78 Get_And_Save_Present_CsOwner_And_CsCandidates
79     [Arguments]    ${node_to_ask}
80     [Documentation]    Store owner index into suite variables.
81     ${cs_owner}    ${cs_candidates}    ClusterManagement.Get_Owner_And_Candidates_For_Device    ${CS_DEVICE_NAME}    ${CS_DEVICE_TYPE}    ${node_to_ask}
82     BuiltIn.Set_Suite_Variable    ${cs_owner}
83     BuiltIn.Set_Suite_Variable    ${cs_candidates}
84     BuiltIn.Return_From_Keyword    ${cs_owner}    ${cs_candidates}
85
86 Verify_Singleton_Constant_On_Node
87     [Arguments]    ${node_to_ask}    ${cs_exp_constant}
88     [Documentation]    Verify that the expected constant is return from the given node.
89     ${constant} =    MdsalLowlevel.Get_Singleton_Constant    ${node_to_ask}
90     BuiltIn.Should_Be_Equal    ${cs_exp_constant}    ${constant}
91
92 Verify_Singleton_Constant_On_Nodes
93     [Arguments]    ${index_list}    ${cs_exp_constant}
94     [Documentation]    Iterate over all cluster nodes and all should return expected constant.
95     : FOR    ${index}    IN    @{index_list}
96     \    Verify_Singleton_Constant_On_Node    ${index}    ${cs_exp_constant}
97
98 Verify_Singleton_Constant_During_Isolation
99     [Documentation]    Iterate over all non-isolated cluster nodes. They should return the correct constant.
100     : FOR    ${index}    IN    @{cs_all_indices}
101     \    BuiltIn.Run_Keyword_If    "${index}" == "${cs_isolated_index}"    BuiltIn.Log    Node not triggered, behavior not well described, see bugs 8207, 8214.
102     \    BuiltIn.Run_Keyword_Unless    "${index}" == "${cs_isolated_index}"    Verify_Singleton_Constant_On_Node    ${index}    ${CS_CONSTANT_PREFIX}${cs_owner}
103
104 Isolate_Owner_And_Verify_Isolated
105     [Documentation]    Isolate the owner cluster node. Wait until the new owner is elected and store new values of owner and candidates.
106     ClusterManagement.Isolate_Member_From_List_Or_All    ${cs_owner}
107     BuiltIn.Set_Suite_Variable    ${cs_isolated_index}    ${cs_owner}
108     ${non_isolated_list} =    ClusterManagement.List_Indices_Minus_Member    ${cs_isolated_index}    member_index_list=${cs_all_indices}
109     ${node_to_ask} =    Collections.Get_From_list    ${non_isolated_list}    0
110     BuiltIn.Wait_Until_Keyword_Succeeds    70s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}    member_index_list=${non_isolated_list}
111     BuiltIn.Wait_Until_Keyword_Succeeds    30s    2s    ClusterManagement.Check_New_Owner_Got_Elected_For_Device    ${CS_DEVICE_NAME}    ${CS_DEVICE_TYPE}    ${cs_isolated_index}
112     ...    ${node_to_ask}    http_timeout=125
113     Get_And_Save_Present_CsOwner_And_CsCandidates    ${node_to_ask}
114     BuiltIn.Wait_Until_Keyword_Succeeds    60s    3s    Verify_Singleton_Constant_During_Isolation
115
116 Rejoin_Node_And_Verify_Rejoined
117     [Documentation]    Rejoin isolated node.
118     ClusterManagement.Rejoin_Member_From_List_Or_All    ${cs_isolated_index}
119     BuiltIn.Wait_Until_Keyword_Succeeds    70s    10s    ShardStability.Shards_Stability_Get_Details    ${DEFAULT_SHARD_LIST}
120
121 Register_Flapping_Singleton_On_Nodes
122     [Arguments]    ${index_list}
123     [Documentation]    Register a candidate application on each node which starts the test.
124     : FOR    ${index}    IN    @{index_list}
125     \    MdsalLowlevel.Register_Flapping_Singleton    ${index}
126
127 Unregister_Flapping_Singleton_On_Nodes_And_Validate_Results
128     [Arguments]    ${index_list}    ${rate_limit_to_pass}    ${test_duration}
129     [Documentation]    Unregister the testing service and check recevied statistics.
130     ${movements_count} =    BuiltIn.Set_Variable    ${0}
131     : FOR    ${index}    IN    @{index_list}
132     \    ${count} =    MdsalLowlevel.Unregister_Flapping_Singleton    ${index}
133     \    BuiltIn.Run_Keyword_If    ${count} < 0    BuiltIn.Fail    No failure should have occured during the ${test_duration} timeout.
134     \    ${movements_count} =    BuiltIn.Evaluate    ${movements_count}+${count}
135     ${seconds} =    DateTime.Convert_Time    ${test_duration}
136     ${rate} =    BuiltIn.Evaluate    ${movements_count}/${seconds}
137     BuiltIn.Run_Keyword_If    ${rate} < ${rate_limit_to_pass}    BuiltIn.Fail    Acceptance rate ${rate_limit_to_pass} not reached, actual rate is ${rate}.