David Bainbridge | 117d23e | 2019-09-30 20:37:51 +0000 | [diff] [blame] | 1 | # 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 Bainbridge | 117d23e | 2019-09-30 20:37:51 +0000 | [diff] [blame] | 14 | # voltctl common functions |
| 15 | |
| 16 | *** Settings *** |
| 17 | Documentation Library for various utilities |
| 18 | Library SSHLibrary |
David Bainbridge | 117d23e | 2019-09-30 20:37:51 +0000 | [diff] [blame] | 19 | Library String |
| 20 | Library DateTime |
| 21 | Library Process |
| 22 | Library Collections |
| 23 | Library RequestsLibrary |
| 24 | Library OperatingSystem |
| 25 | |
| 26 | *** Keywords *** |
| 27 | Lookup Service IP |
| 28 | [Arguments] ${namespace} ${name} |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 29 | [Documentation] Uses kubectl to resolve a service name to an IP |
Gilles Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 30 | ${rc} ${ip}= Run and Return Rc and Output |
| 31 | ... kubectl get svc -n ${namespace} ${name} -o jsonpath={.spec.clusterIP} |
David Bainbridge | 117d23e | 2019-09-30 20:37:51 +0000 | [diff] [blame] | 32 | Should Be Equal as Integers ${rc} 0 |
| 33 | [Return] ${ip} |
| 34 | |
| 35 | Lookup Service PORT |
| 36 | [Arguments] ${namespace} ${name} |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 37 | [Documentation] Uses kubectl to resolve a service name to an PORT |
Gilles Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 38 | ${rc} ${port}= Run and Return Rc and Output |
| 39 | ... kubectl get svc -n ${namespace} ${name} -o jsonpath={.spec.ports[0].port} |
David Bainbridge | 117d23e | 2019-09-30 20:37:51 +0000 | [diff] [blame] | 40 | Should Be Equal as Integers ${rc} 0 |
| 41 | [Return] ${port} |
suraj gour | d64356b | 2019-11-07 13:26:20 +0000 | [diff] [blame] | 42 | |
| 43 | Restart Pod |
| 44 | [Arguments] ${namespace} ${name} |
| 45 | [Documentation] Uses kubectl to force delete pod |
suraj gour | 067451d | 2019-11-13 11:20:13 +0000 | [diff] [blame] | 46 | ${rc} ${restart_pod_name}= Run and Return Rc and Output |
| 47 | ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}' |
suraj gour | d64356b | 2019-11-07 13:26:20 +0000 | [diff] [blame] | 48 | Log ${restart_pod_name} |
suraj gour | 067451d | 2019-11-13 11:20:13 +0000 | [diff] [blame] | 49 | Should Not Be Empty ${restart_pod_name} Unable to parse pod name |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 50 | ${rc} ${output}= Run and Return Rc and Output |
| 51 | ... kubectl delete pod ${restart_pod_name} -n ${namespace} --grace-period=0 --force |
suraj gour | d64356b | 2019-11-07 13:26:20 +0000 | [diff] [blame] | 52 | Log ${output} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 53 | |
Scott Baker | 60e570d | 2020-02-02 22:10:13 -0800 | [diff] [blame] | 54 | Exec 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 |
| 58 | ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}' |
| 59 | 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 | |
| 66 | Exec 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 |
| 70 | ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}' |
| 71 | 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 Baker | 0478bab | 2020-04-10 17:19:57 -0700 | [diff] [blame] | 82 | Copy 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 Baker | 60e570d | 2020-02-02 22:10:13 -0800 | [diff] [blame] | 94 | Apply 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 Baker | 0478bab | 2020-04-10 17:19:57 -0700 | [diff] [blame] | 101 | Delete 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 gour | 1ecfae9 | 2019-12-20 15:11:40 +0000 | [diff] [blame] | 108 | Validate 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 Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 111 | ${length}= Run kubectl get pod -n ${namespace} -o name | wc -l |
| 112 | ${matched}= Set Variable False |
| 113 | FOR ${index} IN RANGE ${length} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 114 | ${currentPodName}= Run |
| 115 | ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.containerStatuses[0].name}" |
suraj gour | 1ecfae9 | 2019-12-20 15:11:40 +0000 | [diff] [blame] | 116 | Log Required Pod : ${pod_name} |
| 117 | Log Current Pod: ${currentPodName} |
Andy Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 118 | ${matched}= Set Variable If '${currentPodName}'=='${pod_name}' True False |
| 119 | Exit For Loop If ${matched} |
suraj gour | 1ecfae9 | 2019-12-20 15:11:40 +0000 | [diff] [blame] | 120 | END |
Andy Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 121 | Should Be True ${matched} No pod ${podname} found |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 122 | ${currentStatusofPod}= Run |
| 123 | ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.phase}" |
suraj gour | 1ecfae9 | 2019-12-20 15:11:40 +0000 | [diff] [blame] | 124 | Log ${currentStatusofPod} |
| 125 | Should Contain ${currentStatusofPod} ${expectedStatus} |
| 126 | |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 127 | Verify All Voltha Pods For Any Error Logs |
| 128 | [Arguments] ${datetime} |
| 129 | [Documentation] This keyword checks for the error occurence in the voltha pods |
| 130 | &{errorPodDict} Create Dictionary |
| 131 | &{containerDict} Get Container Dictionary |
| 132 | FOR ${podName} IN @{PODLIST1} |
| 133 | ${containerName} Get From Dictionary ${containerDict} ${podName} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 134 | ${rc} ${logOutput} Run And Return Rc And Output |
| 135 | ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName} |
| 136 | Run Keyword And Ignore Error |
| 137 | ... Run Keyword If '${logOutput}'=='${EMPTY}' |
| 138 | ... Run Keywords Log No Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 139 | ... AND Continue For Loop |
| 140 | ${errorDict} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput} |
| 141 | ${returnStatusFlagList} Get Dictionary Keys ${errorDict} |
| 142 | ${returnStatusFlag} Get From List ${returnStatusFlagList} 0 |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 143 | Run Keyword And Ignore Error |
| 144 | ... Run Keyword If '${returnStatusFlag}'=='Nologfound' |
| 145 | ... Run Keywords Log No Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 146 | ... AND Continue For Loop |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 147 | Run Keyword And Ignore Error |
| 148 | ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound' |
| 149 | ... Run Keywords Log Unexpected Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 150 | ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict} |
| 151 | END |
| 152 | FOR ${podName} IN @{PODLIST2} |
| 153 | ${containerName} Get From Dictionary ${containerDict} ${podName} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 154 | ${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.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 159 | ... AND Continue For Loop |
| 160 | ${errorDict} Check For Error Logs in Pod Type2 Given the Log Output ${logOutput} |
| 161 | ${returnStatusFlagList} Get Dictionary Keys ${errorDict} |
| 162 | ${returnStatusFlag} Get From List ${returnStatusFlagList} 0 |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 163 | Run Keyword And Ignore Error |
| 164 | ... Run Keyword If '${returnStatusFlag}'=='Nologfound' |
| 165 | ... Run Keywords Log No Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 166 | ... AND Continue For Loop |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 167 | Run Keyword And Ignore Error |
| 168 | ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound' |
| 169 | ... Run Keywords Log Unexpected Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 170 | ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict} |
| 171 | END |
| 172 | Print to Console Error Statement logged in the following pods : ${errorPodDict} |
| 173 | [Return] ${errorPodDict} |
| 174 | |
| 175 | Check For Error Logs in Pod Type1 Given the Log Output |
| 176 | [Arguments] ${logOutput} ${logLevel}=error ${errorMessage}=${EMPTY} |
| 177 | [Documentation] Checks for error message in the particular list of pods |
| 178 | Log ${logOutput} |
| 179 | ${linesContainingLog} = Get Lines Matching Regexp ${logOutput} .*\s\${logLevel}.* partial_match=true |
| 180 | ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 181 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' |
| 182 | ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound |
| 183 | ${linesContainingError} = Get Lines Matching Regexp |
| 184 | ... ${logOutput} .*\s\${logLevel}.*${errorMessage} partial_match=true |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 185 | ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 186 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' |
| 187 | ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 188 | Log {linesContainingError} |
| 189 | &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog} |
| 190 | [Return] ${errorDict} |
| 191 | |
| 192 | Check For Error Logs in Pod Type2 Given the Log Output |
| 193 | [Arguments] ${logOutput} ${logLevel}=warn ${errorMessage}=${EMPTY} |
| 194 | [Documentation] Checks for error message in the particular set of pods |
| 195 | Log ${logOutput} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 196 | ${linesContainingLog} = Get Lines Matching Regexp |
| 197 | ... ${logOutput} .*?\s.*level.*${logLevel}.* partial_match=true |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 198 | ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 199 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' |
| 200 | ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound |
| 201 | ${linesContainingError} = Get Lines Matching Regexp |
| 202 | ... ${logOutput} .*?\s.*level.*${logLevel}.*msg.*${errorMessage} partial_match=true |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 203 | ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 204 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' |
| 205 | ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 206 | Log {linesContainingError} |
| 207 | &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog} |
| 208 | [Return] ${errorDict} |
| 209 | |
| 210 | Get Container Dictionary |
| 211 | [Documentation] Creates a mapping for pod name and container name and returns the same |
| 212 | &{containerDict} Create Dictionary |
| 213 | ${containerName} Set Variable ${EMPTY} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 214 | ${podName} Run kubectl get deployment -n voltha | awk 'NR>1 {print $1}' |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 215 | @{podNameList}= Split To Lines ${podName} |
| 216 | Append To List ${podNameList} voltha-etcd-cluster voltha-kafka voltha-ro-core voltha-zookeeper |
| 217 | Log ${podNameList} |
| 218 | #Creatiing dictionary to correspond pod name and container name |
| 219 | FOR ${pod} IN @{podNameList} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 220 | ${containerName} Run kubectl get pod -n voltha | grep ${pod} | awk '{print $1}' |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 221 | &{containerDict} Set To Dictionary ${containerDict} ${pod} ${containerName} |
| 222 | END |
| 223 | Log ${containerDict} |
| 224 | [Return] ${containerDict} |
| 225 | |
| 226 | Validate Error For Given Pods |
| 227 | [Arguments] ${datetime} ${podDict} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 228 | [Documentation] |
| 229 | ... This keyword is used to get the list of pods if there is any unexpected error |
| 230 | ... in a particular pod(s) given the time-${datetime} from which the log needs to |
| 231 | ... be analysed and the dictionary of pods and the error in the dictionary format |
| 232 | ... ${podDict] . |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 233 | ... |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 234 | ... Usage: ${returnStatusFlag} Validate Error For Given Pods ${datetime} ${podDict} |
| 235 | ... |
| 236 | ... Arguments: |
| 237 | ... |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 238 | ... ${datetime} = time from which the log needs to be taken |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 239 | ... ${podDict} = Key-value pair of the pod name and the error msg |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 240 | ... |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 241 | ... Example: ${podDict} = Set Dictionary ${podDict} radius sample error message. |
| 242 | ... |
| 243 | ... In case the radius pod log has any other error than the expected |
| 244 | ... error, then the podname will be returned |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 245 | ${podList} = Get Dictionary Keys ${podDict} |
| 246 | FOR ${podName} IN @{podList} |
| 247 | ${containerName} Get From Dictionary ${containerDict} ${podName} |
| 248 | ${expectedError} Get From Dictionary ${podDict} ${podName} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 249 | ${rc} ${logOutput} Run And Return Rc And Output |
| 250 | ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName} |
| 251 | Run Keyword And Ignore Error |
| 252 | ... Run Keyword If '${logOutput}'=='${EMPTY}' |
| 253 | ... Run Keywords Log No Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 254 | ... AND Continue For Loop |
| 255 | ${returnStatusFlag} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 256 | Run Keyword And Ignore Error |
| 257 | ... Run Keyword If '${returnStatusFlag}'=='Nologfound' |
| 258 | ... Run Keywords Log No Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 259 | ... AND Continue For Loop |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 260 | Run Keyword And Ignore Error |
| 261 | ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound' |
| 262 | ... Run Keywords Log Unexpected Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 263 | ... AND Append To List ${errorPodList} ${podName} |
| 264 | END |
| 265 | [Return] ${errorPodList} |
| 266 | |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 267 | Delete K8s Pod |
| 268 | [Arguments] ${namespace} ${name} |
| 269 | [Documentation] Uses kubectl to delete a named POD |
| 270 | ${rc} Run and Return Rc |
| 271 | ... kubectl delete -n ${namespace} pod/${name} |
| 272 | Should Be Equal as Integers ${rc} 0 |
| 273 | |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 274 | Delete K8s Pods By Label |
| 275 | [Arguments] ${namespace} ${key} ${value} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 276 | [Documentation] Uses kubectl to delete a PODs, filtering by label |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 277 | ${rc}= Run and Return Rc |
| 278 | ... kubectl -n ${namespace} delete pods -l${key}=${value} |
| 279 | Should Be Equal as Integers ${rc} 0 |
| 280 | |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 281 | Scale K8s Deployment |
| 282 | [Arguments] ${namespace} ${name} ${count} |
| 283 | [Documentation] Uses kubectl to scale a named deployment |
| 284 | ${rc} Run and Return Rc |
| 285 | ... kubectl scale --replicas=${count} -n ${namespace} deploy/${name} |
| 286 | Should Be Equal as Integers ${rc} 0 |
| 287 | |
| 288 | Pod Exists |
| 289 | [Arguments] ${namespace} ${name} |
| 290 | [Documentation] Succeeds it the named POD exists |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 291 | ${rc} ${count} Run and Return Rc |
| 292 | ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep ${name} |
Andy Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 293 | Should Be True ${count}>0 Pod ${name} not found |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 294 | |
| 295 | Pod Does Not Exist |
| 296 | [Arguments] ${namespace} ${name} |
| 297 | [Documentation] Succeeds if the named POD does not exist |
| 298 | ${rc} ${count} Run and Return Rc And Output |
| 299 | ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep -c ${name} |
| 300 | Should Be Equal As Integers ${count} 0 |
Andy Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 301 | Should Be True ${count}==0 Pod ${name} exists but should not |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 302 | |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 303 | Pods Do Not Exist By Label |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 304 | [Arguments] ${namespace} ${key} ${value} |
| 305 | [Documentation] Succeeds if the named POD does not exist |
| 306 | ${rc} ${count} Run and Return Rc And Output |
| 307 | ... kubectl get -n ${namespace} pod -l${key}=${value} -o json | jq -r ".items[].metadata.name" | wc -l |
| 308 | Should Be Equal As Integers ${count} 0 |
Andy Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 309 | Should Be True ${count}==0 Pod with label ${key}=${value} exists but should not |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 310 | |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 311 | Get Available Deployment Replicas |
| 312 | [Arguments] ${namespace} ${name} |
| 313 | [Documentation] Succeeds if the named POD exists and has a ready count > 0 |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 314 | ${rc} ${count} Run and Return Rc and Output |
| 315 | ... kubectl get -n ${namespace} deploy/${name} -o jsonpath='{.status.availableReplicas}' |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 316 | ${result}= Run Keyword If '${count}' == '' Set Variable 0 |
| 317 | ... ELSE Set Variable ${count} |
| 318 | [Return] ${result} |
| 319 | |
| 320 | Check Expected Available Deployment Replicas |
| 321 | [Arguments] ${namespace} ${name} ${expected} |
| 322 | [Documentation] Succeeds if the named deployment has the expected number of available replicas |
| 323 | ${count}= Get Available Deployment Replicas ${namespace} ${name} |
| 324 | Should Be Equal As Integers ${expected} ${count} |
| 325 | |
| 326 | Get Deployment Replica Count |
| 327 | [Arguments] ${namespace} ${name} |
| 328 | [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment |
| 329 | ${rc} ${value} Run and Return Rc and Output |
| 330 | ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}' |
| 331 | Should Be Equal as Integers ${rc} 0 |
| 332 | ${replicas}= Run Keyword If '${value}' == '' Set Variable 0 |
| 333 | ... ELSE Set Variable ${value} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 334 | [Return] ${replicas} |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 335 | |
| 336 | Does Deployment Have Replicas |
| 337 | [Arguments] ${namespace} ${name} ${expected_count} |
| 338 | [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment |
| 339 | ${rc} ${value} Run and Return Rc and Output |
| 340 | ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}' |
| 341 | Should Be Equal as Integers ${rc} 0 |
| 342 | ${replicas}= Run Keyword If '${value}' == '' Set Variable 0 |
| 343 | ... ELSE Set Variable ${value} |
| 344 | Should be Equal as Integers ${replicas} ${expected_count} |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 345 | |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 346 | Pods Are Ready By Label |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 347 | [Arguments] ${namespace} ${key} ${value} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 348 | [Documentation] Check that all pods with a label are ready |
| 349 | ${output}= Run |
| 350 | ... kubectl -n ${namespace} get pods -l ${key}=${value} -o=jsonpath="{.items[].status.containerStatuses[].ready}" |
| 351 | Should Not Contain ${output} "false" |
Gayathri.Selvan | 4939896 | 2020-01-13 07:19:12 +0000 | [diff] [blame] | 352 | |
hwchiu | 58af72d | 2020-01-14 00:50:35 +0000 | [diff] [blame] | 353 | Check Expected Running Pods Number By Label |
| 354 | [Arguments] ${namespace} ${key} ${value} ${number} |
| 355 | [Documentation] Succeeds if the desired pod has expected number replicas |
| 356 | ${rc} ${count} Run and Return Rc and Output |
| 357 | ... kubectl -n ${namespace} get pods -l ${key}=${value} -o json | jq -r ".items[].status.phase" | wc -l |
| 358 | Should Be Equal as Integers ${count} ${number} |
Gayathri.Selvan | f68ea4b | 2020-02-03 07:36:39 +0000 | [diff] [blame] | 359 | |