From a88dcd5e345294f13ed659d9b79f9b15ecbe3e6b Mon Sep 17 00:00:00 2001 From: Nirdesh Shukla Date: Thu, 5 Jan 2017 11:16:57 -0800 Subject: [PATCH] Supplying ssh keys and env variable to container for e2e testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit adding missing pkg and sample test file a minor fix for CI to consume key from correct location correcting CI faiure reading SSH_KEY_OPT correctly code cleanup restarting CI run Adding support SSH_KEY_PATH for local test run, no need to set environment vars any more Adding target for e2e tests (addressing Ritesh's comment) Fix Admin Cli command to list selected columns for Filesystem Type an… (#845) * Fix Admin Cli command to list selected columns for Filesystem Type and Disk Format adding new test target @test-all adding inline comment adding test target to drone script (Addressing Ritesh's comment) testing out CI failure adding e2e-test target to pick up at CI using drone script --- misc/drone-scripts/deploy-and-test-wrapper.sh | 2 +- misc/scripts/build.sh | 15 ++++++++++++++ vmdk_plugin/E2E_Tests/sample_e2e_test.go | 20 +++++++++++++++++++ vmdk_plugin/Makefile | 18 +++++++++++++---- 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 vmdk_plugin/E2E_Tests/sample_e2e_test.go diff --git a/misc/drone-scripts/deploy-and-test-wrapper.sh b/misc/drone-scripts/deploy-and-test-wrapper.sh index 86148900a..5b832c281 100755 --- a/misc/drone-scripts/deploy-and-test-wrapper.sh +++ b/misc/drone-scripts/deploy-and-test-wrapper.sh @@ -86,7 +86,7 @@ log "starting deploy and test" INCLUDE_HOSTD="false" -if make -s deploy-esx deploy-vm testasroot testremote TEST_VOL_NAME=vol.build$BUILD_NUMBER; +if make -s deploy-esx deploy-vm testasroot e2e-dkrVolDriver-test testremote TEST_VOL_NAME=vol.build$BUILD_NUMBER; then echo "=> Build Complete" `date` #stop_build $VM1 $BUILD_NUMBER diff --git a/misc/scripts/build.sh b/misc/scripts/build.sh index 8a583c5e8..b50ac7f7f 100755 --- a/misc/scripts/build.sh +++ b/misc/scripts/build.sh @@ -124,9 +124,24 @@ then $DOCKER run --rm -it -v $PWD/..:$dir -w $dir $pylint_container $MAKE_ESX pylint else docker_socket=/var/run/docker.sock + if [ -z $SSH_KEY_OPT ] + then + SSH_KEY_OPT="-i /root/.ssh/id_rsa" + fi + ssh_key_opt_container=`echo $SSH_KEY_OPT | cut -d" " -f2` + ssh_key_path=$SSH_KEY_PATH + if [ -z $ssh_key_path ] + then + ssh_key_path=~/.ssh/id_rsa + fi $DOCKER run --privileged --rm -it \ -e "PKG_VERSION=$PKG_VERSION" \ -e "INCLUDE_UI=$INCLUDE_UI" \ + -e "ESX=$2" \ + -e "VM1=$4" \ + -e "VM2=$3" \ + -e "SSH_KEY_OPT=$SSH_KEY_OPT" \ -v $docker_socket:$docker_socket \ + -v $ssh_key_path:$ssh_key_opt_container:ro \ -v $PWD/..:$dir -w $dir $plug_container $MAKE $1 fi diff --git a/vmdk_plugin/E2E_Tests/sample_e2e_test.go b/vmdk_plugin/E2E_Tests/sample_e2e_test.go new file mode 100644 index 000000000..b962d0545 --- /dev/null +++ b/vmdk_plugin/E2E_Tests/sample_e2e_test.go @@ -0,0 +1,20 @@ +package e2e_test + +import "testing" +import "os/exec" +import "fmt" +import "os" +import "strings" + +//TODO: This is a sample testcase and will be removed after finishing the review. + +func TestSomething(t *testing.T) { + var err error + var out []byte + + out, err = exec.Command("/usr/bin/ssh", strings.Split(os.Getenv("SSH_KEY_OPT")," ")[0], strings.Split(os.Getenv("SSH_KEY_OPT")," ")[1], "-q", "-kTax", "-o StrictHostKeyChecking=no", "root@"+os.Getenv("ESX"), "/usr/lib/vmware/vmdkops/bin/vmdkops_admin.py", "ls").CombinedOutput() + fmt.Printf("\nerr=>%s.....\nout=>%s", err, out) + + out, err = exec.Command("/usr/bin/ssh", strings.Split(os.Getenv("SSH_KEY_OPT")," ")[0], strings.Split(os.Getenv("SSH_KEY_OPT")," ")[1], "-q", "-kTax", "-o StrictHostKeyChecking=no", "root@"+os.Getenv("VM1"), "ifconfig").CombinedOutput() + fmt.Printf("\nerr=>%s .....\nout=>%s", err, out) +} diff --git a/vmdk_plugin/Makefile b/vmdk_plugin/Makefile index 0ec569cac..c6c8738ad 100644 --- a/vmdk_plugin/Makefile +++ b/vmdk_plugin/Makefile @@ -299,8 +299,8 @@ test: .PHONY: testasroot testasroot: $(log_target) - $(GO) test $(PLUGIN)/drivers/vmdk/vmdkops -cover - $(GO) test $(PLUGIN)/utils/config -cover + $(GO) test $(PLUGIN)/drivers/vmdk/vmdkops -cover -v + $(GO) test $(PLUGIN)/utils/config -cover -v # does sanity check of create/remove docker volume on the guest TEST_VOL_NAME ?= DefaultTestVol @@ -314,7 +314,7 @@ checkremote: @$(SSH) $(TEST_VM) docker -H $(VM2_DOCKER) ps > /dev/null 2>/dev/null || \ (echo VM2 $(VM2): $(CONN_MSG); exit 1) -.PHONY: test-vm test-esx test-all testremote +.PHONY: test-vm test-esx test-all testremote e2e-test # test-vm runs GO unit tests and plugin test suite on a guest VM # expects binaries to be deployed ot the VM and ESX (see deploy-all target) test-vm: checkremote deploy-vm-test @@ -330,7 +330,17 @@ test-esx: $(MAKE) --directory=$(ESX_SRC) $@ testremote: test-esx test-vm -test-all: test testremote +test-all: test e2e-test testremote + +# An end-to-end test target for vSphere Docker Volume Driver +e2e-test: + $(log_target) + $(SCRIPTS)/build.sh e2e-dkrVolDriver-test "$(ESX)" "$(VM1)" "$(VM2)" + +.PHONY: e2e-dkrVolDriver-test +e2e-dkrVolDriver-test: + $(log_target) + $(GO) test $(PLUGIN)/E2E_Tests -cover -v .PHONY:clean-vm clean-esx clean-all clean-docker clean-vm: