Merge pull request #64 from tpaullee/add-test-directory

Add example setup, open-iscsi, libiscsi test scripts
This commit is contained in:
Lei Xue
2017-10-05 08:16:49 +08:00
committed by GitHub
8 changed files with 367 additions and 1 deletions

View File

@@ -26,7 +26,7 @@ script:
- hack/verify-gofmt.sh
- export GOPATH=`pwd`/Godeps/_workspace/:$GOPATH
- go test -v ./pkg/...
- dd if=/dev/zero of=/var/tmp/disk.img bs=1024 count=10240
- dd if=/dev/zero of=/var/tmp/disk.img bs=1024 count=102400
- mkdir ${HOME}/.gotgt
- echo '{"storages":[{"deviceID":1000,"path":"file:/var/tmp/disk.img","online":true}],"iscsiportals":[{"id":0,"portal":"127.0.0.1:3260"}],"iscsitargets":{"iqn.2016-09.com.gotgt.gostor:example_tgt_0":{"tpgts":{"1":[0]},"luns":{"0":1000}}}}' > ${HOME}/.gotgt/config.json
- ./gotgt daemon --log debug 1>/dev/null 2>&1 &

View File

@@ -48,6 +48,7 @@ Note that the examples directory is intended to show static configurations that
### Test
You can test this with [open-iscsi](http://www.open-iscsi.com/) or [libiscsi](https://github.com/gostor/libiscsi).
For more information and example test scripts, please refer to the [test directory](./test).
## Performance

48
test/README.md Normal file
View File

@@ -0,0 +1,48 @@
## Test Coverage
Note that open-iscsi and libiscsi are separate iSCSI initiator packages
and have no interdependency. We should test the target library with both
packages to maximize coverage.
The open-iscsi has a kernel component and it will rebuild kernel after
inserting a few modules. If you have many kernel bootable images,
your should remember which one to use for open-iscsi testing.
### Test Scripts
Five separate example shell scripts are here to facilitate and automate
testing, although automatic testing will be submitted to travis.ci.com via
the .travis.yml file. As more features are developed and bugs are fixed,
please remember to update both the test scripts and the .yml file.
Manual testing by the developers and testers should consult the
setup-dev-test.sh, gotgt-daemon.sh libiscsi-gotgt-test.sh,
openiscsi-gotgt-test.sh and test-cleanup.sh files.
You need to set up two exported environment variable LIBISCSIPATH and GOTGTPATH.
These are the location where to have the source code for libiscsi and gotgt.
Normally, they should be set once for all in your home directory's .bashrc file
for conveniences. Development and test environment setup is normally done once
per client and updated only as required. Kicking off target daemon is needed
before testing and after a successful rebuild of the target library.
The shell script names implies the intended functions,
You should run setup-dev-test.sh first and then gotgt-daemon.sh.
Some test scripts leave state information in your environment and make the
repeat testing unpredictable. You can consult and run test-cleanup.sh to do
some state cleaning.
These have been tested with Ubuntu Linux versions as of 2017.
Please update them as more Linux variants and platforms are verified or added.
### Noises in the test results
Note that the "[FAILED]" lines during the libiscsi test are often
due to the standard procedure to check the unknown devices with inquiry command.
It will not impact the real test. The "CUnit" testing noises can also
be safely ignored.
Also note that some testing using fdisk and mkfs in the openiscsi-gotgt-test.sh
create state information for the partition and the file system.
You should run the test-cleanup.sh to remove those state information.
That is not foolproof however, and you may need to do some manually.
## Making contributions
As a way to get you started and get you familiar with the gotgt project,
you can check out this file at issue [#55]
(https://github.com/gostor/gotgt/issues/55)
to improve the target library code to pass more test cases (by libiscsi).
Some are relatively straightforward.

54
test/gotgt-daemon.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/sh
# Build and Kick off the gotgt daemon
# Assuming the development and testing environment was setup and all
# required binaries are up-to-date
# For reading compatibility between these scripts and the automated .yml file
# TRAVIS_BUILD_DIR=$GOTGTPATH
cd $GOTGTPATH
./autogen.sh
./configure
## Normally, above steps are done only once and repeated only as required
# Back up through gotgt, gostor, github.com, and src (4 ..'s)
# to avoid GOPATH must be absolute problem.
export GOPATH=`pwd`/../../../..
make
###### run some formatting check and unit testing
export GOPATH=`pwd`/Godeps/_workspace/:$GOPATH
./hack/verify-gofmt.sh
## TO-DO/TO-RESOLVE supply some test files to do more unit testing
go test -v ./pkg/...
### create target json configuration file for testing
### create a flat file for target backend for testing
[ ! -d ${HOME}/.gotgt ] && mkdir ${HOME}/.gotgt
#
echo '{"storages":[{"deviceID":1000,"path":"file:/var/tmp/disk.img","online":true}],' > ${HOME}/.gotgt/config.json
echo '"iscsiportals":[{"id":0,"portal":"127.0.0.1:3260"}],' >> ${HOME}/.gotgt/config.json
echo '"iscsitargets":{"iqn.2016-09.com.gotgt.gostor:example_tgt_0":{"tpgts":{"1":[0]},"luns":{"0":1000}}}}' >> ${HOME}/.gotgt/config.json
[ ! -f /var/tmp/disk.img ] && touch /var/tmp/disk.img
dd if=/dev/zero of=/var/tmp/disk.img bs=1024 count=102400
## kick off the target library daemon for testing purposes
## Note that the grep command would be always in the ps command output
[ `ps -ef | grep "gotgt daemon" | wc -l ` -gt 1 ] && killall gotgt
#./gotgt --help
#./gotgt daemon --help
./gotgt daemon --log debug 1>/dev/null 2>&1 &
# Or watching the daemon
#./gotgt daemon --log debug 1> debug.daemon 2>&1 &
# tail -f debug.daemon
#
sleep 2
ps -ef | grep "gotgt daemon"
##
exit 0

53
test/libiscsi-gotgt-test.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/bin/sh
# Run libiscsi test cases
# Assuming libiscsi binaries are built and the gotgt daemon is running
LOCALHOSTPORT=127.0.0.1:3260
TARGET=iqn.2016-09.com.gotgt.gostor:example_tgt_0
TESTCU=${LIBISCSIPATH}/test-tool/iscsi-test-cu
${LIBISCSIPATH}/utils/iscsi-ls -s iscsi://${LOCALHOSTPORT}/${TARGET}
echo
${LIBISCSIPATH}/utils/iscsi-inq iscsi://${LOCALHOSTPORT}/${TARGET}/0
echo
${LIBISCSIPATH}/utils/iscsi-readcapacity16 iscsi://${LOCALHOSTPORT}/${TARGET}/0
NEWCASES="ALL.PrinReadKeys"
TESTCASES="ALL.Inquiry.Standard\
ALL.Inquiry.AllocLength ALL.Inquiry.MandatoryVPDSBC\
ALL.Inquiry.SupportedVPD ALL.Inquiry.VersionDescriptors \
ALL.Inquiry.EVPD ALL.Mandatory ALL.ModeSense6 ALL.NoMedia \
ALL.Prefetch10 ALL.Prefetch16 ALL.PreventAllow \
ALL.ReadCapacity10 ALL.ReadCapacity16 ALL.Read6 \
ALL.Read10 ALL.Read12 ALL.Read16 ALL.ReadOnly \
ALL.ReportSupportedOpcodes.Simple ALL.Reserve6.Simple \
ALL.StartStopUnit ALL.TestUnitReady \
ALL.Write10 ALL.Write16 ALL.Write12 ALL.WriteVerify10 \
ALL.WriteVerify16 ALL.WriteVerify12 ALL.WriteAtomic16.BeyondEol \
ALL.WriteAtomic16.ZeroBlocks ALL.WriteAtomic16.WriteProtect \
ALL.WriteAtomic16.DpoFua \
ALL.WriteSame10.Simple ALL.WriteSame16.Simple \
ALL.Verify10 ALL.Verify12 ALL.Verify16 \
ALL.iSCSITMF ALL.iSCSIcmdsn \
"
#for i in $NEWCASES
echo "\n====== Test started"
date
for i in $TESTCASES
do {
${TESTCU} -d -A --test=$i iscsi://${LOCALHOSTPORT}/${TARGET}/0
echo "===";
} done
date
echo "====== Test ended"
# sanity check example below
# ./libiscsi-gotgt-test.sh > libiscsi-runoutput.txt 2>&1 &
# grep "Test:" libiscsi-runoutput.txt | wc
# grep "passed" libiscsi-runoutput.txt | wc
exit 0

107
test/openiscsi-gotgt-test.sh Executable file
View File

@@ -0,0 +1,107 @@
#!/bin/sh
# Run open-iscsi test cases
# Assuming open-iscsi package and binaries are installed properly, and
# the gotgt daemon is running
LOCALHOST=127.0.0.1
# track test environment
date
uname -a
df -hT
sudo lsblk -l
echo "==== iscsi initiator test"
# some simple iscsi initiator tests
sudo iscsiadm -m discovery -t sendtargets -p ${LOCALHOST}
echo
sudo iscsiadm -m node -L all
echo
sudo iscsiadm -m session
echo "==== end of iscsi initiator test"
# Assuming /dev/sdb is the disk presented at the iSCSI backend
# You don't want to mess up with your true /dev/sdb in the system if there is
# one already. You need to modify this script and other test scripts as needed.
# Let's confirm that, and error out if necessary.
# Might need to add clean-up scripts to unmount over /var/tmp/test
# sudo umount /var/tmp/test
mount | grep sdb1
mount | grep "var/tmp/test"
if [ $? -eq 0 ]
then
sudo umount /var/tmp/test
fi
sudo fdisk -l
echo "====Examine disk /dev/sdb to be be sure ..."
sudo fdisk -l | grep "Disk /dev/sdb: 100 MiB"
if [ $? -ne 0 ]
then
echo "Warning: /dev/sdb: 100 MiB not found!"
echo "Revise your test script as required."
exit 1
fi
echo "Continue...."
echo "=== Create a partition, mkfs, mount and do some I/O"
## Mount and prepare a test directory for open-iscsi testing
##
## n: add a new partition
## p: primary partition
## 1: partition number
## \n: use default (2048) for the first sector
## \n: use default (20479) for the last sector
### This will create a new partition 1 of type 'Linux' and of size 9 MiB.
## t: change partition type
## c: change to W95 FAT32 (LBA)
## a: Enable the bootable flag for partition 1
## 1: (unknown command ????? XXX)
## w: write the table to disk and exit
# write a partition table
# In order for the following to work,
# Delete existing /dev/sdb1 partition if found
sudo lsblk -l | grep sdb1
if [ $? -eq 0 ]
then
/bin/echo -e "p\nd\nw" | sudo fdisk /dev/sdb
fi
/bin/echo -e "n\np\n1\n\n\nt\nc\na\n1\nw" | sudo fdisk /dev/sdb
# it might prompt for confirmation if previous file system is detected
sudo mkfs.ext3 /dev/sdb1
sudo mkdir -p /var/tmp/test
sudo mount /dev/sdb1 /var/tmp/test
mount | grep sdb1
sudo ls -lh /var/tmp/test/
##
## TO-DO we can do more open-iscsi testing just with this.
##
#
sudo chmod 777 /var/tmp/test
# should measure performance with large count below on a huge file system
time sudo dd if=/dev/mem of=/var/tmp/test/mem-file bs=4096 count=100
cp /var/tmp/test/mem-file /var/tmp/test/mem-file-2
md5sum /var/tmp/test/mem-file
md5sum /var/tmp/test/mem-file-2
### umount and remount the file system
sudo umount /var/tmp/test
sudo mount /dev/sdb1 /var/tmp/test
md5sum /var/tmp/test/mem-file
md5sum /var/tmp/test/mem-file-2
# umount and some clean-up
sudo umount /var/tmp/test
exit 0

77
test/setup-dev-test.sh Executable file
View File

@@ -0,0 +1,77 @@
#!/bin/sh
# set up environment for both development and testing
# This should be the fist script to run in the test directory
# Note that it is ASSUMED that before all these test directory scripts are used
# 0) Go language package is installed
# 1) gotgt project directory is created
# and project is cloned with git per project README.md
# build and build verification can be done with gotgt-dameon.sh
# 2) libiscsi directory is created
# git clone and build can be done with this shell script
#
[ ! -n "$LIBISCSIPATH" ] && echo "Need LIBISCSIPATH definition" && exit 1
[ ! -n "$GOTGTPATH" ] && echo "Need GOTGTPATH definition" && exit 2
[ ! -d $LIBISCSIPATH ] && echo "Need $LIBISCSIPATH directory" && exit 3
[ ! -d $GOTGTPATH ] && echo "Need $GOTGTPATH directory" && exit 4
#exit 0
## This system update could induce errors on updating ubuntu content
sudo apt-get update
#Make sure that these packages are installed
#NOTE: The scripts are tested on Ubuntu, please feel free to generalize to
# other platforms.
sudo apt-get install automake
sudo apt-get install autogen autoconf libtool
##### Get Go dependency tools/fixes package
# https://github.com/tools/godep
# Needed once only and again as required.
cd $GOTGTPATH
go get github.com/tools/godep
#
# libc unit testing package, this is required by libiscsi package
sudo apt-get install -y libcunit1 libcunit1-doc libcunit1-dev
#
##### Get libiscsi package and build for testing purposes
cd $LIBISCSIPATH
git clone https://github.com/gostor/libiscsi .
export ISCSITEST=yes
./autogen.sh
# TO-DO/TO-RESOLVE
# autoreconf: configure.ac: not using Gettext
./configure 2>&1 >/dev/null
make 2>&1 >/dev/null
# TO-DO/TO-RESOLVE
# ar: `u' modifier ignored since `D' is the default (see `U')
# check expected binaries for successful build
[ ! -x ./test-tool/iscsi-test-cu ] && echo "./test-tool/iscsi-test-cu not built" && exit 5
[ ! -x ./utils/iscsi-ls ] && echo "./utils/iscsi-ls not built" && exit 6
[ ! -x ./utils/iscsi-inq ] && echo "./utils/iscsi-inq not built" && exit 7
[ ! -x ./utils/iscsi-readcapacity16 ] && echo "./utils/iscsi-readcapacity16 not built" && exit 8
##### Get open-iscsi project package bits
# open-iscsi project
# https://github.com/open-iscsi/open-iscsi
#
# Install open-iscsi package and watch for kernel build
uname -a
echo
sudo apt-get install -y open-iscsi
# Need to do this only once and re-do it as required.
# For example, /boot initrd.img-4.10.19 kernel version
## Remember the new kernel version for future boot if open-iscsi testing is to
## to performed.
# TO-DO/TO-RESOLVE
# cp: cannot stat '/etc/iscsi/initiatorname.iscsi': No such file or directory
## sanity check expected files for successful installation
[ ! -x /sbin/iscsiadm ] && echo "/sbin/iscsiadm not built" && exit 9
exit 0

26
test/test-cleanup.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/sh
# Trying our best to clean up the test environment to repeat the test.
[ ! -n "$LIBISCSIPATH" ] && echo "Need LIBISCSIPATH defintion" && exit 1
[ ! -d $LIBISCSIPATH ] && echo "Need $LIBISCSIPATH directory" && exit 3
[ ! -x /sbin/iscsiadm ] && echo "/sbin/iscsiadm not built" && exit 9
# kill off daemon
#killall gotgt
# empty backend file
echo > /var/tmp/disk.img
# empty config file
echo > ${HOME}/.gotgt/config.jason
# Delete existing /dev/sdb1 partition if found
sudo lsblk -l | grep sdb1
if [ $? -eq 0 ]
then
/bin/echo -e "p\nd\nw" | sudo fdisk /dev/sdb
fi
#unmount /var/tmp/test
sudo umount /var/tmp/test
exit 0