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