Migrate Get Requests invocations(libraries)
[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
19 Library             Collections
20 Library             String
21 Resource            ${CURDIR}/ClusterManagement.robot
22
23
24 *** Variables ***
25 &{stored_details}
26 @{DEFAULT_SHARD_LIST}
27 ...                         default:config
28 ...                         default:operational
29 ...                         topology:config
30 ...                         topology:operational
31 ...                         inventory:config
32 ...                         inventory:operational
33 ...                         entity-ownership:operational
34
35
36 *** Keywords ***
37 Shards_Stability_Init_Details
38     [Documentation]    Initialize data for given shards.
39     ...    ${shard_list} should be initialized as @{list} shard_name1:shard_type1 shard_name2:shard..
40     [Arguments]    ${shard_list}    ${member_index_list}=${EMPTY}
41     ${shards_details} =    Shards_Stability_Get_Details    ${shard_list}    member_index_list=${member_index_list}
42     BuiltIn.Set_Suite_Variable    ${stored_details}    ${shards_details}
43
44 Shards_Stability_Get_Details
45     [Documentation]    Return shard details stored in dictionary.
46     ...    ${shard_list} should be initialized as @{list} shard_name1:shard_type1 shard_name2:shard..
47     [Arguments]    ${shard_list}    ${member_index_list}=${EMPTY}    ${verify_restconf}=False    ${http_timeout}=${EMPTY}
48     &{shards_details} =    BuiltIn.Create_Dictionary
49     CompareStream.Run_Keyword_If_At_Least_Phosphorus
50     ...    Collections.Remove_Values_From_List
51     ...    ${shard_list}
52     ...    entity-ownership:operational
53     FOR    ${shard_details}    IN    @{shard_list}
54         ${shard_name}    ${shard_type} =    String.Split_String    ${shard_details}    separator=:
55         ${leader}    ${followers} =    ClusterManagement.Get_Leader_And_Followers_For_Shard
56         ...    shard_name=${shard_name}
57         ...    shard_type=${shard_type}
58         ...    member_index_list=${member_index_list}
59         ...    verify_restconf=${verify_restconf}
60         ...    http_timeout=${http_timeout}
61         Collections.Sort_List    ${followers}
62         Collections.Set_To_Dictionary    ${shards_details}    ${shard_name}_${shard_type}_leader=${leader}
63         Collections.Set_To_Dictionary    ${shards_details}    ${shard_name}_${shard_type}_followers=${followers}
64     END
65     RETURN    ${shards_details}
66
67 Shards_Stability_Verify
68     [Documentation]    Verify that present details as the same as the stored one from Shards_Stability_Init_Details
69     [Arguments]    ${shard_list}    ${member_index_list}=${EMPTY}
70     ${present_details} =    Shards_Stability_Get_Details    ${shard_list}    member_index_list=${member_index_list}
71     Shards_Stability_Compare_Same    ${present_details}
72
73 Shards_Stability_Compare_Same
74     [Documentation]    Compare two distionaries created by Shards_Stability_Get_Details
75     [Arguments]    ${details}    ${stateless_details}=${EMPTY}
76     ${exp_details} =    BuiltIn.Set_Variable_If
77     ...    "${stateless_details}" == "${EMPTY}"
78     ...    ${stored_details}
79     ...    ${stateless_details}
80     Collections.Log_Dictionary    ${exp_details}
81     Collections.Log_Dictionary    ${details}
82     Collections.Dictionaries_Should_Be_Equal    ${exp_details}    ${details}
83
84 Set_Shard_Location
85     [Documentation]    Move default/topology config/operational shard location to local or remote node as requested
86     ...    towards the given member.
87     [Arguments]    ${requested_leader_idx}
88     ClusterAdmin.Make_Leader_Local    ${requested_leader_idx}    default    config
89     ClusterAdmin.Make_Leader_Local    ${requested_leader_idx}    default    operational
90     ClusterAdmin.Make_Leader_Local    ${requested_leader_idx}    topology    config
91     ClusterAdmin.Make_Leader_Local    ${requested_leader_idx}    topology    operational
92
93 Verify_Shard_Leader_Located_As_Expected
94     [Documentation]    Verify default/topology config/operational shard leader location is as expected
95     [Arguments]    ${expected_leader_idx}    ${http_timeout}=${EMPTY}
96     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard
97     ...    shard_name=default
98     ...    shard_type=config
99     ...    verify_restconf=False
100     ...    http_timeout=${http_timeout}
101     BuiltIn.Should_Be_Equal_As_Numbers    ${expected_leader_idx}    ${leader}
102     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard
103     ...    shard_name=default
104     ...    shard_type=operational
105     ...    verify_restconf=False
106     ...    http_timeout=${http_timeout}
107     BuiltIn.Should_Be_Equal_As_Numbers    ${expected_leader_idx}    ${leader}
108     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard
109     ...    shard_name=topology
110     ...    shard_type=config
111     ...    verify_restconf=False
112     ...    http_timeout=${http_timeout}
113     BuiltIn.Should_Be_Equal_As_Numbers    ${expected_leader_idx}    ${leader}
114     ${leader}    ${follower_list} =    ClusterManagement.Get_Leader_And_Followers_For_Shard
115     ...    shard_name=topology
116     ...    shard_type=operational
117     ...    verify_restconf=False
118     ...    http_timeout=${http_timeout}
119     BuiltIn.Should_Be_Equal_As_Numbers    ${expected_leader_idx}    ${leader}