blob: bb909d1506df9e6b48b545201f6a3629780f7000 [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
Hardik Windlassec86c232021-02-02 13:56:12 +000071 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}
Matteo Scandoloa80b4732020-09-04 13:51:10 -070077
78Exec Pod And Return Output And RC
79 [Arguments] ${namespace} ${name} ${command}
80 [Documentation] Uses kubectl to execute a command in the pod and return the output
81 ${rc} ${exec_pod_name}= Run and Return Rc and Output
82 ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}'
Holger Hildebrandt23147742020-11-16 10:13:21 +000083 Log ${exec_pod_name}
84 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
85 ${rc} ${output}= Run and Return Rc and Output
86 ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- ${command}
87 Log ${output}
Matteo Scandoloa80b4732020-09-04 13:51:10 -070088 [return] ${output} ${rc}
Holger Hildebrandt23147742020-11-16 10:13:21 +000089
Scott Baker60e570d2020-02-02 22:10:13 -080090Exec Pod Separate Stderr
91 [Arguments] ${namespace} ${name} ${command}
92 [Documentation] Uses kubectl to execute a command in the pod and return the stderr and stdout
93 ${rc} ${exec_pod_name}= Run and Return Rc and Output
Andrea Campanella1b25ac52020-09-09 14:34:31 +020094 ... kubectl -n ${namespace} get pods -l app=${name} -o name
Scott Baker60e570d2020-02-02 22:10:13 -080095 Log ${exec_pod_name}
96 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
97 @{args}= Split String ${command}
98 ${result}= Run Process
99 ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- @{args}
100 ${stdout}= Set Variable ${result.stdout}
101 ${stderr}= Set Variable ${result.stderr}
102 Log ${stdout}
103 Log ${stderr}
104 [return] ${stdout} ${stderr}
105
Scott Baker0478bab2020-04-10 17:19:57 -0700106Copy File To Pod
107 [Arguments] ${namespace} ${name} ${src} ${dest}
108 [Documentation] Uses kubectl to copy a file to a pod
109 ${rc} ${exec_pod_name}= Run and Return Rc and Output
110 ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}'
111 Log ${exec_pod_name}
112 Should Not Be Empty ${exec_pod_name} Unable to parse pod name
113 ${rc} ${output}= Run and Return Rc and Output
114 ... kubectl cp -n ${namespace} ${src} ${exec_pod_name}:${dest}
115 Log ${output}
116 [return] ${output}
117
Scott Baker60e570d2020-02-02 22:10:13 -0800118Apply Kubernetes Resources
119 [Arguments] ${resource_yaml} ${namespace}
120 [Documentation] Use kubectl to create resources given a yaml file
121 ${rc} Run and Return Rc
122 ... kubectl apply -n ${namespace} -f ${resource_yaml}
123 Should Be Equal as Integers ${rc} 0
124
Scott Baker0478bab2020-04-10 17:19:57 -0700125Delete Kubernetes Resources
126 [Arguments] ${resource_yaml} ${namespace}
127 [Documentation] Use kubectl to delete resources given a yaml file
128 ${rc} Run and Return Rc
129 ... kubectl delete -n ${namespace} -f ${resource_yaml}
130 Should Be Equal as Integers ${rc} 0
131
suraj gour1ecfae92019-12-20 15:11:40 +0000132Validate Pod Status
133 [Arguments] ${pod_name} ${namespace} ${expectedStatus}
134 [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 -0700135 ${length}= Run kubectl get pod -n ${namespace} -o name | wc -l
136 ${matched}= Set Variable False
137 FOR ${index} IN RANGE ${length}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700138 ${currentPodName}= Run
139 ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.containerStatuses[0].name}"
suraj gour1ecfae92019-12-20 15:11:40 +0000140 Log Required Pod : ${pod_name}
141 Log Current Pod: ${currentPodName}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700142 ${matched}= Set Variable If '${currentPodName}'=='${pod_name}' True False
143 Exit For Loop If ${matched}
suraj gour1ecfae92019-12-20 15:11:40 +0000144 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700145 Should Be True ${matched} No pod ${podname} found
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700146 ${currentStatusofPod}= Run
147 ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.phase}"
suraj gour1ecfae92019-12-20 15:11:40 +0000148 Log ${currentStatusofPod}
149 Should Contain ${currentStatusofPod} ${expectedStatus}
150
Matteo Scandoloa80b4732020-09-04 13:51:10 -0700151Get Pod Name By Label
152 [Arguments] ${namespace} ${label_key} ${label_value}
153 [Documentation] Return a pod name from a given label
154 ${rc} ${pod_name}= Run and Return Rc and Output
155 ... kubectl get pods -n ${namespace} -l ${label_key}=${label_value} --no-headers | awk '{print $1}'
156 Should Not Be Empty ${pod_name} Pod not found
157 [return] ${pod_name}
158
Hung-Wei Chiu2bee4d42020-04-24 11:31:50 -0700159Validate Pods Status By Label
160 [Arguments] ${namespace} ${label_key} ${label_value} ${expectedStatus}
161 [Documentation] To run the kubectl command and check the status of all pods filter
162 ... by label matche the expected status
163 ${command}= Catenate
164 ... kubectl -n ${namespace} get pods -l ${label_key}=${label_value}
165 ... -o=jsonpath="{.items[?(.status.phase=='${expectedStatus}')].status.phase}"
166 ${pods_status}= Run ${command}
167 Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus}
168
Andrea Campanella4c404632020-08-26 14:41:36 +0200169Validate Pods Status By Name
170 [Arguments] ${namespace} ${name} ${expectedStatus}
171 [Documentation] To run the kubectl command and check the status of all pods filter
172 ... by label matche the expected status
173 ${command}= Catenate
174 ... kubectl -n ${namespace} get pods ${name}
175 ... -o=jsonpath="{.status.phase}"
176 ${pods_status}= Run ${command}
177 Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus}
178
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000179Verify All Voltha Pods For Any Error Logs
180 [Arguments] ${datetime}
181 [Documentation] This keyword checks for the error occurence in the voltha pods
182 &{errorPodDict} Create Dictionary
Matteo Scandolo142e6272020-04-29 17:36:59 -0700183 &{containerDict} Get Container Dictionary voltha
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000184 FOR ${podName} IN @{PODLIST1}
185 ${containerName} Get From Dictionary ${containerDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700186 ${rc} ${logOutput} Run And Return Rc And Output
187 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
188 Run Keyword And Ignore Error
189 ... Run Keyword If '${logOutput}'=='${EMPTY}'
190 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000191 ... AND Continue For Loop
192 ${errorDict} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput}
193 ${returnStatusFlagList} Get Dictionary Keys ${errorDict}
194 ${returnStatusFlag} Get From List ${returnStatusFlagList} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700195 Run Keyword And Ignore Error
196 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
197 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000198 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700199 Run Keyword And Ignore Error
200 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
201 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000202 ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict}
203 END
204 FOR ${podName} IN @{PODLIST2}
205 ${containerName} Get From Dictionary ${containerDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700206 ${rc} ${logOutput} Run And Return Rc And Output
207 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
208 Run Keyword And Ignore Error
209 ... Run Keyword If '${logOutput}'=='${EMPTY}'
210 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000211 ... AND Continue For Loop
212 ${errorDict} Check For Error Logs in Pod Type2 Given the Log Output ${logOutput}
213 ${returnStatusFlagList} Get Dictionary Keys ${errorDict}
214 ${returnStatusFlag} Get From List ${returnStatusFlagList} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700215 Run Keyword And Ignore Error
216 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
217 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000218 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700219 Run Keyword And Ignore Error
220 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
221 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000222 ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict}
223 END
224 Print to Console Error Statement logged in the following pods : ${errorPodDict}
225 [Return] ${errorPodDict}
226
227Check For Error Logs in Pod Type1 Given the Log Output
228 [Arguments] ${logOutput} ${logLevel}=error ${errorMessage}=${EMPTY}
229 [Documentation] Checks for error message in the particular list of pods
230 Log ${logOutput}
231 ${linesContainingLog} = Get Lines Matching Regexp ${logOutput} .*\s\${logLevel}.* partial_match=true
232 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700233 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
234 ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound
235 ${linesContainingError} = Get Lines Matching Regexp
236 ... ${logOutput} .*\s\${logLevel}.*${errorMessage} partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000237 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700238 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
239 ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000240 Log {linesContainingError}
241 &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog}
242 [Return] ${errorDict}
243
244Check For Error Logs in Pod Type2 Given the Log Output
245 [Arguments] ${logOutput} ${logLevel}=warn ${errorMessage}=${EMPTY}
246 [Documentation] Checks for error message in the particular set of pods
247 Log ${logOutput}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700248 ${linesContainingLog} = Get Lines Matching Regexp
249 ... ${logOutput} .*?\s.*level.*${logLevel}.* partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000250 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700251 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
252 ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound
253 ${linesContainingError} = Get Lines Matching Regexp
254 ... ${logOutput} .*?\s.*level.*${logLevel}.*msg.*${errorMessage} partial_match=true
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000255 ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700256 ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS'
257 ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000258 Log {linesContainingError}
259 &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog}
260 [Return] ${errorDict}
261
262Get Container Dictionary
Matteo Scandolo142e6272020-04-29 17:36:59 -0700263 [Arguments] ${namespace}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000264 [Documentation] Creates a mapping for pod name and container name and returns the same
265 &{containerDict} Create Dictionary
266 ${containerName} Set Variable ${EMPTY}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700267 ${podName} Run kubectl get deployment -n ${namespace} | awk 'NR>1 {print $1}'
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000268 @{podNameList}= Split To Lines ${podName}
269 Append To List ${podNameList} voltha-etcd-cluster voltha-kafka voltha-ro-core voltha-zookeeper
270 Log ${podNameList}
271 #Creatiing dictionary to correspond pod name and container name
272 FOR ${pod} IN @{podNameList}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700273 ${containerName} Run kubectl get pod -n ${namespace} | grep ${pod} | awk '{print $1}'
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000274 &{containerDict} Set To Dictionary ${containerDict} ${pod} ${containerName}
275 END
276 Log ${containerDict}
277 [Return] ${containerDict}
278
279Validate Error For Given Pods
280 [Arguments] ${datetime} ${podDict}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700281 [Documentation]
282 ... This keyword is used to get the list of pods if there is any unexpected error
283 ... in a particular pod(s) given the time-${datetime} from which the log needs to
284 ... be analysed and the dictionary of pods and the error in the dictionary format
285 ... ${podDict] .
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000286 ...
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700287 ... Usage: ${returnStatusFlag} Validate Error For Given Pods ${datetime} ${podDict}
288 ...
289 ... Arguments:
290 ...
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000291 ... ${datetime} = time from which the log needs to be taken
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700292 ... ${podDict} = Key-value pair of the pod name and the error msg
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000293 ...
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700294 ... Example: ${podDict} = Set Dictionary ${podDict} radius sample error message.
295 ...
296 ... In case the radius pod log has any other error than the expected
297 ... error, then the podname will be returned
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000298 ${podList} = Get Dictionary Keys ${podDict}
299 FOR ${podName} IN @{podList}
300 ${containerName} Get From Dictionary ${containerDict} ${podName}
301 ${expectedError} Get From Dictionary ${podDict} ${podName}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700302 ${rc} ${logOutput} Run And Return Rc And Output
303 ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName}
304 Run Keyword And Ignore Error
305 ... Run Keyword If '${logOutput}'=='${EMPTY}'
306 ... Run Keywords Log No Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000307 ... AND Continue For Loop
308 ${returnStatusFlag} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700309 Run Keyword And Ignore Error
310 ... Run Keyword If '${returnStatusFlag}'=='Nologfound'
311 ... Run Keywords Log No Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000312 ... AND Continue For Loop
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700313 Run Keyword And Ignore Error
314 ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound'
315 ... Run Keywords Log Unexpected Error Log found in pod ${podName}
Gayathri.Selvan61fbcdb2019-11-14 05:08:19 +0000316 ... AND Append To List ${errorPodList} ${podName}
317 END
318 [Return] ${errorPodList}
319
David Bainbridgef81cd642019-11-20 00:14:47 +0000320Delete K8s Pod
321 [Arguments] ${namespace} ${name}
322 [Documentation] Uses kubectl to delete a named POD
323 ${rc} Run and Return Rc
324 ... kubectl delete -n ${namespace} pod/${name}
325 Should Be Equal as Integers ${rc} 0
326
hwchiu85695932019-12-18 08:05:25 +0000327Delete K8s Pods By Label
328 [Arguments] ${namespace} ${key} ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700329 [Documentation] Uses kubectl to delete a PODs, filtering by label
hwchiu85695932019-12-18 08:05:25 +0000330 ${rc}= Run and Return Rc
331 ... kubectl -n ${namespace} delete pods -l${key}=${value}
332 Should Be Equal as Integers ${rc} 0
333
Andrea Campanella4c404632020-08-26 14:41:36 +0200334Delete K8s Pods By Name
335 [Arguments] ${namespace} ${value}
336 [Documentation] Uses kubectl to delete a PODs, filtering by label
337 ${rc}= Run and Return Rc
338 ... kubectl -n ${namespace} delete pods ${value}
339 Should Be Equal as Integers ${rc} 0
340
David Bainbridgef81cd642019-11-20 00:14:47 +0000341Scale K8s Deployment
342 [Arguments] ${namespace} ${name} ${count}
343 [Documentation] Uses kubectl to scale a named deployment
344 ${rc} Run and Return Rc
345 ... kubectl scale --replicas=${count} -n ${namespace} deploy/${name}
346 Should Be Equal as Integers ${rc} 0
347
Andrea Campanella3dcce272021-01-15 16:04:47 +0100348Get K8s Deployment by Pod Label
349 [Arguments] ${namespace} ${key} ${value}
350 [Documentation] Uses kubectl to scale a deployment given the app name of the pod
351 ${rc} ${name} Run And Return Rc And Output
352 ... kubectl describe rs -n ${namespace} -l ${key}=${value} | grep "Controlled By" | awk -F'/' '{print $2}'
353 Should Be Equal as Integers ${rc} 0
354 [Return] ${name}
355
356Scale K8s Deployment by Pod Label
357 [Arguments] ${namespace} ${key} ${value} ${count}
358 [Documentation] Uses kubectl to scale a deployment given the app name of the pod
359 ${name} Get K8s Deployment by Pod Label ${namespace} ${key} ${value}
360 Scale K8s Deployment ${namespace} ${name} ${count}
361
David Bainbridgef81cd642019-11-20 00:14:47 +0000362Pod Exists
363 [Arguments] ${namespace} ${name}
364 [Documentation] Succeeds it the named POD exists
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700365 ${rc} ${count} Run and Return Rc
366 ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep ${name}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700367 Should Be True ${count}>0 Pod ${name} not found
David Bainbridgef81cd642019-11-20 00:14:47 +0000368
369Pod Does Not Exist
370 [Arguments] ${namespace} ${name}
371 [Documentation] Succeeds if the named POD does not exist
372 ${rc} ${count} Run and Return Rc And Output
373 ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep -c ${name}
374 Should Be Equal As Integers ${count} 0
Andy Bavierb63f6d22020-03-12 15:34:37 -0700375 Should Be True ${count}==0 Pod ${name} exists but should not
David Bainbridgef81cd642019-11-20 00:14:47 +0000376
TorstenThiemed2cd91d2020-07-28 07:13:44 +0000377Wait For Pods Not Exist
378 [Arguments] ${namespace} ${list_names}
379 [Documentation] Checks the passed PODs are no longer existing
380 FOR ${pod_name} IN @{list_names}
381 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s
382 ... Pod Does Not Exist ${namespace} ${pod_name}
383 END
384
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700385Pods Do Not Exist By Label
hwchiu85695932019-12-18 08:05:25 +0000386 [Arguments] ${namespace} ${key} ${value}
387 [Documentation] Succeeds if the named POD does not exist
388 ${rc} ${count} Run and Return Rc And Output
389 ... kubectl get -n ${namespace} pod -l${key}=${value} -o json | jq -r ".items[].metadata.name" | wc -l
390 Should Be Equal As Integers ${count} 0
Andy Bavierb63f6d22020-03-12 15:34:37 -0700391 Should Be True ${count}==0 Pod with label ${key}=${value} exists but should not
hwchiu85695932019-12-18 08:05:25 +0000392
David Bainbridgef81cd642019-11-20 00:14:47 +0000393Get Available Deployment Replicas
394 [Arguments] ${namespace} ${name}
395 [Documentation] Succeeds if the named POD exists and has a ready count > 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700396 ${rc} ${count} Run and Return Rc and Output
397 ... kubectl get -n ${namespace} deploy/${name} -o jsonpath='{.status.availableReplicas}'
David Bainbridgef81cd642019-11-20 00:14:47 +0000398 ${result}= Run Keyword If '${count}' == '' Set Variable 0
399 ... ELSE Set Variable ${count}
400 [Return] ${result}
401
Andrea Campanella3dcce272021-01-15 16:04:47 +0100402Check Expected Available Deployment Replicas By Pod Label
403 [Arguments] ${namespace} ${key} ${value} ${expected}
404 [Documentation] Succeeds if the named deployment has the expected number of available replicas
405 ${name} Get K8s Deployment by Pod Label ${namespace} ${key} ${value}
406 Check Expected Available Deployment Replicas ${namespace} ${name} ${expected}
407
David Bainbridgef81cd642019-11-20 00:14:47 +0000408Check Expected Available Deployment Replicas
409 [Arguments] ${namespace} ${name} ${expected}
410 [Documentation] Succeeds if the named deployment has the expected number of available replicas
411 ${count}= Get Available Deployment Replicas ${namespace} ${name}
412 Should Be Equal As Integers ${expected} ${count}
413
414Get Deployment Replica Count
415 [Arguments] ${namespace} ${name}
416 [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment
417 ${rc} ${value} Run and Return Rc and Output
418 ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}'
419 Should Be Equal as Integers ${rc} 0
420 ${replicas}= Run Keyword If '${value}' == '' Set Variable 0
421 ... ELSE Set Variable ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700422 [Return] ${replicas}
David Bainbridgef81cd642019-11-20 00:14:47 +0000423
424Does Deployment Have Replicas
425 [Arguments] ${namespace} ${name} ${expected_count}
426 [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment
427 ${rc} ${value} Run and Return Rc and Output
428 ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}'
429 Should Be Equal as Integers ${rc} 0
430 ${replicas}= Run Keyword If '${value}' == '' Set Variable 0
431 ... ELSE Set Variable ${value}
432 Should be Equal as Integers ${replicas} ${expected_count}
hwchiu85695932019-12-18 08:05:25 +0000433
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700434Pods Are Ready By Label
hwchiu85695932019-12-18 08:05:25 +0000435 [Arguments] ${namespace} ${key} ${value}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700436 [Documentation] Check that all pods with a label are ready
437 ${output}= Run
438 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o=jsonpath="{.items[].status.containerStatuses[].ready}"
TorstenThiemed2cd91d2020-07-28 07:13:44 +0000439 Should Not Contain ${output} false
440
441Wait For Pods Ready
442 [Arguments] ${namespace} ${list_apps}
443 [Documentation] Checks the passed PODs are ready
444 FOR ${app_name} IN @{list_apps}
445 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s
446 ... Pods Are Ready By Label ${namespace} app ${app_name}
447 END
Gayathri.Selvan49398962020-01-13 07:19:12 +0000448
hwchiu58af72d2020-01-14 00:50:35 +0000449Check Expected Running Pods Number By Label
450 [Arguments] ${namespace} ${key} ${value} ${number}
451 [Documentation] Succeeds if the desired pod has expected number replicas
452 ${rc} ${count} Run and Return Rc and Output
453 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o json | jq -r ".items[].status.phase" | wc -l
454 Should Be Equal as Integers ${count} ${number}
Andrea Campanella962fe832020-09-21 10:41:47 +0200455
456Get Number of Running Pods Number By Label
457 [Arguments] ${namespace} ${key} ${value}
458 [Documentation] Returns the number of pods for a given label
459 ${rc} ${count} Run and Return Rc and Output
460 ... kubectl -n ${namespace} get pods -l ${key}=${value} -o name | wc -l
461 [Return] ${count}