blob: 5d8eb5a7190a711f9f1870f3e7eff50f21bb17a5 [file] [log] [blame]
David Bainbridge117d23e2019-09-30 20:37:51 +00001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
David Bainbridge117d23e2019-09-30 20:37:51 +000014# voltctl common functions
15
16*** Settings ***
17Documentation Library for various utilities
18Library SSHLibrary
David Bainbridge117d23e2019-09-30 20:37:51 +000019Library String
20Library DateTime
21Library Process
22Library Collections
23Library RequestsLibrary
24Library OperatingSystem
25
26*** Keywords ***
27Lookup Service IP
28 [Arguments] ${namespace} ${name}
David Bainbridgef81cd642019-11-20 00:14:47 +000029 [Documentation] Uses kubectl to resolve a service name to an IP
Gilles Depatie675a2062019-10-22 12:44:42 -040030 ${rc} ${ip}= Run and Return Rc and Output
31 ... kubectl get svc -n ${namespace} ${name} -o jsonpath={.spec.clusterIP}
David Bainbridge117d23e2019-09-30 20:37:51 +000032 Should Be Equal as Integers ${rc} 0
33 [Return] ${ip}
34
35Lookup Service PORT
36 [Arguments] ${namespace} ${name}
David Bainbridgef81cd642019-11-20 00:14:47 +000037 [Documentation] Uses kubectl to resolve a service name to an PORT
Gilles Depatie675a2062019-10-22 12:44:42 -040038 ${rc} ${port}= Run and Return Rc and Output
39 ... kubectl get svc -n ${namespace} ${name} -o jsonpath={.spec.ports[0].port}
David Bainbridge117d23e2019-09-30 20:37:51 +000040 Should Be Equal as Integers ${rc} 0
41 [Return] ${port}
suraj gourd64356b2019-11-07 13:26:20 +000042
43Restart Pod
44 [Arguments] ${namespace} ${name}
45 [Documentation] Uses kubectl to force delete pod
suraj gour067451d2019-11-13 11:20:13 +000046 ${rc} ${restart_pod_name}= Run and Return Rc and Output
47 ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}'
suraj gourd64356b2019-11-07 13:26:20 +000048 Log ${restart_pod_name}
suraj gour067451d2019-11-13 11:20:13 +000049 Should Not Be Empty ${restart_pod_name} Unable to parse pod name
Zack Williamsa8fe75a2020-01-10 14:25:27 -070050 ${rc} ${output}= Run and Return Rc and Output
51 ... kubectl delete pod ${restart_pod_name} -n ${namespace} --grace-period=0 --force
suraj gourd64356b2019-11-07 13:26:20 +000052 Log ${output}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +000053
Scott Baker60e570d2020-02-02 22:10:13 -080054Exec Pod
55 [Arguments] ${namespace} ${name} ${command}
56 [Documentation] Uses kubectl to execute a command in the pod and return the output
57 ${rc} ${exec_pod_name}= Run and Return Rc and Output
Andrea Campanella1b25ac52020-09-09 14:34:31 +020058 ... kubectl -n ${namespace} get pods -l app=${name} -o name
Scott Baker60e570d2020-02-02 22:10:13 -080059 Log ${exec_pod_name}
60 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
61 ${rc} ${output}= Run and Return Rc and Output
62 ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- ${command}
63 Log ${output}
64 [return] ${output}
65
66Exec Pod Separate Stderr
67 [Arguments] ${namespace} ${name} ${command}
68 [Documentation] Uses kubectl to execute a command in the pod and return the stderr and stdout
69 ${rc} ${exec_pod_name}= Run and Return Rc and Output
Andrea Campanella1b25ac52020-09-09 14:34:31 +020070 ... kubectl -n ${namespace} get pods -l app=${name} -o name
Scott Baker60e570d2020-02-02 22:10:13 -080071 Log ${exec_pod_name}
72 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
73 @{args}= Split String ${command}
74 ${result}= Run Process
75 ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- @{args}
76 ${stdout}= Set Variable ${result.stdout}
77 ${stderr}= Set Variable ${result.stderr}
78 Log ${stdout}
79 Log ${stderr}
80 [return] ${stdout} ${stderr}
81
Scott Baker0478bab2020-04-10 17:19:57 -070082Copy File To Pod
83 [Arguments] ${namespace} ${name} ${src} ${dest}
84 [Documentation] Uses kubectl to copy a file to a pod
85 ${rc} ${exec_pod_name}= Run and Return Rc and Output
86 ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}'
87 Log ${exec_pod_name}
88 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
89 ${rc} ${output}= Run and Return Rc and Output
90 ... kubectl cp -n ${namespace} ${src} ${exec_pod_name}:${dest}
91 Log ${output}
92 [return] ${output}
93
Scott Baker60e570d2020-02-02 22:10:13 -080094Apply Kubernetes Resources
95 [Arguments] ${resource_yaml} ${namespace}
96 [Documentation] Use kubectl to create resources given a yaml file
97 ${rc} Run and Return Rc
98 ... kubectl apply -n ${namespace} -f ${resource_yaml}
99 Should Be Equal as Integers ${rc} 0
100
Scott Baker0478bab2020-04-10 17:19:57 -0700101Delete Kubernetes Resources
102 [Arguments] ${resource_yaml} ${namespace}
103 [Documentation] Use kubectl to delete resources given a yaml file
104 ${rc} Run and Return Rc
105 ... kubectl delete -n ${namespace} -f ${resource_yaml}
106 Should Be Equal as Integers ${rc} 0
107
suraj gour1ecfae92019-12-20 15:11:40 +0000108Validate Pod Status
109 [Arguments] ${pod_name} ${namespace} ${expectedStatus}
110 [Documentation] To run the kubectl command and check the status of the given pod matches the expected status
Andy Bavierb63f6d22020-03-12 15:34:37 -0700111 ${length}= Run kubectl get pod -n ${namespace} -o name | wc -l
112 ${matched}= Set Variable False
113 FOR ${index} IN RANGE ${length}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700114 ${currentPodName}= Run
115 ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.containerStatuses[0].name}"
suraj gour1ecfae92019-12-20 15:11:40 +0000116 Log Required Pod : ${pod_name}
117 Log Current Pod: ${currentPodName}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700118 ${matched}= Set Variable If '${currentPodName}'=='${pod_name}' True False
119 Exit For Loop If ${matched}
suraj gour1ecfae92019-12-20 15:11:40 +0000120 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700121 Should Be True ${matched} No pod ${podname} found
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700122 ${currentStatusofPod}= Run
123 ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.phase}"
suraj gour1ecfae92019-12-20 15:11:40 +0000124 Log ${currentStatusofPod}
125 Should Contain ${currentStatusofPod} ${expectedStatus}
126
Hung-Wei Chiu2bee4d42020-04-24 11:31:50 -0700127Validate Pods Status By Label
128 [Arguments] ${namespace} ${label_key} ${label_value} ${expectedStatus}
129 [Documentation] To run the kubectl command and check the status of all pods filter
130 ... by label matche the expected status
131 ${command}= Catenate
132 ... kubectl -n ${namespace} get pods -l ${label_key}=${label_value}
133 ... -o=jsonpath="{.items[?(.status.phase=='${expectedStatus}')].status.phase}"
134 ${pods_status}= Run ${command}
135 Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus}
136
Andrea Campanella4c404632020-08-26 14:41:36 +0200137Validate Pods Status By Name
138 [Arguments] ${namespace} ${name} ${expectedStatus}
139 [Documentation] To run the kubectl command and check the status of all pods filter
140 ... by label matche the expected status
141 ${command}= Catenate
142 ... kubectl -n ${namespace} get pods ${name}
143 ... -o=jsonpath="{.status.phase}"
144 ${pods_status}= Run ${command}
145 Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus}
146
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000147Verify All Voltha Pods For Any Error Logs
148 [Arguments] ${datetime}
149 [Documentation] This keyword checks for the error occurence in the voltha pods
150 &{errorPodDict} Create Dictionary
Matteo Scandolo142e6272020-04-29 17:36:59 -0700151 &{containerDict} Get Container Dictionary voltha
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000152 FOR ${podName} IN @{PODLIST1}
153 ${containerName} Get From Dictionary ${containerDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700154 ${rc} ${logOutput} Run And Return Rc And Output
155 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
156 Run Keyword And Ignore Error
157 ... Run Keyword If '${logOutput}'=='${EMPTY}'
158 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000159 ... AND Continue For Loop
160 ${errorDict} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput}
161 ${returnStatusFlagList} Get Dictionary Keys ${errorDict}
162 ${returnStatusFlag} Get From List ${returnStatusFlagList} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700163 Run Keyword And Ignore Error
164 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
165 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000166 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700167 Run Keyword And Ignore Error
168 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
169 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000170 ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict}
171 END
172 FOR ${podName} IN @{PODLIST2}
173 ${containerName} Get From Dictionary ${containerDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700174 ${rc} ${logOutput} Run And Return Rc And Output
175 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
176 Run Keyword And Ignore Error
177 ... Run Keyword If '${logOutput}'=='${EMPTY}'
178 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000179 ... AND Continue For Loop
180 ${errorDict} Check For Error Logs in Pod Type2 Given the Log Output ${logOutput}
181 ${returnStatusFlagList} Get Dictionary Keys ${errorDict}
182 ${returnStatusFlag} Get From List ${returnStatusFlagList} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700183 Run Keyword And Ignore Error
184 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
185 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000186 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700187 Run Keyword And Ignore Error
188 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
189 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000190 ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict}
191 END
192 Print to Console Error Statement logged in the following pods : ${errorPodDict}
193 [Return] ${errorPodDict}
194
195Check For Error Logs in Pod Type1 Given the Log Output
196 [Arguments] ${logOutput} ${logLevel}=error ${errorMessage}=${EMPTY}
197 [Documentation] Checks for error message in the particular list of pods
198 Log ${logOutput}
199 ${linesContainingLog} = Get Lines Matching Regexp ${logOutput} .*\s\${logLevel}.* partial_match=true
200 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700201 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
202 ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound
203 ${linesContainingError} = Get Lines Matching Regexp
204 ... ${logOutput} .*\s\${logLevel}.*${errorMessage} partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000205 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700206 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
207 ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000208 Log {linesContainingError}
209 &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog}
210 [Return] ${errorDict}
211
212Check For Error Logs in Pod Type2 Given the Log Output
213 [Arguments] ${logOutput} ${logLevel}=warn ${errorMessage}=${EMPTY}
214 [Documentation] Checks for error message in the particular set of pods
215 Log ${logOutput}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700216 ${linesContainingLog} = Get Lines Matching Regexp
217 ... ${logOutput} .*?\s.*level.*${logLevel}.* partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000218 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700219 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
220 ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound
221 ${linesContainingError} = Get Lines Matching Regexp
222 ... ${logOutput} .*?\s.*level.*${logLevel}.*msg.*${errorMessage} partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000223 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700224 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
225 ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000226 Log {linesContainingError}
227 &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog}
228 [Return] ${errorDict}
229
230Get Container Dictionary
Matteo Scandolo142e6272020-04-29 17:36:59 -0700231 [Arguments] ${namespace}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000232 [Documentation] Creates a mapping for pod name and container name and returns the same
233 &{containerDict} Create Dictionary
234 ${containerName} Set Variable ${EMPTY}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700235 ${podName} Run kubectl get deployment -n ${namespace} | awk 'NR>1 {print $1}'
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000236 @{podNameList}= Split To Lines ${podName}
237 Append To List ${podNameList} voltha-etcd-cluster voltha-kafka voltha-ro-core voltha-zookeeper
238 Log ${podNameList}
239 #Creatiing dictionary to correspond pod name and container name
240 FOR ${pod} IN @{podNameList}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700241 ${containerName} Run kubectl get pod -n ${namespace} | grep ${pod} | awk '{print $1}'
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000242 &{containerDict} Set To Dictionary ${containerDict} ${pod} ${containerName}
243 END
244 Log ${containerDict}
245 [Return] ${containerDict}
246
247Validate Error For Given Pods
248 [Arguments] ${datetime} ${podDict}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700249 [Documentation]
250 ... This keyword is used to get the list of pods if there is any unexpected error
251 ... in a particular pod(s) given the time-${datetime} from which the log needs to
252 ... be analysed and the dictionary of pods and the error in the dictionary format
253 ... ${podDict] .
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000254 ...
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700255 ... Usage: ${returnStatusFlag} Validate Error For Given Pods ${datetime} ${podDict}
256 ...
257 ... Arguments:
258 ...
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000259 ... ${datetime} = time from which the log needs to be taken
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700260 ... ${podDict} = Key-value pair of the pod name and the error msg
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000261 ...
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700262 ... Example: ${podDict} = Set Dictionary ${podDict} radius sample error message.
263 ...
264 ... In case the radius pod log has any other error than the expected
265 ... error, then the podname will be returned
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000266 ${podList} = Get Dictionary Keys ${podDict}
267 FOR ${podName} IN @{podList}
268 ${containerName} Get From Dictionary ${containerDict} ${podName}
269 ${expectedError} Get From Dictionary ${podDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700270 ${rc} ${logOutput} Run And Return Rc And Output
271 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
272 Run Keyword And Ignore Error
273 ... Run Keyword If '${logOutput}'=='${EMPTY}'
274 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000275 ... AND Continue For Loop
276 ${returnStatusFlag} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700277 Run Keyword And Ignore Error
278 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
279 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000280 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700281 Run Keyword And Ignore Error
282 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
283 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000284 ... AND Append To List ${errorPodList} ${podName}
285 END
286 [Return] ${errorPodList}
287
David Bainbridgef81cd642019-11-20 00:14:47 +0000288Delete K8s Pod
289 [Arguments] ${namespace} ${name}
290 [Documentation] Uses kubectl to delete a named POD
291 ${rc} Run and Return Rc
292 ... kubectl delete -n ${namespace} pod/${name}
293 Should Be Equal as Integers ${rc} 0
294
hwchiu85695932019-12-18 08:05:25 +0000295Delete K8s Pods By Label
296 [Arguments] ${namespace} ${key} ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700297 [Documentation] Uses kubectl to delete a PODs, filtering by label
hwchiu85695932019-12-18 08:05:25 +0000298 ${rc}= Run and Return Rc
299 ... kubectl -n ${namespace} delete pods -l${key}=${value}
300 Should Be Equal as Integers ${rc} 0
301
Andrea Campanella4c404632020-08-26 14:41:36 +0200302Delete K8s Pods By Name
303 [Arguments] ${namespace} ${value}
304 [Documentation] Uses kubectl to delete a PODs, filtering by label
305 ${rc}= Run and Return Rc
306 ... kubectl -n ${namespace} delete pods ${value}
307 Should Be Equal as Integers ${rc} 0
308
David Bainbridgef81cd642019-11-20 00:14:47 +0000309Scale K8s Deployment
310 [Arguments] ${namespace} ${name} ${count}
311 [Documentation] Uses kubectl to scale a named deployment
312 ${rc} Run and Return Rc
313 ... kubectl scale --replicas=${count} -n ${namespace} deploy/${name}
314 Should Be Equal as Integers ${rc} 0
315
316Pod Exists
317 [Arguments] ${namespace} ${name}
318 [Documentation] Succeeds it the named POD exists
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700319 ${rc} ${count} Run and Return Rc
320 ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep ${name}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700321 Should Be True ${count}>0 Pod ${name} not found
David Bainbridgef81cd642019-11-20 00:14:47 +0000322
323Pod Does Not Exist
324 [Arguments] ${namespace} ${name}
325 [Documentation] Succeeds if the named POD does not exist
326 ${rc} ${count} Run and Return Rc And Output
327 ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep -c ${name}
328 Should Be Equal As Integers ${count} 0
Andy Bavierb63f6d22020-03-12 15:34:37 -0700329 Should Be True ${count}==0 Pod ${name} exists but should not
David Bainbridgef81cd642019-11-20 00:14:47 +0000330
TorstenThiemed2cd91d2020-07-28 07:13:44 +0000331Wait For Pods Not Exist
332 [Arguments] ${namespace} ${list_names}
333 [Documentation] Checks the passed PODs are no longer existing
334 FOR ${pod_name} IN @{list_names}
335 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s
336 ... Pod Does Not Exist ${namespace} ${pod_name}
337 END
338
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700339Pods Do Not Exist By Label
hwchiu85695932019-12-18 08:05:25 +0000340 [Arguments] ${namespace} ${key} ${value}
341 [Documentation] Succeeds if the named POD does not exist
342 ${rc} ${count} Run and Return Rc And Output
343 ... kubectl get -n ${namespace} pod -l${key}=${value} -o json | jq -r ".items[].metadata.name" | wc -l
344 Should Be Equal As Integers ${count} 0
Andy Bavierb63f6d22020-03-12 15:34:37 -0700345 Should Be True ${count}==0 Pod with label ${key}=${value} exists but should not
hwchiu85695932019-12-18 08:05:25 +0000346
David Bainbridgef81cd642019-11-20 00:14:47 +0000347Get Available Deployment Replicas
348 [Arguments] ${namespace} ${name}
349 [Documentation] Succeeds if the named POD exists and has a ready count > 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700350 ${rc} ${count} Run and Return Rc and Output
351 ... kubectl get -n ${namespace} deploy/${name} -o jsonpath='{.status.availableReplicas}'
David Bainbridgef81cd642019-11-20 00:14:47 +0000352 ${result}= Run Keyword If '${count}' == '' Set Variable 0
353 ... ELSE Set Variable ${count}
354 [Return] ${result}
355
356Check Expected Available Deployment Replicas
357 [Arguments] ${namespace} ${name} ${expected}
358 [Documentation] Succeeds if the named deployment has the expected number of available replicas
359 ${count}= Get Available Deployment Replicas ${namespace} ${name}
360 Should Be Equal As Integers ${expected} ${count}
361
362Get Deployment Replica Count
363 [Arguments] ${namespace} ${name}
364 [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment
365 ${rc} ${value} Run and Return Rc and Output
366 ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}'
367 Should Be Equal as Integers ${rc} 0
368 ${replicas}= Run Keyword If '${value}' == '' Set Variable 0
369 ... ELSE Set Variable ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700370 [Return] ${replicas}
David Bainbridgef81cd642019-11-20 00:14:47 +0000371
372Does Deployment Have Replicas
373 [Arguments] ${namespace} ${name} ${expected_count}
374 [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment
375 ${rc} ${value} Run and Return Rc and Output
376 ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}'
377 Should Be Equal as Integers ${rc} 0
378 ${replicas}= Run Keyword If '${value}' == '' Set Variable 0
379 ... ELSE Set Variable ${value}
380 Should be Equal as Integers ${replicas} ${expected_count}
hwchiu85695932019-12-18 08:05:25 +0000381
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700382Pods Are Ready By Label
hwchiu85695932019-12-18 08:05:25 +0000383 [Arguments] ${namespace} ${key} ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700384 [Documentation] Check that all pods with a label are ready
385 ${output}= Run
386 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o=jsonpath="{.items[].status.containerStatuses[].ready}"
TorstenThiemed2cd91d2020-07-28 07:13:44 +0000387 Should Not Contain ${output} false
388
389Wait For Pods Ready
390 [Arguments] ${namespace} ${list_apps}
391 [Documentation] Checks the passed PODs are ready
392 FOR ${app_name} IN @{list_apps}
393 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s
394 ... Pods Are Ready By Label ${namespace} app ${app_name}
395 END
Gayathri.Selvan49398962020-01-13 07:19:12 +0000396
hwchiu58af72d2020-01-14 00:50:35 +0000397Check Expected Running Pods Number By Label
398 [Arguments] ${namespace} ${key} ${value} ${number}
399 [Documentation] Succeeds if the desired pod has expected number replicas
400 ${rc} ${count} Run and Return Rc and Output
401 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o json | jq -r ".items[].status.phase" | wc -l
402 Should Be Equal as Integers ${count} ${number}