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. |
| 14 | |
| 15 | # voltctl common functions |
| 16 | |
| 17 | *** Settings *** |
| 18 | Documentation Library for various utilities |
| 19 | Library SSHLibrary |
| 20 | Library HttpLibrary.HTTP |
| 21 | Library String |
| 22 | Library DateTime |
| 23 | Library Process |
| 24 | Library Collections |
| 25 | Library RequestsLibrary |
| 26 | Library OperatingSystem |
| 27 | |
| 28 | *** Keywords *** |
| 29 | Lookup Service IP |
| 30 | [Arguments] ${namespace} ${name} |
| 31 | [Documentation] Uses kubeclt to resolve a service name to an IP |
Gilles Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 32 | ${rc} ${ip}= Run and Return Rc and Output |
| 33 | ... kubectl get svc -n ${namespace} ${name} -o jsonpath={.spec.clusterIP} |
David Bainbridge | 117d23e | 2019-09-30 20:37:51 +0000 | [diff] [blame] | 34 | Should Be Equal as Integers ${rc} 0 |
| 35 | [Return] ${ip} |
| 36 | |
| 37 | Lookup Service PORT |
| 38 | [Arguments] ${namespace} ${name} |
| 39 | [Documentation] Uses kubeclt to resolve a service name to an PORT |
Gilles Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 40 | ${rc} ${port}= Run and Return Rc and Output |
| 41 | ... kubectl get svc -n ${namespace} ${name} -o jsonpath={.spec.ports[0].port} |
David Bainbridge | 117d23e | 2019-09-30 20:37:51 +0000 | [diff] [blame] | 42 | Should Be Equal as Integers ${rc} 0 |
| 43 | [Return] ${port} |
suraj gour | d64356b | 2019-11-07 13:26:20 +0000 | [diff] [blame] | 44 | |
| 45 | Restart Pod |
| 46 | [Arguments] ${namespace} ${name} |
| 47 | [Documentation] Uses kubectl to force delete pod |
suraj gour | 067451d | 2019-11-13 11:20:13 +0000 | [diff] [blame] | 48 | ${rc} ${restart_pod_name}= Run and Return Rc and Output |
| 49 | ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}' |
suraj gour | d64356b | 2019-11-07 13:26:20 +0000 | [diff] [blame] | 50 | Log ${restart_pod_name} |
suraj gour | 067451d | 2019-11-13 11:20:13 +0000 | [diff] [blame] | 51 | Should Not Be Empty ${restart_pod_name} Unable to parse pod name |
suraj gour | d64356b | 2019-11-07 13:26:20 +0000 | [diff] [blame] | 52 | ${rc} ${output}= Run and Return Rc and Output kubectl delete pod ${restart_pod_name} -n ${namespace} --grace-period=0 --force |
| 53 | Log ${output} |
Gayathri.Selvan | 61fbcdb | 2019-11-14 05:08:19 +0000 | [diff] [blame] | 54 | |
| 55 | Verify All Voltha Pods For Any Error Logs |
| 56 | [Arguments] ${datetime} |
| 57 | [Documentation] This keyword checks for the error occurence in the voltha pods |
| 58 | &{errorPodDict} Create Dictionary |
| 59 | &{containerDict} Get Container Dictionary |
| 60 | FOR ${podName} IN @{PODLIST1} |
| 61 | ${containerName} Get From Dictionary ${containerDict} ${podName} |
| 62 | ${rc} ${logOutput} Run And Return Rc And Output ${KUBECTL_CONFIG};kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName} |
| 63 | Run Keyword And Ignore Error Run Keyword If '${logOutput}'=='${EMPTY}' Run Keywords Log No Log found in pod ${podName} |
| 64 | ... AND Continue For Loop |
| 65 | ${errorDict} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput} |
| 66 | ${returnStatusFlagList} Get Dictionary Keys ${errorDict} |
| 67 | ${returnStatusFlag} Get From List ${returnStatusFlagList} 0 |
| 68 | Run Keyword And Ignore Error Run Keyword If '${returnStatusFlag}'=='Nologfound' Run Keywords Log No Error Log found in pod ${podName} |
| 69 | ... AND Continue For Loop |
| 70 | Run Keyword And Ignore Error Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound' Run Keywords Log Unexpected Error Log found in pod ${podName} |
| 71 | ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict} |
| 72 | END |
| 73 | FOR ${podName} IN @{PODLIST2} |
| 74 | ${containerName} Get From Dictionary ${containerDict} ${podName} |
| 75 | ${rc} ${logOutput} Run And Return Rc And Output ${KUBECTL_CONFIG};kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName} |
| 76 | Run Keyword And Ignore Error Run Keyword If '${logOutput}'=='${EMPTY}' Run Keywords Log No Log found in pod ${podName} |
| 77 | ... AND Continue For Loop |
| 78 | ${errorDict} Check For Error Logs in Pod Type2 Given the Log Output ${logOutput} |
| 79 | ${returnStatusFlagList} Get Dictionary Keys ${errorDict} |
| 80 | ${returnStatusFlag} Get From List ${returnStatusFlagList} 0 |
| 81 | Run Keyword And Ignore Error Run Keyword If '${returnStatusFlag}'=='Nologfound' Run Keywords Log No Error Log found in pod ${podName} |
| 82 | ... AND Continue For Loop |
| 83 | Run Keyword And Ignore Error Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound' Run Keywords Log Unexpected Error Log found in pod ${podName} |
| 84 | ... AND Set to Dictionary ${errorPodDict} ${podName} ${errorDict} |
| 85 | END |
| 86 | Print to Console Error Statement logged in the following pods : ${errorPodDict} |
| 87 | [Return] ${errorPodDict} |
| 88 | |
| 89 | Check For Error Logs in Pod Type1 Given the Log Output |
| 90 | [Arguments] ${logOutput} ${logLevel}=error ${errorMessage}=${EMPTY} |
| 91 | [Documentation] Checks for error message in the particular list of pods |
| 92 | Log ${logOutput} |
| 93 | ${linesContainingLog} = Get Lines Matching Regexp ${logOutput} .*\s\${logLevel}.* partial_match=true |
| 94 | ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog} |
| 95 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' Nologfound '${is_exec_status}'=='FAIL' Errorlogfound |
| 96 | ${linesContainingError} = Get Lines Matching Regexp ${logOutput} .*\s\${logLevel}.*${errorMessage} partial_match=true |
| 97 | ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError} |
| 98 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound |
| 99 | Log {linesContainingError} |
| 100 | &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog} |
| 101 | [Return] ${errorDict} |
| 102 | |
| 103 | Check For Error Logs in Pod Type2 Given the Log Output |
| 104 | [Arguments] ${logOutput} ${logLevel}=warn ${errorMessage}=${EMPTY} |
| 105 | [Documentation] Checks for error message in the particular set of pods |
| 106 | Log ${logOutput} |
| 107 | ${linesContainingLog} = Get Lines Matching Regexp ${logOutput} .*?\s.*level.*${logLevel}.* partial_match=true |
| 108 | ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingLog} |
| 109 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' Nologfound '${is_exec_status}'=='FAIL' Errorlogfound |
| 110 | ${linesContainingError} = Get Lines Matching Regexp ${logOutput} .*?\s.*level.*${logLevel}.*msg.*${errorMessage} partial_match=true |
| 111 | ${is_exec_status} ${output} Run Keyword And Ignore Error Should Be Empty ${linesContainingError} |
| 112 | ${returnStatusFlag} Set Variable If '${is_exec_status}'=='PASS' UnexpectedErrorfound '${is_exec_status}'=='FAIL' MatchingErrorlogfound |
| 113 | Log {linesContainingError} |
| 114 | &{errorDict} Create Dictionary ${returnStatusFlag} ${linesContainingLog} |
| 115 | [Return] ${errorDict} |
| 116 | |
| 117 | Get Container Dictionary |
| 118 | [Documentation] Creates a mapping for pod name and container name and returns the same |
| 119 | &{containerDict} Create Dictionary |
| 120 | ${containerName} Set Variable ${EMPTY} |
| 121 | ${podName} Run ${KUBECTL_CONFIG};kubectl get deployment -n voltha | awk 'NR>1 {print $1}' |
| 122 | @{podNameList}= Split To Lines ${podName} |
| 123 | Append To List ${podNameList} voltha-etcd-cluster voltha-kafka voltha-ro-core voltha-zookeeper |
| 124 | Log ${podNameList} |
| 125 | #Creatiing dictionary to correspond pod name and container name |
| 126 | FOR ${pod} IN @{podNameList} |
| 127 | ${containerName} Run ${KUBECTL_CONFIG};kubectl get pod -n voltha | grep ${pod} | awk '{print $1}' |
| 128 | &{containerDict} Set To Dictionary ${containerDict} ${pod} ${containerName} |
| 129 | END |
| 130 | Log ${containerDict} |
| 131 | [Return] ${containerDict} |
| 132 | |
| 133 | Validate Error For Given Pods |
| 134 | [Arguments] ${datetime} ${podDict} |
| 135 | [Documentation] This keyword is used to get the list of pods if there is any unexpected error in a particular pod(s) given the time-${datetime} from which the log needs to be analysed and the dictionary of pods and the error in the dictionary format ${podDict] . |
| 136 | ... |
| 137 | ... Usage : ${returnStatusFlag} Validate Error For Given Pods ${datetime} ${podDict} |
| 138 | ... where, |
| 139 | ... ${datetime} = time from which the log needs to be taken |
| 140 | ... ${podDict} = Key-value pair of the pod name and the error msg expected like ${podDict} = Set Dictionary ${podDict} radius sample error message. |
| 141 | ... |
| 142 | ... In case the radius pod log has any other error than the expected error, then the podname will be returned |
| 143 | ${podList} = Get Dictionary Keys ${podDict} |
| 144 | FOR ${podName} IN @{podList} |
| 145 | ${containerName} Get From Dictionary ${containerDict} ${podName} |
| 146 | ${expectedError} Get From Dictionary ${podDict} ${podName} |
| 147 | ${rc} ${logOutput} Run And Return Rc And Output ${KUBECTL_CONFIG};kubectl logs --timestamps -n voltha --since-time=${datetime} ${containerName} |
| 148 | Run Keyword And Ignore Error Run Keyword If '${logOutput}'=='${EMPTY}' Run Keywords Log No Log found in pod ${podName} |
| 149 | ... AND Continue For Loop |
| 150 | ${returnStatusFlag} Check For Error Logs in Pod Type1 Given the Log Output ${logOutput} |
| 151 | Run Keyword And Ignore Error Run Keyword If '${returnStatusFlag}'=='Nologfound' Run Keywords Log No Error Log found in pod ${podName} |
| 152 | ... AND Continue For Loop |
| 153 | Run Keyword And Ignore Error Run Keyword If '${returnStatusFlag}'=='UnexpectedErrorfound' Run Keywords Log Unexpected Error Log found in pod ${podName} |
| 154 | ... AND Append To List ${errorPodList} ${podName} |
| 155 | END |
| 156 | [Return] ${errorPodList} |
| 157 | |