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: set up sanity test and fix sanity test failures #67

Merged
merged 3 commits into from
Oct 19, 2021
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
29 changes: 29 additions & 0 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Linux Unit tests
on:
pull_request: {}
push: {}

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.17
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Sanity test
env:
GITHUB_ACTIONS: true
run: |
export PATH=$PATH:$HOME/.local/bin
make
echo "is running in github actions: $GITHUB_ACTIONS"
make sanity-test
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ all: build

include release-tools/build.make

GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(GOPATH)/bin
export GOPATH GOBIN

.PHONY: sanity-test
sanity-test:
./test/sanity/run-test.sh
27 changes: 20 additions & 7 deletions pkg/iscsi/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,44 @@ type nodeServer struct {
}

func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
if req.GetVolumeCapability() == nil {
return nil, status.Error(codes.InvalidArgument, "Volume capability missing in request")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}
if len(req.GetTargetPath()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path not provided")
}

iscsiInfo, err := getISCSIInfo(req)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
diskMounter := getISCSIDiskMounter(iscsiInfo, req)

util := &ISCSIUtil{}
_, err = util.AttachDisk(*diskMounter)
if err != nil {
if _, err := util.AttachDisk(*diskMounter); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &csi.NodePublishVolumeResponse{}, nil
}

func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
diskUnmounter := getISCSIDiskUnmounter(req)
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}
targetPath := req.GetTargetPath()
if len(targetPath) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path not provided")
}

diskUnmounter := getISCSIDiskUnmounter(req)

iscsiutil := &ISCSIUtil{}
err := iscsiutil.DetachDisk(*diskUnmounter, targetPath)
if err != nil {
if err := iscsiutil.DetachDisk(*diskUnmounter, targetPath); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &csi.NodeUnpublishVolumeResponse{}, nil
}

Expand Down
8 changes: 8 additions & 0 deletions test/sanity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Sanity Tests
Testing CSI driver using the [`sanity`](https://github.com/kubernetes-csi/csi-test/tree/master/pkg/sanity) package test suite.

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

1 change: 1 addition & 0 deletions test/sanity/params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source: "//127.0.0.1/share"
81 changes: 81 additions & 0 deletions test/sanity/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

# Copyright 2021 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 iscsiplugin'
if [ -z "$GITHUB_ACTIONS" ]
then
# if not running on github actions, do not use sudo
pkill -f iscsiplugin
else
# if running on github actions, use sudo
sudo pkill -f iscsiplugin
fi
echo 'Deleting CSI sanity test binary'
rm -rf csi-test
}

trap cleanup EXIT

function install_csi_sanity_bin {
echo 'Installing CSI sanity test binary...'
mkdir -p $GOPATH/src/github.com/kubernetes-csi
pushd $GOPATH/src/github.com/kubernetes-csi
export GO111MODULE=off
git clone https://github.com/kubernetes-csi/csi-test.git -b v4.3.0
pushd csi-test/cmd/csi-sanity
make install
popd
popd
}

if [[ -z "$(command -v csi-sanity)" ]]; then
install_csi_sanity_bin
fi

readonly endpoint='unix:///tmp/csi.sock'
nodeid='CSINode'
if [[ "$#" -gt 0 ]] && [[ -n "$1" ]]; then
nodeid="$1"
fi

ARCH=$(uname -p)
if [[ "${ARCH}" == "x86_64" || ${ARCH} == "unknown" ]]; then
ARCH="amd64"
fi

if [ -z "$GITHUB_ACTIONS" ]
then
# if not running on github actions, do not use sudo
bin/iscsiplugin --endpoint "$endpoint" --nodeid "$nodeid" -v=5 &
else
# if running on github actions, use sudo
sudo bin/iscsiplugin --endpoint "$endpoint" --nodeid "$nodeid" -v=5 &
fi

echo 'Begin to run sanity test...'
skipTests='Controller Server|should work|should be idempotent|should remove target path'
CSI_SANITY_BIN=$GOPATH/bin/csi-sanity
if [ -z "$GITHUB_ACTIONS" ]
then
# if not running on github actions, do not use sudo
"$CSI_SANITY_BIN" --ginkgo.v --csi.secrets="$(pwd)/test/sanity/secrets.yaml" --csi.testvolumeparameters="$(pwd)/test/sanity/params.yaml" --csi.endpoint="$endpoint" --ginkgo.skip="$skipTests"
else
# if running on github actions, use sudo
sudo "$CSI_SANITY_BIN" --ginkgo.v --csi.secrets="$(pwd)/test/sanity/secrets.yaml" --csi.testvolumeparameters="$(pwd)/test/sanity/params.yaml" --csi.endpoint="$endpoint" --ginkgo.skip="$skipTests"
fi
3 changes: 3 additions & 0 deletions test/sanity/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NodeStageVolumeSecret:
username: sanity
password: sanitytestpassword