Upgrade RF syntax for v3.2 compatibility
[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 ...               Variable @{DEFAULT_SHARD_LIST} contains default module shards.
18 Library           Collections
19 Library           String
20 Resource          ${CURDIR}/ClusterManagement.robot
21
22 *** Variables ***
23 &{stored_details}
24 @{DEFAULT_SHARD_LIST}    default:config    default:operational    topology:config    topology:operational    inventory:config    inventory:operational    entity-ownership:operational
25
26 *** Keywords ***
27 Shards_Stability_Init_Details
28     [Arguments]    ${shard_list}    ${member_index_list}=${EMPTY}
29     [Documentation]    Initialize data for given shards.
30     ...    ${shard_list} should be initialized as @{list} shard_name1:shard_type1 shard_name2:shard..
31     ${shards_details} =    Shards_Stability_Get_Details    ${shard_list}    member_index_list=${member_index_list}
32     BuiltIn.Set_Suite_Variable    ${stored_details}    ${shards_details}
33
34 Shards_Stability_Get_Details
35     [Arguments]    ${shard_list}    ${member_index_list}=${EMPTY}    ${verify_restconf}=False    ${http_timeout}=${EMPTY}
36     [Documentation]    Return shard details stored in dictionary.
37     ...    ${shard_list} should be initialized as @{list} shard_name1:shard_type1 shard_name2:shard..
38     &{shards_details}    BuiltIn.Create_Dictionary
39     FOR    ${shard_details}    IN    @{shard_list}
40         ${shard_name}    ${shard_type}    String.Split_String    ${shard_details}    separator=:
41         ${leader}    ${followers}    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=${shard_name}    shard_type=${shard_type}    member_index_list=${member_index_list}
42         ...    verify_restconf=${verify_restconf}    http_timeout=${http_timeout}
43         Collections.Sort_List    ${followers}
44         Collections.Set_To_Dictionary    ${shards_details}    ${shard_name}_${shard_type}_leader=${leader}
45         Collections.Set_To_Dictionary    ${shards_details}    ${shard_name}_${shard_type}_followers=${followers}
46     END
47     BuiltIn.Return_From_Keyword    ${shards_details}
48
49 Shards_Stability_Verify
50     [Arguments]    ${shard_list}    ${member_index_list}=${EMPTY}
51     [Documentation]    Verify that present details as the same as the stored one from Shards_Stability_Init_Details
52     ${present_details} =    Shards_Stability_Get_Details    ${shard_list}    member_index_list=${member_index_list}
53     Shards_Stability_Compare_Same    ${present_details}
54
55 Shards_Stability_Compare_Same
56     [Arguments]    ${details}    ${stateless_details}=${EMPTY}
57     [Documentation]    Compare two distionaries created by Shards_Stability_Get_Details
58     ${exp_details} =    BuiltIn.Set_Variable_If    "${stateless_details}" == "${EMPTY}"    ${stored_details}    ${stateless_details}
59     Collections.Log_Dictionary    ${exp_details}
60     Collections.Log_Dictionary    ${details}
61     Collections.Dictionaries_Should_Be_Equal    ${exp_details}    ${details}
62
63 Set_Shard_Location
64     [Arguments]    ${requested_leader_idx}
65     [Documentation]    Move default/topology config/operational shard location to local or remote node as requested
66     ...    towards the given member.
67     ClusterAdmin.Make_Leader_Local    ${requested_leader_idx}    default    config
68     ClusterAdmin.Make_Leader_Local    ${requested_leader_idx}    default    operational
69     ClusterAdmin.Make_Leader_Local    ${requested_leader_idx}    topology    config
70     ClusterAdmin.Make_Leader_Local    ${requested_leader_idx}    topology    operational
71
72 Verify_Shard_Leader_Located_As_Expected
73     [Arguments]    ${expected_leader_idx}    ${http_timeout}=${EMPTY}
74     [Documentation]    Verify default/topology config/operational shard leader location is as expected
75     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=default    shard_type=config    verify_restconf=False    http_timeout=${http_timeout}
76     BuiltIn.Should_Be_Equal_As_Numbers    ${expected_leader_idx}    ${leader}
77     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=default    shard_type=operational    verify_restconf=False    http_timeout=${http_timeout}
78     BuiltIn.Should_Be_Equal_As_Numbers    ${expected_leader_idx}    ${leader}
79     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=topology    shard_type=config    verify_restconf=False    http_timeout=${http_timeout}
80     BuiltIn.Should_Be_Equal_As_Numbers    ${expected_leader_idx}    ${leader}
81     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard    shard_name=topology    shard_type=operational    verify_restconf=False    http_timeout=${http_timeout}
82     BuiltIn.Should_Be_Equal_As_Numbers    ${expected_leader_idx}    ${leader}