From 00b5fc0fdd4abd48724a6134cfa18bff9bb5e002 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 --- esx_service/cli/vmdkops_admin.py | 2 +- misc/scripts/build.sh | 15 +++++++++++++++ vmdk_plugin/E2E_Tests/sample_e2e_test.go | 20 ++++++++++++++++++++ vmdk_plugin/Makefile | 17 +++++++++++++---- 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 vmdk_plugin/E2E_Tests/sample_e2e_test.go diff --git a/esx_service/cli/vmdkops_admin.py b/esx_service/cli/vmdkops_admin.py index 1a1df078f..809610cb7 100644 --- a/esx_service/cli/vmdkops_admin.py +++ b/esx_service/cli/vmdkops_admin.py @@ -124,7 +124,7 @@ def commands(): '-c': { 'help': 'Display selected columns', 'choices': ['volume', 'datastore', 'created-by', 'created', - 'attached-to', 'policy', 'capacity', 'used', + 'attached-to', 'policy', 'capacity', 'used','disk-format', 'fstype', 'access', 'attach-as'], 'metavar': 'Col1,Col2,...' }, 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..386b4b0d7 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-tests # 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,16 @@ test-esx: $(MAKE) --directory=$(ESX_SRC) $@ testremote: test-esx test-vm -test-all: test testremote +test-all: test e2e-tests testremote + +e2e-tests: + $(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: