Add suite for prefixcounting and shard monitoring
[integration/test.git] / csit / libraries / ShardStability.robot
1 *** Settings ***
2 Documentation     Robot library to monitor shard stability.
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 ...               This is a "stateful" library to monitor shard leaders and candidates. During the initial phase
11 ...               all leaders and followeres are stored and then checked with new value on verify.
12 ...               TODO: investigate whether pure stateless library would be easier or harder to use.
13 ...
14 ...               Requirements: ClusterManagement.ClusterManagement_Setup must be called before Shard_Stability_Init
15 ...
16 ...               It is possible to use it for stateless comparison.
17 Library           Collections
18 Library           String
19 Resource          ${CURDIR}/ClusterManagement.robot
20
21 *** Variables ***
22 &{stored_details}
23
24 *** Keywords ***
25 Shards_Stability_Init_Details
26     [Arguments]    ${shard_list}    ${member_index_list}=${EMPTY}
27     [Documentation]    Initialize data for given shards.
28     ...    ${shard_list} should be initialized as @{list} shard_name1:shard_type1 shard_name2:shard..
29     ${shards_details} =    Shards_Stability_Get_Details    ${shard_list}    member_index_list=${member_index_list}
30     BuiltIn.Set_Suite_Variable    ${stored_details}    ${shards_details}
31
32 Shards_Stability_Get_Details
33     [Arguments]    ${shard_list}    ${member_index_list}=${EMPTY}
34     [Documentation]    Return shard details stored in dictionary.
35     ...    ${shard_list} should be initialized as @{list} shard_name1:shard_type1 shard_name2:shard..
36     &{shards_details}    BuiltIn.Create_Dictionary
37     : FOR    ${shard_details}    IN    @{shard_list}
38     \    ${shard_name}    ${shard_type}    String.Split_String    ${shard_details}    separator=:
39     \    ${leader}    ${followers}    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    member_index_list=${member_index_list}
40     \    Collections.Sort_List    ${followers}
41     \    Collections.Set_To_Dictionary    ${shards_details}    ${shard_name}_${shard_type}_leader=${leader}
42     \    Collections.Set_To_Dictionary    ${shards_details}    ${shard_name}_${shard_type}_followers=${followers}
43     BuiltIn.Return_From_Keyword    ${shards_details}
44
45 Shards_Stability_Verify
46     [Arguments]    ${shard_list}    ${member_index_list}=${EMPTY}
47     [Documentation]    Verify that present details as the same as the stored one from Shards_Stability_Init_Details
48     ${present_details} =    Shards_Stability_Get_Details    ${shard_list}    member_index_list=${member_index_list}
49     Shards_Stability_Compare_Same    ${present_details}
50
51 Shards_Stability_Compare_Same
52     [Arguments]    ${details}    ${stateless_details}=${EMPTY}
53     [Documentation]    Compare two distionaries created by Shards_Stability_Get_Details
54     ${exp_details} =    BuiltIn.Set_Variable_If    "${stateless_details}" == "${EMPTY}"    ${stored_details}    ${stateless_details}
55     Collections.Log_Dictionary    ${exp_details}
56     Collections.Log_Dictionary    ${details}
57     Collections.Dictionaries_Should_Be_Equal    ${exp_details}    ${details}