add volume test to master

Signed-off-by: Ulrica Zhang <1002432810@qq.com>
This commit is contained in:
Ulrica Zhang 2021-01-18 15:49:19 +08:00
parent c5162ae0bd
commit d0dc668b1a
8 changed files with 667 additions and 0 deletions

63
test/volumeTest/deleteVol.sh Executable file
View File

@ -0,0 +1,63 @@
#!/bin/bash
#author:Ulrica Zhang
#delete volume test
source ./test_basic.sh
#sleep to wait for delete volume
#sleep 60s
#1.name&authKey true
create_vol "test_delete_1" "1" "1"
check_create "success" "1" "delete"
del_vol "test_delete_1" ${authKey}
check_msg "success" "1" "delete"
#2.name wrong
create_vol "test_delete_2" "1" "1"
check_create "success" "2" "delete"
randomName_2=$(random_str "10")
del_vol ${randomName_2} ${authKey}
check_msg "\"msg\": \"vol not exists\"" "2" "delete"
del_vol "test_delete_2" ${authKey}
check_delete "success" "2" "delete"
#3.authKey wrong
create_vol "test_delete_3" "1" "1"
check_create "success" "3" "delete"
randomKey_3=$(random_str "32")
del_vol "test_delete_3" ${randomKey_3}
check_msg "\"msg\": \"client and server auth key do not match\"" "3" "delete"
del_vol "test_delete_3" ${authKey}
check_delete "success" "3" "delete"
#4.name&authKey wrong
create_vol "test_delete_4" "1" "1"
check_create "success" "4" "delete"
randomName_4=$(random_str "10")
randomKey_4=$(random_str "32")
del_vol ${randomName_4} ${randomKey_4}
check_msg "\"msg\": \"vol not exists\"" "4" "delete"
del_vol "test_delete_4" ${authKey}
check_delete "success" "4" "delete"
#5.name&authKey empty
create_vol "test_delete_5" "1" "1"
check_create "success" "5" "delete"
del_vol " " " "
check_msg "parameter name not found" "5" "delete"
del_vol "test_delete_5" ${authKey}
check_delete "success" "5" "delete"

71
test/volumeTest/getVol.sh Executable file
View File

@ -0,0 +1,71 @@
#!/bin/bash
#author:Ulrica Zhang
#get volume test
source ./test_basic.sh
#sleep to wait for delete volume
#sleep 60s
create_num=50000
#1.name&authKey true
create_vol "test_get_1" "1" "1"
check_create "success" "1" "get"
get_vol "test_get_1" ${authKey}
check_msg "\"msg\": \"success\"" "1" "get"
del_vol "test_get_1" ${authKey}
check_delete "success" "1" "get"
#2.name wrong
create_vol "test_get_2" "1" "1"
check_create "success" "2" "get"
randomName_2=$(random_str "10")
get_vol ${randomName_2} ${authKey}
check_msg "\"msg\": \"vol not exists\"" "2" "get"
del_vol "test_get_2" ${authKey}
check_delete "success" "2" "get"
#3.authKey wrong
create_vol "test_get_3" "1" "1"
check_create "success" "3" "get"
randomKey_3=$(random_str "32")
get_vol "test_get_3" ${randomKey_3}
check_msg "\"msg\": \"client and server auth key do not match\"" "3" "get"
del_vol "test_get_3" ${authKey}
check_delete "success" "3" "get"
#4.name&authKey wrong
create_vol "test_get_4" "1" "1"
check_create "success" "4" "get"
randomName_4=$(random_str "10")
randomKey_4=$(random_str "32")
get_vol ${randomName_4} ${randomKey_4}
check_msg "\"msg\": \"vol not exists\"" "4" "get"
del_vol "test_get_4" ${authKey}
check_delete "success" "4" "get"
#5.name&authKey empty
create_vol "test_get_5" "1" "1"
check_create "success" "5" "get"
get_vol "" ""
check_msg "parameter name not found" "5" "get"
del_vol "test_get_5" ${authKey}
check_delete "success" "5" "get"
#6. duration at 5w volume environment
create_vol_specific "${create_num}" "test_get_6" "1" "1"
echo "test get operation duration from ${create_num} volumes ..."
time get_vol "test_get_6_1" ${authKey}
del_vol_specific "${create_num}" "test_get_6" ${authKey}

35
test/volumeTest/listVol.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
#author:Ulrica Zhang
#list volume test
source ./test_basic.sh
#sleep to wait for delete volume
#sleep 60s
create_num=50000
create_5w=50000
create_vol_specific "${create_num}" "test_list" "1" "1"
#1.keyword true
list_vol "test_list"
check_msg "\"msg\": \"success\"" "1" "list"
#2.keyword wrong
randomKey_2=$(random_str "10")
list_vol ${randomKey_2}
check_msg "\"msg\": \"success\"" "2" "list"
#3.keyword empty
list_vol ""
check_msg "\"msg\": \"success\"" "3" "list"
del_vol_specific "${create_num}" "test_list" ${authKey}
#4.list at 5w volumes environment
create_vol_specific "${create_5w}" "test_list_4" "1" "1"
echo "test list operation duration from ${create_num} volumes ..."
time list_vol "test_list_12_1" ${authKey}
check_msg "\"msg\": \"success\"" "4" "list"
del_vol_specific "${create_num}" "test_list_5" ${authKey}

58
test/volumeTest/statVol.sh Executable file
View File

@ -0,0 +1,58 @@
#!/bin/bash
#author:Ulrica Zhang
#stat volume test
source ./test_basic.sh
#sleep to wait for delete volume
#sleep 60s
#1.name true
create_vol "test_stat_1" "1" "1"
check_create "success" "1" "stat"
stat_vol "test_stat_1"
check_msg "success" "1" "stat"
del_vol "test_stat_1" ${authKey}
check_delete "success" "1" "stat"
#2.name wrong
create_vol "test_stat_2" "1" "1"
check_create "success" "2" "stat"
randomName_2=$(random_str "10")
stat_vol ${randomName_2}
check_msg "\"msg\": \"vol not exists\"" "2" "stat"
del_vol "test_stat_2" ${authKey}
check_delete "success" "2" "stat"
#3.name empty
create_vol "test_stat_3" "1" "1"
check_create "success" "3" "stat"
stat_vol ""
check_msg "parameter name not found" "3" "stat"
del_vol "test_stat_3" ${authKey}
check_delete "success" "3" "stat"
#preparation for following operations
create_vol "test_stat" "10" "1"
check_create "success" "4_5_6_7" "stat"
mnt_dir "test_stat"
#4.new volume
stat_vol "test_stat"
check_msg "\"UsedSize\": 0" "4" "stat"
#5.used volume
cover_write_file "/cfs/mnt/test_stat_file" "1024"
sleep 1m
stat_vol "test_stat"
cat return_record
check_msg "\"UsedRatio\": \"0.10\"" "5" "stat"
umnt_dir
del_vol "test_stat" ${authKey}
check_delete "success" "4_5_6_7" "stat"

268
test/volumeTest/test_basic.sh Executable file
View File

@ -0,0 +1,268 @@
#!/bin/bash
#author:Ulrica Zhang
#test volume basic operation
#basic information
master_addr="192.168.0.11:17010"
master_addrs="192.168.0.11:17010,192.168.0.12:17010,192.168.0.13:17010"
Owner='cfs'
cfs_client=./cfs-client
#authKey
printf ${Owner}|md5sum>md5File
read authKey<md5File
authKey=${authKey:0:32}
rm md5File
#echo ${authKey}
#random strings
random_str(){
length=$1
(head -c 32 /dev/urandom | base32) > randomStrFile
read randomStr < randomStrFile
randomStr=${randomStr:0:${length}}
rm randomStrFile
echo ${randomStr}
}
#curl call
parse_curl(){
operation=$1
url="http://${master_addr}${operation}"
#echo $url > return_record
curl -s ${url}|python -m json.tool > return_record
}
#parse_curl "user/info?user=cfs"
#check message
check_msg(){
message=$1
test_num=$2
test_name=$3
check_type=$4
grep "${message}" ./return_record > /dev/null
if [ $? -ne 0 ]
then
echo "a_test_${test_name}_${test_num} ${check_type} fail!"
cp return_record a_err_record_${test_name}_${test_num}_${check_type}
else
echo "a_test_${test_name}_${test_num} ${check_type} success!"
fi
}
#check create testing volume
check_create(){
message=$1
test_num=$2
test_name=$3
check_type=$4
grep "${message}" ./return_record > /dev/null
if [ $? -ne 0 ]
then
echo "b_${test_name}_${test_num} ${check_type} create fail!"
cp return_record b_err_create_${test_name}_${test_num}_${check_type}
fi
}
#check delete testing volume
check_delete(){
message=$1
test_num=$2
test_name=$3
check_type=$4
grep "${message}" ./return_record > /dev/null
if [ $? -ne 0 ]
then
echo "c_${test_name}_${test_num} ${check_type} delete fail!"
cp return_record c_err_delete_${test_name}_${test_num}_${check_type}
fi
}
#get accesskey
accessKey=0
getAccessKey(){
userID=$1
parse_curl "/user/info?user=${userID}"
grep "access_key" ./return_record > accessKeyFile
read accessKey < accessKeyFile
accessKey=${accessKey:15:16}
rm accessKeyFile
#cp return_record accessKey.file
}
#get secretKey
secretKey=0
getSecretKey(){
userID=$1
parse_curl "/user/info?user=${userID}"
grep "secret_key" ./return_record > secretKeyFile
read secretKey < secretKeyFile
secretKey=${secretKey:15:32}
rm secretKeyFile
#cp return_record secretKey.file
}
#mount directory
mnt_dir(){
mkdir -p /cfs/mnt
mkdir -p /cfs/log
volName=$1
getAccessKey "${Owner}"
getSecretKey "${Owner}"
#echo "access key: ${accessKey}"
#echo "secret key: ${secretKey}"
${cfs_client} --masterAddr=${master_addrs} --mountPoint=/cfs/mnt --volName=${volName} --owner=${Owner} --logDir=/cfs/log --logLevel=info --accessKey=${accessKey} --secretKey=${secretKey} >/dev/null
}
#umount directory
umnt_dir(){
umount /cfs/mnt
rm -rf /cfs
}
#write file
write_file(){
fileName=$1
fileSize=$2
dd if=/dev/zero of=${fileName} bs=1M count=${fileSize}
}
#write_file "writeFile.txt" 1024
#covered write file
cover_write_file(){
fileName=$1
fileSize=$2
dd if=/dev/zero of=${fileName} bs=1M count=${fileSize}
#random_str ${fileSize}>${fileName}
}
#cover_write_file "writeFile.txt" 1024
#appended write file
append_write_file(){
fileName=$1
fileSize=$2
random_str ${fileSize}>>${fileName}
}
#create volume
create_vol(){
volName=$1
capacity=$2
mpCount=$3
parameter=$4
operation="/admin/createVol?name=${volName}&capacity=${capacity}&owner=${Owner}&mpCount=${mpCount}${parameter}"
parse_curl ${operation}
}
#create specific number of volumes
create_vol_specific(){
num=$1
volName=$2
capacity=$3
mpCount=$4
for i in $(seq 1 ${num})
do
name="${volName}_${i}"
create_vol ${name} ${capacity} ${mpCount}
done
}
#delete volume
del_vol(){
volName=$1
Key=$2
operation="/vol/delete?name=${volName}&authKey=${Key}"
# echo ${operation}
parse_curl ${operation}
}
#delete specific number of volumes
del_vol_specific(){
num=$1
volName=$2
Key=$3
for i in $(seq 1 ${num})
do
name="${volName}_${i}"
del_vol ${name} ${Key}
done
}
#get volume
get_vol(){
volName=$1
Key=$2
operation="/client/vol?name=${volName}&authKey=${Key}"
parse_curl ${operation}
}
#stat volume
stat_vol(){
volName=$1
operation="/client/volStat?name=${volName}"
parse_curl ${operation}
}
#update volume
update_vol(){
volName=$1
updateCapacity=$2
Key=$3
parameter=$4
operation="/vol/update?name=${volName}&capacity=${updateCapacity}&authKey=${Key}${parameter}"
#echo ${operation}
parse_curl ${operation}
}
#get volume list
list_vol(){
keywords=$1
operation="/vol/list?keywords=${keywords}"
parse_curl ${operation}
}
#add token
add_token(){
volName=$1
tokenType=$2
Key=$3
operation="/token/add?name=${volName}&tokenType=${tokenType}&authKey=${Key}"
parse_curl ${operation}
}
#update token
update_token(){
volName=$1
tokenValue=$2
tokenType=$3
Key=$4
operation="/token/update?name=${volName}&token=${tokenValue}&tokenType=${tokenType}&authKey=${Key}"
parse_curl ${operation}
}
#delete token
delete_token(){
volName=$1
tokenValue=$2
Key=$3
operation="/token/delete?name=${volName}&token=${tokenValue}&authKey=${Key}"
parse_curl ${operation}
}
#get token
get_token(){
volName=$1
tokenValue=$2
operation="/token/get?name=${volName}&token=${tokenValue}"
parse_curl ${operation}
}
#update zone
update_zone(){
Name=$1
Enable=$2
operation="zone/update?name=${name}&enable=${Enable}"
parse_curl ${operation}
}

17
test/volumeTest/test_volume.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
#author:Ulrica Zhang
#volume operation test
echo "---------------1.delete operation-----------------"
./deleteVol.sh
echo "---------------2.get operation--------------------"
./getVol.sh
echo "---------------3.stat operation-------------------"
./statVol.sh
echo "---------------4.update volume operation----------"
./updateVol.sh
echo "---------------5.list volume operation------------"
./listVol.sh
rm return_record
echo "---------------test end---------------------------"

150
test/volumeTest/updateVol.sh Executable file
View File

@ -0,0 +1,150 @@
#!/bin/bash
#author:Ulrica Zhang
#update volume test
source ./test_basic.sh
#sleep to wait for delete volume
#sleep 60s
create_num=50000
#1.name&authKey true
create_vol "test_update_1" "1" "1"
check_create "success" "1" "update"
update_vol "test_update_1" "2" ${authKey}
cat return_record
check_msg "\"msg\": \"success\"" "1" "update"
del_vol "test_update_1" ${authKey}
check_delete "success" "1" "update"
#2.name wrong
create_vol "test_update_2" "1" "1"
check_create "success" "2" "update"
randomName_2=$(random_str "10")
update_vol ${randomName_2} "2" ${authKey}
check_msg "\"msg\": \"vol not exists\"" "2" "update"
del_vol "test_update_2" ${authKey}
check_delete "success" "2" "update"
#3.authKey wrong
create_vol "test_update_3" "1" "1"
check_create "success" "3" "update"
randomKey_3=$(random_str "32")
update_vol "test_update_3" "2" ${randomKey_3}
check_msg "\"msg\": \"client and server auth key do not match\"" "3" "update"
del_vol "test_update_3" ${authKey}
check_delete "success" "3" "update"
#4.name&authKey wrong
create_vol "test_update_4" "1" "1"
check_create "success" "4" "update"
randomName_4=$(random_str "10")
randomKey_4=$(random_str "32")
update_vol ${randomName_4} "2" ${randomKey_4}
check_msg "\"msg\": \"vol not exists\"" "4" "update"
del_vol "test_update_4" ${authKey}
check_delete "success" "4" "update"
#5.name&authKey empty
create_vol "test_update_5" "1" "1"
check_create "success" "5" "update"
update_vol "" "2" ""
check_msg "parameter name not found" "5" "update"
del_vol "test_update_5" ${authKey}
check_delete "success" "5" "update"
#6.capacity=old
create_vol "test_update_6" "1" "1"
check_create "success" "6" "update"
update_vol "test_update_6" "1" ${authKey}
check_msg "\"msg\": \"success\"" "6" "update"
del_vol "test_update_6" ${authKey}
check_delete "success" "6" "update"
#7.capacity<old
create_vol "test_update_7" "2" "1"
check_create "success" "7" "update"
update_vol "test_update_7" "1" ${authKey}
check_msg "\"msg\": \"success\"" "7" "update"
del_vol "test_update_7" ${authKey}
check_delete "success" "7" "update"
#8.capacity<volUsedSpace
#preparation for following operations
create_vol "test_update_8" "10" "1"
check_create "success" "8" "stat"
mnt_dir "test_update_8"
write_file "/cfs/mnt/test_update_file" "1024"
sleep 3m
update_vol "test_update_8" "1" ${authKey}
#cat return_record
check_msg "has to be 20 percent larger than the used space" "8" "update"
umnt_dir
del_vol "test_update_8" ${authKey}
check_delete "success" "8" "update"
#9.zoneName=empty
create_vol "test_update_9" "2" "1"
check_create "success" "9" "update"
update_vol "test_update_9" "1" ${authKey} "&zoneName="
check_msg "\"msg\": \"success\"" "9" "update"
del_vol "test_update_9" ${authKey}
check_delete "success" "9" "update"
#10.zoneName=default
create_vol "test_update_10" "2" "1"
check_create "success" "10" "update"
update_vol "test_update_10" "1" ${authKey} "&zoneName=default"
check_msg "success" "10" "update"
del_vol "test_update_10" ${authKey}
check_delete "success" "10" "update"
#11.zoneName=other exited zone
create_vol "test_update_11" "2" "1" "&zoneName=testUpdate11_zone"
check_create "success" "11" "update"
update_vol "test_update_11" "1" ${authKey} "&zoneName=test_update_11_zone"
check_msg "hhhhhh" "11" "update"
del_vol "test_update_11" ${authKey}
check_delete "success" "11" "update"
#11.zoneName=non-exited zone
create_vol "test_update_11" "2" "1"
check_create "success" "11" "update"
randomName_11=$(random_str "10")
update_vol "test_update_11" "1" ${authKey} "&zoneName=${randomName_11}"
check_msg "not found " "11" "update"
del_vol "test_update_11" ${authKey}
check_delete "success" "11" "update"
#12.update at 5w volumes environment
create_vol_specific "${create_num}" "test_update_12" "1" "1"
echo "test update operation duration from ${create_num} volumes ..."
time update_vol "test_update_12_1" "2" ${authKey}
check_msg "\"msg\": \"success\"" "12" "update"
del_vol_specific "${create_num}" "test_update_12" ${authKey}

View File

@ -0,0 +1,5 @@
# volumeTest
## 执行测试程序
`./test_volume.sh`