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

test: add integration tests #88

Merged
merged 1 commit into from
Nov 17, 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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ all: nfs
sanity-test: nfs
./test/sanity/run-test.sh

.PHONY: integration-test
integration-test: nfs
./test/integration/run-test.sh

.PHONY: local-build-push
local-build-push: nfs
docker build -t $(LOCAL_USER)/nfsplugin:latest .
Expand All @@ -69,7 +73,7 @@ local-k8s-uninstall:

.PHONY: nfs
nfs:
CGO_ENABLED=0 GOOS=linux go build -a -ldflags ${LDFLAGS} -o bin/nfsplugin ./cmd/nfsplugin
CGO_ENABLED=0 GOOS=linux go build -a -ldflags ${LDFLAGS} -mod vendor -o bin/nfsplugin ./cmd/nfsplugin

.PHONY: container
container: nfs
Expand Down
12 changes: 12 additions & 0 deletions test/integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Integration Test
Integration test verifies the functionality of CSI driver as a standalone server outside Kubernetes. It exercises the lifecycle of the volume by creating, attaching, staging, mounting volumes and the reverse operations.

## Run Integration Tests Locally
### Prerequisite
- Make sure golang is installed.
- Make sure Docker is installed and running. The test will spin up a docker container hosting the NFS server.

### Run integration tests
```
make integration-test
```
96 changes: 96 additions & 0 deletions test/integration/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

# Copyright 2020 The Kubernetes 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 -eo pipefail

function cleanup {
echo 'pkill -f nfsplugin'
pkill -f nfsplugin
echo 'Uninstalling NFS server on localhost'
docker rm nfs -f
}
trap cleanup EXIT

function install_csc_bin {
echo 'Installing CSC binary...'
export set GOPATH=$HOME/go
export set PATH=$PATH:$GOPATH/bin
go get github.com/rexray/gocsi/csc
pushd $GOPATH/src/github.com/rexray/gocsi/csc
make build
popd
}

function provision_nfs_server {
echo 'Installing NFS server on localhost'
apt-get update -y
apt-get install -y nfs-common
docker run -d --name nfs --privileged -p 2049:2049 -v $(pwd)/nfsshare:/nfsshare -e SHARED_DIRECTORY=/nfsshare itsthenetwork/nfs-server-alpine:latest
}

provision_nfs_server
install_csc_bin

readonly volname="citest-$(date +%s)"
readonly volsize="2147483648"
readonly endpoint="tcp://127.0.0.1:10000"
readonly target_path="/tmp/targetpath"
readonly params="server=127.0.0.1,share=/"

nodeid='CSINode'
if [[ "$#" -gt 0 ]] && [[ -n "$1" ]]; then
nodeid="$1"
fi

# Run CSI driver as a background service
bin/nfsplugin --endpoint "$endpoint" --nodeid "$nodeid" -v=5 &
sleep 5

echo 'Begin to run integration test...'

# Begin to run CSI functions one by one
echo "Create volume test:"
value="$(csc controller new --endpoint "$endpoint" --cap 1,block "$volname" --req-bytes "$volsize" --params "$params")"
sleep 15

volumeid="$(echo "$value" | awk '{print $1}' | sed 's/"//g')"
echo "Got volume id: $volumeid"

csc controller validate-volume-capabilities --endpoint "$endpoint" --cap 1,block "$volumeid"

echo "stage volume test:"
csc node stage --endpoint "$endpoint" --cap 1,block --staging-target-path "$staging_target_path" "$volumeid"

echo "publish volume test:"
csc node publish --endpoint "$endpoint" --cap 1,block --vol-context "$params" --target-path "$target_path" "$volumeid"
sleep 2

echo "unpublish volume test:"
csc node unpublish --endpoint "$endpoint" --target-path "$target_path" "$volumeid"
sleep 2

echo "unstage volume test:"
csc node unstage --endpoint "$endpoint" --staging-target-path "$staging_target_path" "$volumeid"
sleep 2

echo "Delete volume test:"
csc controller del --endpoint "$endpoint" "$volumeid"
sleep 15

csc identity plugin-info --endpoint "$endpoint"
csc node get-info --endpoint "$endpoint"

echo "Integration test is completed."
6 changes: 5 additions & 1 deletion test/sanity/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## Sanity Tests
Testing the NFS CSI driver using the [`sanity`](https://github.com/kubernetes-csi/csi-test/tree/master/pkg/sanity) package test suite.

## Run Sanity Tests Locally
### Prerequisite
- Make sure golang is installed.
- Make sure Docker is installed and running. The test will spin up a docker container hosting the NFS server.

### Run sanity tests
```
make sanity-test
```

3 changes: 1 addition & 2 deletions test/sanity/params.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

server: 127.0.0.1
share: /
share: /
6 changes: 4 additions & 2 deletions test/sanity/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function cleanup {
pkill -f nfsplugin
echo 'Deleting CSI sanity test binary'
rm -rf csi-test
echo 'Uninstalling NFS server on localhost'
docker rm nfs -f
}
trap cleanup EXIT

Expand All @@ -36,7 +38,7 @@ function provision_nfs_server {
echo 'Installing NFS server on localhost'
apt-get update -y
apt-get install -y nfs-common
docker run -d --name nfs --privileged -p 2049:2049 -v $(pwd):/nfsshare -e SHARED_DIRECTORY=/nfsshare itsthenetwork/nfs-server-alpine:latest
docker run -d --name nfs --privileged -p 2049:2049 -v $(pwd)/nfsshare:/nfsshare -e SHARED_DIRECTORY=/nfsshare itsthenetwork/nfs-server-alpine:latest
}

provision_nfs_server
Expand All @@ -52,4 +54,4 @@ bin/nfsplugin --endpoint "$endpoint" --nodeid "$nodeid" -v=5 &

echo 'Begin to run sanity test...'
readonly CSI_SANITY_BIN='csi-test/cmd/csi-sanity/csi-sanity'
"$CSI_SANITY_BIN" --ginkgo.v --ginkgo.noColor --csi.testvolumeparameters="$(pwd)/test/sanity/params.yaml" --csi.endpoint="$endpoint" --ginkgo.skip="should not fail when requesting to create a volume with already existing name and same capacity|should fail when requesting to create a volume with already existing name and different capacity|should work|should fail when the requested volume does not exist"
"$CSI_SANITY_BIN" --ginkgo.v --csi.testvolumeparameters="$(pwd)/test/sanity/params.yaml" --csi.endpoint="$endpoint" --ginkgo.skip="should not fail when requesting to create a volume with already existing name and same capacity|should fail when requesting to create a volume with already existing name and different capacity|should work|should fail when the requested volume does not exist"