Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sanity): adding CSI Sanity test #232

Merged
merged 2 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ install:
before_script:
- "./buildscripts/travis-build.sh"
script:
- sudo -E env "PATH=$PATH" make ci
- sudo -E env "PATH=$PATH" make ci || travis_terminate 1
- sudo -E env "PATH=$PATH" make sanity || travis_terminate 1
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 CSI Sanity 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
93 changes: 93 additions & 0 deletions ci/sanity.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

# 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.
# 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 -ex
test_repo="kubernetes-csi"

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"
}

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 ========================"
dumpControllerLogs 1000
dumpAgentLogs 1000
}

function initializeCSISanitySuite() {
echo "=============== Initialize CSI Sanity test suite ==============="
cat <<EOT >> /tmp/parameters.json
{
"node": "$HOSTNAME",
"poolname": "zfspv-pool",
"wait": "yes",
"thinprovision": "yes"
}
EOT

sudo rm -rf /tmp/csi.sock
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
git clone -b "v4.0.1" "$CSI_TEST_REPO" "$CSI_REPO_PATH"
else
cd "$CSI_REPO_PATH"
git pull "$CSI_REPO_PATH"
fi

cd "$CSI_REPO_PATH/cmd/csi-sanity"
make clean
make

UUID=$(kubectl get pod -n kube-system openebs-zfs-controller-0 -o 'jsonpath={.metadata.uid}')
SOCK_PATH=/var/lib/kubelet/pods/"$UUID"/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 startTestSuite() {
echo "================== Start csi-sanity test suite ================="
./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
exit 1
fi
exit 0
}

initializeCSISanitySuite

# do not exit in case of error, let us print the logs
set +e

startTestSuite
21 changes: 16 additions & 5 deletions pkg/driver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package driver

import (
"strings"
"sync"

"github.com/container-storage-interface/spec/lib/go/csi"
Expand Down Expand Up @@ -103,10 +104,12 @@ func GetVolAndMountInfo(
mountinfo.MountOptions = append(mountinfo.MountOptions, "ro")
}

volName := strings.ToLower(req.GetVolumeId())

getOptions := metav1.GetOptions{}
vol, err := volbuilder.NewKubeclient().
WithNamespace(zfs.OpenEBSNamespace).
Get(req.GetVolumeId(), getOptions)
Get(volName, getOptions)

if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -277,7 +280,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 @@ -289,7 +292,7 @@ func (ns *node) NodeUnstageVolume(
req *csi.NodeUnstageVolumeRequest,
) (*csi.NodeUnstageVolumeResponse, error) {

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

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

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

vol, err := zfs.GetZFSVolume(volumeID)

if err != nil {
return nil, status.Errorf(
codes.Internal,
codes.NotFound,
"failed to handle NodeExpandVolume Request for %s, {%s}",
req.VolumeId,
err.Error(),
Expand Down Expand Up @@ -351,7 +362,7 @@ func (ns *node) NodeGetVolumeStats(
}

if mount.IsMountPath(path) == false {
return nil, status.Error(codes.InvalidArgument, "path is not a mount path")
return nil, status.Error(codes.NotFound, "path is not a mount path")
}

var sfs unix.Statfs_t
Expand Down
Loading