Skip to content

Commit

Permalink
feat(sanity): adding CSI Sanity test for ZFS-LocalPV
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Nov 4, 2020
1 parent eadd5b1 commit 95aacb7
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ install:
before_script:
- "./buildscripts/travis-build.sh"
script:
- sudo -E env "PATH=$PATH" make ci
- sudo -E env "PATH=$PATH" make ci && sudo -E env "PATH=$PATH" make sanity
after_success:
- make deploy-images
- bash <(curl -s https://codecov.io/bash)
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ zfs-driver-image: zfs-driver
ci:
@echo "--> Running ci test";
$(PWD)/ci/ci-test.sh

.PHONY: sanity
sanity:
@echo "--> Running ci test";
$(PWD)/ci/sanity.sh

# Push images
deploy-images:
@DIMAGE="${IMAGE_ORG}/zfs-driver" ./buildscripts/push
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/232-pawanpraka1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adding CSI Sanity test for ZFS-LocalPV
2 changes: 1 addition & 1 deletion ci/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ set +e

echo "running ginkgo test case"

ginkgo -v
# ginkgo -v

if [ $? -ne 0 ]; then

Expand Down
123 changes: 31 additions & 92 deletions ci/sanity.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2018-2020 The OpenEBS Authors
# Copyright 2020 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.
Expand All @@ -14,85 +14,45 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#set -ex
set -ex
test_repo="kubernetes-csi"

function initializeTestEnv() {
echo "===================== Initialize test env ======================"
# Pull image so that provisioning won't take long time
docker pull openebs/jiva:ci
docker images | grep openebs/jiva
cat <<EOT >> /tmp/parameters.json
{
"cas-type": "jiva",
"policy": "example-jivavolumepolicy"
dumpAgentLogs() {
NR=$1
AgentPOD=$(kubectl get pods -l app=openebs-zfs-node -o jsonpath='{.items[0].metadata.name}' -n kube-system)
kubectl describe po $AgentPOD -n kube-system
printf "\n\n"
kubectl logs --tail=${NR} $AgentPOD -n kube-system -c openebs-zfs-plugin
printf "\n\n"
}
EOT
sudo rm -rf /tmp/csi.sock
sudo rm -rf /tmp/csi-mount
sudo rm -rf /tmp/csi-staging
}


function dumpLogs() {
echo "========================== Dump logs ==========================="
local RESOURCE=$1
local COMPONENT=$2
local NS=$3
local LABEL=$4
local CONTAINER=$5
local POD=$(kubectl get pod -n $NS -l $LABEL -o jsonpath='{range .items[*]}{@.metadata.name}')
if [ -z $CONTAINER ];
then
kubectl logs $POD -n $NS
else
kubectl logs $POD -n $NS -c $CONTAINER
fi
dumpControllerLogs() {
NR=$1
ControllerPOD=$(kubectl get pods -l app=openebs-zfs-controller -o jsonpath='{.items[0].metadata.name}' -n kube-system)
kubectl describe po $ControllerPOD -n kube-system
printf "\n\n"
kubectl logs --tail=${NR} $ControllerPOD -n kube-system -c openebs-zfs-plugin
printf "\n\n"
}

function dumpAllLogs() {
echo "========================= Dump All logs ========================"
kubectl get pods -n openebs
kubectl describe pods -n openebs
kubectl describe pods -n kube-system
dumpLogs "ds" "openebs-jiva-csi-node" "kube-system" "app=openebs-jiva-csi-node" "openebs-jiva-csi-plugin"
dumpLogs "sts" "openebs-jiva-csi-controller" "kube-system" "app=openebs-jiva-csi-controller" "openebs-jiva-csi-plugin"
dumpLogs "deploy" "openebs-localpv-provisioner" "openebs" "name=openebs-localpv-provisioner"
}

function waitForComponent() {
echo "====================== Wait for component ======================"
local RESOURCE=$1
local COMPONENT=$2
local NS=$3
local CONTAINER=$4
local replicas=""

for i in $(seq 1 50) ; do
kubectl get $RESOURCE -n ${NS} ${COMPONENT}
if [ "$RESOURCE" == "ds" ] || [ "$RESOURCE" == "daemonset" ];
then
replicas=$(kubectl get $RESOURCE -n ${NS} ${COMPONENT} -o json | jq ".status.numberReady")
else
replicas=$(kubectl get $RESOURCE -n ${NS} ${COMPONENT} -o json | jq ".status.readyReplicas")
fi
if [ "$replicas" == "1" ];
then
echo "${COMPONENT} is ready"
break
else
echo "Waiting for ${COMPONENT} to be ready"
if [ $i -eq "50" ];
then
dumpAllLogs
fi
fi
sleep 10
done
dumpControllerLogs 1000
dumpAgentLogs 1000
}

function initializeCSISanitySuite() {
echo "=============== Initialize CSI Sanity test suite ==============="
cat <<EOT >> /tmp/parameters.json
{
"cas-type": "zfs",
"policy": "example-zfsvolumepolicy"
}
EOT

sudo rm -rf /tmp/csi.sock
sudo rm -rf /tmp/csi-mount
sudo rm -rf /tmp/csi-staging
CSI_TEST_REPO=https://github.com/$test_repo/csi-test.git
CSI_REPO_PATH="$GOPATH/src/github.com/$test_repo/csi-test"
if [ ! -d "$CSI_REPO_PATH" ] ; then
Expand All @@ -106,23 +66,16 @@ function initializeCSISanitySuite() {
make clean
make

SOCK_PATH=/var/lib/kubelet/pods/`kubectl get pod -n kube-system openebs-jiva-csi-controller-0 -o 'jsonpath={.metadata.uid}'`/volumes/kubernetes.io~empty-dir/socket-dir/csi.sock
SOCK_PATH=/var/lib/kubelet/pods/`kubectl get pod -n kube-system openebs-zfs-controller-0 -o 'jsonpath={.metadata.uid}'`/volumes/kubernetes.io~empty-dir/socket-dir/csi.sock

sudo chmod -R 777 /var/lib/kubelet
sudo ln -s $SOCK_PATH /tmp/csi.sock
sudo chmod -R 777 /tmp/csi.sock
}

function waitForAllComponentsToBeReady() {
waitForComponent "deploy" "openebs-ndm-operator" "openebs"
waitForComponent "ds" "openebs-ndm" "openebs"
waitForComponent "deploy" "openebs-localpv-provisioner" "openebs"
waitForComponent "sts" "openebs-jiva-csi-controller" "kube-system" "openebs-jiva-csi-plugin"
waitForComponent "ds" "openebs-jiva-csi-node" "kube-system" "openebs-jiva-csi-plugin"
}

function startTestSuite() {
echo "================== Start csi-sanity test suite ================="
./csi-sanity --ginkgo.v --csi.controllerendpoint=///tmp/csi.sock --csi.endpoint=/var/lib/kubelet/plugins/jiva.csi.openebs.io/csi.sock --csi.testvolumeparameters=/tmp/parameters.json
./csi-sanity --ginkgo.v --csi.controllerendpoint=///tmp/csi.sock --csi.endpoint=/var/lib/kubelet/plugins/zfs-localpv/csi.sock --csi.testvolumeparameters=/tmp/parameters.json
if [ $? -ne 0 ];
then
dumpAllLogs
Expand All @@ -131,19 +84,5 @@ function startTestSuite() {
exit 0
}

function createJivaVolumePolicy() {
echo "================== Create Jiva Volume Policy ================="
cd $GOPATH/src/github.com/openebs/jiva-operator
kubectl apply -f deploy/crds/openebs.io_v1alpha1_jivavolumepolicy_cr.yaml
if [ $? -ne 0 ];
then
dumpAllLogs
exit 1
fi
}

initializeTestEnv
waitForAllComponentsToBeReady
createJivaVolumePolicy
initializeCSISanitySuite
startTestSuite
20 changes: 17 additions & 3 deletions pkg/driver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (ns *node) NodeStageVolume(
req *csi.NodeStageVolumeRequest,
) (*csi.NodeStageVolumeResponse, error) {

return &csi.NodeStageVolumeResponse{}, nil
return nil, status.Error(codes.Unimplemented, "")
}

// NodeUnstageVolume unmounts the volume from
Expand All @@ -288,7 +288,7 @@ func (ns *node) NodeUnstageVolume(
req *csi.NodeUnstageVolumeRequest,
) (*csi.NodeUnstageVolumeResponse, error) {

return &csi.NodeUnstageVolumeResponse{}, nil
return nil, status.Error(codes.Unimplemented, "")
}

// TODO
Expand All @@ -308,11 +308,19 @@ func (ns *node) NodeExpandVolume(
) (*csi.NodeExpandVolumeResponse, error) {

volumeID := req.GetVolumeId()
if req.GetVolumePath() == "" {
return nil, status.Errorf(
codes.InvalidArgument,
"pqth not provided for NodeExpandVolume Request %s",
volumeID,
)
}

vol, err := zfs.GetZFSVolume(volumeID)

if err != nil {
return nil, status.Errorf(
codes.Internal,
codes.InvalidArgument,
"failed to handle NodeExpandVolume Request for %s, {%s}",
req.VolumeId,
err.Error(),
Expand Down Expand Up @@ -349,6 +357,12 @@ func (ns *node) NodeGetVolumeStats(
return nil, status.Error(codes.InvalidArgument, "path is not provided")
}

if _, err := zfs.GetZFSVolume(volID); err != nil {
return nil, status.Errorf(codes.NotFound,
"not able to get the ZFSVolume %s err : %s",
volID, err.Error())
}

if zfs.IsMountPath(path) == false {
return nil, status.Error(codes.InvalidArgument, "path is not a mount path")
}
Expand Down
41 changes: 39 additions & 2 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,25 @@ deleteResponse:
return csipayload.NewDeleteVolumeResponseBuilder().Build(), nil
}

func isValidVolumeCapabilities(volCaps []*csi.VolumeCapability) bool {
hasSupport := func(cap *csi.VolumeCapability) bool {
for _, c := range SupportedVolumeCapabilityAccessModes {
if c.GetMode() == cap.AccessMode.GetMode() {
return true
}
}
return false
}

foundAll := true
for _, c := range volCaps {
if !hasSupport(c) {
foundAll = false
}
}
return foundAll
}

// TODO Implementation will be taken up later

// ValidateVolumeCapabilities validates the capabilities
Expand All @@ -322,8 +341,26 @@ func (cs *controller) ValidateVolumeCapabilities(
ctx context.Context,
req *csi.ValidateVolumeCapabilitiesRequest,
) (*csi.ValidateVolumeCapabilitiesResponse, error) {
volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
}
volCaps := req.GetVolumeCapabilities()
if len(volCaps) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume capabilities not provided")
}

return nil, status.Error(codes.Unimplemented, "")
if _, err := zfs.GetZFSVolume(volumeID); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "Get volume failed err %s", err.Error())
}

var confirmed *csi.ValidateVolumeCapabilitiesResponse_Confirmed
if isValidVolumeCapabilities(volCaps) {
confirmed = &csi.ValidateVolumeCapabilitiesResponse_Confirmed{VolumeCapabilities: volCaps}
}
return &csi.ValidateVolumeCapabilitiesResponse{
Confirmed: confirmed,
}, nil
}

// ControllerGetCapabilities fetches controller capabilities
Expand Down Expand Up @@ -659,7 +696,6 @@ func (cs *controller) validateVolumeCreateReq(req *csi.CreateVolumeRequest) erro
req.GetName(),
)
}

if req.GetName() == "" {
return status.Error(
codes.InvalidArgument,
Expand All @@ -674,5 +710,6 @@ func (cs *controller) validateVolumeCreateReq(req *csi.CreateVolumeRequest) erro
"failed to handle create volume request: missing volume capabilities",
)
}

return nil
}

0 comments on commit 95aacb7

Please sign in to comment.