Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Refactoring work: defining SSH params to reuse #872

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
18 changes: 9 additions & 9 deletions vmdk_plugin/E2E_Tests/createVolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
package e2e_test

import (
"testing"
"os"
TestUtil "github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils/test_util"
volumeNameUtil "github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils"
TestUtil "github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils/test_util"
"os"
"testing"
)

// Test objective: create volume on fresh setup very first time and verifies the volume
// is created successfully.

/*

The issue was observed on photon so steps are mentioned for photon OS only in fact
The issue was observed on photon so steps are mentioned for photon OS only in fact
test should be OS agnostic.

1. create docker volume using following command
Expand All @@ -46,16 +46,16 @@ expectation: volume should be created correctly

*/

func TestVolumeCreationFristTime(t *testing.T) {
func TestVolumeCreationFirstTime(t *testing.T) {
var err error
var out []byte
volumeName := volumeNameUtil.GetVolumeNameWithTimeStamp("abc")

// create volume
out, err = TestUtil.CreateDefaultVolume(os.Getenv("VM1"), volumeName)
if (err != nil) {
t.Fatalf("\nError has occurred [%s] \n\twhile creating volume [%s] very first time: err -> %v", out, volumeName, err)

if err != nil {
t.Fatalf("\nError has occurred [%s] \n\twhile creating volume [%s] very first time: err -> %v", out, volumeName, err)
} else {
t.Logf("\nTestcase passed: successfully able to create volume [%s]\n", out)
// delete volume
Expand Down
19 changes: 14 additions & 5 deletions vmdk_plugin/utils/test_util/VolumeCreationTestUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@ import (
"strings"
)

var SSH_OPTS []string = []string{strings.Split(os.Getenv("SSH_KEY_OPT"), " ")[0], strings.Split(os.Getenv("SSH_KEY_OPT"), " ")[1], "-q", "-kTax", "-o StrictHostKeyChecking=no"}

// This util method is going to create vsphere docker volume with
// defaults.
func CreateDefaultVolume(ip string, name string) ([]byte, error) {

fmt.Printf("\ncreating volume [%s] on VM[%s]", name, ip)

return 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@"+ip, "docker volume create --driver=vmdk --name="+name).CombinedOutput()

return InvokeCommand(ip, "docker volume create --driver=vmdk --name="+name)
}

// This helper deletes the created volume as per passed volume name.
func DeleteVolume(name string, ip string) ([]byte, error) {
fmt.Printf("\ndestroying volume [%s]", name)
return InvokeCommand(ip, "docker volume rm "+name)
}

return 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@"+ip, "docker volume rm "+name).CombinedOutput()
// This helper method can be consumed by test directly to invoke
// any command on the remote host.
// remoteHostIP:
// remote machine address to execute on the machine
// cmd:
// A command string to be executed on the remote host as per
// remoteHostIP value
func InvokeCommand(remoteHostIP string, cmd string) ([]byte, error) {
return exec.Command("/usr/bin/ssh", append(SSH_OPTS, "root@"+remoteHostIP, cmd)...).CombinedOutput()
}