blob: 2ffe9801d4023cef7e380c6a41a8efcb25936d2f [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
You Wang8fff6a02018-10-15 16:26:54 -070024Resource ../../Framework/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
49 Run ${export_kubeconfig}; cd ${HELM_CHARTS_DIR}; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
50 Run ${export_kubeconfig}; cd ${HELM_CHARTS_DIR}; helm dep up voltha
51 Run ${export_kubeconfig}; helm install -n voltha -f ${KUBERNETES_YAML} --set etcd-operator.customResources.createEtcdClusterCRD=false ${HELM_CHARTS_DIR}/voltha
52 Run ${export_kubeconfig}; helm upgrade -f ${KUBERNETES_YAML} --set etcd-operator.customResources.createEtcdClusterCRD=true voltha ${HELM_CHARTS_DIR}/voltha
53 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
63 [Arguments] ${datetime} ${container_name}
64 ${rc} ${output}= Run And Return Rc And Output ${export_kubeconfig}; kubectl logs --timestamps --since-time=${datetime} ${container_name}
65 Log ${output}
66
67Log Kubernetes Containers Logs Since Time
68 [Arguments] ${datetime} ${container_list}
69 : FOR ${container_name} IN @{container_list}
70 \ Log Kubernetes Container Log Since Time ${datetime} ${container_name}
71
72Get Kubernetes POD Name By Prefix
73 [Arguments] ${prefix}
74 [Documentation] Return the first POD name that starts with the specified prefix
Kailash Khalasibf1478b2018-10-17 11:58:58 -070075 ${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 -070076 [Return] ${output}