blob: 35b05cf8553be16a1cd68a5edc259476c6cdf1ff [file] [log] [blame]
You Wang0c2b3662018-10-01 16:56:17 -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 utils/utils.py
23Library restApi.py
Zack Williamsc6722d52020-01-13 16:34:33 -070024Resource utils/utils.robot
You Wang0c2b3662018-10-01 16:56:17 -070025
26*** Keywords ***
27Helm Chart is Removed
You Wang88e1d852018-10-05 11:44:19 -070028 [Arguments] ${helm_chart}
You Wang0c2b3662018-10-01 16:56:17 -070029 [Documentation] Verify the specified helm chart has been removed
You Wang88e1d852018-10-05 11:44:19 -070030 ${rc}= Run And Return Rc ${export_kubeconfig}; helm ls -q | grep ${helm_chart}
You Wang0c2b3662018-10-01 16:56:17 -070031 Should Be Equal As Integers ${rc} 1
32
33Kubernetes PODs in Namespace are Removed
You Wang88e1d852018-10-05 11:44:19 -070034 [Arguments] ${namespace}
You Wang0c2b3662018-10-01 16:56:17 -070035 [Documentation] Verify all Kubernetes pods in specified namespace have been removed
You Wang88e1d852018-10-05 11:44:19 -070036 ${rc} ${output}= Run And Return Rc And Output ${export_kubeconfig}; kubectl get pods --no-headers -n ${namespace}
You Wang0c2b3662018-10-01 16:56:17 -070037 Should Contain ${output} No resources found
38
39Kubernetes PODs in Namespace are Running
You Wang88e1d852018-10-05 11:44:19 -070040 [Arguments] ${namespace} ${pod_num}
You Wang0c2b3662018-10-01 16:56:17 -070041 [Documentation] Verify the number of Kubernetes pods that are running in specified namespace is as expected
You Wang88e1d852018-10-05 11:44:19 -070042 ${rc} ${output}= Run And Return Rc And Output ${export_kubeconfig}; kubectl get pods -n ${namespace} | grep -i running | grep 1/1 | wc -l
You Wang0c2b3662018-10-01 16:56:17 -070043 Should Be Equal As Integers ${output} ${pod_num}
You Wang5be816a2018-10-11 16:45:31 -070044
45Reinstall Voltha
46 Run ${export_kubeconfig}; helm delete --purge voltha
47 Wait Until Keyword Succeeds 60s 10s Helm Chart is Removed voltha
48 Wait Until Keyword Succeeds 120s 10s Kubernetes PODs in Namespace are Removed voltha
You Wangddd04242018-11-29 16:41:31 -080049 Sleep 10s
You Wang5be816a2018-10-11 16:45:31 -070050 Run ${export_kubeconfig}; cd ${HELM_CHARTS_DIR}; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
51 Run ${export_kubeconfig}; cd ${HELM_CHARTS_DIR}; helm dep up voltha
You Wangddd04242018-11-29 16:41:31 -080052 Run ${export_kubeconfig}; helm install -n voltha -f ${KUBERNETES_YAML} ${HELM_CHARTS_DIR}/voltha
You Wang5be816a2018-10-11 16:45:31 -070053 Wait Until Keyword Succeeds 60s 10s Kubernetes PODs in Namespace are Running voltha ${VOLTHA_POD_NUM}
54 Sleep 10s
You Wang8fff6a02018-10-15 16:26:54 -070055
56Get Current Datetime On Kubernetes Node
57 [Arguments] ${ip} ${user} ${pass}
58 ${result}= Login And Run Command On Remote System date +"%Y-%m-%dT%H:%M:%S.%NZ" ${ip} ${user} ${pass}
59 ${result}= Get Line ${result} 0
60 [Return] ${result}
61
62Log Kubernetes Container Log Since Time
You Wang41ca5372018-10-19 13:36:12 -070063 [Arguments] ${datetime} ${pod_prefix}
64 ${rc} ${namespace}= Run And Return Rc And Output ${export_kubeconfig}; kubectl get pods --all-namespaces | grep ' ${pod_prefix}' | head -1 | awk '{print $1}'
65 ${rc} ${pod_name}= Run And Return Rc And Output ${export_kubeconfig}; kubectl get pods --all-namespaces | grep ' ${pod_prefix}' | head -1 | awk '{print $2}'
66 ${rc} ${output}= Run Keyword If '${pod_prefix}' == 'onos' Run And Return Rc And Output ${export_kubeconfig}; kubectl logs --timestamps -n ${namespace} --since-time=${datetime} ${pod_name} -c onos
67 ... ELSE Run And Return Rc And Output ${export_kubeconfig}; kubectl logs --timestamps -n ${namespace} --since-time=${datetime} ${pod_name}
You Wang8fff6a02018-10-15 16:26:54 -070068 Log ${output}
69
70Log Kubernetes Containers Logs Since Time
You Wang41ca5372018-10-19 13:36:12 -070071 [Arguments] ${datetime} ${pod_list}
72 : FOR ${pod_prefix} IN @{pod_list}
73 \ Log Kubernetes Container Log Since Time ${datetime} ${pod_prefix}
You Wang8fff6a02018-10-15 16:26:54 -070074
75Get Kubernetes POD Name By Prefix
76 [Arguments] ${prefix}
77 [Documentation] Return the first POD name that starts with the specified prefix
Kailash Khalasibf1478b2018-10-17 11:58:58 -070078 ${rc} ${output}= Run And Return Rc And Output ${export_kubeconfig}; kubectl get pods --all-namespaces | grep '${prefix}' | head -1 | awk '{print $2}'
You Wang8fff6a02018-10-15 16:26:54 -070079 [Return] ${output}