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

[Task] Support the NFS Testing in the travisCI environment. #219

Merged
merged 8 commits into from
Aug 6, 2018
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ jobs:
install:
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -q
- sudo apt-get install -qqy httpie bats
- sudo apt-get install -qqy httpie bats nfs-kernel-server
- mkdir -p /tmp/nfs
- echo "/tmp/nfs *(rw,sync,no_root_squash)" | sudo tee /etc/exports
- sudo exportfs -r
- sudo showmount -e
script:
- make build
- sudo make src.test-bats
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ src.test-coverage-vagrant:
.PHONY: src.test-bats
src.test-bats:
sed -i.bak "s/localhost:9090/$$(minikube ip):30003/g; s/localhost:27017/$$(minikube ip):31717/g" config/testing.json
echo $$(mminikube ip)
./build/src/cmd/vortex/vortex -config config/testing.json -port 7890 &
@cd tests;\
./test.sh
Expand Down
2 changes: 1 addition & 1 deletion src/entity/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Storage struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Type StorageType `bson:"type" json:"type" validate:"required"`
Name string `bson:"name" json:"name" validate:"required"`
StorageClassName string `bson:"storageClassName" json:"storageClassName" validate:"required"`
StorageClassName string `bson:"storageClassName" json:"storageClassName" validate:"-"`
IP string `bson:"ip" json:"ip" validate:"required,ipv4"`
PATH string `bson:"path" json:"path" validate:"required"`
Fake *FakeStorage `bson:"fake,omitempty" json:"fake,omitempty" validate:"-"` //FakeStorage, for restful testing.
Expand Down
6 changes: 3 additions & 3 deletions src/storageprovider/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func getDeployment(name string, storage *entity.Storage) *appsv1.Deployment {
},
},
Spec: v1.PodSpec{
ServiceAccountName: "nfs-client-provisioner",
ServiceAccountName: "vortex-admin",
Containers: []v1.Container{
{
Name: name,
Expand Down Expand Up @@ -102,7 +102,7 @@ func getStorageClass(name string, provisioner string, storage *entity.Storage) *

// CreateStorage will create storage depandent on NFS storage srovider
func (nfs NFSStorageProvider) CreateStorage(sp *serviceprovider.Container, storage *entity.Storage) error {
namespace := "default"
namespace := "vortex"
name := NFSProvisionerPrefix + storage.ID.Hex()
storageClassName := NFSStorageClassPrefix + storage.ID.Hex()
//Create deployment
Expand All @@ -119,7 +119,7 @@ func (nfs NFSStorageProvider) CreateStorage(sp *serviceprovider.Container, stora

// DeleteStorage will delete stroage
func (nfs NFSStorageProvider) DeleteStorage(sp *serviceprovider.Container, storage *entity.Storage) error {
namespace := "default"
namespace := "vortex"
deployName := NFSProvisionerPrefix + storage.ID.Hex()
storageName := NFSStorageClassPrefix + storage.ID.Hex()

Expand Down
4 changes: 2 additions & 2 deletions src/storageprovider/nfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (suite *StorageTestSuite) TestValidateBeforeCreating() {
}

func (suite *StorageTestSuite) TestCreateStorage() {
namespace := "default"
namespace := "vortex"
storage := entity.Storage{
ID: bson.NewObjectId(),
Type: entity.NFSStorageType,
Expand All @@ -96,7 +96,7 @@ func (suite *StorageTestSuite) TestCreateStorage() {
}

func (suite *StorageTestSuite) TestDeleteStorage() {
namespace := "default"
namespace := "vortex"
storage := &entity.Storage{
ID: bson.NewObjectId(),
Type: entity.NFSStorageType,
Expand Down
5 changes: 5 additions & 0 deletions tests/00-environement/00-env.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@
[ $status = 0 ]
[[ ${lines[0]} != "No resources found." ]]
}

@test "Check NFS server setting" {
showmount -e | grep /tmp/nfs ; echo $?
[ $? = 0 ]
}
1 change: 1 addition & 0 deletions tests/03-storage-pod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json
21 changes: 21 additions & 0 deletions tests/03-storage-pod/init.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
nodeName=`kubectl get nodes | grep "Ready" | awk '{print $1}'`
if [ -z "$podName" ]; then
export name=$(date | md5sum | cut -b 1-19)
export podName="test-pod-$name"
export nfsstorageName="test-nfs-storage-$name"
export volumeName="test-nfs-volume-$name"
nfsIP=`kubectl get nodes -o jsonpath="{.items[0].status.addresses[0].address}"`
#nfsIP="172.17.8.100"

for i in storage volume pod; do
rm -f $i.json
cp $i.info $i.json
done

sed -i "s/@NFSIP@/${nfsIP}/" storage.json
sed -i "s/@NFSSTORAGENAME@/${nfsstorageName}/" storage.json
sed -i "s/@STORAGENAME@/${nfsstorageName}/" volume.json
sed -i "s/@VOLUMENAME@/${volumeName}/" volume.json
sed -i "s/@PODNAME@/${podName}/" pod.json
sed -i "s/@VOLUMENAME@/${volumeName}/" pod.json
fi
24 changes: 24 additions & 0 deletions tests/03-storage-pod/pod.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@PODNAME@",
"labels":{},
"namespace":"default",
"containers":[
{
"name":"first-container",
"image":"busybox",
"command":["sleep","3600"]
}
],
"networks":[
],
"volumes":[
{
"name":"@VOLUMENAME@",
"mountPath":"/tmp"
}
],
"restartPolicy":"Always",
"capability": true,
"networkType": "cluster",
"nodeAffinity": []
}
88 changes: 88 additions & 0 deletions tests/03-storage-pod/script.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bats

load init

@test "Create Storage" {
http -v --check-status 127.0.0.1:7890/v1/storage < storage.json
[ $? = 0 ]
}

@test "List Storage" {
run bash -c 'http http://127.0.0.1:7890/v1/storage/ 2>/dev/null | jq -r ".[0].id"'
id=${output}
run kubectl -n vortex get sc nfs-storageclass-${id} -o jsonpath="{.provisioner}"
[ "$output" = "nfs-provisioner-${id}" ]

NEXT_WAIT_TIME=0
WAIT_LIMIT=40
deploymentName="nfs-provisioner-${id}"
until kubectl -n vortex get deployment ${deploymentName} -o jsonpath="{.status.readyReplicas}" | grep "1" || [ $NEXT_WAIT_TIME -eq $WAIT_LIMIT ]; do
sleep 2
kubectl -n vortex describe deployment ${deploymentName}
NEXT_WAIT_TIME=$((NEXT_WAIT_TIME+ 1))
done
[ $NEXT_WAIT_TIME != $WAIT_LIMIT ]
}

@test "Create Volume" {
http -v --check-status 127.0.0.1:7890/v1/volume < volume.json
[ $? = 0 ]
}

@test "List Volume" {
run bash -c 'http http://127.0.0.1:7890/v1/volume/ 2>/dev/null | jq -r ".[0].id"'
id=${output}
NEXT_WAIT_TIME=0
WAIT_LIMIT=40
pvcName="pvc-${id}"
until kubectl get pvc ${pvcName} -o jsonpath="{.status.phase}" | grep "Bound" || [ $NEXT_WAIT_TIME -eq $WAIT_LIMIT ]; do
sleep 2
kubectl describe pvc ${pvcName}
NEXT_WAIT_TIME=$((NEXT_WAIT_TIME+ 1))
done
[ $NEXT_WAIT_TIME != $WAIT_LIMIT ]
}

@test "Create Pod" {
http -v --check-status 127.0.0.1:7890/v1/pods < pod.json
[ $? = 0 ]
}

@test "List Pod" {
run bash -c "http http://127.0.0.1:7890/v1/pods/ 2>/dev/null | jq -r '.[] | select(.name == \"${podName}\").name'"
[ "$output" = "${podName}" ]
[ $status = 0 ]

NEXT_WAIT_TIME=0
WAIT_LIMIT=40
until kubectl get pods ${podName} -o jsonpath="{.status.phase}" | grep "Running" || [ $NEXT_WAIT_TIME -eq $WAIT_LIMIT ]; do
sleep 2
kubectl get pods ${podName}
NEXT_WAIT_TIME=$((NEXT_WAIT_TIME+ 1))
done
[ $NEXT_WAIT_TIME != $WAIT_LIMIT ]
}

@test "Test NFS" {
kubectl exec ${podName} touch /tmp/testing
find /tmp/nfs | grep testing
[ $? = 0 ]
}

@test "Delete Pod" {
run bash -c 'http http://127.0.0.1:7890/v1/pods/ 2>/dev/null | jq -r ".[0].id"'
run http DELETE http://127.0.0.1:7890/v1/pods/${output} 2>/dev/null
[ $status = 0 ]
}

@test "Delete Volume" {
run bash -c 'http http://127.0.0.1:7890/v1/volume/ 2>/dev/null | jq -r ".[0].id"'
http -v --check-status DELETE http://127.0.0.1:7890/v1/volume/${output}
[ $? = 0 ]
}

@test "Delete Storage" {
run bash -c 'http http://127.0.0.1:7890/v1/storage/ 2>/dev/null | jq -r ".[0].id"'
http -v --check-status DELETE http://127.0.0.1:7890/v1/storage/${output}
[ $? = 0 ]
}
6 changes: 6 additions & 0 deletions tests/03-storage-pod/storage.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "nfs",
"name": "@NFSSTORAGENAME@",
"ip":"@NFSIP@",
"path":"/tmp/nfs"
}
6 changes: 6 additions & 0 deletions tests/03-storage-pod/volume.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"storageName": "@STORAGENAME@",
"name": "@VOLUMENAME@",
"accessMode":"ReadWriteMany",
"capacity":"300Gi"
}