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