Increase waiting in case of leader election
[integration/test.git] / csit / suites / controller / dom_data_broker / ddb-sanity-prefix-based.robot
1 *** Settings ***
2 Documentation     DOMDataBroker testing: Module based shards sanity suite
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 goal is to call several basic rpc form ClusterAdmin.robot and
11 ...               MdsalLowlevel.robot to ensute that those rpcs can be safely used in
12 ...               other suites.
13 ...               It also verify the ability of the odl-controller-test-app to perform
14 ...               several activities.
15 Suite Setup       BuiltIn.Run_Keywords    SetupUtils.Setup_Utils_For_Setup_And_Teardown    http_timeout=30
16 ...               AND    DdbCommons.Create_Prefix_Based_Shard_And_Verify
17 Suite Teardown    BuiltIn.Run_Keywords    DdbCommons.Remove_Prefix_Based_Shard_And_Verify
18 ...               AND    SSHLibrary.Close_All_Connections
19 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
20 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
21 Default Tags      critical
22 Library           SSHLibrary
23 Library           ${CURDIR}/../../../libraries/MdsalLowlevelPy.py
24 Resource          ${CURDIR}/../../../libraries/ClusterAdmin.robot
25 Resource          ${CURDIR}/../../../libraries/ClusterManagement.robot
26 Resource          ${CURDIR}/../../../libraries/controller/DdbCommons.robot
27 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
28
29 *** Variables ***
30 ${PREF_BASED_SHARD}    id-ints
31 ${SHARD_TYPE}     config
32 ${TRANSACTION_RATE_1K}    ${1000}
33 ${DURATION}       ${30}
34 ${SIMPLE_TX}      ${False}
35 ${CHAINED_TX}     ${True}
36 ${ID_PREFIX}      prefix-
37
38 *** Test Cases ***
39 Get_Prefix_Shard_Role
40     [Documentation]    Get prefix shard role.
41     ${all_indices} =    ClusterManagement.List_All_Indices
42     : FOR    ${index}    IN    @{all_indices}
43     \    ${role} =    ClusterAdmin.Get_Prefix_Shard_Role    ${index}    ${PREF_BASED_SHARD}    ${SHARD_TYPE}
44
45 Subscribe_Listener_To_Leader
46     [Documentation]    Subscribe listener to leader.
47     ${all_indices} =    ClusterManagement.List_All_Indices
48     ${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
49     MdsalLowlevel.Subscribe_Ddtl    ${leader}
50     BuiltIn.Sleep    5s
51     ${copy_matches} =    MdsalLowlevel.Unsubscribe_Ddtl    ${leader}
52     BuiltIn.Should_Be_True    ${copy_matches}
53
54 Subscribe_Listener_To_Follower
55     [Documentation]    Subscribe listener to follower.
56     ${all_indices} =    ClusterManagement.List_All_Indices
57     ${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
58     ${follower_idx} =    Collections.Get_From_List    ${follower_list}    ${0}
59     MdsalLowlevel.Subscribe_Ddtl    ${follower_idx}
60     BuiltIn.Sleep    5s
61     ${copy_matches} =    MdsalLowlevel.Unsubscribe_Ddtl    ${follower_idx}
62     BuiltIn.Should_Be_True    ${copy_matches}
63
64 Become_Prefix_Leader
65     [Documentation]    Make the loeader local and verify.
66     ${shard_name} =    BuiltIn.Set_Variable    ${PREF_BASED_SHARD}
67     ${shard_type} =    BuiltIn.Set_Variable    ${SHARD_TYPE}
68     ${all_indices} =    ClusterManagement.List_All_Indices
69     ${old_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
70     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
71     MdsalLowlevel.Become_Prefix_Leader    ${follower1}    ${shard_name}
72     ${leader}    ${follower_list} =    BuiltIn.Wait_Until_Keyword_Succeeds    60s    5s    ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}!!
73     ...    ${shard_type}    ${True}    ${old_leader}    member_index_list=${EMPTY}
74     BuiltIn.Should_Be_Equal_As_Numbers    ${follower1}    ${leader}
75
76 Remove_Leader_Prefix_Shard_Replica_And_Add_It_Back
77     [Documentation]    Remove and add shard replica adn verify it.
78     ${shard_name} =    BuiltIn.Set_Variable    ${PREF_BASED_SHARD}
79     ${shard_type} =    BuiltIn.Set_Variable    ${SHARD_TYPE}
80     ${all_indices} =    ClusterManagement.List_All_Indices
81     ${old_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
82     ClusterAdmin.Remove_Prefix_Shard_Replica    ${old_leader}    ${shard_name}    member-${old_leader}    ${shard_type}
83     BuiltIn.Wait_Until_Keyword_Succeeds    60s    5s    Verify_Shard_Replica_Removed    ${old_leader}    ${shard_name}!!    ${shard_type}
84     ${actual_leader}    ${actual_follower_list} =    BuiltIn.Wait_Until_Keyword_Succeeds    60s    5s    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}!!
85     ...    verify_restconf=False    shard_type=${shard_type}    member_index_list=${follower_list}
86     BuiltIn.Should_Not_Be_Equal_As_Numbers    ${old_leader}    ${actual_leader}
87     BuiltIn.Wait_Until_Keyword_Succeeds    60s    5s    ClusterAdmin.Add_Prefix_Shard_Replica    ${old_leader}    ${shard_name}    ${shard_type}
88     BuiltIn.Wait_Until_Keyword_Succeeds    60s    5s    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index_list=${all_indices}
89     ...    verify_restconf=False
90
91 Remove_Follower_Prefix_Shard_Replica_And_Add_It_Back
92     [Documentation]    Remove and add shard replica adn verify it.
93     ${shard_name} =    BuiltIn.Set_Variable    ${PREF_BASED_SHARD}
94     ${shard_type} =    BuiltIn.Set_Variable    ${SHARD_TYPE}
95     ${all_indices} =    ClusterManagement.List_All_Indices
96     ${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
97     ${follower1} =    Collections.Get_From_List    ${follower_list}    ${0}
98     ClusterAdmin.Remove_Prefix_Shard_Replica    ${follower1}    ${shard_name}    member-${follower1}    ${shard_type}
99     BuiltIn.Wait_Until_Keyword_Succeeds    60s    5s    DdbCommons.Verify_Shard_Replica_Removed    ${follower1}    ${shard_name}!!    ${shard_type}
100     ${new_indices_list} =    ClusterManagement.List_Indices_Minus_Member    ${follower1}
101     ClusterManagement.Verify_Shard_Leader_Elected    ${shard_name}!!    ${shard_type}    ${False}    ${leader}    member_index_list=${new_indices_list}
102     BuiltIn.Wait_Until_Keyword_Succeeds    60s    5s    ClusterAdmin.Add_Prefix_Shard_Replica    ${follower1}    ${shard_name}    ${shard_type}
103     BuiltIn.Wait_Until_Keyword_Succeeds    60s    5s    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}!!    shard_type=${shard_type}    member_index_list=${all_indices}
104     ...    verify_restconf=False
105
106 Produce_Transactions_One_Node_Leader
107     [Documentation]    Produce transactions.
108     ${all_indices} =    ClusterManagement.List_All_Indices
109     ${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
110     ${leader_idx_as_list} =    BuiltIn.Create_List    ${leader}
111     ${leader_ip_as_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${leader_idx_as_list}
112     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${leader_ip_as_list}    ${leader_idx_as_list}    ${ID_PREFIX}    ${DURATION}    ${TRANSACTION_RATE_1K}
113     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
114     : FOR    ${resp}    IN    @{resp_list}
115     \    TemplatedRequests.Check_Status_Code    ${resp}
116
117 Produce_Transactions_One_Node_Follower
118     [Documentation]    Produce transactions.
119     ${all_indices} =    ClusterManagement.List_All_Indices
120     ${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
121     ${follower_idx} =    Collections.Get_From_List    ${follower_list}    ${0}
122     ${follower_idx_as_list} =    BuiltIn.Create_List    ${follower_idx}
123     ${follower_ip_as_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${follower_idx_as_list}
124     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${follower_ip_as_list}    ${follower_idx_as_list}    ${ID_PREFIX}    ${DURATION}    ${TRANSACTION_RATE_1K}
125     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
126     : FOR    ${resp}    IN    @{resp_list}
127     \    TemplatedRequests.Check_Status_Code    ${resp}
128
129 Produce_Transactions
130     [Documentation]    Produce transactions.
131     ${all_indices} =    ClusterManagement.List_All_Indices
132     ${all_ip_list} =    ClusterManagement.Resolve_IP_Address_For_Members    ${all_indices}
133     MdsalLowlevelPy.Start_Produce_Transactions_On_Nodes    ${all_ip_list}    ${all_indices}    ${ID_PREFIX}    ${DURATION}    ${TRANSACTION_RATE_1K}
134     ${resp_list} =    MdsalLowlevelPy.Wait_For_Transactions
135     : FOR    ${resp}    IN    @{resp_list}
136     \    TemplatedRequests.Check_Status_Code    ${resp}