blob: c8cfd694f849a9d1f3615b6b575c04d4b0d64438 [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
Matteo Scandoloa80b4732020-09-04 13:51:10 -070071
72Exec Pod And Return Output And RC
73 [Arguments] ${namespace} ${name} ${command}
74 [Documentation] Uses kubectl to execute a command in the pod and return the output
75 ${rc} ${exec_pod_name}= Run and Return Rc and Output
76 ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}'
77
Holger Hildebrandt23147742020-11-16 10:13:21 +000078 Log ${exec_pod_name}
79 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
80 ${rc} ${output}= Run and Return Rc and Output
81 ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- ${command}
82 Log ${output}
Matteo Scandoloa80b4732020-09-04 13:51:10 -070083 [return] ${output} ${rc}
Holger Hildebrandt23147742020-11-16 10:13:21 +000084
Scott Baker60e570d2020-02-02 22:10:13 -080085Exec Pod Separate Stderr
86 [Arguments] ${namespace} ${name} ${command}
87 [Documentation] Uses kubectl to execute a command in the pod and return the stderr and stdout
88 ${rc} ${exec_pod_name}= Run and Return Rc and Output
Andrea Campanella1b25ac52020-09-09 14:34:31 +020089 ... kubectl -n ${namespace} get pods -l app=${name} -o name
Scott Baker60e570d2020-02-02 22:10:13 -080090 Log ${exec_pod_name}
91 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
92 @{args}= Split String ${command}
93 ${result}= Run Process
94 ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- @{args}
95 ${stdout}= Set Variable ${result.stdout}
96 ${stderr}= Set Variable ${result.stderr}
97 Log ${stdout}
98 Log ${stderr}
99 [return] ${stdout} ${stderr}
100
Scott Baker0478bab2020-04-10 17:19:57 -0700101Copy File To Pod
102 [Arguments] ${namespace} ${name} ${src} ${dest}
103 [Documentation] Uses kubectl to copy a file to a pod
104 ${rc} ${exec_pod_name}= Run and Return Rc and Output
105 ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}'
106 Log ${exec_pod_name}
107 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
108 ${rc} ${output}= Run and Return Rc and Output
109 ... kubectl cp -n ${namespace} ${src} ${exec_pod_name}:${dest}
110 Log ${output}
111 [return] ${output}
112
Scott Baker60e570d2020-02-02 22:10:13 -0800113Apply Kubernetes Resources
114 [Arguments] ${resource_yaml} ${namespace}
115 [Documentation] Use kubectl to create resources given a yaml file
116 ${rc} Run and Return Rc
117 ... kubectl apply -n ${namespace} -f ${resource_yaml}
118 Should Be Equal as Integers ${rc} 0
119
Scott Baker0478bab2020-04-10 17:19:57 -0700120Delete Kubernetes Resources
121 [Arguments] ${resource_yaml} ${namespace}
122 [Documentation] Use kubectl to delete resources given a yaml file
123 ${rc} Run and Return Rc
124 ... kubectl delete -n ${namespace} -f ${resource_yaml}
125 Should Be Equal as Integers ${rc} 0
126
suraj gour1ecfae92019-12-20 15:11:40 +0000127Validate Pod Status
128 [Arguments] ${pod_name} ${namespace} ${expectedStatus}
129 [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 -0700130 ${length}= Run kubectl get pod -n ${namespace} -o name | wc -l
131 ${matched}= Set Variable False
132 FOR ${index} IN RANGE ${length}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700133 ${currentPodName}= Run
134 ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.containerStatuses[0].name}"
suraj gour1ecfae92019-12-20 15:11:40 +0000135 Log Required Pod : ${pod_name}
136 Log Current Pod: ${currentPodName}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700137 ${matched}= Set Variable If '${currentPodName}'=='${pod_name}' True False
138 Exit For Loop If ${matched}
suraj gour1ecfae92019-12-20 15:11:40 +0000139 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700140 Should Be True ${matched} No pod ${podname} found
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700141 ${currentStatusofPod}= Run
142 ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.phase}"
suraj gour1ecfae92019-12-20 15:11:40 +0000143 Log ${currentStatusofPod}
144 Should Contain ${currentStatusofPod} ${expectedStatus}
145
Matteo Scandoloa80b4732020-09-04 13:51:10 -0700146Get Pod Name By Label
147 [Arguments] ${namespace} ${label_key} ${label_value}
148 [Documentation] Return a pod name from a given label
149 ${rc} ${pod_name}= Run and Return Rc and Output
150 ... kubectl get pods -n ${namespace} -l ${label_key}=${label_value} --no-headers | awk '{print $1}'
151 Should Not Be Empty ${pod_name} Pod not found
152 [return] ${pod_name}
153
Hung-Wei Chiu2bee4d42020-04-24 11:31:50 -0700154Validate Pods Status By Label
155 [Arguments] ${namespace} ${label_key} ${label_value} ${expectedStatus}
156 [Documentation] To run the kubectl command and check the status of all pods filter
157 ... by label matche the expected status
158 ${command}= Catenate
159 ... kubectl -n ${namespace} get pods -l ${label_key}=${label_value}
160 ... -o=jsonpath="{.items[?(.status.phase=='${expectedStatus}')].status.phase}"
161 ${pods_status}= Run ${command}
162 Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus}
163
Andrea Campanella4c404632020-08-26 14:41:36 +0200164Validate Pods Status By Name
165 [Arguments] ${namespace} ${name} ${expectedStatus}
166 [Documentation] To run the kubectl command and check the status of all pods filter
167 ... by label matche the expected status
168 ${command}= Catenate
169 ... kubectl -n ${namespace} get pods ${name}
170 ... -o=jsonpath="{.status.phase}"
171 ${pods_status}= Run ${command}
172 Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus}
173
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000174Verify All Voltha Pods For Any Error Logs
175 [Arguments] ${datetime}
176 [Documentation] This keyword checks for the error occurence in the voltha pods
177 &{errorPodDict} Create Dictionary
Matteo Scandolo142e6272020-04-29 17:36:59 -0700178 &{containerDict} Get Container Dictionary voltha
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000179 FOR ${podName} IN @{PODLIST1}
180 ${containerName} Get From Dictionary ${containerDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700181 ${rc} ${logOutput} Run And Return Rc And Output
182 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
183 Run Keyword And Ignore Error
184 ... Run Keyword If '${logOutput}'=='${EMPTY}'
185 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000186 ... AND Continue For Loop
187 ${errorDict} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput}
188 ${returnStatusFlagList} Get Dictionary Keys ${errorDict}
189 ${returnStatusFlag} Get From List ${returnStatusFlagList} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700190 Run Keyword And Ignore Error
191 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
192 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000193 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700194 Run Keyword And Ignore Error
195 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
196 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000197 ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict}
198 END
199 FOR ${podName} IN @{PODLIST2}
200 ${containerName} Get From Dictionary ${containerDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700201 ${rc} ${logOutput} Run And Return Rc And Output
202 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
203 Run Keyword And Ignore Error
204 ... Run Keyword If '${logOutput}'=='${EMPTY}'
205 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000206 ... AND Continue For Loop
207 ${errorDict} Check For Error Logs in Pod Type2 Given the Log Output ${logOutput}
208 ${returnStatusFlagList} Get Dictionary Keys ${errorDict}
209 ${returnStatusFlag} Get From List ${returnStatusFlagList} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700210 Run Keyword And Ignore Error
211 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
212 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000213 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700214 Run Keyword And Ignore Error
215 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
216 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000217 ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict}
218 END
219 Print to Console Error Statement logged in the following pods : ${errorPodDict}
220 [Return] ${errorPodDict}
221
222Check For Error Logs in Pod Type1 Given the Log Output
223 [Arguments] ${logOutput} ${logLevel}=error ${errorMessage}=${EMPTY}
224 [Documentation] Checks for error message in the particular list of pods
225 Log ${logOutput}
226 ${linesContainingLog} = Get Lines Matching Regexp ${logOutput} .*\s\${logLevel}.* partial_match=true
227 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700228 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
229 ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound
230 ${linesContainingError} = Get Lines Matching Regexp
231 ... ${logOutput} .*\s\${logLevel}.*${errorMessage} partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000232 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700233 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
234 ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000235 Log {linesContainingError}
236 &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog}
237 [Return] ${errorDict}
238
239Check For Error Logs in Pod Type2 Given the Log Output
240 [Arguments] ${logOutput} ${logLevel}=warn ${errorMessage}=${EMPTY}
241 [Documentation] Checks for error message in the particular set of pods
242 Log ${logOutput}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700243 ${linesContainingLog} = Get Lines Matching Regexp
244 ... ${logOutput} .*?\s.*level.*${logLevel}.* partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000245 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700246 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
247 ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound
248 ${linesContainingError} = Get Lines Matching Regexp
249 ... ${logOutput} .*?\s.*level.*${logLevel}.*msg.*${errorMessage} partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000250 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700251 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
252 ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000253 Log {linesContainingError}
254 &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog}
255 [Return] ${errorDict}
256
257Get Container Dictionary
Matteo Scandolo142e6272020-04-29 17:36:59 -0700258 [Arguments] ${namespace}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000259 [Documentation] Creates a mapping for pod name and container name and returns the same
260 &{containerDict} Create Dictionary
261 ${containerName} Set Variable ${EMPTY}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700262 ${podName} Run kubectl get deployment -n ${namespace} | awk 'NR>1 {print $1}'
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000263 @{podNameList}= Split To Lines ${podName}
264 Append To List ${podNameList} voltha-etcd-cluster voltha-kafka voltha-ro-core voltha-zookeeper
265 Log ${podNameList}
266 #Creatiing dictionary to correspond pod name and container name
267 FOR ${pod} IN @{podNameList}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700268 ${containerName} Run kubectl get pod -n ${namespace} | grep ${pod} | awk '{print $1}'
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000269 &{containerDict} Set To Dictionary ${containerDict} ${pod} ${containerName}
270 END
271 Log ${containerDict}
272 [Return] ${containerDict}
273
274Validate Error For Given Pods
275 [Arguments] ${datetime} ${podDict}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700276 [Documentation]
277 ... This keyword is used to get the list of pods if there is any unexpected error
278 ... in a particular pod(s) given the time-${datetime} from which the log needs to
279 ... be analysed and the dictionary of pods and the error in the dictionary format
280 ... ${podDict] .
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000281 ...
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700282 ... Usage: ${returnStatusFlag} Validate Error For Given Pods ${datetime} ${podDict}
283 ...
284 ... Arguments:
285 ...
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000286 ... ${datetime} = time from which the log needs to be taken
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700287 ... ${podDict} = Key-value pair of the pod name and the error msg
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000288 ...
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700289 ... Example: ${podDict} = Set Dictionary ${podDict} radius sample error message.
290 ...
291 ... In case the radius pod log has any other error than the expected
292 ... error, then the podname will be returned
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000293 ${podList} = Get Dictionary Keys ${podDict}
294 FOR ${podName} IN @{podList}
295 ${containerName} Get From Dictionary ${containerDict} ${podName}
296 ${expectedError} Get From Dictionary ${podDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700297 ${rc} ${logOutput} Run And Return Rc And Output
298 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
299 Run Keyword And Ignore Error
300 ... Run Keyword If '${logOutput}'=='${EMPTY}'
301 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000302 ... AND Continue For Loop
303 ${returnStatusFlag} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700304 Run Keyword And Ignore Error
305 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
306 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000307 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700308 Run Keyword And Ignore Error
309 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
310 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000311 ... AND Append To List ${errorPodList} ${podName}
312 END
313 [Return] ${errorPodList}
314
David Bainbridgef81cd642019-11-20 00:14:47 +0000315Delete K8s Pod
316 [Arguments] ${namespace} ${name}
317 [Documentation] Uses kubectl to delete a named POD
318 ${rc} Run and Return Rc
319 ... kubectl delete -n ${namespace} pod/${name}
320 Should Be Equal as Integers ${rc} 0
321
hwchiu85695932019-12-18 08:05:25 +0000322Delete K8s Pods By Label
323 [Arguments] ${namespace} ${key} ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700324 [Documentation] Uses kubectl to delete a PODs, filtering by label
hwchiu85695932019-12-18 08:05:25 +0000325 ${rc}= Run and Return Rc
326 ... kubectl -n ${namespace} delete pods -l${key}=${value}
327 Should Be Equal as Integers ${rc} 0
328
Andrea Campanella4c404632020-08-26 14:41:36 +0200329Delete K8s Pods By Name
330 [Arguments] ${namespace} ${value}
331 [Documentation] Uses kubectl to delete a PODs, filtering by label
332 ${rc}= Run and Return Rc
333 ... kubectl -n ${namespace} delete pods ${value}
334 Should Be Equal as Integers ${rc} 0
335
David Bainbridgef81cd642019-11-20 00:14:47 +0000336Scale K8s Deployment
337 [Arguments] ${namespace} ${name} ${count}
338 [Documentation] Uses kubectl to scale a named deployment
339 ${rc} Run and Return Rc
340 ... kubectl scale --replicas=${count} -n ${namespace} deploy/${name}
341 Should Be Equal as Integers ${rc} 0
342
Andrea Campanella3dcce272021-01-15 16:04:47 +0100343Get K8s Deployment by Pod Label
344 [Arguments] ${namespace} ${key} ${value}
345 [Documentation] Uses kubectl to scale a deployment given the app name of the pod
346 ${rc} ${name} Run And Return Rc And Output
347 ... kubectl describe rs -n ${namespace} -l ${key}=${value} | grep "Controlled By" | awk -F'/' '{print $2}'
348 Should Be Equal as Integers ${rc} 0
349 [Return] ${name}
350
351Scale K8s Deployment by Pod Label
352 [Arguments] ${namespace} ${key} ${value} ${count}
353 [Documentation] Uses kubectl to scale a deployment given the app name of the pod
354 ${name} Get K8s Deployment by Pod Label ${namespace} ${key} ${value}
355 Scale K8s Deployment ${namespace} ${name} ${count}
356
David Bainbridgef81cd642019-11-20 00:14:47 +0000357Pod Exists
358 [Arguments] ${namespace} ${name}
359 [Documentation] Succeeds it the named POD exists
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700360 ${rc} ${count} Run and Return Rc
361 ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep ${name}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700362 Should Be True ${count}>0 Pod ${name} not found
David Bainbridgef81cd642019-11-20 00:14:47 +0000363
364Pod Does Not Exist
365 [Arguments] ${namespace} ${name}
366 [Documentation] Succeeds if the named POD does not exist
367 ${rc} ${count} Run and Return Rc And Output
368 ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep -c ${name}
369 Should Be Equal As Integers ${count} 0
Andy Bavierb63f6d22020-03-12 15:34:37 -0700370 Should Be True ${count}==0 Pod ${name} exists but should not
David Bainbridgef81cd642019-11-20 00:14:47 +0000371
TorstenThiemed2cd91d2020-07-28 07:13:44 +0000372Wait For Pods Not Exist
373 [Arguments] ${namespace} ${list_names}
374 [Documentation] Checks the passed PODs are no longer existing
375 FOR ${pod_name} IN @{list_names}
376 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s
377 ... Pod Does Not Exist ${namespace} ${pod_name}
378 END
379
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700380Pods Do Not Exist By Label
hwchiu85695932019-12-18 08:05:25 +0000381 [Arguments] ${namespace} ${key} ${value}
382 [Documentation] Succeeds if the named POD does not exist
383 ${rc} ${count} Run and Return Rc And Output
384 ... kubectl get -n ${namespace} pod -l${key}=${value} -o json | jq -r ".items[].metadata.name" | wc -l
385 Should Be Equal As Integers ${count} 0
Andy Bavierb63f6d22020-03-12 15:34:37 -0700386 Should Be True ${count}==0 Pod with label ${key}=${value} exists but should not
hwchiu85695932019-12-18 08:05:25 +0000387
David Bainbridgef81cd642019-11-20 00:14:47 +0000388Get Available Deployment Replicas
389 [Arguments] ${namespace} ${name}
390 [Documentation] Succeeds if the named POD exists and has a ready count > 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700391 ${rc} ${count} Run and Return Rc and Output
392 ... kubectl get -n ${namespace} deploy/${name} -o jsonpath='{.status.availableReplicas}'
David Bainbridgef81cd642019-11-20 00:14:47 +0000393 ${result}= Run Keyword If '${count}' == '' Set Variable 0
394 ... ELSE Set Variable ${count}
395 [Return] ${result}
396
Andrea Campanella3dcce272021-01-15 16:04:47 +0100397Check Expected Available Deployment Replicas By Pod Label
398 [Arguments] ${namespace} ${key} ${value} ${expected}
399 [Documentation] Succeeds if the named deployment has the expected number of available replicas
400 ${name} Get K8s Deployment by Pod Label ${namespace} ${key} ${value}
401 Check Expected Available Deployment Replicas ${namespace} ${name} ${expected}
402
David Bainbridgef81cd642019-11-20 00:14:47 +0000403Check Expected Available Deployment Replicas
404 [Arguments] ${namespace} ${name} ${expected}
405 [Documentation] Succeeds if the named deployment has the expected number of available replicas
406 ${count}= Get Available Deployment Replicas ${namespace} ${name}
407 Should Be Equal As Integers ${expected} ${count}
408
409Get Deployment Replica Count
410 [Arguments] ${namespace} ${name}
411 [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment
412 ${rc} ${value} Run and Return Rc and Output
413 ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}'
414 Should Be Equal as Integers ${rc} 0
415 ${replicas}= Run Keyword If '${value}' == '' Set Variable 0
416 ... ELSE Set Variable ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700417 [Return] ${replicas}
David Bainbridgef81cd642019-11-20 00:14:47 +0000418
419Does Deployment Have Replicas
420 [Arguments] ${namespace} ${name} ${expected_count}
421 [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment
422 ${rc} ${value} Run and Return Rc and Output
423 ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}'
424 Should Be Equal as Integers ${rc} 0
425 ${replicas}= Run Keyword If '${value}' == '' Set Variable 0
426 ... ELSE Set Variable ${value}
427 Should be Equal as Integers ${replicas} ${expected_count}
hwchiu85695932019-12-18 08:05:25 +0000428
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700429Pods Are Ready By Label
hwchiu85695932019-12-18 08:05:25 +0000430 [Arguments] ${namespace} ${key} ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700431 [Documentation] Check that all pods with a label are ready
432 ${output}= Run
433 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o=jsonpath="{.items[].status.containerStatuses[].ready}"
TorstenThiemed2cd91d2020-07-28 07:13:44 +0000434 Should Not Contain ${output} false
435
436Wait For Pods Ready
437 [Arguments] ${namespace} ${list_apps}
438 [Documentation] Checks the passed PODs are ready
439 FOR ${app_name} IN @{list_apps}
440 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s
441 ... Pods Are Ready By Label ${namespace} app ${app_name}
442 END
Gayathri.Selvan49398962020-01-13 07:19:12 +0000443
hwchiu58af72d2020-01-14 00:50:35 +0000444Check Expected Running Pods Number By Label
445 [Arguments] ${namespace} ${key} ${value} ${number}
446 [Documentation] Succeeds if the desired pod has expected number replicas
447 ${rc} ${count} Run and Return Rc and Output
448 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o json | jq -r ".items[].status.phase" | wc -l
449 Should Be Equal as Integers ${count} ${number}
Andrea Campanella962fe832020-09-21 10:41:47 +0200450
451Get Number of Running Pods Number By Label
452 [Arguments] ${namespace} ${key} ${value}
453 [Documentation] Returns the number of pods for a given label
454 ${rc} ${count} Run and Return Rc and Output
455 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o name | wc -l
456 [Return] ${count}