blob: 213246ea3f720ce5f27ed9b1bf7191e50cb16986 [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
Holger Hildebrandt23147742020-11-16 10:13:21 +000066Exec Pod In Kube
67 [Arguments] ${namespace} ${name} ${command}
68 [Documentation] Uses kubectl to execute a command in the pod and return the output
69 ${rc} ${exec_pod_name}= Run and Return Rc and Output
70 ... kubectl -n ${namespace} get pods -l app.kubernetes.io/name=${name} -o name
71 Log ${exec_pod_name}
72 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
73 ${rc} ${output}= Run and Return Rc and Output
74 ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- ${command}
75 Log ${output}
76 [return] ${output}
77
78
Scott Baker60e570d2020-02-02 22:10:13 -080079Exec Pod Separate Stderr
80 [Arguments] ${namespace} ${name} ${command}
81 [Documentation] Uses kubectl to execute a command in the pod and return the stderr and stdout
82 ${rc} ${exec_pod_name}= Run and Return Rc and Output
Andrea Campanella1b25ac52020-09-09 14:34:31 +020083 ... kubectl -n ${namespace} get pods -l app=${name} -o name
Scott Baker60e570d2020-02-02 22:10:13 -080084 Log ${exec_pod_name}
85 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
86 @{args}= Split String ${command}
87 ${result}= Run Process
88 ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- @{args}
89 ${stdout}= Set Variable ${result.stdout}
90 ${stderr}= Set Variable ${result.stderr}
91 Log ${stdout}
92 Log ${stderr}
93 [return] ${stdout} ${stderr}
94
Scott Baker0478bab2020-04-10 17:19:57 -070095Copy File To Pod
96 [Arguments] ${namespace} ${name} ${src} ${dest}
97 [Documentation] Uses kubectl to copy a file to a pod
98 ${rc} ${exec_pod_name}= Run and Return Rc and Output
99 ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}'
100 Log ${exec_pod_name}
101 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
102 ${rc} ${output}= Run and Return Rc and Output
103 ... kubectl cp -n ${namespace} ${src} ${exec_pod_name}:${dest}
104 Log ${output}
105 [return] ${output}
106
Scott Baker60e570d2020-02-02 22:10:13 -0800107Apply Kubernetes Resources
108 [Arguments] ${resource_yaml} ${namespace}
109 [Documentation] Use kubectl to create resources given a yaml file
110 ${rc} Run and Return Rc
111 ... kubectl apply -n ${namespace} -f ${resource_yaml}
112 Should Be Equal as Integers ${rc} 0
113
Scott Baker0478bab2020-04-10 17:19:57 -0700114Delete Kubernetes Resources
115 [Arguments] ${resource_yaml} ${namespace}
116 [Documentation] Use kubectl to delete resources given a yaml file
117 ${rc} Run and Return Rc
118 ... kubectl delete -n ${namespace} -f ${resource_yaml}
119 Should Be Equal as Integers ${rc} 0
120
suraj gour1ecfae92019-12-20 15:11:40 +0000121Validate Pod Status
122 [Arguments] ${pod_name} ${namespace} ${expectedStatus}
123 [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 -0700124 ${length}= Run kubectl get pod -n ${namespace} -o name | wc -l
125 ${matched}= Set Variable False
126 FOR ${index} IN RANGE ${length}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700127 ${currentPodName}= Run
128 ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.containerStatuses[0].name}"
suraj gour1ecfae92019-12-20 15:11:40 +0000129 Log Required Pod : ${pod_name}
130 Log Current Pod: ${currentPodName}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700131 ${matched}= Set Variable If '${currentPodName}'=='${pod_name}' True False
132 Exit For Loop If ${matched}
suraj gour1ecfae92019-12-20 15:11:40 +0000133 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700134 Should Be True ${matched} No pod ${podname} found
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700135 ${currentStatusofPod}= Run
136 ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.phase}"
suraj gour1ecfae92019-12-20 15:11:40 +0000137 Log ${currentStatusofPod}
138 Should Contain ${currentStatusofPod} ${expectedStatus}
139
Hung-Wei Chiu2bee4d42020-04-24 11:31:50 -0700140Validate Pods Status By Label
141 [Arguments] ${namespace} ${label_key} ${label_value} ${expectedStatus}
142 [Documentation] To run the kubectl command and check the status of all pods filter
143 ... by label matche the expected status
144 ${command}= Catenate
145 ... kubectl -n ${namespace} get pods -l ${label_key}=${label_value}
146 ... -o=jsonpath="{.items[?(.status.phase=='${expectedStatus}')].status.phase}"
147 ${pods_status}= Run ${command}
148 Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus}
149
Andrea Campanella4c404632020-08-26 14:41:36 +0200150Validate Pods Status By Name
151 [Arguments] ${namespace} ${name} ${expectedStatus}
152 [Documentation] To run the kubectl command and check the status of all pods filter
153 ... by label matche the expected status
154 ${command}= Catenate
155 ... kubectl -n ${namespace} get pods ${name}
156 ... -o=jsonpath="{.status.phase}"
157 ${pods_status}= Run ${command}
158 Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus}
159
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000160Verify All Voltha Pods For Any Error Logs
161 [Arguments] ${datetime}
162 [Documentation] This keyword checks for the error occurence in the voltha pods
163 &{errorPodDict} Create Dictionary
Matteo Scandolo142e6272020-04-29 17:36:59 -0700164 &{containerDict} Get Container Dictionary voltha
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000165 FOR ${podName} IN @{PODLIST1}
166 ${containerName} Get From Dictionary ${containerDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700167 ${rc} ${logOutput} Run And Return Rc And Output
168 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
169 Run Keyword And Ignore Error
170 ... Run Keyword If '${logOutput}'=='${EMPTY}'
171 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000172 ... AND Continue For Loop
173 ${errorDict} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput}
174 ${returnStatusFlagList} Get Dictionary Keys ${errorDict}
175 ${returnStatusFlag} Get From List ${returnStatusFlagList} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700176 Run Keyword And Ignore Error
177 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
178 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000179 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700180 Run Keyword And Ignore Error
181 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
182 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000183 ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict}
184 END
185 FOR ${podName} IN @{PODLIST2}
186 ${containerName} Get From Dictionary ${containerDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700187 ${rc} ${logOutput} Run And Return Rc And Output
188 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
189 Run Keyword And Ignore Error
190 ... Run Keyword If '${logOutput}'=='${EMPTY}'
191 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000192 ... AND Continue For Loop
193 ${errorDict} Check For Error Logs in Pod Type2 Given the Log Output ${logOutput}
194 ${returnStatusFlagList} Get Dictionary Keys ${errorDict}
195 ${returnStatusFlag} Get From List ${returnStatusFlagList} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700196 Run Keyword And Ignore Error
197 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
198 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000199 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700200 Run Keyword And Ignore Error
201 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
202 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000203 ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict}
204 END
205 Print to Console Error Statement logged in the following pods : ${errorPodDict}
206 [Return] ${errorPodDict}
207
208Check For Error Logs in Pod Type1 Given the Log Output
209 [Arguments] ${logOutput} ${logLevel}=error ${errorMessage}=${EMPTY}
210 [Documentation] Checks for error message in the particular list of pods
211 Log ${logOutput}
212 ${linesContainingLog} = Get Lines Matching Regexp ${logOutput} .*\s\${logLevel}.* partial_match=true
213 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700214 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
215 ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound
216 ${linesContainingError} = Get Lines Matching Regexp
217 ... ${logOutput} .*\s\${logLevel}.*${errorMessage} partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000218 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700219 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
220 ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000221 Log {linesContainingError}
222 &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog}
223 [Return] ${errorDict}
224
225Check For Error Logs in Pod Type2 Given the Log Output
226 [Arguments] ${logOutput} ${logLevel}=warn ${errorMessage}=${EMPTY}
227 [Documentation] Checks for error message in the particular set of pods
228 Log ${logOutput}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700229 ${linesContainingLog} = Get Lines Matching Regexp
230 ... ${logOutput} .*?\s.*level.*${logLevel}.* partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000231 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700232 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
233 ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound
234 ${linesContainingError} = Get Lines Matching Regexp
235 ... ${logOutput} .*?\s.*level.*${logLevel}.*msg.*${errorMessage} partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000236 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700237 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
238 ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000239 Log {linesContainingError}
240 &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog}
241 [Return] ${errorDict}
242
243Get Container Dictionary
Matteo Scandolo142e6272020-04-29 17:36:59 -0700244 [Arguments] ${namespace}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000245 [Documentation] Creates a mapping for pod name and container name and returns the same
246 &{containerDict} Create Dictionary
247 ${containerName} Set Variable ${EMPTY}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700248 ${podName} Run kubectl get deployment -n ${namespace} | awk 'NR>1 {print $1}'
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000249 @{podNameList}= Split To Lines ${podName}
250 Append To List ${podNameList} voltha-etcd-cluster voltha-kafka voltha-ro-core voltha-zookeeper
251 Log ${podNameList}
252 #Creatiing dictionary to correspond pod name and container name
253 FOR ${pod} IN @{podNameList}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700254 ${containerName} Run kubectl get pod -n ${namespace} | grep ${pod} | awk '{print $1}'
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000255 &{containerDict} Set To Dictionary ${containerDict} ${pod} ${containerName}
256 END
257 Log ${containerDict}
258 [Return] ${containerDict}
259
260Validate Error For Given Pods
261 [Arguments] ${datetime} ${podDict}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700262 [Documentation]
263 ... This keyword is used to get the list of pods if there is any unexpected error
264 ... in a particular pod(s) given the time-${datetime} from which the log needs to
265 ... be analysed and the dictionary of pods and the error in the dictionary format
266 ... ${podDict] .
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000267 ...
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700268 ... Usage: ${returnStatusFlag} Validate Error For Given Pods ${datetime} ${podDict}
269 ...
270 ... Arguments:
271 ...
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000272 ... ${datetime} = time from which the log needs to be taken
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700273 ... ${podDict} = Key-value pair of the pod name and the error msg
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000274 ...
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700275 ... Example: ${podDict} = Set Dictionary ${podDict} radius sample error message.
276 ...
277 ... In case the radius pod log has any other error than the expected
278 ... error, then the podname will be returned
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000279 ${podList} = Get Dictionary Keys ${podDict}
280 FOR ${podName} IN @{podList}
281 ${containerName} Get From Dictionary ${containerDict} ${podName}
282 ${expectedError} Get From Dictionary ${podDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700283 ${rc} ${logOutput} Run And Return Rc And Output
284 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
285 Run Keyword And Ignore Error
286 ... Run Keyword If '${logOutput}'=='${EMPTY}'
287 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000288 ... AND Continue For Loop
289 ${returnStatusFlag} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700290 Run Keyword And Ignore Error
291 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
292 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000293 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700294 Run Keyword And Ignore Error
295 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
296 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000297 ... AND Append To List ${errorPodList} ${podName}
298 END
299 [Return] ${errorPodList}
300
David Bainbridgef81cd642019-11-20 00:14:47 +0000301Delete K8s Pod
302 [Arguments] ${namespace} ${name}
303 [Documentation] Uses kubectl to delete a named POD
304 ${rc} Run and Return Rc
305 ... kubectl delete -n ${namespace} pod/${name}
306 Should Be Equal as Integers ${rc} 0
307
hwchiu85695932019-12-18 08:05:25 +0000308Delete K8s Pods By Label
309 [Arguments] ${namespace} ${key} ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700310 [Documentation] Uses kubectl to delete a PODs, filtering by label
hwchiu85695932019-12-18 08:05:25 +0000311 ${rc}= Run and Return Rc
312 ... kubectl -n ${namespace} delete pods -l${key}=${value}
313 Should Be Equal as Integers ${rc} 0
314
Andrea Campanella4c404632020-08-26 14:41:36 +0200315Delete K8s Pods By Name
316 [Arguments] ${namespace} ${value}
317 [Documentation] Uses kubectl to delete a PODs, filtering by label
318 ${rc}= Run and Return Rc
319 ... kubectl -n ${namespace} delete pods ${value}
320 Should Be Equal as Integers ${rc} 0
321
David Bainbridgef81cd642019-11-20 00:14:47 +0000322Scale K8s Deployment
323 [Arguments] ${namespace} ${name} ${count}
324 [Documentation] Uses kubectl to scale a named deployment
325 ${rc} Run and Return Rc
326 ... kubectl scale --replicas=${count} -n ${namespace} deploy/${name}
327 Should Be Equal as Integers ${rc} 0
328
Andrea Campanellab2d09f12021-01-15 16:04:47 +0100329Get K8s Deployment by Pod Label
330 [Arguments] ${namespace} ${key} ${value}
331 [Documentation] Uses kubectl to scale a deployment given the app name of the pod
332 ${rc} ${name} Run And Return Rc And Output
333 ... kubectl describe rs -n ${namespace} -l ${key}=${value} | grep "Controlled By" | awk -F'/' '{print $2}'
334 Should Be Equal as Integers ${rc} 0
335 [Return] ${name}
336
337Scale K8s Deployment by Pod Label
338 [Arguments] ${namespace} ${key} ${value} ${count}
339 [Documentation] Uses kubectl to scale a deployment given the app name of the pod
340 ${name} Get K8s Deployment by Pod Label ${namespace} ${key} ${value}
341 Scale K8s Deployment ${namespace} ${name} ${count}
342
David Bainbridgef81cd642019-11-20 00:14:47 +0000343Pod Exists
344 [Arguments] ${namespace} ${name}
345 [Documentation] Succeeds it the named POD exists
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700346 ${rc} ${count} Run and Return Rc
347 ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep ${name}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700348 Should Be True ${count}>0 Pod ${name} not found
David Bainbridgef81cd642019-11-20 00:14:47 +0000349
350Pod Does Not Exist
351 [Arguments] ${namespace} ${name}
352 [Documentation] Succeeds if the named POD does not exist
353 ${rc} ${count} Run and Return Rc And Output
354 ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep -c ${name}
355 Should Be Equal As Integers ${count} 0
Andy Bavierb63f6d22020-03-12 15:34:37 -0700356 Should Be True ${count}==0 Pod ${name} exists but should not
David Bainbridgef81cd642019-11-20 00:14:47 +0000357
TorstenThiemed2cd91d2020-07-28 07:13:44 +0000358Wait For Pods Not Exist
359 [Arguments] ${namespace} ${list_names}
360 [Documentation] Checks the passed PODs are no longer existing
361 FOR ${pod_name} IN @{list_names}
362 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s
363 ... Pod Does Not Exist ${namespace} ${pod_name}
364 END
365
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700366Pods Do Not Exist By Label
hwchiu85695932019-12-18 08:05:25 +0000367 [Arguments] ${namespace} ${key} ${value}
368 [Documentation] Succeeds if the named POD does not exist
369 ${rc} ${count} Run and Return Rc And Output
370 ... kubectl get -n ${namespace} pod -l${key}=${value} -o json | jq -r ".items[].metadata.name" | wc -l
371 Should Be Equal As Integers ${count} 0
Andy Bavierb63f6d22020-03-12 15:34:37 -0700372 Should Be True ${count}==0 Pod with label ${key}=${value} exists but should not
hwchiu85695932019-12-18 08:05:25 +0000373
David Bainbridgef81cd642019-11-20 00:14:47 +0000374Get Available Deployment Replicas
375 [Arguments] ${namespace} ${name}
376 [Documentation] Succeeds if the named POD exists and has a ready count > 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700377 ${rc} ${count} Run and Return Rc and Output
378 ... kubectl get -n ${namespace} deploy/${name} -o jsonpath='{.status.availableReplicas}'
David Bainbridgef81cd642019-11-20 00:14:47 +0000379 ${result}= Run Keyword If '${count}' == '' Set Variable 0
380 ... ELSE Set Variable ${count}
381 [Return] ${result}
382
Andrea Campanellab2d09f12021-01-15 16:04:47 +0100383Check Expected Available Deployment Replicas By Pod Label
384 [Arguments] ${namespace} ${key} ${value} ${expected}
385 [Documentation] Succeeds if the named deployment has the expected number of available replicas
386 ${name} Get K8s Deployment by Pod Label ${namespace} ${key} ${value}
387 Check Expected Available Deployment Replicas ${namespace} ${name} ${expected}
388
David Bainbridgef81cd642019-11-20 00:14:47 +0000389Check Expected Available Deployment Replicas
390 [Arguments] ${namespace} ${name} ${expected}
391 [Documentation] Succeeds if the named deployment has the expected number of available replicas
392 ${count}= Get Available Deployment Replicas ${namespace} ${name}
393 Should Be Equal As Integers ${expected} ${count}
394
395Get Deployment Replica Count
396 [Arguments] ${namespace} ${name}
397 [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment
398 ${rc} ${value} Run and Return Rc and Output
399 ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}'
400 Should Be Equal as Integers ${rc} 0
401 ${replicas}= Run Keyword If '${value}' == '' Set Variable 0
402 ... ELSE Set Variable ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700403 [Return] ${replicas}
David Bainbridgef81cd642019-11-20 00:14:47 +0000404
405Does Deployment Have Replicas
406 [Arguments] ${namespace} ${name} ${expected_count}
407 [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment
408 ${rc} ${value} Run and Return Rc and Output
409 ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}'
410 Should Be Equal as Integers ${rc} 0
411 ${replicas}= Run Keyword If '${value}' == '' Set Variable 0
412 ... ELSE Set Variable ${value}
413 Should be Equal as Integers ${replicas} ${expected_count}
hwchiu85695932019-12-18 08:05:25 +0000414
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700415Pods Are Ready By Label
hwchiu85695932019-12-18 08:05:25 +0000416 [Arguments] ${namespace} ${key} ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700417 [Documentation] Check that all pods with a label are ready
418 ${output}= Run
419 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o=jsonpath="{.items[].status.containerStatuses[].ready}"
TorstenThiemed2cd91d2020-07-28 07:13:44 +0000420 Should Not Contain ${output} false
421
422Wait For Pods Ready
423 [Arguments] ${namespace} ${list_apps}
424 [Documentation] Checks the passed PODs are ready
425 FOR ${app_name} IN @{list_apps}
426 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s
427 ... Pods Are Ready By Label ${namespace} app ${app_name}
428 END
Gayathri.Selvan49398962020-01-13 07:19:12 +0000429
hwchiu58af72d2020-01-14 00:50:35 +0000430Check Expected Running Pods Number By Label
431 [Arguments] ${namespace} ${key} ${value} ${number}
432 [Documentation] Succeeds if the desired pod has expected number replicas
433 ${rc} ${count} Run and Return Rc and Output
434 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o json | jq -r ".items[].status.phase" | wc -l
435 Should Be Equal as Integers ${count} ${number}
Andrea Campanella962fe832020-09-21 10:41:47 +0200436
437Get Number of Running Pods Number By Label
438 [Arguments] ${namespace} ${key} ${value}
439 [Documentation] Returns the number of pods for a given label
440 ${rc} ${count} Run and Return Rc and Output
441 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o name | wc -l
442 [Return] ${count}