blob: 14857dd95960eea7e2ba49427f5b7091da7414f9 [file] [log] [blame]
Zack Williams821c5022020-01-15 15:11:46 -07001# 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*** Settings ***
16Documentation Library of functions related to kubectl and helm
17Library SSHLibrary
18Library Collections
19Library String
20Library OperatingSystem
21Library RequestsLibrary
22Library CORDRobot
23Resource utils.resource
24
25*** Keywords ***
26Helm Chart is Removed
27 [Documentation] Verify the specified helm chart has been removed
28 [Arguments] ${helm_chart}
29 ${rc}= Run And Return Rc
30 ... helm ls -q | grep ${helm_chart}
31 Should Be Equal As Integers ${rc} 1
32
33Kubernetes PODs in Namespace are Removed
34 [Documentation] Verify all Kubernetes pods in specified namespace have been removed
35 [Arguments] ${namespace}
36 ${rc} ${output}= Run And Return Rc And Output
37 ... kubectl get pods --no-headers -n ${namespace}
38 Should Contain ${output} No resources found
39
40Kubernetes PODs in Namespace are Running
41 [Documentation] Verify the number of Kubernetes pods that are running
42 ... in specified namespace is as expected
43 [Arguments] ${namespace} ${pod_num}
44 ${rc} ${output}= Run And Return Rc And Output
45 ... kubectl get pods -n ${namespace} | grep -i running | grep 1/1 | wc -l
46 Should Be Equal As Integers ${output} ${pod_num}
47
48Reinstall Voltha
49 [Documentation] Remove voltha helm chart and wait
50 Run helm delete --purge voltha
51 Wait Until Keyword Succeeds 60s 10s
52 ... Helm Chart is Removed voltha
53 Wait Until Keyword Succeeds 120s 10s
54 ... Kubernetes PODs in Namespace are Removed voltha
55 Sleep 10s
56 Run helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
57 # FIXME - HELM_CHARTS_DIR should a parameter
58 Run cd ${HELM_CHARTS_DIR}; helm dep up voltha
59 # FIXME - KUBERNETES_YAML should a parameter
60 Run helm install -n voltha -f ${KUBERNETES_YAML} ${HELM_CHARTS_DIR}/voltha
61 Wait Until Keyword Succeeds 60s 10s
62 ... Kubernetes PODs in Namespace are Running voltha ${VOLTHA_POD_NUM}
63 Sleep 10s
64
65Get Current Datetime On Kubernetes Node
66 [Documentation] Get UTC datetime in RFC3339ish format
67 [Arguments] ${ip} ${user} ${pass}
68 ${result}= Login And Run Command On Remote System
69 ... date -u +"%Y-%m-%dT%H:%M:%S.%NZ" ${ip} ${user} ${pass}
70 # FIXME - is this needed? Does date return multiple lines?
71 ${result}= Get Line ${result} 0
72 [Return] ${result}
73
74Log Kubernetes Container Log Since Time
75 [Documentation] Returns the output of kubectl logs of a pod since timestamp
76 [Arguments] ${datetime} ${pod_prefix}
77 # FIXME - rc var isn't checked and then overwritten in this set of commands
78 ${rc} ${namespace}= Run And Return Rc And Output
79 ... kubectl get pods --all-namespaces | grep ' ${pod_prefix}' | head -1 | awk '{print $1}'
80 ${rc} ${pod_name}= Run And Return Rc And Output
81 ... kubectl get pods --all-namespaces | grep ' ${pod_prefix}' | head -1 | awk '{print $2}'
82 ${rc} ${output}= Run Keyword If '${pod_prefix}' == 'onos'
83 ... Run And Return Rc And Output
84 ... kubectl logs --timestamps -n ${namespace} --since-time=${datetime} ${pod_name} -c onos
85 ... ELSE Run And Return Rc And Output
86 ... kubectl logs --timestamps -n ${namespace} --since-time=${datetime} ${pod_name}
87 Log ${output}
88
89Log Kubernetes Containers Logs Since Time
90 [Documentation] Given a datetime and list of containers, print logs for those containers
91 [Arguments] ${datetime} ${pod_list}
92 FOR ${pod_prefix} IN @{pod_list}
93 Log Kubernetes Container Log Since Time ${datetime} ${pod_prefix}
94 END
95
96Get Kubernetes POD Name By Prefix
97 [Documentation] Return the first POD name that starts with the specified prefix
98 [Arguments] ${prefix}
99 ${rc} ${output}= Run And Return Rc And Outputi
100 ... kubectl get pods --all-namespaces | grep '${prefix}' | head -1 | awk '{print $2}'
101 [Return] ${output}