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 |
Andrea Campanella | 1b25ac5 | 2020-09-09 14:34:31 +0200 | [diff] [blame] | 58 | ... kubectl -n ${namespace} get pods -l app=${name} -o name |
Scott Baker | 60e570d | 2020-02-02 22:10:13 -0800 | [diff] [blame] | 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 | |
Holger Hildebrandt | 2314774 | 2020-11-16 10:13:21 +0000 | [diff] [blame] | 66 | Exec Pod In Kube |
TorstenThieme | fe7099e | 2021-01-29 08:41:04 +0000 | [diff] [blame] | 67 | [Arguments] ${namespace} ${name} ${command} ${grep}=${EMPTY} |
Holger Hildebrandt | 2314774 | 2020-11-16 10:13:21 +0000 | [diff] [blame] | 68 | [Documentation] Uses kubectl to execute a command in the pod and return the output |
TorstenThieme | fe7099e | 2021-01-29 08:41:04 +0000 | [diff] [blame] | 69 | ${rc} ${exec_pod_name}= Run Keyword If '${grep}'=='${EMPTY}' |
| 70 | ... Run and Return Rc and Output kubectl -n ${namespace} get pods -l app.kubernetes.io/name=${name} -o name |
| 71 | ... ELSE Run and Return Rc and Output |
| 72 | ... kubectl -n ${namespace} get pods -l app.kubernetes.io/name=${name} -o name \| grep ${grep} |
Hardik Windlass | ec86c23 | 2021-02-02 13:56:12 +0000 | [diff] [blame] | 73 | Log ${exec_pod_name} |
| 74 | Should Not Be Empty ${exec_pod_name} Unable to parse pod name |
| 75 | ${rc} ${output}= Run and Return Rc and Output |
| 76 | ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- ${command} |
| 77 | Log ${output} |
| 78 | [return] ${output} |
Matteo Scandolo | a80b473 | 2020-09-04 13:51:10 -0700 | [diff] [blame] | 79 | |
| 80 | Exec Pod And Return Output And RC |
| 81 | [Arguments] ${namespace} ${name} ${command} |
| 82 | [Documentation] Uses kubectl to execute a command in the pod and return the output |
| 83 | ${rc} ${exec_pod_name}= Run and Return Rc and Output |
| 84 | ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}' |
Holger Hildebrandt | 2314774 | 2020-11-16 10:13:21 +0000 | [diff] [blame] | 85 | Log ${exec_pod_name} |
| 86 | Should Not Be Empty ${exec_pod_name} Unable to parse pod name |
| 87 | ${rc} ${output}= Run and Return Rc and Output |
| 88 | ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- ${command} |
| 89 | Log ${output} |
Matteo Scandolo | a80b473 | 2020-09-04 13:51:10 -0700 | [diff] [blame] | 90 | [return] ${output} ${rc} |
Holger Hildebrandt | 2314774 | 2020-11-16 10:13:21 +0000 | [diff] [blame] | 91 | |
Scott Baker | 60e570d | 2020-02-02 22:10:13 -0800 | [diff] [blame] | 92 | Exec Pod Separate Stderr |
| 93 | [Arguments] ${namespace} ${name} ${command} |
| 94 | [Documentation] Uses kubectl to execute a command in the pod and return the stderr and stdout |
| 95 | ${rc} ${exec_pod_name}= Run and Return Rc and Output |
Andrea Campanella | 1b25ac5 | 2020-09-09 14:34:31 +0200 | [diff] [blame] | 96 | ... kubectl -n ${namespace} get pods -l app=${name} -o name |
Scott Baker | 60e570d | 2020-02-02 22:10:13 -0800 | [diff] [blame] | 97 | Log ${exec_pod_name} |
| 98 | Should Not Be Empty ${exec_pod_name} Unable to parse pod name |
| 99 | @{args}= Split String ${command} |
| 100 | ${result}= Run Process |
| 101 | ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- @{args} |
| 102 | ${stdout}= Set Variable ${result.stdout} |
| 103 | ${stderr}= Set Variable ${result.stderr} |
| 104 | Log ${stdout} |
| 105 | Log ${stderr} |
| 106 | [return] ${stdout} ${stderr} |
| 107 | |
Scott Baker | 0478bab | 2020-04-10 17:19:57 -0700 | [diff] [blame] | 108 | Copy File To Pod |
| 109 | [Arguments] ${namespace} ${name} ${src} ${dest} |
| 110 | [Documentation] Uses kubectl to copy a file to a pod |
| 111 | ${rc} ${exec_pod_name}= Run and Return Rc and Output |
| 112 | ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}' |
| 113 | Log ${exec_pod_name} |
| 114 | Should Not Be Empty ${exec_pod_name} Unable to parse pod name |
| 115 | ${rc} ${output}= Run and Return Rc and Output |
| 116 | ... kubectl cp -n ${namespace} ${src} ${exec_pod_name}:${dest} |
| 117 | Log ${output} |
| 118 | [return] ${output} |
| 119 | |
Scott Baker | 60e570d | 2020-02-02 22:10:13 -0800 | [diff] [blame] | 120 | Apply Kubernetes Resources |
| 121 | [Arguments] ${resource_yaml} ${namespace} |
| 122 | [Documentation] Use kubectl to create resources given a yaml file |
| 123 | ${rc} Run and Return Rc |
| 124 | ... kubectl apply -n ${namespace} -f ${resource_yaml} |
| 125 | Should Be Equal as Integers ${rc} 0 |
| 126 | |
Scott Baker | 0478bab | 2020-04-10 17:19:57 -0700 | [diff] [blame] | 127 | Delete Kubernetes Resources |
| 128 | [Arguments] ${resource_yaml} ${namespace} |
| 129 | [Documentation] Use kubectl to delete resources given a yaml file |
| 130 | ${rc} Run and Return Rc |
| 131 | ... kubectl delete -n ${namespace} -f ${resource_yaml} |
| 132 | Should Be Equal as Integers ${rc} 0 |
| 133 | |
suraj gour | 1ecfae9 | 2019-12-20 15:11:40 +0000 | [diff] [blame] | 134 | Validate Pod Status |
| 135 | [Arguments] ${pod_name} ${namespace} ${expectedStatus} |
| 136 | [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] | 137 | ${length}= Run kubectl get pod -n ${namespace} -o name | wc -l |
| 138 | ${matched}= Set Variable False |
| 139 | FOR ${index} IN RANGE ${length} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 140 | ${currentPodName}= Run |
| 141 | ... 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] | 142 | Log Required Pod : ${pod_name} |
| 143 | Log Current Pod: ${currentPodName} |
Andy Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 144 | ${matched}= Set Variable If '${currentPodName}'=='${pod_name}' True False |
| 145 | Exit For Loop If ${matched} |
suraj gour | 1ecfae9 | 2019-12-20 15:11:40 +0000 | [diff] [blame] | 146 | END |
Andy Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 147 | Should Be True ${matched} No pod ${podname} found |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 148 | ${currentStatusofPod}= Run |
| 149 | ... kubectl get pod -n ${namespace} -o=jsonpath="{.items[${index}].status.phase}" |
suraj gour | 1ecfae9 | 2019-12-20 15:11:40 +0000 | [diff] [blame] | 150 | Log ${currentStatusofPod} |
| 151 | Should Contain ${currentStatusofPod} ${expectedStatus} |
| 152 | |
Matteo Scandolo | a80b473 | 2020-09-04 13:51:10 -0700 | [diff] [blame] | 153 | Get Pod Name By Label |
| 154 | [Arguments] ${namespace} ${label_key} ${label_value} |
| 155 | [Documentation] Return a pod name from a given label |
| 156 | ${rc} ${pod_name}= Run and Return Rc and Output |
| 157 | ... kubectl get pods -n ${namespace} -l ${label_key}=${label_value} --no-headers | awk '{print $1}' |
| 158 | Should Not Be Empty ${pod_name} Pod not found |
| 159 | [return] ${pod_name} |
| 160 | |
Hung-Wei Chiu | 2bee4d4 | 2020-04-24 11:31:50 -0700 | [diff] [blame] | 161 | Validate Pods Status By Label |
| 162 | [Arguments] ${namespace} ${label_key} ${label_value} ${expectedStatus} |
| 163 | [Documentation] To run the kubectl command and check the status of all pods filter |
| 164 | ... by label matche the expected status |
| 165 | ${command}= Catenate |
| 166 | ... kubectl -n ${namespace} get pods -l ${label_key}=${label_value} |
| 167 | ... -o=jsonpath="{.items[?(.status.phase=='${expectedStatus}')].status.phase}" |
| 168 | ${pods_status}= Run ${command} |
| 169 | Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus} |
| 170 | |
Andrea Campanella | 4c40463 | 2020-08-26 14:41:36 +0200 | [diff] [blame] | 171 | Validate Pods Status By Name |
| 172 | [Arguments] ${namespace} ${name} ${expectedStatus} |
| 173 | [Documentation] To run the kubectl command and check the status of all pods filter |
| 174 | ... by label matche the expected status |
| 175 | ${command}= Catenate |
| 176 | ... kubectl -n ${namespace} get pods ${name} |
| 177 | ... -o=jsonpath="{.status.phase}" |
| 178 | ${pods_status}= Run ${command} |
| 179 | Should Not Be Equal ${pods_status} ${EMPTY} Can't filter out Pods with exptected status ${expectedStatus} |
| 180 | |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 181 | Verify All Voltha Pods For Any Error Logs |
| 182 | [Arguments] ${datetime} |
| 183 | [Documentation] This keyword checks for the error occurence in the voltha pods |
| 184 | &{errorPodDict} Create Dictionary |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 185 | &{containerDict} Get Container Dictionary voltha |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 186 | FOR ${podName} IN @{PODLIST1} |
| 187 | ${containerName} Get From Dictionary ${containerDict} ${podName} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 188 | ${rc} ${logOutput} Run And Return Rc And Output |
| 189 | ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName} |
| 190 | Run Keyword And Ignore Error |
| 191 | ... Run Keyword If '${logOutput}'=='${EMPTY}' |
| 192 | ... Run Keywords Log No Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 193 | ... AND Continue For Loop |
| 194 | ${errorDict} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput} |
| 195 | ${returnStatusFlagList} Get Dictionary Keys ${errorDict} |
| 196 | ${returnStatusFlag} Get From List ${returnStatusFlagList} 0 |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 197 | Run Keyword And Ignore Error |
| 198 | ... Run Keyword If '${returnStatusFlag}'=='Nologfound' |
| 199 | ... Run Keywords Log No Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 200 | ... AND Continue For Loop |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 201 | Run Keyword And Ignore Error |
| 202 | ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound' |
| 203 | ... Run Keywords Log Unexpected Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 204 | ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict} |
| 205 | END |
| 206 | FOR ${podName} IN @{PODLIST2} |
| 207 | ${containerName} Get From Dictionary ${containerDict} ${podName} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 208 | ${rc} ${logOutput} Run And Return Rc And Output |
| 209 | ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName} |
| 210 | Run Keyword And Ignore Error |
| 211 | ... Run Keyword If '${logOutput}'=='${EMPTY}' |
| 212 | ... Run Keywords Log No Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 213 | ... AND Continue For Loop |
| 214 | ${errorDict} Check For Error Logs in Pod Type2 Given the Log Output ${logOutput} |
| 215 | ${returnStatusFlagList} Get Dictionary Keys ${errorDict} |
| 216 | ${returnStatusFlag} Get From List ${returnStatusFlagList} 0 |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 217 | Run Keyword And Ignore Error |
| 218 | ... Run Keyword If '${returnStatusFlag}'=='Nologfound' |
| 219 | ... Run Keywords Log No Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 220 | ... AND Continue For Loop |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 221 | Run Keyword And Ignore Error |
| 222 | ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound' |
| 223 | ... Run Keywords Log Unexpected Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 224 | ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict} |
| 225 | END |
| 226 | Print to Console Error Statement logged in the following pods : ${errorPodDict} |
| 227 | [Return] ${errorPodDict} |
| 228 | |
| 229 | Check For Error Logs in Pod Type1 Given the Log Output |
| 230 | [Arguments] ${logOutput} ${logLevel}=error ${errorMessage}=${EMPTY} |
| 231 | [Documentation] Checks for error message in the particular list of pods |
| 232 | Log ${logOutput} |
| 233 | ${linesContainingLog} = Get Lines Matching Regexp ${logOutput} .*\s\${logLevel}.* partial_match=true |
| 234 | ${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] | 235 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' |
| 236 | ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound |
| 237 | ${linesContainingError} = Get Lines Matching Regexp |
| 238 | ... ${logOutput} .*\s\${logLevel}.*${errorMessage} partial_match=true |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 239 | ${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] | 240 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' |
| 241 | ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 242 | Log {linesContainingError} |
| 243 | &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog} |
| 244 | [Return] ${errorDict} |
| 245 | |
| 246 | Check For Error Logs in Pod Type2 Given the Log Output |
| 247 | [Arguments] ${logOutput} ${logLevel}=warn ${errorMessage}=${EMPTY} |
| 248 | [Documentation] Checks for error message in the particular set of pods |
| 249 | Log ${logOutput} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 250 | ${linesContainingLog} = Get Lines Matching Regexp |
| 251 | ... ${logOutput} .*?\s.*level.*${logLevel}.* partial_match=true |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 252 | ${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] | 253 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' |
| 254 | ... Nologfound '${is_exec_status}'=='FAIL' Errorlogfound |
| 255 | ${linesContainingError} = Get Lines Matching Regexp |
| 256 | ... ${logOutput} .*?\s.*level.*${logLevel}.*msg.*${errorMessage} partial_match=true |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 257 | ${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] | 258 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' |
| 259 | ... UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 260 | Log {linesContainingError} |
| 261 | &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog} |
| 262 | [Return] ${errorDict} |
| 263 | |
| 264 | Get Container Dictionary |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 265 | [Arguments] ${namespace} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 266 | [Documentation] Creates a mapping for pod name and container name and returns the same |
| 267 | &{containerDict} Create Dictionary |
| 268 | ${containerName} Set Variable ${EMPTY} |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 269 | ${podName} Run kubectl get deployment -n ${namespace} | awk 'NR>1 {print $1}' |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 270 | @{podNameList}= Split To Lines ${podName} |
| 271 | Append To List ${podNameList} voltha-etcd-cluster voltha-kafka voltha-ro-core voltha-zookeeper |
| 272 | Log ${podNameList} |
| 273 | #Creatiing dictionary to correspond pod name and container name |
| 274 | FOR ${pod} IN @{podNameList} |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 275 | ${containerName} Run kubectl get pod -n ${namespace} | grep ${pod} | awk '{print $1}' |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 276 | &{containerDict} Set To Dictionary ${containerDict} ${pod} ${containerName} |
| 277 | END |
| 278 | Log ${containerDict} |
| 279 | [Return] ${containerDict} |
| 280 | |
| 281 | Validate Error For Given Pods |
| 282 | [Arguments] ${datetime} ${podDict} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 283 | [Documentation] |
| 284 | ... This keyword is used to get the list of pods if there is any unexpected error |
| 285 | ... in a particular pod(s) given the time-${datetime} from which the log needs to |
| 286 | ... be analysed and the dictionary of pods and the error in the dictionary format |
| 287 | ... ${podDict] . |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 288 | ... |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 289 | ... Usage: ${returnStatusFlag} Validate Error For Given Pods ${datetime} ${podDict} |
| 290 | ... |
| 291 | ... Arguments: |
| 292 | ... |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 293 | ... ${datetime} = time from which the log needs to be taken |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 294 | ... ${podDict} = Key-value pair of the pod name and the error msg |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 295 | ... |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 296 | ... Example: ${podDict} = Set Dictionary ${podDict} radius sample error message. |
| 297 | ... |
| 298 | ... In case the radius pod log has any other error than the expected |
| 299 | ... error, then the podname will be returned |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 300 | ${podList} = Get Dictionary Keys ${podDict} |
| 301 | FOR ${podName} IN @{podList} |
| 302 | ${containerName} Get From Dictionary ${containerDict} ${podName} |
| 303 | ${expectedError} Get From Dictionary ${podDict} ${podName} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 304 | ${rc} ${logOutput} Run And Return Rc And Output |
| 305 | ... kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName} |
| 306 | Run Keyword And Ignore Error |
| 307 | ... Run Keyword If '${logOutput}'=='${EMPTY}' |
| 308 | ... Run Keywords Log No Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 309 | ... AND Continue For Loop |
| 310 | ${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] | 311 | Run Keyword And Ignore Error |
| 312 | ... Run Keyword If '${returnStatusFlag}'=='Nologfound' |
| 313 | ... Run Keywords Log No Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 314 | ... AND Continue For Loop |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 315 | Run Keyword And Ignore Error |
| 316 | ... Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound' |
| 317 | ... Run Keywords Log Unexpected Error Log found in pod ${podName} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 318 | ... AND Append To List ${errorPodList} ${podName} |
| 319 | END |
| 320 | [Return] ${errorPodList} |
| 321 | |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 322 | Delete K8s Pod |
| 323 | [Arguments] ${namespace} ${name} |
| 324 | [Documentation] Uses kubectl to delete a named POD |
| 325 | ${rc} Run and Return Rc |
| 326 | ... kubectl delete -n ${namespace} pod/${name} |
| 327 | Should Be Equal as Integers ${rc} 0 |
| 328 | |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 329 | Delete K8s Pods By Label |
| 330 | [Arguments] ${namespace} ${key} ${value} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 331 | [Documentation] Uses kubectl to delete a PODs, filtering by label |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 332 | ${rc}= Run and Return Rc |
| 333 | ... kubectl -n ${namespace} delete pods -l${key}=${value} |
| 334 | Should Be Equal as Integers ${rc} 0 |
| 335 | |
Andrea Campanella | 4c40463 | 2020-08-26 14:41:36 +0200 | [diff] [blame] | 336 | Delete K8s Pods By Name |
| 337 | [Arguments] ${namespace} ${value} |
| 338 | [Documentation] Uses kubectl to delete a PODs, filtering by label |
| 339 | ${rc}= Run and Return Rc |
| 340 | ... kubectl -n ${namespace} delete pods ${value} |
| 341 | Should Be Equal as Integers ${rc} 0 |
| 342 | |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 343 | Scale K8s Deployment |
| 344 | [Arguments] ${namespace} ${name} ${count} |
| 345 | [Documentation] Uses kubectl to scale a named deployment |
| 346 | ${rc} Run and Return Rc |
| 347 | ... kubectl scale --replicas=${count} -n ${namespace} deploy/${name} |
| 348 | Should Be Equal as Integers ${rc} 0 |
| 349 | |
Andrea Campanella | 3dcce27 | 2021-01-15 16:04:47 +0100 | [diff] [blame] | 350 | Get K8s Deployment by Pod Label |
| 351 | [Arguments] ${namespace} ${key} ${value} |
| 352 | [Documentation] Uses kubectl to scale a deployment given the app name of the pod |
| 353 | ${rc} ${name} Run And Return Rc And Output |
| 354 | ... kubectl describe rs -n ${namespace} -l ${key}=${value} | grep "Controlled By" | awk -F'/' '{print $2}' |
| 355 | Should Be Equal as Integers ${rc} 0 |
| 356 | [Return] ${name} |
| 357 | |
| 358 | Scale K8s Deployment by Pod Label |
| 359 | [Arguments] ${namespace} ${key} ${value} ${count} |
| 360 | [Documentation] Uses kubectl to scale a deployment given the app name of the pod |
| 361 | ${name} Get K8s Deployment by Pod Label ${namespace} ${key} ${value} |
| 362 | Scale K8s Deployment ${namespace} ${name} ${count} |
| 363 | |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 364 | Pod Exists |
| 365 | [Arguments] ${namespace} ${name} |
| 366 | [Documentation] Succeeds it the named POD exists |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 367 | ${rc} ${count} Run and Return Rc |
| 368 | ... 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] | 369 | Should Be True ${count}>0 Pod ${name} not found |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 370 | |
| 371 | Pod Does Not Exist |
| 372 | [Arguments] ${namespace} ${name} |
| 373 | [Documentation] Succeeds if the named POD does not exist |
| 374 | ${rc} ${count} Run and Return Rc And Output |
| 375 | ... kubectl get -n ${namespace} pod -o json | jq -r ".items[].metadata.name" | grep -c ${name} |
| 376 | Should Be Equal As Integers ${count} 0 |
Andy Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 377 | Should Be True ${count}==0 Pod ${name} exists but should not |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 378 | |
TorstenThieme | d2cd91d | 2020-07-28 07:13:44 +0000 | [diff] [blame] | 379 | Wait For Pods Not Exist |
| 380 | [Arguments] ${namespace} ${list_names} |
| 381 | [Documentation] Checks the passed PODs are no longer existing |
TorstenThieme | fe7099e | 2021-01-29 08:41:04 +0000 | [diff] [blame] | 382 | FOR ${pod_name} IN @{list_names} |
TorstenThieme | d2cd91d | 2020-07-28 07:13:44 +0000 | [diff] [blame] | 383 | Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s |
TorstenThieme | fe7099e | 2021-01-29 08:41:04 +0000 | [diff] [blame] | 384 | ... Pod Does Not Exist ${namespace} ${pod_name} |
TorstenThieme | d2cd91d | 2020-07-28 07:13:44 +0000 | [diff] [blame] | 385 | END |
| 386 | |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 387 | Pods Do Not Exist By Label |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 388 | [Arguments] ${namespace} ${key} ${value} |
| 389 | [Documentation] Succeeds if the named POD does not exist |
| 390 | ${rc} ${count} Run and Return Rc And Output |
| 391 | ... kubectl get -n ${namespace} pod -l${key}=${value} -o json | jq -r ".items[].metadata.name" | wc -l |
| 392 | Should Be Equal As Integers ${count} 0 |
Andy Bavier | b63f6d2 | 2020-03-12 15:34:37 -0700 | [diff] [blame] | 393 | 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] | 394 | |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 395 | Get Available Deployment Replicas |
| 396 | [Arguments] ${namespace} ${name} |
| 397 | [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] | 398 | ${rc} ${count} Run and Return Rc and Output |
| 399 | ... kubectl get -n ${namespace} deploy/${name} -o jsonpath='{.status.availableReplicas}' |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 400 | ${result}= Run Keyword If '${count}' == '' Set Variable 0 |
| 401 | ... ELSE Set Variable ${count} |
| 402 | [Return] ${result} |
| 403 | |
Andrea Campanella | 3dcce27 | 2021-01-15 16:04:47 +0100 | [diff] [blame] | 404 | Check Expected Available Deployment Replicas By Pod Label |
| 405 | [Arguments] ${namespace} ${key} ${value} ${expected} |
| 406 | [Documentation] Succeeds if the named deployment has the expected number of available replicas |
| 407 | ${name} Get K8s Deployment by Pod Label ${namespace} ${key} ${value} |
| 408 | Check Expected Available Deployment Replicas ${namespace} ${name} ${expected} |
| 409 | |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 410 | Check Expected Available Deployment Replicas |
| 411 | [Arguments] ${namespace} ${name} ${expected} |
| 412 | [Documentation] Succeeds if the named deployment has the expected number of available replicas |
| 413 | ${count}= Get Available Deployment Replicas ${namespace} ${name} |
| 414 | Should Be Equal As Integers ${expected} ${count} |
| 415 | |
| 416 | Get Deployment Replica Count |
| 417 | [Arguments] ${namespace} ${name} |
| 418 | [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment |
| 419 | ${rc} ${value} Run and Return Rc and Output |
| 420 | ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}' |
| 421 | Should Be Equal as Integers ${rc} 0 |
| 422 | ${replicas}= Run Keyword If '${value}' == '' Set Variable 0 |
| 423 | ... ELSE Set Variable ${value} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 424 | [Return] ${replicas} |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 425 | |
| 426 | Does Deployment Have Replicas |
| 427 | [Arguments] ${namespace} ${name} ${expected_count} |
| 428 | [Documentation] Uses kubectl to fetch the number of configured replicas on a deployment |
| 429 | ${rc} ${value} Run and Return Rc and Output |
| 430 | ... kubectl -n ${namespace} get deploy/${name} -o 'jsonpath={.status.replicas}' |
| 431 | Should Be Equal as Integers ${rc} 0 |
| 432 | ${replicas}= Run Keyword If '${value}' == '' Set Variable 0 |
| 433 | ... ELSE Set Variable ${value} |
| 434 | Should be Equal as Integers ${replicas} ${expected_count} |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 435 | |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 436 | Pods Are Ready By Label |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 437 | [Arguments] ${namespace} ${key} ${value} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 438 | [Documentation] Check that all pods with a label are ready |
| 439 | ${output}= Run |
| 440 | ... kubectl -n ${namespace} get pods -l ${key}=${value} -o=jsonpath="{.items[].status.containerStatuses[].ready}" |
TorstenThieme | d2cd91d | 2020-07-28 07:13:44 +0000 | [diff] [blame] | 441 | Should Not Contain ${output} false |
| 442 | |
| 443 | Wait For Pods Ready |
| 444 | [Arguments] ${namespace} ${list_apps} |
| 445 | [Documentation] Checks the passed PODs are ready |
TorstenThieme | fe7099e | 2021-01-29 08:41:04 +0000 | [diff] [blame] | 446 | FOR ${app_name} IN @{list_apps} |
TorstenThieme | d2cd91d | 2020-07-28 07:13:44 +0000 | [diff] [blame] | 447 | Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 3s |
TorstenThieme | fe7099e | 2021-01-29 08:41:04 +0000 | [diff] [blame] | 448 | ... Pods Are Ready By Label ${namespace} app ${app_name} |
TorstenThieme | d2cd91d | 2020-07-28 07:13:44 +0000 | [diff] [blame] | 449 | END |
Gayathri.Selvan | 4939896 | 2020-01-13 07:19:12 +0000 | [diff] [blame] | 450 | |
hwchiu | 58af72d | 2020-01-14 00:50:35 +0000 | [diff] [blame] | 451 | Check Expected Running Pods Number By Label |
| 452 | [Arguments] ${namespace} ${key} ${value} ${number} |
| 453 | [Documentation] Succeeds if the desired pod has expected number replicas |
| 454 | ${rc} ${count} Run and Return Rc and Output |
| 455 | ... kubectl -n ${namespace} get pods -l ${key}=${value} -o json | jq -r ".items[].status.phase" | wc -l |
| 456 | Should Be Equal as Integers ${count} ${number} |
Andrea Campanella | 962fe83 | 2020-09-21 10:41:47 +0200 | [diff] [blame] | 457 | |
| 458 | Get Number of Running Pods Number By Label |
| 459 | [Arguments] ${namespace} ${key} ${value} |
| 460 | [Documentation] Returns the number of pods for a given label |
| 461 | ${rc} ${count} Run and Return Rc and Output |
| 462 | ... kubectl -n ${namespace} get pods -l ${key}=${value} -o name | wc -l |
| 463 | [Return] ${count} |