Move new Clustering Keywords
[integration/test.git] / test / csit / libraries / ClusterKeywords.txt
1 *** Settings ***
2 Resource          Utils.txt
3 Library           Collections
4
5 *** Variables ***
6
7 *** Keywords ***
8 Get Controller List
9     [Arguments]    ${exclude_controller}=${EMPTY}
10     [Documentation]  Creates a list of all controllers minus any excluded controller.
11     Log    ${exclude_controller}
12     @{searchlist}    Create List    ${CONTROLLER}    ${CONTROLLER1}    ${CONTROLLER2}
13     Remove Values From List    ${searchlist}    ${exclude_controller}
14     Log    ${searchlist}
15     [Return]    ${searchlist}
16
17 Get Leader And Verify
18     [Arguments]    ${shard_name}    ${old_leader}=${EMPTY}
19     [Documentation]    Returns the IP addr or hostname of the leader of the specified shard.
20     ...    Controllers are specifed in the pybot command line.
21     ${searchlist}    Get Controller List    ${old_leader}
22     ${leader}    GetLeader    ${shard_name}    ${3}    ${3}    ${1}    ${PORT}
23     ...    @{searchlist}
24     Should Not Be Equal As Strings    ${leader}    None
25     Run Keyword If    '${old_leader}'!='${EMPTY}'    Should Not Be Equal    ${old_leader}    ${leader}
26     [Return]    ${leader}
27
28 Wait For Leader To Be Found
29     [Arguments]    ${shard_name}
30     [Documentation]    Waits until the leader of the specified shard is found.
31     ${leader}    Wait Until Keyword Succeeds    12s    2s    Get Leader And Verify    ${shard_name}
32     Log    ${leader}
33     [Return]    ${leader}
34
35 Switch Leader
36     [Arguments]    ${shard_name}    ${current_leader}
37     [Documentation]    Forces a change of leadership by shutting down the current leader.
38     Stop One Or More Controllers    ${current_leader}
39     ${new_leader}    Wait Until Keyword Succeeds    60s    2s    Get Leader And Verify    ${shard_name}    ${current_leader}
40     # TODO: Future enhanement: make sure the other controller is a follower and not a master or candidate.
41     Log    ${new_leader}
42     [Return]    ${new_leader}
43
44 Get All Followers
45     [Arguments]    ${shard_name}    ${exclude_controller}=${EMPTY}
46     [Documentation]    Returns the IP addresses or hostnames of all followers of the specified shard.
47     ${searchlist}    Get Controller List    ${exclude_controller}
48     ${followers}    GetFollowers    ${shard_name}    ${3}    ${3}    ${1}    ${PORT}
49     ...    @{searchlist}
50     Log    ${followers}
51     Should Not Be Empty    ${followers}
52     [Return]    ${followers}
53
54 Add Cars And Verify
55     [Arguments]    ${controller_ip}    ${num_cars}    ${timeout}=12s
56     [Documentation]    Initializes shard and then adds the specified number of cars and performs a GET as a check.
57     ${resp}    InitCar    ${controller_ip}    ${PORT}
58     Should Be Equal As Strings    ${resp.status_code}    204
59     ${resp}    AddCar    ${controller_ip}    ${RESTCONFPORT}    ${num_cars}    204
60     Should Be Equal As Strings    ${resp.status_code}    204
61     Wait Until Keyword Succeeds    ${timeout}    2s    Get Cars And Verify    ${controller_ip}    ${num_cars}
62
63 Add Cars And Verify Without Init
64     [Arguments]    ${controller_ip}    ${num_cars}    ${timeout}=12s
65     [Documentation]    Adds cars to an initialized cars shard then performs a GET as a check.
66     Comment    First car add may return 409, but subsequent should be 204
67     ${resp}    AddCar    ${controller_ip}    ${RESTCONFPORT}    ${num_cars}    204    409
68     Should Be Equal As Strings    ${resp.status_code}    204
69     Wait Until Keyword Succeeds    ${timeout}    2s    Get Cars And Verify    ${controller_ip}    ${num_cars}
70
71 Get Cars And Verify
72     [Arguments]    ${controller_ip}    ${num_cars}
73     [Documentation]    Gets cars and verifies that the manufacturer is correct.
74     # TODO: Future enhanement: verify all fields.
75     ${resp}    Getcars    ${controller_ip}    ${RESTCONFPORT}    ${0}
76     Should Be Equal As Strings    ${resp.status_code}    200
77     : FOR    ${i}    IN RANGE    1    ${num_cars}+1
78     \    Should Contain    ${resp.content}    manufacturer${i}
79
80 Add People And Verify
81     [Arguments]    ${controller_ip}    ${num_people}
82     [Documentation]    Note: The first AddPerson call passed with 0 posts directly to the data store to get
83     ...    the people container created so the subsequent AddPerson RPC calls that put to the
84     ...    person list will succeed.
85     ${resp}    AddPerson    ${controller_ip}    ${RESTCONFPORT}    ${0}    204
86     Should Be Equal As Strings    ${resp.status_code}    204
87     Wait Until Keyword Succeeds    12s    2s    Get One Person And Verify    ${controller_ip}    ${0}
88     ${resp}    AddPerson    ${controller_ip}    ${RESTCONFPORT}    ${num_people}    200
89     Wait Until Keyword Succeeds    12s    2s    Get People And Verify    ${controller_ip}    ${num_people}
90
91 Get One Person And Verify
92     [Arguments]    ${controller_ip}    ${number}
93     [Documentation]    Gets a person and verifies that the user ID is correct.
94     # TODO: Future enhanement: verify all fields.
95     ${resp}    GetPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
96     Should Be Equal As Strings    ${resp.status_code}    200
97     Should Contain    ${resp.content}    user${number}
98
99 Get People And Verify
100     [Arguments]    ${controller_ip}    ${num_people}
101     [Documentation]    Gets multiple people and verifies that the user IDs are correct.
102     # TODO: Future enhanement: verify all fields.
103     ${resp}    GetPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
104     Should Be Equal As Strings    ${resp.status_code}    200
105     : FOR    ${i}    IN RANGE    1    ${num_people}+1
106     \    Should Contain    ${resp.content}    user${i}
107
108 Add Car Person And Verify
109     [Arguments]    ${controller_ip}
110     [Documentation]    Add a car-person via the data store and get the car-person from Leader.
111     ...    Note: This is done to get the car-people container created so subsequent
112     ...    BuyCar RPC puts to the car-person list will succeed.
113     AddCarPerson    ${controller_ip}    ${RESTCONFPORT}    ${0}
114     Wait Until Keyword Succeeds    60s    2s    Get One Car-Person Mapping And Verify    ${controller_ip}    ${0}
115
116 Get One Car-Person Mapping And Verify
117     [Arguments]    ${controller_ip}    ${number}
118     [Documentation]    Gets a car person mapping and verifies that the user ID is correct.
119     ${resp}    GetCarPersonMappings    ${controller_ip}    ${RESTCONFPORT}    ${0}
120     Should Be Equal As Strings    ${resp.status_code}    200
121     Should Contain    ${resp.content}    user${number}
122
123 Get Car-Person Mappings And Verify
124     [Arguments]    ${controller_ip}    ${num_entries}
125     ${resp}    GetCarPersonMappings    ${controller_ip}    ${RESTCONFPORT}    ${0}
126     Should Be Equal As Strings    ${resp.status_code}    200
127     : FOR    ${i}    IN RANGE    1    ${num_entries}+1
128     \    Should Contain    ${resp.content}    user${i}
129
130 Buy Cars And Verify
131     [Arguments]    ${controller_ip}    ${num_entries}    ${start}=${0}
132     Wait Until Keyword Succeeds    60s    2s    BuyCar    ${controller_ip}    ${RESTCONFPORT}    ${num_entries}
133     ...    ${start}
134
135 Check Cars Deleted
136     [Arguments]    ${controller_ip}
137     ${resp}    Getcars    ${controller_ip}    ${RESTCONFPORT}    ${0}
138     Should Be Equal As Strings    ${resp.status_code}    404
139
140 Delete All Cars And Verify
141     [Arguments]    ${controller_ip}
142     DeleteAllCars    ${controller_ip}    ${RESTCONFPORT}    ${0}
143     Wait Until Keyword Succeeds    60s    2s    Check Cars Deleted    ${controller_ip}
144
145 Check People Deleted
146     [Arguments]    ${controller_ip}
147     ${resp}    GetPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
148     Should Be Equal As Strings    ${resp.status_code}    404
149
150 Delete All People And Verify
151     [Arguments]    ${controller_ip}
152     DeleteAllPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
153     Wait Until Keyword Succeeds    60s    2s    Check People Deleted    ${controller_ip}
154
155 Check Cars-Persons Deleted
156     [Arguments]    ${controller_ip}
157     ${resp}    GetCarPersonMappings    ${controller_ip}    ${RESTCONFPORT}    ${0}
158     Should Be Equal As Strings    ${resp.status_code}    404
159
160 Delete All Cars-Persons And Verify
161     [Arguments]    ${controller_ip}
162     DeleteAllCarsPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
163     Wait Until Keyword Succeeds    60s    2s    Check Cars-Persons Deleted    ${controller_ip}
164
165 Stop One Or More Controllers
166     [Arguments]    @{controllers}
167     [Documentation]    Give this keyword a scalar or list of controllers to be stopped.
168     ${cmd} =    Set Variable    ${KARAF_HOME}/bin/stop
169     : FOR    ${ip}    IN    @{controllers}
170     \    Run Command On Remote System    ${ip}    ${cmd}
171     : FOR    ${ip}    IN    @{controllers}
172     \    Wait Until Keyword Succeeds    120 s   3 s    Controller Down Check    ${ip}
173
174 Start One Or More Controllers
175     [Arguments]    @{controllers}
176     [Documentation]    Give this keyword a scalar or list of controllers to be started.
177     ${cmd} =    Set Variable    ${KARAF_HOME}/bin/start
178     : FOR    ${ip}    IN    @{controllers}
179     \    Run Command On Remote System    ${ip}    ${cmd}
180     # TODO: This should throw an error if controller never comes up.
181     : FOR    ${ip}    IN    @{controllers}
182     \    UtilLibrary.Wait For Controller Up    ${ip}    ${RESTCONFPORT}
183
184 Kill One Or More Controllers
185     [Arguments]    @{controllers}
186     [Documentation]    Give this keyword a scalar or list of controllers to be stopped.
187     ${cmd} =    Set Variable    ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh
188     log    ${cmd}
189     : FOR    ${ip}    IN    @{controllers}
190     \    Run Command On Remote System    ${ip}    ${cmd}
191     : FOR    ${ip}    IN    @{controllers}
192     \    Wait Until Keyword Succeeds    12 s    3 s    Controller Down Check    ${ip}
193
194 Controller Down Check
195     [Arguments]    ${ip}
196     [Documentation]    Checks to see if a controller is down by verifying that the karaf process isn't present.
197     ${cmd} =    Set Variable    ps axf | grep karaf | grep -v grep | wc -l
198     ${response}    Run Command On Remote System    ${ip}    ${cmd}
199     Log    Number of controller instances running: ${response}
200     Should Start With    ${response}    0    Controller process found or there may be extra instances of karaf running on the host machine.
201
202 Clean One Or More Journals
203     [Arguments]    @{controllers}
204     [Documentation]    Give this keyword a scalar or list of controllers on which to clean journals.
205     ${del_cmd} =    Set Variable    rm -rf ${KARAF_HOME}/journal
206     : FOR    ${ip}    IN    @{controllers}
207     \    Run Command On Remote System    ${ip}    ${del_cmd}
208
209 Clean One Or More Snapshots
210     [Arguments]    @{controllers}
211     [Documentation]    Give this keyword a scalar or list of controllers on which to clean snapshots.
212     ${del_cmd} =    Set Variable    rm -rf ${KARAF_HOME}/snapshots
213     : FOR    ${ip}    IN    @{controllers}
214     \    Run Command On Remote System    ${ip}    ${del_cmd}
215
216 Show Cluster Configuation Files
217     [Arguments]    @{controllers}
218     [Documentation]    Prints out the cluster configuration files for one or more controllers.
219     Log    controllers: @{controllers}
220     ${cmd} =    Set Variable    cat ${KARAF_HOME}/configuration/initial/akka.conf
221     : FOR    ${ip}    IN    @{controllers}
222     \    Run Command On Remote System    ${ip}    ${cmd}
223     ${cmd} =    Set Variable    cat ${KARAF_HOME}/configuration/initial/modules.conf
224     : FOR    ${ip}    IN    @{controllers}
225     \    Run Command On Remote System    ${ip}    ${cmd}
226     ${cmd} =    Set Variable    cat ${KARAF_HOME}/configuration/initial/module-shards.conf
227     : FOR    ${ip}    IN    @{controllers}
228     \    Run Command On Remote System    ${ip}    ${cmd}
229     ${cmd} =    Set Variable    cat ${KARAF_HOME}/configuration/initial/jolokia.xml
230     : FOR    ${ip}    IN    @{controllers}
231     \    Run Command On Remote System    ${ip}    ${cmd}
232     ${cmd} =    Set Variable    cat ${KARAF_HOME}/etc/initial/org.apache.karaf.management.cfg
233     : FOR    ${ip}    IN    @{controllers}
234     \    Run Command On Remote System    ${ip}    ${cmd}
235     ${cmd} =    Set Variable    cat ${KARAF_HOME}/etc/org.apache.karaf.features.cfg
236     : FOR    ${ip}    IN    @{controllers}
237     \    Run Command On Remote System    ${ip}    ${cmd}