|
| 1 | +# Copyright 2019 The OpenEBS Authors. |
| 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 | +#!/usr/bin/env bash |
| 16 | + |
| 17 | +set -e |
| 18 | + |
| 19 | +LVM_OPERATOR=deploy/lvm-operator.yaml |
| 20 | +SNAP_CLASS=deploy/sample/lvmsnapclass.yaml |
| 21 | + |
| 22 | +export LVM_NAMESAPCE="openebs" |
| 23 | +export TEST_DIR="tests" |
| 24 | + |
| 25 | +# Prepare env for runnging BDD tests |
| 26 | +# Minikube is already running |
| 27 | +kubectl apply -f $LVM_OPERATOR |
| 28 | +kubectl apply -f $SNAP_CLASS |
| 29 | + |
| 30 | +dumpAgentLogs() { |
| 31 | + NR=$1 |
| 32 | + AgentPOD=$(kubectl get pods -l app=openebs-lvm-node -o jsonpath='{.items[0].metadata.name}' -n kube-system) |
| 33 | + kubectl describe po $AgentPOD -n kube-system |
| 34 | + printf "\n\n" |
| 35 | + kubectl logs --tail=${NR} $AgentPOD -n kube-system -c openebs-lvm-plugin |
| 36 | + printf "\n\n" |
| 37 | +} |
| 38 | + |
| 39 | +dumpControllerLogs() { |
| 40 | + NR=$1 |
| 41 | + ControllerPOD=$(kubectl get pods -l app=openebs-lvm-controller -o jsonpath='{.items[0].metadata.name}' -n kube-system) |
| 42 | + kubectl describe po $ControllerPOD -n kube-system |
| 43 | + printf "\n\n" |
| 44 | + kubectl logs --tail=${NR} $ControllerPOD -n kube-system -c openebs-lvm-plugin |
| 45 | + printf "\n\n" |
| 46 | +} |
| 47 | + |
| 48 | +isPodReady(){ |
| 49 | + [ "$(kubectl get po "$1" -o 'jsonpath={.status.conditions[?(@.type=="Ready")].status}' -n kube-system)" = 'True' ] |
| 50 | +} |
| 51 | + |
| 52 | +isDriverReady(){ |
| 53 | + for pod in $lvmDriver;do |
| 54 | + isPodReady $pod || return 1 |
| 55 | + done |
| 56 | +} |
| 57 | + |
| 58 | +waitForLVMDriver() { |
| 59 | + period=120 |
| 60 | + interval=1 |
| 61 | + |
| 62 | + i=0 |
| 63 | + while [ "$i" -le "$period" ]; do |
| 64 | + lvmDriver="$(kubectl get pods -l role=openebs-lvm -o 'jsonpath={.items[*].metadata.name}' -n kube-system)" |
| 65 | + if isDriverReady $lvmDriver; then |
| 66 | + return 0 |
| 67 | + fi |
| 68 | + |
| 69 | + i=$(( i + interval )) |
| 70 | + echo "Waiting for lvm-driver to be ready..." |
| 71 | + sleep "$interval" |
| 72 | + done |
| 73 | + |
| 74 | + echo "Waited for $period seconds, but all pods are not ready yet." |
| 75 | + return 1 |
| 76 | +} |
| 77 | + |
| 78 | +# wait for lvm-driver to be up |
| 79 | +waitForLVMDriver |
| 80 | + |
| 81 | +cd $TEST_DIR |
| 82 | + |
| 83 | +kubectl get po -n kube-system |
| 84 | + |
| 85 | +set +e |
| 86 | + |
| 87 | +echo "running ginkgo test case" |
| 88 | + |
| 89 | +ginkgo -v |
| 90 | + |
| 91 | +if [ $? -ne 0 ]; then |
| 92 | + |
| 93 | +sudo pvscan --cache |
| 94 | + |
| 95 | +sudo lvmdisplay |
| 96 | + |
| 97 | +echo "******************** LVM Controller logs***************************** " |
| 98 | +dumpControllerLogs 1000 |
| 99 | + |
| 100 | +echo "********************* LVM Agent logs *********************************" |
| 101 | +dumpAgentLogs 1000 |
| 102 | + |
| 103 | +echo "get all the pods" |
| 104 | +kubectl get pods -owide --all-namespaces |
| 105 | + |
| 106 | +echo "get pvc and pv details" |
| 107 | +kubectl get pvc,pv -oyaml --all-namespaces |
| 108 | + |
| 109 | +echo "get snapshot details" |
| 110 | +kubectl get volumesnapshot.snapshot -oyaml --all-namespaces |
| 111 | + |
| 112 | +echo "get sc details" |
| 113 | +kubectl get sc --all-namespaces -oyaml |
| 114 | + |
| 115 | +echo "get lvm volume details" |
| 116 | +kubectl get lvmvolumes.local.openebs.io -n openebs -oyaml |
| 117 | + |
| 118 | +echo "get lvm snapshot details" |
| 119 | +kubectl get lvmsnapshots.local.openebs.io -n openebs -oyaml |
| 120 | + |
| 121 | +exit 1 |
| 122 | +fi |
| 123 | + |
| 124 | +echo "\n\n######### All test cases passed #########\n\n" |
0 commit comments