Skip to content

Commit

Permalink
feat(bdd): add BDD integration tests (#7)
Browse files Browse the repository at this point in the history
Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored Mar 31, 2021
1 parent 5ea9893 commit 6449455
Show file tree
Hide file tree
Showing 345 changed files with 206,990 additions and 7 deletions.
34 changes: 33 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,41 @@ jobs:
- name: Upload Coverage Report
uses: codecov/codecov-action@v1

bdd-test:
needs: ['unit-test']
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
kubernetes: [v1.20.1]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go 1.14
uses: actions/setup-go@v2
with:
go-version: 1.14.7

- name: Setup Minikube-Kubernetes
uses: manusa/[email protected]
with:
minikube version: v1.16.0
kubernetes version: ${{ matrix.kubernetes }}
github token: ${{ secrets.GITHUB_TOKEN }}

- name: Build images locally
run: make device-driver-image || exit 1;

- name: bootstrap
run: make bootstrap

- name: Running tests
run: ./ci/ci-test.sh

csi-driver:
runs-on: ubuntu-latest
needs: ['lint', 'unit-test']
needs: ['lint', 'unit-test', 'bdd-test']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
34 changes: 33 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,41 @@ jobs:
- name: Upload Coverage Report
uses: codecov/codecov-action@v1

bdd-test:
needs: ['unit-test']
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
kubernetes: [v1.20.1]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go 1.14
uses: actions/setup-go@v2
with:
go-version: 1.14.7

- name: Setup Minikube-Kubernetes
uses: manusa/[email protected]
with:
minikube version: v1.16.0
kubernetes version: ${{ matrix.kubernetes }}
github token: ${{ secrets.GITHUB_TOKEN }}

- name: Build images locally
run: make device-driver-image || exit 1;

- name: bootstrap
run: make bootstrap

- name: Running tests
run: ./ci/ci-test.sh

csi-driver:
runs-on: ubuntu-latest
needs: ['lint', 'unit-test']
needs: ['lint', 'unit-test', 'bdd-test']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
125 changes: 125 additions & 0 deletions ci/ci-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env bash
# Copyright 2021 The OpenEBS Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


set -e

# setup a block device and meta partition on the disk
truncate -s 1024G /tmp/disk.img
disk=`sudo losetup -f /tmp/disk.img --show`
sudo parted "$disk" mklabel gpt
sudo parted "$disk" mkpart test-device 1MiB 10MiB

DEVICE_OPERATOR=deploy/device-operator.yaml

export DEVICE_DRIVER_NAMESPACE="openebs"
export TEST_DIR="tests"
export NAMESPACE="kube-system"
export KUBECONFIG=$HOME/.kube/config

# Prepare env for running BDD tests
# Minikube is already running
kubectl apply -f $DEVICE_OPERATOR

dumpAgentLogs() {
NR=$1
AgentPOD=$(kubectl get pods -l app=openebs-device-node -o jsonpath='{.items[0].metadata.name}' -n "$NAMESPACE")
kubectl describe po "$AgentPOD" -n "$NAMESPACE"
printf "\n\n"
kubectl logs --tail="${NR}" "$AgentPOD" -n "$NAMESPACE" -c openebs-device-plugin
printf "\n\n"
}

dumpControllerLogs() {
NR=$1
ControllerPOD=$(kubectl get pods -l app=openebs-device-controller -o jsonpath='{.items[0].metadata.name}' -n "$NAMESPACE")
kubectl describe po "$ControllerPOD" -n "$NAMESPACE"
printf "\n\n"
kubectl logs --tail="${NR}" "$ControllerPOD" -n "$NAMESPACE" -c openebs-device-plugin
printf "\n\n"
}

isPodReady(){
[ "$(kubectl get po "$1" -o 'jsonpath={.status.conditions[?(@.type=="Ready")].status}' -n "$NAMESPACE")" = 'True' ]
}

isDriverReady(){
for pod in $deviceDriver;do
isPodReady "$pod" || return 1
done
}

waitForDeviceDriver() {
period=120
interval=1

i=0
while [ "$i" -le "$period" ]; do
deviceDriver="$(kubectl get pods -l role=openebs-device -o 'jsonpath={.items[*].metadata.name}' -n "$NAMESPACE")"
if isDriverReady "$deviceDriver"; then
return 0
fi

i=$(( i + interval ))
echo "Waiting for device-driver to be ready..."
sleep "$interval"
done

echo "Waited for $period seconds, but all pods are not ready yet."
return 1
}

# wait for device-driver to be up
waitForDeviceDriver

cd $TEST_DIR

kubectl get po -n "$NAMESPACE"

set +e

echo "running ginkgo test case"

ginkgo -v

if [ $? -ne 0 ]; then

lsblk -b
sudo fdisk -l
sudo udevadm info ${disk}p1
sudo parted -l

echo "******************** Device Controller logs***************************** "
dumpControllerLogs 1000

echo "********************* Device Agent logs *********************************"
dumpAgentLogs 1000

echo "get all the pods"
kubectl get pods -owide --all-namespaces

echo "get pvc and pv details"
kubectl get pvc,pv -oyaml --all-namespaces

echo "get sc details"
kubectl get sc --all-namespaces -oyaml

echo "get device volume details"
kubectl get devicevolumes.local.openebs.io -n openebs -oyaml

exit 1
fi

printf "\n\n######### All test cases passed #########\n\n"
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ go 1.14

require (
github.com/container-storage-interface/spec v1.2.0
github.com/ghodss/yaml v1.0.0
github.com/golang/protobuf v1.4.3
github.com/kubernetes-csi/csi-lib-utils v0.9.1
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
github.com/openebs/lib-csi v0.2.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.3
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSR
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
cloud.google.com/go v0.46.3 h1:AVXDdKsrtX33oR9fbCMu/+c1o8Ofjq6Ku/MInaLVg5Y=
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
Expand Down Expand Up @@ -96,8 +97,10 @@ github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r
github.com/docker/go-connections v0.3.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/libnetwork v0.0.0-20180830151422-a9cd636e3789/go.mod h1:93m0aTqz6z+g32wla4l4WxTrdtvBRmVzYRkYvasA5Z8=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 h1:cenwrSVm+Z7QLSV/BsnenAOcDXdX4cMv4wP0B/5QbPg=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e h1:p1yVGRW3nmb85p1Sh1ZJSDm4A4iKLS5QNbvUHMgGu/M=
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand All @@ -116,6 +119,7 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v0.0.0-20180820084758-c7ce16629ff4/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
Expand Down
18 changes: 15 additions & 3 deletions pkg/device/device-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func DestroyVolume(vol *apis.DeviceVolume) error {

// DeletePart Todo
func wipefsAndDeletePart(disk string, partNum uint32) error {
_, err := RunCommand(strings.Split(fmt.Sprintf(PartitionWipeFS, disk, partNum), " "))
_, err := RunCommand(strings.Split(fmt.Sprintf(getPartitionPath(disk, partNum), disk, partNum), " "))
if err != nil {
klog.Errorf("WipeFS failed %s", err)
return err
Expand Down Expand Up @@ -212,8 +212,8 @@ func GetVolumeDevPath(vol *apis.DeviceVolume) (string, error) {
klog.Errorf("%s Partition not found\n", partitionName)
return "", errors.New("Partition not found")
}
return fmt.Sprintf("/dev/%s%d", pList[0].DiskName, pList[0].PartNum), nil

return getPartitionPath(pList[0].DiskName, pList[0].PartNum), nil
}

// RunCommand Todo
Expand Down Expand Up @@ -327,7 +327,8 @@ func getDiskList() ([]diskDetail, error) {
if len(tmp) == 0 {
continue
}
if tmp[5] == "disk" {
// loop is added here for testing purposes
if tmp[5] == "disk" || tmp[5] == "loop" {
tsize, _ := strconv.ParseUint(tmp[3], 10, 64)
result = append(result, diskDetail{tmp[0], tsize})
}
Expand Down Expand Up @@ -409,3 +410,14 @@ func GetDiskDetails() ([]apis.Device, error) {
klog.Infof("%+v", result)
return result, nil
}

// getPartitionPath gets the partition path from disk name and partition number.
func getPartitionPath(diskName string, partNum uint32) string {
r := regexp.MustCompile(".+[0-9]+$")
// if the disk name ends in a number, then partition will be of the format /dev/nvme0n1p1
if r.MatchString(diskName) {
return fmt.Sprintf("/dev/%sp%d", diskName, partNum)
} else {
return fmt.Sprintf("/dev/%s%d", diskName, partNum)
}
}
Loading

0 comments on commit 6449455

Please sign in to comment.